Skip to content

Commit

Permalink
Auto merge of rust-lang#132219 - bjorn3:rustc_protected_visibility, r…
Browse files Browse the repository at this point in the history
…=<try>

Use protected visibility for librustc_driver.so when possible

This should make rustc faster to start by reducing the load on the dynamic linker.
  • Loading branch information
bors committed Oct 27, 2024
2 parents de7cef7 + e6cf7da commit f43c51d
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit f43c51d

Please sign in to comment.