Skip to content

Commit

Permalink
Use protected symbols when building rustc_driver
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlattimore committed Oct 31, 2024
1 parent 759e07f commit d1f7f68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@
# - If building for a zkvm target, "compiler-builtins-mem" will be added.
#std-features = ["panic_unwind"]

# Whether to use protected symbols when compiling rustc. Doing so produces a binary that starts
# faster. Setting this to true when linking with GNU ld < 2.40 will likely result in link errors.
# Defaults to true when using lld to link rustc.
#use-protected-symbols = true

# =============================================================================
# Options for specific targets
#
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,10 @@ pub fn rustc_cargo(
cargo.rustflag("-l").rustflag("Enzyme-19");
}

if builder.build.config.rust_use_protected_symbols {
cargo.rustflag("-Zdefault-visibility=protected");
}

// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
// and may just be a time sink.
if compiler.stage != 0 {
Expand Down
11 changes: 11 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ pub struct Config {
pub rust_lto: RustcLto,
pub rust_validate_mir_opts: Option<u32>,
pub rust_std_features: BTreeSet<String>,
pub rust_use_protected_symbols: bool,
pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool,
pub llvm_libunwind_default: Option<LlvmLibunwind>,
Expand Down Expand Up @@ -1166,6 +1167,7 @@ define_config! {
lto: Option<String> = "lto",
validate_mir_opts: Option<u32> = "validate-mir-opts",
std_features: Option<BTreeSet<String>> = "std-features",
use_protected_symbols: Option<bool> = "use-protected-symbols",
}
}

Expand Down Expand Up @@ -1223,6 +1225,7 @@ impl Config {
dist_include_mingw_linker: true,
dist_compression_profile: "fast".into(),
rustc_parallel: true,
rust_use_protected_symbols: false,

stdout_is_tty: std::io::stdout().is_terminal(),
stderr_is_tty: std::io::stderr().is_terminal(),
Expand Down Expand Up @@ -1725,6 +1728,7 @@ impl Config {
strip,
lld_mode,
std_features: std_features_toml,
use_protected_symbols,
} = rust;

is_user_configured_rust_channel = channel.is_some();
Expand Down Expand Up @@ -1769,6 +1773,12 @@ impl Config {
set(&mut config.lld_mode, lld_mode);
set(&mut config.llvm_bitcode_linker_enabled, llvm_bitcode_linker);

// Default to using protected symbols only when linking with LLD.
if config.lld_mode != LldMode::Unused {
config.rust_use_protected_symbols = true;
}
set(&mut config.rust_use_protected_symbols, use_protected_symbols);

config.rust_randomize_layout = randomize_layout.unwrap_or_default();
config.llvm_tools_enabled = llvm_tools.unwrap_or(true);
config.rustc_parallel =
Expand Down Expand Up @@ -3102,6 +3112,7 @@ fn check_incompatible_options_for_ci_rustc(
download_rustc: _,
validate_mir_opts: _,
frame_pointers: _,
use_protected_symbols: _,
} = ci_rust_config;

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

0 comments on commit d1f7f68

Please sign in to comment.