提交 5986dd87 编写于 作者: B bors

Auto merge of #79883 - frewsxcv:frewsxcv-san, r=shepmaster

Enable ASan, TSan, UBSan for aarch64-apple-darwin.

I confirmed ASan, TSan, UBSan all work for me locally with `clang` on my new Macbook Air.

~This requires https://github.com/rust-lang/llvm-project/pull/86~
...@@ -895,7 +895,7 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) { ...@@ -895,7 +895,7 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
.unwrap_or_default(); .unwrap_or_default();
match sess.opts.target_triple.triple() { match sess.opts.target_triple.triple() {
"x86_64-apple-darwin" => { "aarch64-apple-darwin" | "x86_64-apple-darwin" => {
// On Apple platforms, the sanitizer is always built as a dylib, and // On Apple platforms, the sanitizer is always built as a dylib, and
// LLVM will link to `@rpath/*.dylib`, so we need to specify an // LLVM will link to `@rpath/*.dylib`, so we need to specify an
// rpath to the library as well (the rpath should be absolute, see // rpath to the library as well (the rpath should be absolute, see
......
...@@ -1522,6 +1522,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { ...@@ -1522,6 +1522,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
} }
const ASAN_SUPPORTED_TARGETS: &[&str] = &[ const ASAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-fuchsia", "aarch64-fuchsia",
"aarch64-unknown-linux-gnu", "aarch64-unknown-linux-gnu",
"x86_64-apple-darwin", "x86_64-apple-darwin",
...@@ -1529,11 +1530,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) { ...@@ -1529,11 +1530,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
"x86_64-unknown-freebsd", "x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu", "x86_64-unknown-linux-gnu",
]; ];
const LSAN_SUPPORTED_TARGETS: &[&str] = const LSAN_SUPPORTED_TARGETS: &[&str] = &[
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; "aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
];
const MSAN_SUPPORTED_TARGETS: &[&str] = const MSAN_SUPPORTED_TARGETS: &[&str] =
&["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"]; &["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"];
const TSAN_SUPPORTED_TARGETS: &[&str] = &[ const TSAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu", "aarch64-unknown-linux-gnu",
"x86_64-apple-darwin", "x86_64-apple-darwin",
"x86_64-unknown-freebsd", "x86_64-unknown-freebsd",
......
...@@ -356,15 +356,12 @@ fn copy_sanitizers( ...@@ -356,15 +356,12 @@ fn copy_sanitizers(
let dst = libdir.join(&runtime.name); let dst = libdir.join(&runtime.name);
builder.copy(&runtime.path, &dst); builder.copy(&runtime.path, &dst);
if target == "x86_64-apple-darwin" { if target == "x86_64-apple-darwin" || target == "aarch64-apple-darwin" {
// Update the library install name reflect the fact it has been renamed. // Update the library’s install name to reflect that it has has been renamed.
let status = Command::new("install_name_tool") apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name));
.arg("-id") // Upon renaming the install name, the code signature of the file will invalidate,
.arg(format!("@rpath/{}", runtime.name)) // so we will sign it again.
.arg(&dst) apple_darwin_sign_file(&dst);
.status()
.expect("failed to execute `install_name_tool`");
assert!(status.success());
} }
target_deps.push(dst); target_deps.push(dst);
...@@ -373,6 +370,27 @@ fn copy_sanitizers( ...@@ -373,6 +370,27 @@ fn copy_sanitizers(
target_deps target_deps
} }
fn apple_darwin_update_library_name(library_path: &Path, new_name: &str) {
let status = Command::new("install_name_tool")
.arg("-id")
.arg(new_name)
.arg(library_path)
.status()
.expect("failed to execute `install_name_tool`");
assert!(status.success());
}
fn apple_darwin_sign_file(file_path: &Path) {
let status = Command::new("codesign")
.arg("-f") // Force to rewrite the existing signature
.arg("-s")
.arg("-")
.arg(file_path)
.status()
.expect("failed to execute `codesign`");
assert!(status.success());
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct StartupObjects { pub struct StartupObjects {
pub compiler: Compiler, pub compiler: Compiler,
......
...@@ -802,6 +802,7 @@ fn supported_sanitizers( ...@@ -802,6 +802,7 @@ fn supported_sanitizers(
}; };
match &*target.triple { match &*target.triple {
"aarch64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]),
"aarch64-fuchsia" => common_libs("fuchsia", "aarch64", &["asan"]), "aarch64-fuchsia" => common_libs("fuchsia", "aarch64", &["asan"]),
"aarch64-unknown-linux-gnu" => { "aarch64-unknown-linux-gnu" => {
common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan"]) common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan"])
......
...@@ -31,7 +31,12 @@ with runtime flag `ASAN_OPTIONS=detect_leaks=1` on macOS. ...@@ -31,7 +31,12 @@ with runtime flag `ASAN_OPTIONS=detect_leaks=1` on macOS.
AddressSanitizer is supported on the following targets: AddressSanitizer is supported on the following targets:
* `aarch64-apple-darwin`
* `aarch64-fuchsia`
* `aarch64-unknown-linux-gnu`
* `x86_64-apple-darwin` * `x86_64-apple-darwin`
* `x86_64-fuchsia`
* `x86_64-unknown-freebsd`
* `x86_64-unknown-linux-gnu` * `x86_64-unknown-linux-gnu`
AddressSanitizer works with non-instrumented code although it will impede its AddressSanitizer works with non-instrumented code although it will impede its
...@@ -169,10 +174,26 @@ Shadow byte legend (one shadow byte represents 8 application bytes): ...@@ -169,10 +174,26 @@ Shadow byte legend (one shadow byte represents 8 application bytes):
==39249==ABORTING ==39249==ABORTING
``` ```
# LeakSanitizer
LeakSanitizer is run-time memory leak detector.
LeakSanitizer is supported on the following targets:
* `aarch64-apple-darwin`
* `aarch64-unknown-linux-gnu`
* `x86_64-apple-darwin`
* `x86_64-unknown-linux-gnu`
# MemorySanitizer # MemorySanitizer
MemorySanitizer is detector of uninitialized reads. It is only supported on the MemorySanitizer is detector of uninitialized reads.
`x86_64-unknown-linux-gnu` target.
MemorySanitizer is supported on the following targets:
* `aarch64-unknown-linux-gnu`
* `x86_64-unknown-freebsd`
* `x86_64-unknown-linux-gnu`
MemorySanitizer requires all program code to be instrumented. C/C++ dependencies MemorySanitizer requires all program code to be instrumented. C/C++ dependencies
need to be recompiled using Clang with `-fsanitize=memory` option. Failing to need to be recompiled using Clang with `-fsanitize=memory` option. Failing to
...@@ -219,7 +240,10 @@ $ cargo run -Zbuild-std --target x86_64-unknown-linux-gnu ...@@ -219,7 +240,10 @@ $ cargo run -Zbuild-std --target x86_64-unknown-linux-gnu
ThreadSanitizer is a data race detection tool. It is supported on the following ThreadSanitizer is a data race detection tool. It is supported on the following
targets: targets:
* `aarch64-apple-darwin`
* `aarch64-unknown-linux-gnu`
* `x86_64-apple-darwin` * `x86_64-apple-darwin`
* `x86_64-unknown-freebsd`
* `x86_64-unknown-linux-gnu` * `x86_64-unknown-linux-gnu`
To work correctly ThreadSanitizer needs to be "aware" of all synchronization To work correctly ThreadSanitizer needs to be "aware" of all synchronization
......
// Verifies that no_sanitze attribute can be used to // Verifies that no_sanitize attribute can be used to
// selectively disable sanitizer instrumentation. // selectively disable sanitizer instrumentation.
// //
// needs-sanitizer-address // needs-sanitizer-address
......
error: `-Zsanitizer=leak` only works with targets: aarch64-unknown-linux-gnu, x86_64-apple-darwin, x86_64-unknown-linux-gnu error: `-Zsanitizer=leak` only works with targets: aarch64-apple-darwin, aarch64-unknown-linux-gnu, x86_64-apple-darwin, x86_64-unknown-linux-gnu
error: aborting due to previous error error: aborting due to previous error
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
]; ];
pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[ pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-fuchsia", "aarch64-fuchsia",
"aarch64-unknown-linux-gnu", "aarch64-unknown-linux-gnu",
"x86_64-apple-darwin", "x86_64-apple-darwin",
...@@ -90,13 +91,18 @@ ...@@ -90,13 +91,18 @@
"x86_64-unknown-linux-gnu", "x86_64-unknown-linux-gnu",
]; ];
pub const LSAN_SUPPORTED_TARGETS: &[&str] = pub const LSAN_SUPPORTED_TARGETS: &[&str] = &[
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; "aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
];
pub const MSAN_SUPPORTED_TARGETS: &[&str] = pub const MSAN_SUPPORTED_TARGETS: &[&str] =
&["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"]; &["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"];
pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[ pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu", "aarch64-unknown-linux-gnu",
"x86_64-apple-darwin", "x86_64-apple-darwin",
"x86_64-unknown-freebsd", "x86_64-unknown-freebsd",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册