Skip to content

Commit 87b2721

Browse files
committed
Auto merge of #149848 - bjorn3:alloc_shim_rework2, r=jackh726
Use allocator_shim_contents in allocator_shim_symbols
2 parents d222ddc + cb4c9d3 commit 87b2721

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,9 +1827,9 @@ fn exported_symbols_for_non_proc_macro(
18271827
// Mark allocator shim symbols as exported only if they were generated.
18281828
if export_threshold == SymbolExportLevel::Rust
18291829
&& needs_allocator_shim_for_linking(tcx.dependency_formats(()), crate_type)
1830-
&& tcx.allocator_kind(()).is_some()
1830+
&& let Some(kind) = tcx.allocator_kind(())
18311831
{
1832-
symbols.extend(allocator_shim_symbols(tcx));
1832+
symbols.extend(allocator_shim_symbols(tcx, kind));
18331833
}
18341834

18351835
symbols

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ pub(super) fn exported_symbols_for_lto(
118118
}
119119

120120
// Mark allocator shim symbols as exported only if they were generated.
121-
if export_threshold == SymbolExportLevel::Rust && allocator_kind_for_codegen(tcx).is_some() {
122-
symbols_below_threshold.extend(allocator_shim_symbols(tcx).map(|(name, _kind)| name));
121+
if export_threshold == SymbolExportLevel::Rust
122+
&& let Some(kind) = allocator_kind_for_codegen(tcx)
123+
{
124+
symbols_below_threshold.extend(allocator_shim_symbols(tcx, kind).map(|(name, _kind)| name));
123125
}
124126

125127
symbols_below_threshold

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

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

33
use rustc_abi::{CanonAbi, X86Call};
4-
use rustc_ast::expand::allocator::{
5-
ALLOC_ERROR_HANDLER, ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name,
6-
};
4+
use rustc_ast::expand::allocator::{AllocatorKind, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name};
75
use rustc_data_structures::unord::UnordMap;
86
use rustc_hir::def::DefKind;
97
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId};
@@ -21,6 +19,7 @@ use rustc_target::spec::{Arch, Os, TlsModel};
2119
use tracing::debug;
2220

2321
use crate::back::symbol_export;
22+
use crate::base::allocator_shim_contents;
2423

2524
fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
2625
crates_export_threshold(tcx.crate_types())
@@ -490,14 +489,12 @@ pub(crate) fn provide(providers: &mut Providers) {
490489

491490
pub(crate) fn allocator_shim_symbols(
492491
tcx: TyCtxt<'_>,
492+
kind: AllocatorKind,
493493
) -> impl Iterator<Item = (String, SymbolExportKind)> {
494-
ALLOCATOR_METHODS
495-
.iter()
494+
allocator_shim_contents(tcx, kind)
495+
.into_iter()
496496
.map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
497-
.chain([
498-
mangle_internal_symbol(tcx, global_fn_name(ALLOC_ERROR_HANDLER).as_str()),
499-
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
500-
])
497+
.chain([mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE)])
501498
.map(move |symbol_name| {
502499
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
503500

0 commit comments

Comments
 (0)