mirror of https://github.com/rust-lang/rust.git
build/test the sanitizers only when --enable-sanitizers is used
This commit is contained in:
parent
9af6aa3889
commit
775a93646c
|
@ -649,6 +649,7 @@ opt codegen-tests 1 "run the src/test/codegen tests"
|
||||||
opt option-checking 1 "complain about unrecognized options in this configure script"
|
opt option-checking 1 "complain about unrecognized options in this configure script"
|
||||||
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
|
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
|
||||||
opt vendor 0 "enable usage of vendored Rust crates"
|
opt vendor 0 "enable usage of vendored Rust crates"
|
||||||
|
opt sanitizers 0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"
|
||||||
|
|
||||||
# Optimization and debugging options. These may be overridden by the release channel, etc.
|
# Optimization and debugging options. These may be overridden by the release channel, etc.
|
||||||
opt_nosave optimize 1 "build optimized rust code"
|
opt_nosave optimize 1 "build optimized rust code"
|
||||||
|
|
|
@ -236,6 +236,10 @@ pub fn compiletest(build: &Build,
|
||||||
cmd.env("RUSTC_BOOTSTRAP", "1");
|
cmd.env("RUSTC_BOOTSTRAP", "1");
|
||||||
build.add_rust_test_threads(&mut cmd);
|
build.add_rust_test_threads(&mut cmd);
|
||||||
|
|
||||||
|
if build.config.sanitizers {
|
||||||
|
cmd.env("SANITIZER_SUPPORT", "1");
|
||||||
|
}
|
||||||
|
|
||||||
cmd.arg("--adb-path").arg("adb");
|
cmd.arg("--adb-path").arg("adb");
|
||||||
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
|
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
|
||||||
if target.contains("android") {
|
if target.contains("android") {
|
||||||
|
@ -332,10 +336,7 @@ pub fn krate(build: &Build,
|
||||||
krate: Option<&str>) {
|
krate: Option<&str>) {
|
||||||
let (name, path, features, root) = match mode {
|
let (name, path, features, root) = match mode {
|
||||||
Mode::Libstd => {
|
Mode::Libstd => {
|
||||||
("libstd",
|
("libstd", "src/rustc/std_shim", build.std_features(), "std_shim")
|
||||||
"src/rustc/std_shim",
|
|
||||||
build.std_features(),
|
|
||||||
"std_shim")
|
|
||||||
}
|
}
|
||||||
Mode::Libtest => {
|
Mode::Libtest => {
|
||||||
("libtest", "src/rustc/test_shim", String::new(), "test_shim")
|
("libtest", "src/rustc/test_shim", String::new(), "test_shim")
|
||||||
|
|
|
@ -52,15 +52,14 @@ pub fn std(build: &Build, target: &str, compiler: &Compiler) {
|
||||||
features.push_str(" force_alloc_system");
|
features.push_str(" force_alloc_system");
|
||||||
}
|
}
|
||||||
|
|
||||||
if compiler.stage != 0 && !build.system_llvm(target) {
|
if compiler.stage != 0 && build.config.sanitizers {
|
||||||
// This variable is used by the sanitizer runtime crates, e.g.
|
// This variable is used by the sanitizer runtime crates, e.g.
|
||||||
// rustc_lsan, to build the sanitizer runtime from C code
|
// rustc_lsan, to build the sanitizer runtime from C code
|
||||||
// When this variable is missing, those crates won't compile the C code,
|
// When this variable is missing, those crates won't compile the C code,
|
||||||
// so we don't set this variable during stage0 where llvm-config is
|
// so we don't set this variable during stage0 where llvm-config is
|
||||||
// missing
|
// missing
|
||||||
// We also don't build the runtimes when compiling against system llvm
|
// We also only build the runtimes when --enable-sanitizers (or its
|
||||||
// because some distributions ship llvm packages that have a directory
|
// config.toml equivalent) is used
|
||||||
// layout different from the one that the runtime's build system expects
|
|
||||||
cargo.env("LLVM_CONFIG", build.llvm_config(target));
|
cargo.env("LLVM_CONFIG", build.llvm_config(target));
|
||||||
}
|
}
|
||||||
cargo.arg("--features").arg(features)
|
cargo.arg("--features").arg(features)
|
||||||
|
|
|
@ -48,6 +48,7 @@ pub struct Config {
|
||||||
pub target_config: HashMap<String, Target>,
|
pub target_config: HashMap<String, Target>,
|
||||||
pub full_bootstrap: bool,
|
pub full_bootstrap: bool,
|
||||||
pub extended: bool,
|
pub extended: bool,
|
||||||
|
pub sanitizers: bool,
|
||||||
|
|
||||||
// llvm codegen options
|
// llvm codegen options
|
||||||
pub llvm_assertions: bool,
|
pub llvm_assertions: bool,
|
||||||
|
@ -108,8 +109,6 @@ pub struct Config {
|
||||||
/// Per-target configuration stored in the global configuration structure.
|
/// Per-target configuration stored in the global configuration structure.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Target {
|
pub struct Target {
|
||||||
// `true` if compiling against system LLVM or a pre-built LLVM
|
|
||||||
pub system_llvm: bool,
|
|
||||||
pub llvm_config: Option<PathBuf>,
|
pub llvm_config: Option<PathBuf>,
|
||||||
pub jemalloc: Option<PathBuf>,
|
pub jemalloc: Option<PathBuf>,
|
||||||
pub cc: Option<PathBuf>,
|
pub cc: Option<PathBuf>,
|
||||||
|
@ -150,6 +149,7 @@ struct Build {
|
||||||
python: Option<String>,
|
python: Option<String>,
|
||||||
full_bootstrap: Option<bool>,
|
full_bootstrap: Option<bool>,
|
||||||
extended: Option<bool>,
|
extended: Option<bool>,
|
||||||
|
sanitizers: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TOML representation of various global install decisions.
|
/// TOML representation of various global install decisions.
|
||||||
|
@ -294,6 +294,7 @@ impl Config {
|
||||||
set(&mut config.vendor, build.vendor);
|
set(&mut config.vendor, build.vendor);
|
||||||
set(&mut config.full_bootstrap, build.full_bootstrap);
|
set(&mut config.full_bootstrap, build.full_bootstrap);
|
||||||
set(&mut config.extended, build.extended);
|
set(&mut config.extended, build.extended);
|
||||||
|
set(&mut config.sanitizers, build.sanitizers);
|
||||||
|
|
||||||
if let Some(ref install) = toml.install {
|
if let Some(ref install) = toml.install {
|
||||||
config.prefix = install.prefix.clone().map(PathBuf::from);
|
config.prefix = install.prefix.clone().map(PathBuf::from);
|
||||||
|
@ -437,6 +438,7 @@ impl Config {
|
||||||
("VENDOR", self.vendor),
|
("VENDOR", self.vendor),
|
||||||
("FULL_BOOTSTRAP", self.full_bootstrap),
|
("FULL_BOOTSTRAP", self.full_bootstrap),
|
||||||
("EXTENDED", self.extended),
|
("EXTENDED", self.extended),
|
||||||
|
("SANITIZERS", self.sanitizers),
|
||||||
}
|
}
|
||||||
|
|
||||||
match key {
|
match key {
|
||||||
|
@ -514,7 +516,6 @@ impl Config {
|
||||||
.or_insert(Target::default());
|
.or_insert(Target::default());
|
||||||
let root = parse_configure_path(value);
|
let root = parse_configure_path(value);
|
||||||
target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
|
target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
|
||||||
target.system_llvm = true;
|
|
||||||
}
|
}
|
||||||
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
|
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
|
||||||
let target = self.target_config.entry(self.build.clone())
|
let target = self.target_config.entry(self.build.clone())
|
||||||
|
|
|
@ -124,6 +124,9 @@
|
||||||
# disabled by default.
|
# disabled by default.
|
||||||
#extended = false
|
#extended = false
|
||||||
|
|
||||||
|
# Build the sanitizer runtimes
|
||||||
|
#sanitizers = false
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# General install configuration options
|
# General install configuration options
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
|
@ -717,10 +717,6 @@ impl Build {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn system_llvm(&self, target: &str) -> bool {
|
|
||||||
self.config.target_config.get(target).map(|t| t.system_llvm).unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the path to `FileCheck` binary for the specified target
|
/// Returns the path to `FileCheck` binary for the specified target
|
||||||
fn llvm_filecheck(&self, target: &str) -> PathBuf {
|
fn llvm_filecheck(&self, target: &str) -> PathBuf {
|
||||||
let target_config = self.config.target_config.get(target);
|
let target_config = self.config.target_config.get(target);
|
||||||
|
|
|
@ -127,7 +127,7 @@ pub enum Attribute {
|
||||||
ZExt = 18,
|
ZExt = 18,
|
||||||
InReg = 19,
|
InReg = 19,
|
||||||
SanitizeThread = 20,
|
SanitizeThread = 20,
|
||||||
SanitizeAddress = 21,
|
SanitizeAddress = 21,
|
||||||
SanitizeMemory = 22,
|
SanitizeMemory = 22,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
# NOTE the address sanitizer only supports x86_64 linux
|
# NOTE the address sanitizer only supports x86_64 linux
|
||||||
ifndef IS_WINDOWS
|
ifdef SANITIZER_SUPPORT
|
||||||
ifeq ($(shell uname),Linux)
|
|
||||||
ifeq ($(shell uname -m),x86_64)
|
|
||||||
all:
|
all:
|
||||||
$(RUSTC) -g -Z sanitizer=address -Z print-link-args overflow.rs | grep -q librustc_asan
|
$(RUSTC) -g -Z sanitizer=address -Z print-link-args overflow.rs | grep -q librustc_asan
|
||||||
$(TMPDIR)/overflow 2>&1 | grep -q stack-buffer-overflow
|
$(TMPDIR)/overflow 2>&1 | grep -q stack-buffer-overflow
|
||||||
|
@ -11,11 +9,3 @@ else
|
||||||
all:
|
all:
|
||||||
|
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
# NOTE the leak sanitizer only supports x86_64 linux
|
ifdef SANITIZER_SUPPORT
|
||||||
# Also, this particular sanitizer sometimes doesn't work so we are not going to
|
|
||||||
# run the binary
|
|
||||||
ifndef IS_WINDOWS
|
|
||||||
ifeq ($(shell uname),Linux)
|
|
||||||
ifeq ($(shell uname -m),x86_64)
|
|
||||||
all:
|
all:
|
||||||
$(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | grep -q librustc_lsan
|
$(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | grep -q librustc_lsan
|
||||||
$(TMPDIR)/leak 2>&1 | grep -q 'detected memory leaks'
|
$(TMPDIR)/leak 2>&1 | grep -q 'detected memory leaks'
|
||||||
|
@ -13,11 +8,3 @@ else
|
||||||
all:
|
all:
|
||||||
|
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
# NOTE the memory sanitizer only supports x86_64 linux
|
ifdef SANITIZER_SUPPORT
|
||||||
ifndef IS_WINDOWS
|
|
||||||
ifeq ($(shell uname),Linux)
|
|
||||||
ifeq ($(shell uname -m),x86_64)
|
|
||||||
all:
|
all:
|
||||||
$(RUSTC) -g -Z sanitizer=memory -Z print-link-args uninit.rs | grep -q librustc_msan
|
$(RUSTC) -g -Z sanitizer=memory -Z print-link-args uninit.rs | grep -q librustc_msan
|
||||||
$(TMPDIR)/uninit 2>&1 | grep -q use-of-uninitialized-value
|
$(TMPDIR)/uninit 2>&1 | grep -q use-of-uninitialized-value
|
||||||
|
@ -11,11 +8,3 @@ else
|
||||||
all:
|
all:
|
||||||
|
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
# NOTE the leak sanitizer only supports x86_64 linux
|
ifdef SANITIZER_SUPPORT
|
||||||
ifndef IS_WINDOWS
|
|
||||||
ifeq ($(shell uname),Linux)
|
|
||||||
ifeq ($(shell uname -m),x86_64)
|
|
||||||
all:
|
all:
|
||||||
$(RUSTC) -g -Z sanitizer=thread -Z print-link-args racy.rs | grep -q librustc_tsan
|
$(RUSTC) -g -Z sanitizer=thread -Z print-link-args racy.rs | grep -q librustc_tsan
|
||||||
$(TMPDIR)/racy 2>&1 | grep -q 'data race'
|
$(TMPDIR)/racy 2>&1 | grep -q 'data race'
|
||||||
|
@ -11,11 +8,3 @@ else
|
||||||
all:
|
all:
|
||||||
|
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
all:
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
Loading…
Reference in New Issue