Skip to content

Commit

Permalink
build/test the sanitizers only when --enable-sanitizers is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Feb 8, 2017
1 parent 9af6aa3 commit 775a936
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 65 deletions.
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 sanitizers 0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"

# Optimization and debugging options. These may be overridden by the release channel, etc.
opt_nosave optimize 1 "build optimized rust code"
Expand Down
9 changes: 5 additions & 4 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ pub fn compiletest(build: &Build,
cmd.env("RUSTC_BOOTSTRAP", "1");
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-test-dir").arg(ADB_TEST_DIR);
if target.contains("android") {
Expand Down Expand Up @@ -332,10 +336,7 @@ pub fn krate(build: &Build,
krate: Option<&str>) {
let (name, path, features, root) = match mode {
Mode::Libstd => {
("libstd",
"src/rustc/std_shim",
build.std_features(),
"std_shim")
("libstd", "src/rustc/std_shim", build.std_features(), "std_shim")
}
Mode::Libtest => {
("libtest", "src/rustc/test_shim", String::new(), "test_shim")
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ pub fn std(build: &Build, target: &str, compiler: &Compiler) {
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.
// rustc_lsan, to build the sanitizer runtime from 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
// missing
// We also don't build the runtimes when compiling against system llvm
// because some distributions ship llvm packages that have a directory
// layout different from the one that the runtime's build system expects
// We also only build the runtimes when --enable-sanitizers (or its
// config.toml equivalent) is used
cargo.env("LLVM_CONFIG", build.llvm_config(target));
}
cargo.arg("--features").arg(features)
Expand Down
7 changes: 4 additions & 3 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct Config {
pub target_config: HashMap<String, Target>,
pub full_bootstrap: bool,
pub extended: bool,
pub sanitizers: bool,

// llvm codegen options
pub llvm_assertions: bool,
Expand Down Expand Up @@ -108,8 +109,6 @@ pub struct Config {
/// Per-target configuration stored in the global configuration structure.
#[derive(Default)]
pub struct Target {
// `true` if compiling against system LLVM or a pre-built LLVM
pub system_llvm: bool,
pub llvm_config: Option<PathBuf>,
pub jemalloc: Option<PathBuf>,
pub cc: Option<PathBuf>,
Expand Down Expand Up @@ -150,6 +149,7 @@ struct Build {
python: Option<String>,
full_bootstrap: Option<bool>,
extended: Option<bool>,
sanitizers: Option<bool>,
}

/// TOML representation of various global install decisions.
Expand Down Expand Up @@ -294,6 +294,7 @@ impl Config {
set(&mut config.vendor, build.vendor);
set(&mut config.full_bootstrap, build.full_bootstrap);
set(&mut config.extended, build.extended);
set(&mut config.sanitizers, build.sanitizers);

if let Some(ref install) = toml.install {
config.prefix = install.prefix.clone().map(PathBuf::from);
Expand Down Expand Up @@ -437,6 +438,7 @@ impl Config {
("VENDOR", self.vendor),
("FULL_BOOTSTRAP", self.full_bootstrap),
("EXTENDED", self.extended),
("SANITIZERS", self.sanitizers),
}

match key {
Expand Down Expand Up @@ -514,7 +516,6 @@ impl Config {
.or_insert(Target::default());
let root = parse_configure_path(value);
target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
target.system_llvm = true;
}
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
let target = self.target_config.entry(self.build.clone())
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
# disabled by default.
#extended = false

# Build the sanitizer runtimes
#sanitizers = false

# =============================================================================
# General install configuration options
# =============================================================================
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
fn llvm_filecheck(&self, target: &str) -> PathBuf {
let target_config = self.config.target_config.get(target);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub enum Attribute {
ZExt = 18,
InReg = 19,
SanitizeThread = 20,
SanitizeAddress = 21,
SanitizeAddress = 21,
SanitizeMemory = 22,
}

Expand Down
12 changes: 1 addition & 11 deletions src/test/run-make/sanitizer-address/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
-include ../tools.mk

# NOTE the address sanitizer only supports x86_64 linux
ifndef IS_WINDOWS
ifeq ($(shell uname),Linux)
ifeq ($(shell uname -m),x86_64)
ifdef SANITIZER_SUPPORT
all:
$(RUSTC) -g -Z sanitizer=address -Z print-link-args overflow.rs | grep -q librustc_asan
$(TMPDIR)/overflow 2>&1 | grep -q stack-buffer-overflow
else
all:

endif
else
all:

endif
else
all:

endif
15 changes: 1 addition & 14 deletions src/test/run-make/sanitizer-leak/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
-include ../tools.mk

# NOTE the leak sanitizer only supports x86_64 linux
# 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)
ifdef SANITIZER_SUPPORT
all:
$(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'
else
all:

endif
else
all:

endif
else
all:

endif
13 changes: 1 addition & 12 deletions src/test/run-make/sanitizer-memory/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
-include ../tools.mk

# NOTE the memory sanitizer only supports x86_64 linux
ifndef IS_WINDOWS
ifeq ($(shell uname),Linux)
ifeq ($(shell uname -m),x86_64)
ifdef SANITIZER_SUPPORT
all:
$(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
else
all:

endif
else
all:

endif
else
all:

endif
13 changes: 1 addition & 12 deletions src/test/run-make/sanitizer-thread/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
-include ../tools.mk

# NOTE the leak sanitizer only supports x86_64 linux
ifndef IS_WINDOWS
ifeq ($(shell uname),Linux)
ifeq ($(shell uname -m),x86_64)
ifdef SANITIZER_SUPPORT
all:
$(RUSTC) -g -Z sanitizer=thread -Z print-link-args racy.rs | grep -q librustc_tsan
$(TMPDIR)/racy 2>&1 | grep -q 'data race'
else
all:

endif
else
all:

endif
else
all:

endif

0 comments on commit 775a936

Please sign in to comment.