From dcbe9f7668185f673a4b4a01d110703079b14804 Mon Sep 17 00:00:00 2001 From: danakj Date: Thu, 7 Sep 2023 10:18:05 -0400 Subject: [PATCH 1/2] Enable ASAN/LSAN/TSAN for *-apple-ios-macabi The -macabi targets are iOS running on MacOS, and they use the runtime libraries for MacOS, thus they have the same sanitizers available as the *-apple-darwin targets. --- compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs | 3 ++- compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs | 3 ++- src/bootstrap/compile.rs | 2 ++ src/bootstrap/llvm.rs | 2 ++ src/tools/compiletest/src/util.rs | 5 +++++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs index e2df7e0bdcc79..b29ab14e7f282 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs @@ -1,5 +1,5 @@ use super::apple_base::{opts, Arch}; -use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, TargetOptions}; +use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { let llvm_target = "arm64-apple-ios14.0-macabi"; @@ -7,6 +7,7 @@ pub fn target() -> Target { let arch = Arch::Arm64_macabi; let mut base = opts("ios", arch); base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-target", llvm_target]); + base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD; Target { llvm_target: llvm_target.into(), diff --git a/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs index 50f359c357bdf..fd1926f29456b 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs @@ -1,5 +1,5 @@ use super::apple_base::{opts, Arch}; -use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions}; +use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let llvm_target = "x86_64-apple-ios14.0-macabi"; @@ -7,6 +7,7 @@ pub fn target() -> Target { let arch = Arch::X86_64_macabi; let mut base = opts("ios", arch); base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-target", llvm_target]); + base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD; Target { llvm_target: llvm_target.into(), diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 9c68e5a78d832..1ff93dc3b0631 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -574,7 +574,9 @@ fn copy_sanitizers( || target == "aarch64-apple-darwin" || target == "aarch64-apple-ios" || target == "aarch64-apple-ios-sim" + || target == "aarch64-apple-ios-catalyst" || target == "x86_64-apple-ios" + || target == "x86_64-apple-ios-catalyst" { // Update the library’s install name to reflect that it has been renamed. apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name)); diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index aefed50151314..ca97aa3074479 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -1061,6 +1061,7 @@ fn supported_sanitizers( "aarch64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]), "aarch64-apple-ios" => darwin_libs("ios", &["asan", "tsan"]), "aarch64-apple-ios-sim" => darwin_libs("iossim", &["asan", "tsan"]), + "aarch64-apple-ios-macabi" => darwin_libs("osx", &["asan", "lsan", "tsan"]), "aarch64-unknown-fuchsia" => common_libs("fuchsia", "aarch64", &["asan"]), "aarch64-unknown-linux-gnu" => { common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan", "hwasan"]) @@ -1071,6 +1072,7 @@ fn supported_sanitizers( "x86_64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]), "x86_64-unknown-fuchsia" => common_libs("fuchsia", "x86_64", &["asan"]), "x86_64-apple-ios" => darwin_libs("iossim", &["asan", "tsan"]), + "x86_64-apple-ios-macabi" => darwin_libs("osx", &["asan", "lsan", "tsan"]), "x86_64-unknown-freebsd" => common_libs("freebsd", "x86_64", &["asan", "msan", "tsan"]), "x86_64-unknown-netbsd" => { common_libs("netbsd", "x86_64", &["asan", "lsan", "msan", "tsan"]) diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 17bed38b65e88..02648fe5c2944 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -13,6 +13,7 @@ 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", @@ -22,6 +23,7 @@ pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[ "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", @@ -60,6 +62,7 @@ pub const LSAN_SUPPORTED_TARGETS: &[&str] = &[ // "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", ]; @@ -75,9 +78,11 @@ 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", From 1365771345f16b94a349c3512cd8ade185e68e71 Mon Sep 17 00:00:00 2001 From: danakj Date: Mon, 11 Sep 2023 10:33:50 -0400 Subject: [PATCH 2/2] Document that the macabi sanitizers are shared with darwin Do not rename and resign the darwin sanitizers a second time for macabi. --- src/bootstrap/compile.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 1ff93dc3b0631..cc3f5181aeb45 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -570,13 +570,14 @@ fn copy_sanitizers( let dst = libdir.join(&runtime.name); builder.copy(&runtime.path, &dst); + // The `aarch64-apple-ios-macabi` and `x86_64-apple-ios-macabi` are also supported for + // sanitizers, but they share a sanitizer runtime with `${arch}-apple-darwin`, so we do + // not list them here to rename and sign the runtime library. if target == "x86_64-apple-darwin" || target == "aarch64-apple-darwin" || target == "aarch64-apple-ios" || target == "aarch64-apple-ios-sim" - || target == "aarch64-apple-ios-catalyst" || target == "x86_64-apple-ios" - || target == "x86_64-apple-ios-catalyst" { // Update the library’s install name to reflect that it has been renamed. apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name));