Skip to content

Commit 95ac872

Browse files
committed
No need to export C and compiler-builtins symbols for the executable
1 parent 4ec2c5e commit 95ac872

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1828,9 +1828,11 @@ pub(crate) fn linked_objects(
18281828
are_upstream_rust_objects_already_included(tcx.sess);
18291829
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
18301830
for_each_exported_symbols_include_dep(tcx, crate_type, |exported_symbols, cnum| {
1831-
let exported_symbols = exported_symbols
1832-
.iter()
1833-
.filter(|(_, info)| info.level.is_below_threshold(export_threshold) || info.used);
1831+
let exported_symbols = exported_symbols.iter().filter(|(_, info)| {
1832+
(!matches!(crate_type, CrateType::Executable)
1833+
&& info.level.is_below_threshold(export_threshold))
1834+
|| info.used
1835+
});
18341836
if cnum == LOCAL_CRATE {
18351837
// Since the local crate is always linked directly to object files, `#[used]` works as expected,
18361838
// we only need add undefined symbols.
@@ -1855,7 +1857,9 @@ pub(crate) fn linked_objects(
18551857
);
18561858
return;
18571859
}
1858-
// FIXME: should be `let lto = upstream_rust_objects_already_included && !ignored_for_lto(tcx.sess, &codegen_results.crate_info, cnum);`
1860+
if matches!(crate_type, CrateType::Executable) && tcx.is_compiler_builtins(cnum) {
1861+
return;
1862+
}
18591863
let lto = upstream_rust_objects_already_included;
18601864
let mut cgus = FxHashSet::default();
18611865
for &(symbol, info) in exported_symbols {

0 commit comments

Comments
 (0)