Skip to content

Use protected visibility for librustc_driver.so when possible #132219

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
12 changes: 12 additions & 0 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,18 @@ pub fn rustc_cargo(
cargo.rustflag("-Clink-args=-Wl,--icf=all");
}

// Use protected visibility for rustc_driver.so. This significantly reduces the
// amount of symbols the dynamic linker has to process at runtime as protected
// symbols defined in the same DSO can't be overwritten by other DSO's and thus
// can be directly referenced rather than going through the GOT. Only do this
// with lld however as ld.bfd versions older than 2.40 will give a linker error
// when using protected symbols with object files compiled by LLVM. See
// https://davidlattimore.github.io/posts/2024/08/27/rust-dylib-rabbit-holes.html
// for more details.
if builder.config.lld_mode.is_used() {
cargo.rustflag("-Zdefault-visibility=protected");
}

if builder.config.rust_profile_use.is_some() && builder.config.rust_profile_generate.is_some() {
panic!("Cannot use and generate PGO profiles at the same time");
}
Expand Down
Loading