Skip to content

Link object files that use #[used] #137426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
No need to export C and compiler-builtins symbols for the executable
  • Loading branch information
dianqk committed Feb 23, 2025
commit bb7755467724233fd955bc431adb3df2123fc265
12 changes: 8 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,9 +1828,11 @@ pub(crate) fn linked_objects(
are_upstream_rust_objects_already_included(tcx.sess);
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for_each_exported_symbols_include_dep(tcx, crate_type, |exported_symbols, cnum| {
let exported_symbols = exported_symbols
.iter()
.filter(|(_, info)| info.level.is_below_threshold(export_threshold) || info.used);
let exported_symbols = exported_symbols.iter().filter(|(_, info)| {
(!matches!(crate_type, CrateType::Executable)
&& info.level.is_below_threshold(export_threshold))
|| info.used
});
if cnum == LOCAL_CRATE {
// Since the local crate is always linked directly to object files, `#[used]` works as expected,
// we only need add undefined symbols.
Expand All @@ -1855,7 +1857,9 @@ pub(crate) fn linked_objects(
);
return;
}
// FIXME: should be `let lto = upstream_rust_objects_already_included && !ignored_for_lto(tcx.sess, &codegen_results.crate_info, cnum);`
if matches!(crate_type, CrateType::Executable) && tcx.is_compiler_builtins(cnum) {
return;
}
let lto = upstream_rust_objects_already_included;
let mut cgus = FxHashSet::default();
for &(symbol, info) in exported_symbols {
Expand Down
Loading