Skip to content

Commit

Permalink
Auto merge of rust-lang#131634 - davidlattimore:lld-protected, r=<try>
Browse files Browse the repository at this point in the history
Use protected visibility when building rustc

rust-lang/compiler-team#782

I wasn't sure about having two commits in a PR, but I figured, at least initially it might make sense to discuss these commits together. Happy to squash, or move the second commit to a separate PR.

I contemplated trying to enable protected visibility for more cases when LLD will be used other than just `-Zlinker-features=+lld`, but that would be more a complex change that probably still wouldn't cover all cases when LLD is used, so went with the simplest option of just checking if the linker-feature is enabled.

r? lqd
  • Loading branch information
bors committed Oct 31, 2024
2 parents c8b8378 + d1f7f68 commit 3639412
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 @@ -781,6 +781,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 @@ -1056,6 +1056,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 @@ -3109,6 +3119,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 3639412

Please sign in to comment.