Skip to content

Commit b3bffc2

Browse files
committed
Auto merge of #132219 - bjorn3:rustc_protected_visibility, r=<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.
2 parents df4ca44 + e6cf7da commit b3bffc2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,18 @@ pub fn rustc_cargo(
10961096
cargo.rustflag("-Clink-args=-Wl,--icf=all");
10971097
}
10981098

1099+
// Use protected visibility for rustc_driver.so. This significantly reduces the
1100+
// amount of symbols the dynamic linker has to process at runtime as protected
1101+
// symbols defined in the same DSO can't be overwritten by other DSO's and thus
1102+
// can be directly referenced rather than going through the GOT. Only do this
1103+
// with lld however as ld.bfd versions older than 2.40 will give a linker error
1104+
// when using protected symbols with object files compiled by LLVM. See
1105+
// https://davidlattimore.github.io/posts/2024/08/27/rust-dylib-rabbit-holes.html
1106+
// for more details.
1107+
if builder.config.lld_mode.is_used() {
1108+
cargo.rustflag("-Zdefault-visibility=protected");
1109+
}
1110+
10991111
if builder.config.rust_profile_use.is_some() && builder.config.rust_profile_generate.is_some() {
11001112
panic!("Cannot use and generate PGO profiles at the same time");
11011113
}

0 commit comments

Comments
 (0)