From dade3c912cd604297fc267e3a46ef1d159b463a9 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 15 Oct 2025 09:00:10 +0000 Subject: [PATCH] Use allocator_shim_contents in allocator_shim_symbols --- compiler/rustc_codegen_ssa/src/back/linker.rs | 4 ++-- compiler/rustc_codegen_ssa/src/back/lto.rs | 6 ++++-- .../rustc_codegen_ssa/src/back/symbol_export.rs | 15 ++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index c73e950bed408..998722897253b 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -1827,9 +1827,9 @@ fn exported_symbols_for_non_proc_macro( // Mark allocator shim symbols as exported only if they were generated. if export_threshold == SymbolExportLevel::Rust && needs_allocator_shim_for_linking(tcx.dependency_formats(()), crate_type) - && tcx.allocator_kind(()).is_some() + && let Some(kind) = tcx.allocator_kind(()) { - symbols.extend(allocator_shim_symbols(tcx)); + symbols.extend(allocator_shim_symbols(tcx, kind)); } symbols diff --git a/compiler/rustc_codegen_ssa/src/back/lto.rs b/compiler/rustc_codegen_ssa/src/back/lto.rs index e6df6a2469f37..6c10834aed681 100644 --- a/compiler/rustc_codegen_ssa/src/back/lto.rs +++ b/compiler/rustc_codegen_ssa/src/back/lto.rs @@ -117,8 +117,10 @@ pub(super) fn exported_symbols_for_lto( } // Mark allocator shim symbols as exported only if they were generated. - if export_threshold == SymbolExportLevel::Rust && allocator_kind_for_codegen(tcx).is_some() { - symbols_below_threshold.extend(allocator_shim_symbols(tcx).map(|(name, _kind)| name)); + if export_threshold == SymbolExportLevel::Rust + && let Some(kind) = allocator_kind_for_codegen(tcx) + { + symbols_below_threshold.extend(allocator_shim_symbols(tcx, kind).map(|(name, _kind)| name)); } symbols_below_threshold diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 9d06de2b35c23..03f44c407b8d5 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -1,9 +1,7 @@ use std::collections::hash_map::Entry::*; use rustc_abi::{CanonAbi, X86Call}; -use rustc_ast::expand::allocator::{ - ALLOC_ERROR_HANDLER, ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name, -}; +use rustc_ast::expand::allocator::{AllocatorKind, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name}; use rustc_data_structures::unord::UnordMap; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId}; @@ -21,6 +19,7 @@ use rustc_target::spec::{Arch, Os, TlsModel}; use tracing::debug; use crate::back::symbol_export; +use crate::base::allocator_shim_contents; fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel { crates_export_threshold(tcx.crate_types()) @@ -487,14 +486,12 @@ pub(crate) fn provide(providers: &mut Providers) { pub(crate) fn allocator_shim_symbols( tcx: TyCtxt<'_>, + kind: AllocatorKind, ) -> impl Iterator { - ALLOCATOR_METHODS - .iter() + allocator_shim_contents(tcx, kind) + .into_iter() .map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str())) - .chain([ - mangle_internal_symbol(tcx, global_fn_name(ALLOC_ERROR_HANDLER).as_str()), - mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE), - ]) + .chain([mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE)]) .map(move |symbol_name| { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));