Skip to content

Commit f43c51d

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 de7cef7 + e6cf7da commit f43c51d

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
@@ -1111,6 +1111,18 @@ pub fn rustc_cargo(
11111111
cargo.rustflag("-Clink-args=-Wl,--icf=all");
11121112
}
11131113

1114+
// Use protected visibility for rustc_driver.so. This significantly reduces the
1115+
// amount of symbols the dynamic linker has to process at runtime as protected
1116+
// symbols defined in the same DSO can't be overwritten by other DSO's and thus
1117+
// can be directly referenced rather than going through the GOT. Only do this
1118+
// with lld however as ld.bfd versions older than 2.40 will give a linker error
1119+
// when using protected symbols with object files compiled by LLVM. See
1120+
// https://davidlattimore.github.io/posts/2024/08/27/rust-dylib-rabbit-holes.html
1121+
// for more details.
1122+
if builder.config.lld_mode.is_used() {
1123+
cargo.rustflag("-Zdefault-visibility=protected");
1124+
}
1125+
11141126
if builder.config.rust_profile_use.is_some() && builder.config.rust_profile_generate.is_some() {
11151127
panic!("Cannot use and generate PGO profiles at the same time");
11161128
}

0 commit comments

Comments
 (0)