Skip to content

Commit bb5fde6

Browse files
committed
Export __rdl_* symbols to the allocator shim when doing LTO
1 parent 5297ef0 commit bb5fde6

File tree

1 file changed

+15
-0
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+15
-0
lines changed

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ffi::CString;
22
use std::sync::Arc;
33

4+
use rustc_ast::expand::allocator::AllocatorKind;
45
use rustc_data_structures::memmap::Mmap;
56
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
67
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportLevel};
@@ -10,6 +11,7 @@ use tracing::info;
1011

1112
use crate::back::symbol_export::{self, symbol_name_for_instance_in_crate};
1213
use crate::back::write::CodegenContext;
14+
use crate::base::allocator_kind_for_codegen;
1315
use crate::errors::{DynamicLinkingWithLTO, LtoDisallowed, LtoDylib, LtoProcMacro};
1416
use crate::traits::*;
1517

@@ -94,6 +96,19 @@ pub(super) fn exported_symbols_for_lto(
9496
.filter_map(|&(s, info): &(ExportedSymbol<'_>, SymbolExportInfo)| {
9597
if info.level.is_below_threshold(export_threshold) || info.used {
9698
Some(symbol_name_for_instance_in_crate(tcx, s, cnum))
99+
} else if export_threshold == SymbolExportLevel::C
100+
&& info.rustc_std_internal_symbol
101+
&& let Some(AllocatorKind::Default) = allocator_kind_for_codegen(tcx)
102+
{
103+
// Export the __rdl_* exports for usage by the allocator shim when not using
104+
// #[global_allocator]. Most of the conditions above are only used to avoid
105+
// unnecessary expensive symbol_name_for_instance_in_crate calls.
106+
let sym = symbol_name_for_instance_in_crate(tcx, s, cnum);
107+
if sym.contains("__rdl_") || sym.contains("__rg_oom") {
108+
Some(sym)
109+
} else {
110+
None
111+
}
97112
} else {
98113
None
99114
}

0 commit comments

Comments
 (0)