Rollup merge of #112794 - bjorn3:fix_lib_global_alloc, r=oli-obk
Fix linker failures when #[global_allocator] is used in a dependency Fixes https://github.com/rust-lang/rust/issues/112715
This commit is contained in:
commit
0688182f9b
4 changed files with 38 additions and 2 deletions
|
@ -13,7 +13,7 @@ use crate::mir::place::PlaceRef;
|
|||
use crate::traits::*;
|
||||
use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCodegen, ModuleKind};
|
||||
|
||||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
use rustc_ast::expand::allocator::{global_fn_name, AllocatorKind, ALLOCATOR_METHODS};
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
|
||||
|
@ -921,7 +921,21 @@ impl CrateInfo {
|
|||
missing_weak_lang_items
|
||||
.iter()
|
||||
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
|
||||
)
|
||||
);
|
||||
if tcx.allocator_kind(()).is_some() {
|
||||
// At least one crate needs a global allocator. This crate may be placed
|
||||
// after the crate that defines it in the linker order, in which case some
|
||||
// linkers return an error. By adding the global allocator shim methods to
|
||||
// the linked_symbols list, linking the generated symbols.o will ensure that
|
||||
// circular dependencies involving the global allocator don't lead to linker
|
||||
// errors.
|
||||
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
|
||||
(
|
||||
format!("{prefix}{}", global_fn_name(method.name).as_str()),
|
||||
SymbolExportKind::Text,
|
||||
)
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue