Skip to content

Commit 4b28573

Browse files
authored
Rollup merge of rust-lang#148247 - bjorn3:minor_symbol_export_cleanup, r=WaffleLapkin
Remove a special case and move another one out of reachable_non_generics One is no longer necessary, the other is best placed in cg_llvm as it works around a cg_llvm bug.
2 parents f8ff304 + e8d88c0 commit 4b28573

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ fn prepare_lto(
7777
// should have default visibility.
7878
symbols_below_threshold.push(c"__llvm_profile_counter_bias".to_owned());
7979

80+
// LTO seems to discard this otherwise under certain circumstances.
81+
symbols_below_threshold.push(c"rust_eh_personality".to_owned());
82+
8083
// If we're performing LTO for the entire crate graph, then for each of our
8184
// upstream dependencies, find the corresponding rlib and load the bitcode
8285
// from the archive.

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
5151
return Default::default();
5252
}
5353

54-
// Check to see if this crate is a "special runtime crate". These
55-
// crates, implementation details of the standard library, typically
56-
// have a bunch of `pub extern` and `#[no_mangle]` functions as the
57-
// ABI between them. We don't want their symbols to have a `C`
58-
// export level, however, as they're just implementation details.
59-
// Down below we'll hardwire all of the symbols to the `Rust` export
60-
// level instead.
61-
let special_runtime_crate =
62-
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
54+
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
6355

6456
let mut reachable_non_generics: DefIdMap<_> = tcx
6557
.reachable_set(())
@@ -104,11 +96,12 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
10496
if tcx.cross_crate_inlinable(def_id) { None } else { Some(def_id) }
10597
})
10698
.map(|def_id| {
107-
// We won't link right if this symbol is stripped during LTO.
108-
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name;
109-
let used = name == "rust_eh_personality";
110-
111-
let export_level = if special_runtime_crate {
99+
let export_level = if is_compiler_builtins {
100+
// We don't want to export compiler-builtins symbols from any
101+
// dylibs, even rust dylibs. Unlike all other crates it gets
102+
// duplicated in every linker invocation and it may otherwise
103+
// unintentionally override definitions of these symbols by
104+
// libgcc or compiler-rt for C code.
112105
SymbolExportLevel::Rust
113106
} else {
114107
symbol_export_level(tcx, def_id.to_def_id())
@@ -131,8 +124,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
131124
SymbolExportKind::Text
132125
},
133126
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
134-
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
135-
|| used,
127+
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER),
136128
rustc_std_internal_symbol: codegen_attrs
137129
.flags
138130
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),

0 commit comments

Comments
 (0)