Skip to content

Commit

Permalink
compiletest: load supported sanitizers from target spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Sep 21, 2023
1 parent bc7bb3c commit 64e27cb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 101 deletions.
18 changes: 18 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ impl PanicStrategy {
}
}

#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Sanitizer {
Address,
Cfi,
Kcfi,
KernelAddress,
Leak,
Memory,
Memtag,
Safestack,
ShadowCallStack,
Thread,
Hwaddress,
}

/// Configuration for compiletest
#[derive(Debug, Default, Clone)]
pub struct Config {
Expand Down Expand Up @@ -560,6 +576,8 @@ pub struct TargetCfg {
pub(crate) panic: PanicStrategy,
#[serde(default)]
pub(crate) dynamic_linking: bool,
#[serde(rename = "supported-sanitizers", default)]
pub(crate) sanitizers: Vec<Sanitizer>,
}

impl TargetCfg {
Expand Down
25 changes: 13 additions & 12 deletions src/tools/compiletest/src/header/needs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::common::{Config, Debugger};
use crate::common::{Config, Debugger, Sanitizer};
use crate::header::IgnoreDecision;
use crate::util;

Expand Down Expand Up @@ -220,19 +220,20 @@ 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;
Self {
sanitizer_support: std::env::var_os("RUSTC_SANITIZER_SUPPORT").is_some(),
sanitizer_address: util::ASAN_SUPPORTED_TARGETS.contains(target),
sanitizer_cfi: util::CFI_SUPPORTED_TARGETS.contains(target),
sanitizer_kcfi: util::KCFI_SUPPORTED_TARGETS.contains(target),
sanitizer_kasan: util::KASAN_SUPPORTED_TARGETS.contains(target),
sanitizer_leak: util::LSAN_SUPPORTED_TARGETS.contains(target),
sanitizer_memory: util::MSAN_SUPPORTED_TARGETS.contains(target),
sanitizer_thread: util::TSAN_SUPPORTED_TARGETS.contains(target),
sanitizer_hwaddress: util::HWASAN_SUPPORTED_TARGETS.contains(target),
sanitizer_memtag: util::MEMTAG_SUPPORTED_TARGETS.contains(target),
sanitizer_shadow_call_stack: util::SHADOWCALLSTACK_SUPPORTED_TARGETS.contains(target),
sanitizer_safestack: util::SAFESTACK_SUPPORTED_TARGETS.contains(target),
sanitizer_address: sanitizers.contains(&Sanitizer::Address),
sanitizer_cfi: sanitizers.contains(&Sanitizer::Cfi),
sanitizer_kcfi: sanitizers.contains(&Sanitizer::Kcfi),
sanitizer_kasan: sanitizers.contains(&Sanitizer::KernelAddress),
sanitizer_leak: sanitizers.contains(&Sanitizer::Leak),
sanitizer_memory: sanitizers.contains(&Sanitizer::Memory),
sanitizer_thread: sanitizers.contains(&Sanitizer::Thread),
sanitizer_hwaddress: sanitizers.contains(&Sanitizer::Hwaddress),
sanitizer_memtag: sanitizers.contains(&Sanitizer::Memtag),
sanitizer_shadow_call_stack: sanitizers.contains(&Sanitizer::ShadowCallStack),
sanitizer_safestack: sanitizers.contains(&Sanitizer::Safestack),
profiler_support: std::env::var_os("RUSTC_PROFILER_SUPPORT").is_some(),
xray: util::XRAY_SUPPORTED_TARGETS.contains(target),

Expand Down
89 changes: 0 additions & 89 deletions src/tools/compiletest/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,6 @@ use tracing::*;
#[cfg(test)]
mod tests;

pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-apple-ios",
"aarch64-apple-ios-sim",
"aarch64-apple-ios-macabi",
"aarch64-unknown-fuchsia",
"aarch64-linux-android",
"aarch64-unknown-linux-gnu",
"arm-linux-androideabi",
"armv7-linux-androideabi",
"i686-linux-android",
"i686-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-apple-ios",
"x86_64-apple-ios-macabi",
"x86_64-unknown-fuchsia",
"x86_64-linux-android",
"x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
];

// FIXME(rcvalle): More targets are likely supported.
pub const CFI_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-unknown-fuchsia",
"aarch64-linux-android",
"aarch64-unknown-freebsd",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-unknown-fuchsia",
"x86_64-pc-solaris",
"x86_64-unknown-freebsd",
"x86_64-unknown-illumos",
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"x86_64-unknown-netbsd",
];

pub const KCFI_SUPPORTED_TARGETS: &[&str] = &["aarch64-linux-none", "x86_64-linux-none"];

pub const KASAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-unknown-none",
"riscv64gc-unknown-none-elf",
"riscv64imac-unknown-none-elf",
"x86_64-unknown-none",
];

pub const LSAN_SUPPORTED_TARGETS: &[&str] = &[
// FIXME: currently broken, see #88132
// "aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-apple-ios-macabi",
"x86_64-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
];

pub const MSAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-unknown-linux-gnu",
"x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
];

pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-apple-ios",
"aarch64-apple-ios-sim",
"aarch64-apple-ios-macabi",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-apple-ios",
"x86_64-apple-ios-macabi",
"x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
];

pub const HWASAN_SUPPORTED_TARGETS: &[&str] =
&["aarch64-linux-android", "aarch64-unknown-linux-gnu"];

pub const MEMTAG_SUPPORTED_TARGETS: &[&str] =
&["aarch64-linux-android", "aarch64-unknown-linux-gnu"];

pub const SHADOWCALLSTACK_SUPPORTED_TARGETS: &[&str] = &["aarch64-linux-android"];

pub const XRAY_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-linux-android",
"aarch64-unknown-linux-gnu",
Expand All @@ -109,8 +22,6 @@ pub const XRAY_SUPPORTED_TARGETS: &[&str] = &[
"x86_64-unknown-openbsd",
];

pub const SAFESTACK_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"];

pub fn make_new_path(path: &str) -> String {
assert!(cfg!(windows));
// Windows just uses PATH as the library search path, so we have to
Expand Down

0 comments on commit 64e27cb

Please sign in to comment.