From 8b585c20eadc63b78b7cb9357b597f61592d51d3 Mon Sep 17 00:00:00 2001 From: erjuan Date: Mon, 11 Nov 2024 16:30:59 +0800 Subject: [PATCH] support -C sanitizer in stable channel support -C sanitizer in stable channel Signed-off-by: fengting --- compiler/rustc_codegen_llvm/src/abi.rs | 2 +- compiler/rustc_codegen_llvm/src/attributes.rs | 4 ++-- compiler/rustc_codegen_ssa/src/back/link.rs | 4 ++-- .../rustc_codegen_ssa/src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/back/write.rs | 2 +- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/options.rs | 4 ++-- compiler/rustc_session/src/session.rs | 14 +++++++------- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index d221bad28ef..f67cddfa7db 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -81,7 +81,7 @@ fn apply_attrs_to_callsite( attrs.push(llattr.create_attr(cx.llcx)); } } - } else if cx.tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) { + } else if cx.tcx.sess.opts.cg.sanitizer.contains(SanitizerSet::MEMORY) { // If we're not optimising, *but* memory sanitizer is on, emit noundef, since it affects // memory sanitizer's behavior. diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 39275272e42..979a5ccde25 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -60,7 +60,7 @@ pub fn sanitize_attrs<'ll>( no_sanitize: SanitizerSet, ) -> SmallVec<[&'ll Attribute; 4]> { let mut attrs = SmallVec::new(); - let enabled = cx.tcx.sess.opts.unstable_opts.sanitizer - no_sanitize; + let enabled = cx.tcx.sess.opts.cg.sanitizer - no_sanitize; if enabled.contains(SanitizerSet::ADDRESS) || enabled.contains(SanitizerSet::KERNELADDRESS) { attrs.push(llvm::AttributeKind::SanitizeAddress.create_attr(cx.llcx)); } @@ -182,7 +182,7 @@ fn probestack_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> { if cx .sess() .opts - .unstable_opts + .cg .sanitizer .intersects(SanitizerSet::ADDRESS | SanitizerSet::THREAD) { diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b603a878746..090acaf2241 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1192,7 +1192,7 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d return; } - let sanitizer = sess.opts.unstable_opts.sanitizer; + let sanitizer = sess.opts.cg.sanitizer; if sanitizer.contains(SanitizerSet::ADDRESS) { link_sanitizer_runtime(sess, linker, "asan"); } @@ -2257,7 +2257,7 @@ fn add_order_independent_options( && crate_type == CrateType::Executable && !matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _)) { - let prefix = if sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::ADDRESS) { + let prefix = if sess.opts.cg.sanitizer.contains(SanitizerSet::ADDRESS) { "asan/" } else { "" diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index a8b6030ac85..588b39662a2 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -274,7 +274,7 @@ fn exported_symbols_provider_local( })); } - if tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) { + if tcx.sess.opts.cg.sanitizer.contains(SanitizerSet::MEMORY) { let mut msan_weak_symbols = Vec::new(); // Similar to profiling, preserve weak msan symbol during LTO. diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index ececa29b231..86311c4958f 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -194,7 +194,7 @@ macro_rules! if_regular { false ), - sanitizer: if_regular!(sess.opts.unstable_opts.sanitizer, SanitizerSet::empty()), + sanitizer: if_regular!(sess.opts.cg.sanitizer, SanitizerSet::empty()), sanitizer_recover: if_regular!( sess.opts.unstable_opts.sanitizer_recover, SanitizerSet::empty() diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f97cb3440d2..13f3a26031a 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1238,7 +1238,7 @@ fn default_configuration(sess: &Session) -> CrateConfig { let panic_strategy = sess.panic_strategy(); ret.insert((sym::panic, Some(panic_strategy.desc_symbol()))); - for mut s in sess.opts.unstable_opts.sanitizer { + for mut s in sess.opts.cg.sanitizer { // KASAN should use the same attribute name as ASAN, as it's still ASAN // under the hood if s == SanitizerSet::KERNELADDRESS { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 7840a0ecf0b..5a53be73cb9 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1362,6 +1362,8 @@ pub(crate) fn parse_dump_solver_proof_tree( "output remarks for these optimization passes (space separated, or \"all\")"), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes (default: no)"), + sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], + "use a sanitizer"), save_temps: bool = (false, parse_bool, [UNTRACKED], "save all temporary output files during compilation (default: no)"), soft_float: bool = (false, parse_bool, [TRACKED], @@ -1712,8 +1714,6 @@ pub(crate) fn parse_dump_solver_proof_tree( written to standard error output)"), report_delayed_bugs: bool = (false, parse_bool, [TRACKED], "immediately print bugs registered with `delay_span_bug` (default: no)"), - sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], - "use a sanitizer"), sanitizer_cfi_canonical_jump_tables: Option = (Some(true), parse_opt_bool, [TRACKED], "enable canonical jump tables (default: yes)"), sanitizer_cfi_generalize_pointers: Option = (None, parse_opt_bool, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 5be122ffbde..338df1219e6 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -773,7 +773,7 @@ pub fn init_features(&self, features: rustc_feature::Features) { } pub fn is_sanitizer_cfi_enabled(&self) -> bool { - self.opts.unstable_opts.sanitizer.contains(SanitizerSet::CFI) + self.opts.cg.sanitizer.contains(SanitizerSet::CFI) } pub fn is_sanitizer_cfi_canonical_jump_tables_disabled(&self) -> bool { @@ -793,7 +793,7 @@ pub fn is_sanitizer_cfi_normalize_integers_enabled(&self) -> bool { } pub fn is_sanitizer_kcfi_enabled(&self) -> bool { - self.opts.unstable_opts.sanitizer.contains(SanitizerSet::KCFI) + self.opts.cg.sanitizer.contains(SanitizerSet::KCFI) } pub fn is_split_lto_unit_enabled(&self) -> bool { @@ -1035,7 +1035,7 @@ pub fn emit_lifetime_markers(&self) -> bool { // AddressSanitizer and KernelAddressSanitizer uses lifetimes to detect use after scope bugs. // MemorySanitizer uses lifetimes to detect use of uninitialized stack variables. // HWAddressSanitizer will use lifetimes to detect use after scope bugs in the future. - || self.opts.unstable_opts.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS | SanitizerSet::MEMORY | SanitizerSet::HWADDRESS) + || self.opts.cg.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS | SanitizerSet::MEMORY | SanitizerSet::HWADDRESS) } pub fn diagnostic_width(&self) -> usize { @@ -1150,7 +1150,7 @@ pub fn fewer_names(&self) -> bool { let more_names = self.opts.output_types.contains_key(&OutputType::LlvmAssembly) || self.opts.output_types.contains_key(&OutputType::Bitcode) // AddressSanitizer and MemorySanitizer use alloca name when reporting an issue. - || self.opts.unstable_opts.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY); + || self.opts.cg.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY); !more_names } } @@ -1588,7 +1588,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { // Sanitizers can only be used on platforms that we know have working sanitizer codegen. let supported_sanitizers = sess.target.options.supported_sanitizers; - let unsupported_sanitizers = sess.opts.unstable_opts.sanitizer - supported_sanitizers; + let unsupported_sanitizers = sess.opts.cg.sanitizer - supported_sanitizers; match unsupported_sanitizers.into_iter().count() { 0 => {} 1 => { @@ -1601,7 +1601,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } // Cannot mix and match sanitizers. - let mut sanitizer_iter = sess.opts.unstable_opts.sanitizer.into_iter(); + let mut sanitizer_iter = sess.opts.cg.sanitizer.into_iter(); if let (Some(first), Some(second)) = (sanitizer_iter.next(), sanitizer_iter.next()) { sess.emit_err(errors::CannotMixAndMatchSanitizers { first: first.to_string(), @@ -1610,7 +1610,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } // Cannot enable crt-static with sanitizers on Linux - if sess.crt_static(None) && !sess.opts.unstable_opts.sanitizer.is_empty() { + if sess.crt_static(None) && !sess.opts.cg.sanitizer.is_empty() { sess.emit_err(errors::CannotEnableCrtStaticLinux); } -- Gitee