diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e563728c893d6..22b31aab6e5ad 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -623,6 +623,7 @@ fn test_codegen_options_tracking_hash() { tracked!(profile_use, Some(PathBuf::from("abc"))); tracked!(relocation_model, Some(RelocModel::Pic)); tracked!(relro_level, Some(RelroLevel::Full)); + tracked!(sanitizer, SanitizerSet::ADDRESS); tracked!(soft_float, true); tracked!(split_debuginfo, Some(SplitDebuginfo::Packed)); tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index c4d802a222b3d..04be7066807c5 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1540,6 +1540,8 @@ options! { "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], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b63c119eee0e4..61dec5c94f89b 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1163,7 +1163,23 @@ 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 supported_stable_sanitizers = sess.target.options.supported_sanitizers.stable_sanitizers(); + let unsupported_sanitizers = sess.opts.cg.sanitizer - supported_stable_sanitizers; + match unsupported_sanitizers.into_iter().count() { + 0 => {} + 1 => { + sess.dcx() + .emit_err(errors::SanitizerNotSupported { us: unsupported_sanitizers.to_string() }); + } + _ => { + sess.dcx().emit_err(errors::SanitizersNotSupported { + us: unsupported_sanitizers.to_string(), + }); + } + } + // Allow both stable and unstable sanitizers to be used as an unstable option for backwards + // compatibility until they are all stabilized. + let supported_sanitizers = sess.target.options.supported_sanitizers.supported_sanitizers(); let unsupported_sanitizers = sess.opts.unstable_opts.sanitizer - supported_sanitizers; match unsupported_sanitizers.into_iter().count() { 0 => {} @@ -1178,7 +1194,8 @@ 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().chain(sess.opts.unstable_opts.sanitizer.into_iter()); if let (Some(first), Some(second)) = (sanitizer_iter.next(), sanitizer_iter.next()) { sess.dcx().emit_err(errors::CannotMixAndMatchSanitizers { first: first.to_string(), diff --git a/compiler/rustc_target/src/spec/base/android.rs b/compiler/rustc_target/src/spec/base/android.rs index 5320f1b4bbbea..f36260e119e22 100644 --- a/compiler/rustc_target/src/spec/base/android.rs +++ b/compiler/rustc_target/src/spec/base/android.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, TargetOptions, TlsModel}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, TargetOptions, TlsModel}; pub fn opts() -> TargetOptions { let mut base = base::linux::opts(); @@ -7,7 +7,8 @@ pub fn opts() -> TargetOptions { base.default_dwarf_version = 2; base.tls_model = TlsModel::Emulated; base.has_thread_local = false; - base.supported_sanitizers = SanitizerSet::ADDRESS; + base.supported_sanitizers = + SanitizerSupport { stable: SanitizerSet::empty(), unstable: SanitizerSet::ADDRESS }; // This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867 // for context. (At that time, there was no `-C force-unwind-tables`, so the only solution // was to always emit `uwtable`). diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 3a69b19ee609c..ccdfea9c197e3 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1364,6 +1364,46 @@ impl ToJson for SanitizerSet { } } +#[derive(Clone, Copy, PartialEq, Hash, Debug)] +/// Sanitizers supported by a target. +pub struct SanitizerSupport { + /// Sanitizers supported by a target that can be used on stable. + pub stable: SanitizerSet, + /// Sanitizers supported by a target that cannot be used on stable. + pub unstable: SanitizerSet, +} + +impl SanitizerSupport { + /// Returns the set of stable sanitizers. + pub fn stable_sanitizers(&self) -> SanitizerSet { + self.stable + } + + /// Returns the set of supported sanitizers. + pub fn supported_sanitizers(&self) -> SanitizerSet { + self.stable | self.unstable + } + + /// Returns the set of unstable sanitizers. + pub fn unstable_sanitizers(&self) -> SanitizerSet { + self.unstable + } + + /// Returns the set of unsupported sanitizers. + pub fn unsupported_sanitizers(&self) -> SanitizerSet { + SanitizerSet::empty() - (self.stable | self.unstable) + } +} + +impl ToJson for SanitizerSupport { + fn to_json(&self) -> Json { + let mut object = serde_json::Map::new(); + object.insert("stable".to_string(), self.stable.to_json()); + object.insert("unstable".to_string(), self.unstable.to_json()); + Json::Object(object) + } +} + #[derive(Clone, Copy, PartialEq, Hash, Debug)] pub enum FramePointer { /// Forces the machine code generator to always preserve the frame pointers. @@ -2271,7 +2311,7 @@ pub struct TargetOptions { /// Note that the support here is at a codegen level. If the machine code with sanitizer /// enabled can generated on this target, but the necessary supporting libraries are not /// distributed with the target, the sanitizer should still appear in this list for the target. - pub supported_sanitizers: SanitizerSet, + pub supported_sanitizers: SanitizerSupport, /// If present it's a default value to use for adjusting the C ABI. pub default_adjusted_cabi: Option, @@ -2506,7 +2546,10 @@ impl Default for TargetOptions { split_debuginfo: Default::default(), // `Off` is supported by default, but targets can remove this manually, e.g. Windows. supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), - supported_sanitizers: SanitizerSet::empty(), + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::empty(), + }, default_adjusted_cabi: None, c_enum_min_bits: None, generate_arange_section: true, @@ -2697,6 +2740,35 @@ impl Target { let mut incorrect_type = vec![]; + let parse_sanitizer_set = |sanitizers_json: &Json| -> Result { + let mut sanitizer_set = SanitizerSet::empty(); + if let Some(sanitizers) = sanitizers_json.as_array() { + for sanitizer in sanitizers { + let name = sanitizer + .as_str() + .ok_or_else(|| "Sanitizer name must be a string".to_string())?; + sanitizer_set |= match name { + "address" => SanitizerSet::ADDRESS, + "cfi" => SanitizerSet::CFI, + "dataflow" => SanitizerSet::DATAFLOW, + "kcfi" => SanitizerSet::KCFI, + "kernel-address" => SanitizerSet::KERNELADDRESS, + "leak" => SanitizerSet::LEAK, + "memory" => SanitizerSet::MEMORY, + "memtag" => SanitizerSet::MEMTAG, + "safestack" => SanitizerSet::SAFESTACK, + "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, + "thread" => SanitizerSet::THREAD, + "hwaddress" => SanitizerSet::HWADDRESS, + _ => return Err(format!("unknown sanitizer {}", name)), + }; + } + } else { + return Err("Expected a list of sanitizers".to_string()); + } + Ok(sanitizer_set) + }; + macro_rules! key { ($key_name:ident) => ( { let name = (stringify!($key_name)).replace("_", "-"); @@ -2930,32 +3002,17 @@ impl Target { )), }).unwrap_or(Ok(())) } ); - ($key_name:ident, SanitizerSet) => ( { - let name = (stringify!($key_name)).replace("_", "-"); - if let Some(o) = obj.remove(&name) { - if let Some(a) = o.as_array() { - for s in a { - base.$key_name |= match s.as_str() { - Some("address") => SanitizerSet::ADDRESS, - Some("cfi") => SanitizerSet::CFI, - Some("dataflow") => SanitizerSet::DATAFLOW, - Some("kcfi") => SanitizerSet::KCFI, - Some("kernel-address") => SanitizerSet::KERNELADDRESS, - Some("leak") => SanitizerSet::LEAK, - Some("memory") => SanitizerSet::MEMORY, - Some("memtag") => SanitizerSet::MEMTAG, - Some("safestack") => SanitizerSet::SAFESTACK, - Some("shadow-call-stack") => SanitizerSet::SHADOWCALLSTACK, - Some("thread") => SanitizerSet::THREAD, - Some("hwaddress") => SanitizerSet::HWADDRESS, - Some(s) => return Err(format!("unknown sanitizer {}", s)), - _ => return Err(format!("not a string: {:?}", s)), - }; - } - } else { - incorrect_type.push(name) - } - } + ($key_name:ident, SanitizerSupport) => ( { + let stable_sanitizers_json = obj.remove("stable") + .unwrap_or_else(|| serde_json::Value::Array(Vec::new())); + let unstable_sanitizers_json = obj.remove("unstable") + .unwrap_or_else(|| serde_json::Value::Array(Vec::new())); + let stable_sanitizers = parse_sanitizer_set(&stable_sanitizers_json)?; + let unstable_sanitizers = parse_sanitizer_set(&unstable_sanitizers_json)?; + base.$key_name = SanitizerSupport { + stable: stable_sanitizers, + unstable: unstable_sanitizers, + }; Ok::<(), String>(()) } ); ($key_name:ident, link_self_contained_components) => ( { @@ -3237,7 +3294,7 @@ impl Target { key!(debuginfo_kind, DebuginfoKind)?; key!(split_debuginfo, SplitDebuginfo)?; key!(supported_split_debuginfo, fallible_list)?; - key!(supported_sanitizers, SanitizerSet)?; + key!(supported_sanitizers, SanitizerSupport)?; key!(default_adjusted_cabi, Option)?; key!(generate_arange_section, bool); key!(supports_stack_protector, bool); diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs index eff1617a4bf0b..ac70f1c5a04e0 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs @@ -1,5 +1,5 @@ use crate::spec::base::apple::{macos_llvm_target, opts, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64; @@ -8,7 +8,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); // FIXME: The leak sanitizer currently fails the tests, see #88132. - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD, + }; Target { // Clang automatically chooses a more specific target based on diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs index e9dddc7fae79a..caba43737f7c1 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{ios_llvm_target, opts, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64; let mut base = opts("ios", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::THREAD, + }; Target { // Clang automatically chooses a more specific target based on diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs index 2d89b6083f7ec..3a13194d17820 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{mac_catalyst_llvm_target, opts, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64_macabi; let mut base = opts("ios", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD, + }; Target { llvm_target: mac_catalyst_llvm_target(arch).into(), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs index fb4ae02325082..484c163d6eabe 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{ios_sim_llvm_target, opts, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64_sim; let mut base = opts("ios", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::THREAD, + }; Target { // Clang automatically chooses a more specific target based on diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos.rs index 7afe224163bcc..02a962157509a 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{opts, visionos_llvm_target, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64; let mut base = opts("visionos", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::THREAD, + }; Target { llvm_target: visionos_llvm_target(arch).into(), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos_sim.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos_sim.rs index 422b2d7b922fc..5b5fe49b1b208 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos_sim.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_visionos_sim.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{opts, visionos_sim_llvm_target, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64_sim; let mut base = opts("visionos", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::THREAD, + }; Target { llvm_target: visionos_sim_llvm_target(arch).into(), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_linux_android.rs b/compiler/rustc_target/src/spec/targets/aarch64_linux_android.rs index bb9bab4569bb4..c3df6989a21b9 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_linux_android.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_linux_android.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; // See https://developer.android.com/ndk/guides/abis.html#arm64-v8a // for target ABI requirements. @@ -21,11 +21,14 @@ pub fn target() -> Target { // the neon (ASIMD) and FP must exist on all android aarch64 targets. features: "+v8a,+neon,+fp-armv8".into(), stack_probes: StackProbeType::Inline, - supported_sanitizers: SanitizerSet::CFI - | SanitizerSet::HWADDRESS - | SanitizerSet::MEMTAG - | SanitizerSet::SHADOWCALLSTACK - | SanitizerSet::ADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::HWADDRESS + | SanitizerSet::MEMTAG + | SanitizerSet::SHADOWCALLSTACK, + }, supports_xray: true, ..base::android::opts() }, diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_freebsd.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_freebsd.rs index 9fec76b891cbf..f83611ee8cc36 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_freebsd.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { Target { @@ -16,10 +16,13 @@ pub fn target() -> Target { features: "+v8a".into(), max_atomic_width: Some(128), stack_probes: StackProbeType::Inline, - supported_sanitizers: SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::MEMORY - | SanitizerSet::THREAD, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }, ..base::freebsd::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_fuchsia.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_fuchsia.rs index 21789e436cac7..9d811eb999f9f 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_fuchsia.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_fuchsia.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { Target { @@ -16,9 +16,10 @@ pub fn target() -> Target { features: "+v8a".into(), max_atomic_width: Some(128), stack_probes: StackProbeType::Inline, - supported_sanitizers: SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::SHADOWCALLSTACK, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::SHADOWCALLSTACK, + }, ..base::fuchsia::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_illumos.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_illumos.rs index 90130880ace71..1d0d4886e67d1 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_illumos.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_illumos.rs @@ -1,10 +1,13 @@ -use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, Target}; +use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, SanitizerSupport, Target}; pub fn target() -> Target { let mut base = base::illumos::opts(); base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-std=c99"]); base.max_atomic_width = Some(128); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI, + }; base.features = "+v8a".into(); Target { diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_gnu.rs index 703a3206af21f..99b9126ca91a5 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_gnu.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { Target { @@ -17,14 +17,17 @@ pub fn target() -> Target { mcount: "\u{1}_mcount".into(), max_atomic_width: Some(128), stack_probes: StackProbeType::Inline, - supported_sanitizers: SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::KCFI - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::MEMTAG - | SanitizerSet::THREAD - | SanitizerSet::HWADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::HWADDRESS + | SanitizerSet::KCFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::MEMTAG + | SanitizerSet::THREAD, + }, supports_xray: true, ..base::linux_gnu::opts() }, diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs index 77689e26380d5..43e38f4c82ba2 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let mut base = base::linux_musl::opts(); @@ -6,11 +6,14 @@ pub fn target() -> Target { base.supports_xray = true; base.features = "+v8a".into(); base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; Target { llvm_target: "aarch64-unknown-linux-musl".into(), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs index b6b25598bec55..f94ee570bf723 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs @@ -1,5 +1,4 @@ -use crate::spec::SanitizerSet; -use crate::spec::{base, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let mut base = base::linux_ohos::opts(); @@ -21,13 +20,16 @@ pub fn target() -> Target { features: "+reserve-x18".into(), mcount: "\u{1}_mcount".into(), stack_probes: StackProbeType::Inline, - supported_sanitizers: SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::MEMTAG - | SanitizerSet::THREAD - | SanitizerSet::HWADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::MEMTAG + | SanitizerSet::THREAD + | SanitizerSet::HWADDRESS, + }, ..base }, } diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_none.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_none.rs index e5a428aade210..77437bd2790de 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_none.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_none.rs @@ -7,8 +7,8 @@ // For example, `-C target-cpu=cortex-a53`. use crate::spec::{ - Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType, Target, - TargetOptions, + Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, SanitizerSupport, + StackProbeType, Target, TargetOptions, }; pub fn target() -> Target { @@ -21,7 +21,10 @@ pub fn target() -> Target { &["--fix-cortex-a53-843419"], ), features: "+v8a,+strict-align,+neon,+fp-armv8".into(), - supported_sanitizers: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS, + }, relocation_model: RelocModel::Static, disable_redzone: true, max_atomic_width: Some(128), diff --git a/compiler/rustc_target/src/spec/targets/arm64e_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/arm64e_apple_darwin.rs index 11c56cf411c37..1721e3e4c6101 100644 --- a/compiler/rustc_target/src/spec/targets/arm64e_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/arm64e_apple_darwin.rs @@ -1,5 +1,5 @@ use crate::spec::base::apple::{macos_llvm_target, opts, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64e; @@ -8,7 +8,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); // FIXME: The leak sanitizer currently fails the tests, see #88132. - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD, + }; Target { // Clang automatically chooses a more specific target based on diff --git a/compiler/rustc_target/src/spec/targets/arm64e_apple_ios.rs b/compiler/rustc_target/src/spec/targets/arm64e_apple_ios.rs index fd8f0ddcb4ddd..dc58d64aec4e5 100644 --- a/compiler/rustc_target/src/spec/targets/arm64e_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/arm64e_apple_ios.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{ios_llvm_target, opts, Arch}; -use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions}; +use crate::spec::{FramePointer, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::Arm64e; let mut base = opts("ios", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::THREAD, + }; Target { // Clang automatically chooses a more specific target based on diff --git a/compiler/rustc_target/src/spec/targets/arm_linux_androideabi.rs b/compiler/rustc_target/src/spec/targets/arm_linux_androideabi.rs index 12c6388a97b69..5981ccb4a15d8 100644 --- a/compiler/rustc_target/src/spec/targets/arm_linux_androideabi.rs +++ b/compiler/rustc_target/src/spec/targets/arm_linux_androideabi.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { Target { @@ -16,7 +16,10 @@ pub fn target() -> Target { abi: "eabi".into(), // https://developer.android.com/ndk/guides/abis.html#armeabi features: "+strict-align,+v5te".into(), - supported_sanitizers: SanitizerSet::ADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS, + }, max_atomic_width: Some(32), ..base::android::opts() }, diff --git a/compiler/rustc_target/src/spec/targets/armv7_linux_androideabi.rs b/compiler/rustc_target/src/spec/targets/armv7_linux_androideabi.rs index e798ef4735436..bfdf238d38fd0 100644 --- a/compiler/rustc_target/src/spec/targets/armv7_linux_androideabi.rs +++ b/compiler/rustc_target/src/spec/targets/armv7_linux_androideabi.rs @@ -1,4 +1,6 @@ -use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, Target, TargetOptions}; +use crate::spec::{ + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, Target, TargetOptions, +}; // This target if is for the baseline of the Android v7a ABI // in thumb mode. It's named armv7-* instead of thumbv7-* @@ -25,7 +27,10 @@ pub fn target() -> Target { options: TargetOptions { abi: "eabi".into(), features: "+v7,+thumb-mode,+thumb2,+vfp3,-d32,-neon".into(), - supported_sanitizers: SanitizerSet::ADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS, + }, max_atomic_width: Some(64), ..base }, diff --git a/compiler/rustc_target/src/spec/targets/i686_linux_android.rs b/compiler/rustc_target/src/spec/targets/i686_linux_android.rs index 585aad10c57cc..f895ac329cb65 100644 --- a/compiler/rustc_target/src/spec/targets/i686_linux_android.rs +++ b/compiler/rustc_target/src/spec/targets/i686_linux_android.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions}; // See https://developer.android.com/ndk/guides/abis.html#x86 // for target ABI requirements. @@ -26,6 +26,12 @@ pub fn target() -> Target { i128:128-f64:32:64-f80:32-n8:16:32-S128" .into(), arch: "x86".into(), - options: TargetOptions { supported_sanitizers: SanitizerSet::ADDRESS, ..base }, + options: TargetOptions { + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS, + }, + ..base + }, } } diff --git a/compiler/rustc_target/src/spec/targets/i686_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/i686_pc_windows_msvc.rs index 970b43ad109ba..eb7e55e5908f1 100644 --- a/compiler/rustc_target/src/spec/targets/i686_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/i686_pc_windows_msvc.rs @@ -1,10 +1,11 @@ -use crate::spec::{base, LinkerFlavor, Lld, SanitizerSet, Target}; +use crate::spec::{base, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, Target}; pub fn target() -> Target { let mut base = base::windows_msvc::opts(); base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.supported_sanitizers = SanitizerSet::ADDRESS; + base.supported_sanitizers = + SanitizerSupport { stable: SanitizerSet::empty(), unstable: SanitizerSet::ADDRESS }; base.add_pre_link_args( LinkerFlavor::Msvc(Lld::No), diff --git a/compiler/rustc_target/src/spec/targets/i686_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/i686_unknown_linux_gnu.rs index 1d4916cabfdf3..f44a67d424624 100644 --- a/compiler/rustc_target/src/spec/targets/i686_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/i686_unknown_linux_gnu.rs @@ -1,10 +1,13 @@ -use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; +use crate::spec::{ + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, +}; pub fn target() -> Target { let mut base = base::linux_gnu::opts(); base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.supported_sanitizers = SanitizerSet::ADDRESS; + base.supported_sanitizers = + SanitizerSupport { stable: SanitizerSet::empty(), unstable: SanitizerSet::ADDRESS }; base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]); base.stack_probes = StackProbeType::Inline; diff --git a/compiler/rustc_target/src/spec/targets/riscv64_linux_android.rs b/compiler/rustc_target/src/spec/targets/riscv64_linux_android.rs index 27629199ea55e..a7f72d65e8220 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64_linux_android.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64_linux_android.rs @@ -1,6 +1,8 @@ use std::borrow::Cow; -use crate::spec::{base, CodeModel, SanitizerSet, SplitDebuginfo, Target, TargetOptions}; +use crate::spec::{ + base, CodeModel, SanitizerSet, SanitizerSupport, SplitDebuginfo, Target, TargetOptions, +}; pub fn target() -> Target { Target { @@ -19,7 +21,10 @@ pub fn target() -> Target { cpu: "generic-rv64".into(), features: "+m,+a,+f,+d,+c,+zba,+zbb,+zbs,+v".into(), llvm_abiname: "lp64d".into(), - supported_sanitizers: SanitizerSet::ADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS, + }, max_atomic_width: Some(64), supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), ..base::android::opts() diff --git a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_fuchsia.rs b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_fuchsia.rs index a600ee7656685..b8d77e1c5f188 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_fuchsia.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_fuchsia.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, CodeModel, SanitizerSet, Target, TargetOptions}; +use crate::spec::{base, CodeModel, SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { Target { @@ -18,7 +18,10 @@ pub fn target() -> Target { features: "+m,+a,+f,+d,+c".into(), llvm_abiname: "lp64d".into(), max_atomic_width: Some(64), - supported_sanitizers: SanitizerSet::SHADOWCALLSTACK, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::SHADOWCALLSTACK, + }, ..base::fuchsia::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_none_elf.rs index 9f128d07a99f7..59ea0b27292f9 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_none_elf.rs @@ -1,6 +1,7 @@ -use crate::spec::SanitizerSet; -use crate::spec::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy}; -use crate::spec::{RelocModel, Target, TargetOptions}; +use crate::spec::{ + Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, SanitizerSupport, + Target, TargetOptions, +}; pub fn target() -> Target { Target { @@ -27,7 +28,10 @@ pub fn target() -> Target { code_model: Some(CodeModel::Medium), emit_debug_gdb_scripts: false, eh_frame_header: false, - supported_sanitizers: SanitizerSet::KERNELADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::KERNELADDRESS, + }, ..Default::default() }, } diff --git a/compiler/rustc_target/src/spec/targets/riscv64imac_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv64imac_unknown_none_elf.rs index 1ab6aebcea947..d6ed7be13dac3 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64imac_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64imac_unknown_none_elf.rs @@ -1,5 +1,7 @@ -use crate::spec::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy}; -use crate::spec::{RelocModel, SanitizerSet, Target, TargetOptions}; +use crate::spec::{ + Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, SanitizerSupport, + Target, TargetOptions, +}; pub fn target() -> Target { Target { @@ -25,7 +27,10 @@ pub fn target() -> Target { code_model: Some(CodeModel::Medium), emit_debug_gdb_scripts: false, eh_frame_header: false, - supported_sanitizers: SanitizerSet::KERNELADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::KERNELADDRESS, + }, ..Default::default() }, } diff --git a/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_gnu.rs index be68c5b1c8862..3a24919ac85e5 100644 --- a/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_gnu.rs @@ -1,5 +1,5 @@ use crate::abi::Endian; -use crate::spec::{base, SanitizerSet, StackProbeType, Target}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target}; pub fn target() -> Target { let mut base = base::linux_gnu::opts(); @@ -13,8 +13,13 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); base.min_global_align = Some(16); base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = - SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; Target { llvm_target: "s390x-unknown-linux-gnu".into(), diff --git a/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_musl.rs index 619e83ce620bf..56008df103c70 100644 --- a/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_musl.rs @@ -1,5 +1,5 @@ use crate::abi::Endian; -use crate::spec::{base, SanitizerSet, StackProbeType, Target}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target}; pub fn target() -> Target { let mut base = base::linux_musl::opts(); @@ -14,8 +14,13 @@ pub fn target() -> Target { base.min_global_align = Some(16); base.static_position_independent_executables = true; base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = - SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; Target { llvm_target: "s390x-unknown-linux-musl".into(), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs index 1716c590aa503..8d05d79cbc5c1 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs @@ -1,6 +1,7 @@ use crate::spec::base::apple::{macos_llvm_target, opts, Arch}; -use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet}; -use crate::spec::{Target, TargetOptions}; +use crate::spec::{ + Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, Target, TargetOptions, +}; pub fn target() -> Target { let arch = Arch::X86_64; @@ -8,8 +9,13 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); // penryn+ supports cmpxchg16b base.frame_pointer = FramePointer::Always; base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]); - base.supported_sanitizers = - SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::THREAD, + }; Target { // Clang automatically chooses a more specific target based on diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs index fa22c2907d271..48113b8ec8813 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs @@ -1,12 +1,15 @@ use crate::spec::base::apple::{ios_sim_llvm_target, opts, Arch}; -use crate::spec::{SanitizerSet, Target, TargetOptions}; +use crate::spec::{SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { // x86_64-apple-ios is a simulator target, even though it isn't declared // that way in the target name like the other ones... let arch = Arch::X86_64_sim; let mut base = opts("ios", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::THREAD, + }; Target { llvm_target: ios_sim_llvm_target(arch).into(), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs index 9b479de81652c..14eaf3aca87bf 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs @@ -1,10 +1,13 @@ use crate::spec::base::apple::{mac_catalyst_llvm_target, opts, Arch}; -use crate::spec::{SanitizerSet, Target, TargetOptions}; +use crate::spec::{SanitizerSet, SanitizerSupport, Target, TargetOptions}; pub fn target() -> Target { let arch = Arch::X86_64_macabi; let mut base = opts("ios", arch); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD, + }; Target { llvm_target: mac_catalyst_llvm_target(arch).into(), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_linux_android.rs b/compiler/rustc_target/src/spec/targets/x86_64_linux_android.rs index 92711bbe246b7..d8242bd7b83d4 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_linux_android.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_linux_android.rs @@ -1,5 +1,6 @@ use crate::spec::{ - base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, TargetOptions, + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, + TargetOptions, }; pub fn target() -> Target { @@ -25,6 +26,12 @@ pub fn target() -> Target { data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(), arch: "x86_64".into(), - options: TargetOptions { supported_sanitizers: SanitizerSet::ADDRESS, ..base }, + options: TargetOptions { + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS, + }, + ..base + }, } } diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_solaris.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_solaris.rs index 4dbe049a4b782..bd140b9f25121 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_solaris.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_solaris.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, StackProbeType, Target}; +use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, SanitizerSupport, StackProbeType, Target}; pub fn target() -> Target { let mut base = base::solaris::opts(); @@ -8,7 +8,10 @@ pub fn target() -> Target { base.vendor = "pc".into(); base.max_atomic_width = Some(64); base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD, + }; Target { llvm_target: "x86_64-pc-solaris".into(), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs index 3ef3e5114e682..433dd791cd002 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, Target}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, Target}; pub fn target() -> Target { let mut base = base::windows_msvc::opts(); @@ -6,7 +6,8 @@ pub fn target() -> Target { base.features = "+cx16,+sse3,+sahf".into(); base.plt_by_default = false; base.max_atomic_width = Some(128); - base.supported_sanitizers = SanitizerSet::ADDRESS; + base.supported_sanitizers = + SanitizerSupport { stable: SanitizerSet::empty(), unstable: SanitizerSet::ADDRESS }; Target { llvm_target: "x86_64-pc-windows-msvc".into(), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_freebsd.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_freebsd.rs index 15146a5ef7299..c8731e6bbaf75 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_freebsd.rs @@ -1,4 +1,6 @@ -use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; +use crate::spec::{ + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, +}; pub fn target() -> Target { let mut base = base::freebsd::opts(); @@ -7,8 +9,13 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = - SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::MEMORY | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; base.supports_xray = true; Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_fuchsia.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_fuchsia.rs index 80cdeab0a677c..08719d273b6d5 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_fuchsia.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_fuchsia.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, SanitizerSet, StackProbeType, Target}; +use crate::spec::{base, SanitizerSet, SanitizerSupport, StackProbeType, Target}; pub fn target() -> Target { let mut base = base::fuchsia::opts(); @@ -6,7 +6,10 @@ pub fn target() -> Target { base.plt_by_default = false; base.max_atomic_width = Some(64); base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK, + }; base.supports_xray = true; Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_illumos.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_illumos.rs index c52cdf466abe7..5e441235ce990 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_illumos.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_illumos.rs @@ -1,4 +1,4 @@ -use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, Target}; +use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, SanitizerSupport, Target}; pub fn target() -> Target { let mut base = base::illumos::opts(); @@ -6,7 +6,10 @@ pub fn target() -> Target { base.cpu = "x86-64".into(); base.plt_by_default = false; base.max_atomic_width = Some(64); - base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD, + }; Target { // LLVM does not currently have a separate illumos target, diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs index 11fb28a9aed7f..3d3703726ebc9 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs @@ -1,4 +1,6 @@ -use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; +use crate::spec::{ + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, +}; pub fn target() -> Target { let mut base = base::linux_gnu::opts(); @@ -8,14 +10,17 @@ pub fn target() -> Target { base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.stack_probes = StackProbeType::Inline; base.static_position_independent_executables = true; - base.supported_sanitizers = SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::KCFI - | SanitizerSet::DATAFLOW - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::SAFESTACK - | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::DATAFLOW + | SanitizerSet::KCFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::SAFESTACK + | SanitizerSet::THREAD, + }; base.supports_xray = true; Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs index 66237f071028d..04927bf787307 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs @@ -1,4 +1,6 @@ -use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; +use crate::spec::{ + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, +}; pub fn target() -> Target { let mut base = base::linux_musl::opts(); @@ -8,11 +10,14 @@ pub fn target() -> Target { base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.stack_probes = StackProbeType::Inline; base.static_position_independent_executables = true; - base.supported_sanitizers = SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; base.supports_xray = true; Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_ohos.rs index db8db1d253824..12c0b558d6d11 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_ohos.rs @@ -1,4 +1,6 @@ -use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; +use crate::spec::{ + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, +}; pub fn target() -> Target { let mut base = base::linux_ohos::opts(); @@ -7,11 +9,14 @@ pub fn target() -> Target { base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.stack_probes = StackProbeType::Inline; base.static_position_independent_executables = true; - base.supported_sanitizers = SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; base.supports_xray = true; Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_netbsd.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_netbsd.rs index 38ae3a4fe4248..d3f13663bc438 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_netbsd.rs @@ -1,5 +1,6 @@ use crate::spec::{ - base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, TargetOptions, + base, Cc, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, StackProbeType, Target, + TargetOptions, }; pub fn target() -> Target { @@ -9,11 +10,14 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.stack_probes = StackProbeType::Inline; - base.supported_sanitizers = SanitizerSet::ADDRESS - | SanitizerSet::CFI - | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + }; base.supports_xray = true; Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_none.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_none.rs index 5846dc16d66b5..874d6a2b37bb6 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_none.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_none.rs @@ -5,7 +5,9 @@ // features. use crate::spec::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy}; -use crate::spec::{RelroLevel, SanitizerSet, StackProbeType, Target, TargetOptions}; +use crate::spec::{ + RelroLevel, SanitizerSet, SanitizerSupport, StackProbeType, Target, TargetOptions, +}; pub fn target() -> Target { let opts = TargetOptions { @@ -21,7 +23,10 @@ pub fn target() -> Target { features: "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float" .into(), - supported_sanitizers: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS, + supported_sanitizers: SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS, + }, disable_redzone: true, panic_strategy: PanicStrategy::Abort, code_model: Some(CodeModel::Kernel), diff --git a/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs index b17e21e5d1206..d0d334fa4d79d 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs @@ -1,6 +1,7 @@ use crate::spec::base::apple::{macos_llvm_target, opts, Arch}; -use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet}; -use crate::spec::{Target, TargetOptions}; +use crate::spec::{ + Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet, SanitizerSupport, Target, TargetOptions, +}; pub fn target() -> Target { let arch = Arch::X86_64h; @@ -8,8 +9,13 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); base.frame_pointer = FramePointer::Always; base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]); - base.supported_sanitizers = - SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD; + base.supported_sanitizers = SanitizerSupport { + stable: SanitizerSet::empty(), + unstable: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::THREAD, + }; // x86_64h is core2-avx without a few of the features which would otherwise // be guaranteed, so we need to disable those. This imitates clang's logic: diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index aa69791b3b4b4..3fa4c98e135be 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -632,7 +632,7 @@ pub struct TargetCfg { #[serde(default)] pub(crate) dynamic_linking: bool, #[serde(rename = "supported-sanitizers", default)] - pub(crate) sanitizers: Vec, + pub(crate) sanitizers: HashMap>, #[serde(rename = "supports-xray", default)] pub(crate) xray: bool, #[serde(default = "default_reloc_model")] diff --git a/src/tools/compiletest/src/header/needs.rs b/src/tools/compiletest/src/header/needs.rs index db154932d5b54..7a926854d82db 100644 --- a/src/tools/compiletest/src/header/needs.rs +++ b/src/tools/compiletest/src/header/needs.rs @@ -240,7 +240,15 @@ impl CachedNeedsConditions { path.iter().any(|dir| dir.join("x86_64-w64-mingw32-dlltool").is_file()); let target = &&*config.target; - let sanitizers = &config.target_cfg().sanitizers; + let sanitizers: Vec<_> = config + .target_cfg() + .sanitizers + .get("stable") + .unwrap_or(&Vec::new()) + .iter() + .chain(config.target_cfg().sanitizers.get("unstable").unwrap_or(&Vec::new()).iter()) + .cloned() + .collect(); Self { sanitizer_support: std::env::var_os("RUSTC_SANITIZER_SUPPORT").is_some(), sanitizer_address: sanitizers.contains(&Sanitizer::Address),