Skip to content

Commit a5ff397

Browse files
committed
Avoid attempting to export allocator shim during LTO
The allocator shim no longer participates in LTO.
1 parent 92ee14f commit a5ff397

File tree

3 files changed

+18
-39
lines changed

3 files changed

+18
-39
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::{env, io, iter, mem, str};
66

77
use cc::windows_registry;
8+
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name};
89
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
910
use rustc_metadata::{
1011
find_native_static_library, try_find_native_dynamic_library, try_find_native_static_library,
@@ -16,14 +17,16 @@ use rustc_middle::middle::exported_symbols::{
1617
};
1718
use rustc_middle::ty::TyCtxt;
1819
use rustc_session::Session;
19-
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
20+
use rustc_session::config::{
21+
self, CrateType, DebugInfo, LinkerPluginLto, Lto, OomStrategy, OptLevel, Strip,
22+
};
2023
use rustc_span::sym;
24+
use rustc_symbol_mangling::mangle_internal_symbol;
2125
use rustc_target::spec::{Cc, LinkOutputKind, LinkerFlavor, Lld};
2226
use tracing::{debug, warn};
2327

2428
use super::command::Command;
2529
use super::symbol_export;
26-
use crate::back::symbol_export::allocator_shim_symbols;
2730
use crate::base::needs_allocator_shim_for_linking;
2831
use crate::errors;
2932

@@ -1846,7 +1849,17 @@ fn exported_symbols_for_non_proc_macro(
18461849
&& needs_allocator_shim_for_linking(tcx.dependency_formats(()), crate_type)
18471850
&& tcx.allocator_kind(()).is_some()
18481851
{
1849-
symbols.extend(allocator_shim_symbols(tcx));
1852+
for symbol_name in ALLOCATOR_METHODS
1853+
.iter()
1854+
.map(|method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
1855+
.chain([
1856+
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
1857+
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
1858+
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
1859+
])
1860+
{
1861+
symbols.push((symbol_name, SymbolExportKind::Text));
1862+
}
18501863
}
18511864

18521865
symbols

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
99
use rustc_session::config::{CrateType, Lto};
1010
use tracing::info;
1111

12-
use crate::back::symbol_export::{self, allocator_shim_symbols, symbol_name_for_instance_in_crate};
12+
use crate::back::symbol_export::{self, symbol_name_for_instance_in_crate};
1313
use crate::back::write::CodegenContext;
1414
use crate::base::allocator_kind_for_codegen;
1515
use crate::errors::{DynamicLinkingWithLTO, LtoDisallowed, LtoDylib, LtoProcMacro};
@@ -130,11 +130,6 @@ pub(super) fn exported_symbols_for_lto(
130130
}
131131
}
132132

133-
// Mark allocator shim symbols as exported only if they were generated.
134-
if export_threshold == SymbolExportLevel::Rust && allocator_kind_for_codegen(tcx).is_some() {
135-
symbols_below_threshold.extend(allocator_shim_symbols(tcx).map(|(name, _kind)| name));
136-
}
137-
138133
symbols_below_threshold
139134
}
140135

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::hash_map::Entry::*;
22

33
use rustc_abi::{CanonAbi, X86Call};
4-
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name};
54
use rustc_data_structures::unord::UnordMap;
65
use rustc_hir::def::DefKind;
76
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId};
@@ -13,13 +12,10 @@ use rustc_middle::middle::exported_symbols::{
1312
use rustc_middle::query::LocalCrate;
1413
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolName, Ty, TyCtxt};
1514
use rustc_middle::util::Providers;
16-
use rustc_session::config::{CrateType, OomStrategy};
17-
use rustc_symbol_mangling::mangle_internal_symbol;
15+
use rustc_session::config::CrateType;
1816
use rustc_target::spec::TlsModel;
1917
use tracing::debug;
2018

21-
use crate::back::symbol_export;
22-
2319
fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
2420
crates_export_threshold(tcx.crate_types())
2521
}
@@ -491,31 +487,6 @@ pub(crate) fn provide(providers: &mut Providers) {
491487
upstream_monomorphizations_for_provider;
492488
}
493489

494-
pub(crate) fn allocator_shim_symbols(
495-
tcx: TyCtxt<'_>,
496-
) -> impl Iterator<Item = (String, SymbolExportKind)> {
497-
ALLOCATOR_METHODS
498-
.iter()
499-
.map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
500-
.chain([
501-
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
502-
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
503-
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
504-
])
505-
.map(move |symbol_name| {
506-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
507-
508-
(
509-
symbol_export::exporting_symbol_name_for_instance_in_crate(
510-
tcx,
511-
exported_symbol,
512-
LOCAL_CRATE,
513-
),
514-
SymbolExportKind::Text,
515-
)
516-
})
517-
}
518-
519490
fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel {
520491
// We export anything that's not mangled at the "C" layer as it probably has
521492
// to do with ABI concerns. We do not, however, apply such treatment to

0 commit comments

Comments
 (0)