Auto merge of #149848 - bjorn3:alloc_shim_rework2, r=jackh726

Use allocator_shim_contents in allocator_shim_symbols
This commit is contained in:
bors 2026-01-24 07:04:14 +00:00
commit 87b2721871
3 changed files with 12 additions and 13 deletions

View file

@ -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

View file

@ -118,8 +118,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

View file

@ -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())
@ -490,14 +489,12 @@ pub(crate) fn provide(providers: &mut Providers) {
pub(crate) fn allocator_shim_symbols(
tcx: TyCtxt<'_>,
kind: AllocatorKind,
) -> impl Iterator<Item = (String, SymbolExportKind)> {
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));