From 977730bac8470c35135d3113bf8c4ed367cc6b68 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Sun, 27 Oct 2024 13:54:31 +1100 Subject: [PATCH] Use protected symbols when building rustc_driver --- src/bootstrap/src/core/build_steps/compile.rs | 4 ++++ src/bootstrap/src/core/config/config.rs | 2 ++ src/bootstrap/src/core/config/flags.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index e13d4ccc6182..b812de9a9698 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1057,6 +1057,10 @@ pub fn rustc_cargo( cargo.rustflag("-l").rustflag("Enzyme-19"); } + if builder.build.config.protected_symbol_definitions { + 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 { diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 139ca7eb52e7..334c96c48cd2 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -295,6 +295,7 @@ pub struct Config { pub llvm_profile_generate: bool, pub llvm_libunwind_default: Option, pub enable_bolt_settings: bool, + pub protected_symbol_definitions: bool, pub reproducible_artifacts: Vec, @@ -1308,6 +1309,7 @@ impl Config { config.llvm_profile_generate = flags.llvm_profile_generate; config.enable_bolt_settings = flags.enable_bolt_settings; config.bypass_bootstrap_lock = flags.bypass_bootstrap_lock; + config.protected_symbol_definitions = flags.protected_symbol_definitions; // Infer the rest of the configuration. diff --git a/src/bootstrap/src/core/config/flags.rs b/src/bootstrap/src/core/config/flags.rs index bfeb811508c0..ec5b72ac71c4 100644 --- a/src/bootstrap/src/core/config/flags.rs +++ b/src/bootstrap/src/core/config/flags.rs @@ -161,6 +161,9 @@ pub struct Flags { /// Enable BOLT link flags #[arg(global = true, long)] pub enable_bolt_settings: bool, + /// Use protected symbol definitions in rustc_driver + #[arg(global = true, long, default_value_t = true)] + pub protected_symbol_definitions: bool, /// Skip stage0 compiler validation #[arg(global = true, long)] pub skip_stage0_validation: bool,