Skip to content

Commit d1f7f68

Browse files
Use protected symbols when building rustc_driver
1 parent 759e07f commit d1f7f68

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

config.example.toml

+5
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,11 @@
780780
# - If building for a zkvm target, "compiler-builtins-mem" will be added.
781781
#std-features = ["panic_unwind"]
782782

783+
# Whether to use protected symbols when compiling rustc. Doing so produces a binary that starts
784+
# faster. Setting this to true when linking with GNU ld < 2.40 will likely result in link errors.
785+
# Defaults to true when using lld to link rustc.
786+
#use-protected-symbols = true
787+
783788
# =============================================================================
784789
# Options for specific targets
785790
#

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

+4
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,10 @@ pub fn rustc_cargo(
10571057
cargo.rustflag("-l").rustflag("Enzyme-19");
10581058
}
10591059

1060+
if builder.build.config.rust_use_protected_symbols {
1061+
cargo.rustflag("-Zdefault-visibility=protected");
1062+
}
1063+
10601064
// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
10611065
// and may just be a time sink.
10621066
if compiler.stage != 0 {

src/bootstrap/src/core/config/config.rs

+11
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ pub struct Config {
291291
pub rust_lto: RustcLto,
292292
pub rust_validate_mir_opts: Option<u32>,
293293
pub rust_std_features: BTreeSet<String>,
294+
pub rust_use_protected_symbols: bool,
294295
pub llvm_profile_use: Option<String>,
295296
pub llvm_profile_generate: bool,
296297
pub llvm_libunwind_default: Option<LlvmLibunwind>,
@@ -1166,6 +1167,7 @@ define_config! {
11661167
lto: Option<String> = "lto",
11671168
validate_mir_opts: Option<u32> = "validate-mir-opts",
11681169
std_features: Option<BTreeSet<String>> = "std-features",
1170+
use_protected_symbols: Option<bool> = "use-protected-symbols",
11691171
}
11701172
}
11711173

@@ -1223,6 +1225,7 @@ impl Config {
12231225
dist_include_mingw_linker: true,
12241226
dist_compression_profile: "fast".into(),
12251227
rustc_parallel: true,
1228+
rust_use_protected_symbols: false,
12261229

12271230
stdout_is_tty: std::io::stdout().is_terminal(),
12281231
stderr_is_tty: std::io::stderr().is_terminal(),
@@ -1725,6 +1728,7 @@ impl Config {
17251728
strip,
17261729
lld_mode,
17271730
std_features: std_features_toml,
1731+
use_protected_symbols,
17281732
} = rust;
17291733

17301734
is_user_configured_rust_channel = channel.is_some();
@@ -1769,6 +1773,12 @@ impl Config {
17691773
set(&mut config.lld_mode, lld_mode);
17701774
set(&mut config.llvm_bitcode_linker_enabled, llvm_bitcode_linker);
17711775

1776+
// Default to using protected symbols only when linking with LLD.
1777+
if config.lld_mode != LldMode::Unused {
1778+
config.rust_use_protected_symbols = true;
1779+
}
1780+
set(&mut config.rust_use_protected_symbols, use_protected_symbols);
1781+
17721782
config.rust_randomize_layout = randomize_layout.unwrap_or_default();
17731783
config.llvm_tools_enabled = llvm_tools.unwrap_or(true);
17741784
config.rustc_parallel =
@@ -3102,6 +3112,7 @@ fn check_incompatible_options_for_ci_rustc(
31023112
download_rustc: _,
31033113
validate_mir_opts: _,
31043114
frame_pointers: _,
3115+
use_protected_symbols: _,
31053116
} = ci_rust_config;
31063117

31073118
// There are two kinds of checks for CI rustc incompatible options:

0 commit comments

Comments
 (0)