ASan and TSan are supported on macOS, and this commit enables their support. The sanitizers are always built as *.dylib on Apple platforms, so they cannot be statically linked into the corresponding `rustc_?san.rlib`. The dylibs are directly copied to `lib/rustlib/x86_64-apple-darwin/lib/` instead. Note, although Xcode also ships with their own copies of ASan/TSan dylibs, we cannot use them due to version mismatch. There is a caveat: the sanitizer libraries are linked as @rpath, so the user needs to additionally pass `-C rpath`: rustc -Z sanitizer=address -C rpath file.rs ^~~~~~~~ Otherwise there will be a runtime error: dyld: Library not loaded: @rpath/libclang_rt.asan_osx_dynamic.dylib Referenced from: /path/to/executable Reason: image not found Abort trap: 6 The next commit includes a temporary change in compiler to force the linker to emit a usable @rpath.
36 lines
1.1 KiB
Rust
36 lines
1.1 KiB
Rust
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
extern crate build_helper;
|
|
extern crate cmake;
|
|
|
|
use std::env;
|
|
use build_helper::sanitizer_lib_boilerplate;
|
|
|
|
use cmake::Config;
|
|
|
|
fn main() {
|
|
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
|
let native = match sanitizer_lib_boilerplate("msan") {
|
|
Ok(native) => native,
|
|
_ => return,
|
|
};
|
|
|
|
Config::new(&native.src_dir)
|
|
.define("COMPILER_RT_BUILD_SANITIZERS", "ON")
|
|
.define("COMPILER_RT_BUILD_BUILTINS", "OFF")
|
|
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
|
.define("LLVM_CONFIG_PATH", llvm_config)
|
|
.out_dir(&native.out_dir)
|
|
.build_target("msan")
|
|
.build();
|
|
}
|
|
}
|