From 0c285fb25c3792d3acc3b8c22f1c74607d8cd0fb Mon Sep 17 00:00:00 2001 From: tyler Date: Sun, 14 Jul 2019 15:56:23 -0700 Subject: [PATCH 1/4] expand osx sanitizer support (lsan, dylib, cdylib, staticlib) --- src/bootstrap/compile.rs | 2 +- src/librustc/middle/dependency_format.rs | 10 +- src/librustc/session/mod.rs | 8 +- src/librustc_lsan/build.rs | 1 + src/librustc_metadata/creader.rs | 157 ++++++++---------- src/libstd/Cargo.toml | 1 + .../sanitizer-address/Makefile | 6 - .../sanitizer-c-staticlib-link/Makefile | 20 +++ .../sanitizer-c-staticlib-link/library.rs | 5 + .../program.c | 0 .../sanitizer-cdylib-link/Makefile | 3 +- .../sanitizer-dylib-link/Makefile | 3 +- .../sanitizer-invalid-cratetype/Makefile | 5 - .../sanitizer-invalid-target/Makefile | 2 +- .../run-make-fulldeps/sanitizer-leak/Makefile | 3 - .../sanitizer-staticlib-link/Makefile | 9 +- .../sanitizer-staticlib-link/program.rs | 7 + 17 files changed, 120 insertions(+), 122 deletions(-) create mode 100644 src/test/run-make-fulldeps/sanitizer-c-staticlib-link/Makefile create mode 100644 src/test/run-make-fulldeps/sanitizer-c-staticlib-link/library.rs rename src/test/run-make-fulldeps/{sanitizer-staticlib-link => sanitizer-c-staticlib-link}/program.c (100%) create mode 100644 src/test/run-make-fulldeps/sanitizer-staticlib-link/program.rs diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 4cd793adaf574..f1f3f583d8906 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -285,7 +285,7 @@ fn copy_apple_sanitizer_dylibs( platform: &str, into: &Path, ) { - for &sanitizer in &["asan", "tsan"] { + for &sanitizer in &["asan", "lsan", "tsan"] { let filename = format!("lib__rustc__clang_rt.{}_{}_dynamic.dylib", sanitizer, platform); let mut src_path = native_dir.join(sanitizer); src_path.push("build"); diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 96b99fe4cdce2..943646760a355 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -210,6 +210,8 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { // quite yet, so do so here. activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret, &|cnum| tcx.is_panic_runtime(cnum)); + activate_injected_dep(*sess.injected_sanitizer_runtime.get(), &mut ret, + &|cnum| tcx.is_sanitizer_runtime(cnum)); // When dylib B links to dylib A, then when using B we must also link to A. // It could be the case, however, that the rlib for A is present (hence we @@ -285,11 +287,13 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option { } }).collect::>(); - // Our allocator/panic runtime may not have been linked above if it wasn't - // explicitly linked, which is the case for any injected dependency. Handle - // that here and activate them. + // Our allocator/panic/sanitizer runtime may not have been linked above if + // it wasn't explicitly linked, which is the case for any injected + // dependency. Handle that here and activate them. activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret, &|cnum| tcx.is_panic_runtime(cnum)); + activate_injected_dep(*sess.injected_sanitizer_runtime.get(), &mut ret, + &|cnum| tcx.is_sanitizer_runtime(cnum)); Some(ret) } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 61dac678912df..32a9f242789c1 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -111,11 +111,12 @@ pub struct Session { /// The maximum number of stackframes allowed in const eval. pub const_eval_stack_frame_limit: usize, - /// The metadata::creader module may inject an allocator/panic_runtime - /// dependency if it didn't already find one, and this tracks what was - /// injected. + /// The metadata::creader module may inject an allocator/panic_runtime/ + /// sanitizer dependency if it didn't already find one, and this tracks what + /// was injected. pub allocator_kind: Once>, pub injected_panic_runtime: Once>, + pub injected_sanitizer_runtime: Once>, /// Map from imported macro spans (which consist of /// the localized span for the macro body) to the @@ -1249,6 +1250,7 @@ fn build_session_( next_node_id: OneThread::new(Cell::new(NodeId::from_u32(1))), allocator_kind: Once::new(), injected_panic_runtime: Once::new(), + injected_sanitizer_runtime: Once::new(), imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())), incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)), cgu_reuse_tracker, diff --git a/src/librustc_lsan/build.rs b/src/librustc_lsan/build.rs index b8c7b7c2d5537..1e837d0576cf0 100644 --- a/src/librustc_lsan/build.rs +++ b/src/librustc_lsan/build.rs @@ -20,6 +20,7 @@ fn main() { .out_dir(&native.out_dir) .build_target(&target) .build(); + native.fixup_sanitizer_lib_name("lsan"); } println!("cargo:rerun-if-env-changed=LLVM_CONFIG"); } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index d5f1e715186f4..d3148f0f4ff71 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -762,105 +762,78 @@ impl<'a> CrateLoader<'a> { } fn inject_sanitizer_runtime(&mut self) { - if let Some(ref sanitizer) = self.sess.opts.debugging_opts.sanitizer { - // Sanitizers can only be used on some tested platforms with - // executables linked to `std` - const ASAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", - "x86_64-apple-darwin"]; - const TSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", - "x86_64-apple-darwin"]; - const LSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; - const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; - - let supported_targets = match *sanitizer { - Sanitizer::Address => ASAN_SUPPORTED_TARGETS, - Sanitizer::Thread => TSAN_SUPPORTED_TARGETS, - Sanitizer::Leak => LSAN_SUPPORTED_TARGETS, - Sanitizer::Memory => MSAN_SUPPORTED_TARGETS, - }; - if !supported_targets.contains(&&*self.sess.opts.target_triple.triple()) { - self.sess.err(&format!("{:?}Sanitizer only works with the `{}` target", - sanitizer, - supported_targets.join("` or `") - )); + // Sanitizers can only be used on some tested platforms with + // executables linked to `std` + const ASAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", + "x86_64-apple-darwin"]; + const TSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", + "x86_64-apple-darwin"]; + const LSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", + "x86_64-apple-darwin"]; + const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; + + let sanitizer = match self.sess.opts.debugging_opts.sanitizer { + Some(ref sanitizer) => sanitizer, + None => { + self.sess.injected_sanitizer_runtime.set(None); return } + }; - // firstyear 2017 - during testing I was unable to access an OSX machine - // to make this work on different crate types. As a result, today I have - // only been able to test and support linux as a target. - if self.sess.opts.target_triple.triple() == "x86_64-unknown-linux-gnu" { - if !self.sess.crate_types.borrow().iter().all(|ct| { - match *ct { - // Link the runtime - config::CrateType::Staticlib | - config::CrateType::Executable => true, - // This crate will be compiled with the required - // instrumentation pass - config::CrateType::Rlib | - config::CrateType::Dylib | - config::CrateType::Cdylib => - false, - _ => { - self.sess.err(&format!("Only executables, staticlibs, \ - cdylibs, dylibs and rlibs can be compiled with \ - `-Z sanitizer`")); - false - } - } - }) { - return - } - } else { - if !self.sess.crate_types.borrow().iter().all(|ct| { - match *ct { - // Link the runtime - config::CrateType::Executable => true, - // This crate will be compiled with the required - // instrumentation pass - config::CrateType::Rlib => false, - _ => { - self.sess.err(&format!("Only executables and rlibs can be \ - compiled with `-Z sanitizer`")); - false - } - } - }) { - return - } + let supported_targets = match *sanitizer { + Sanitizer::Address => ASAN_SUPPORTED_TARGETS, + Sanitizer::Thread => TSAN_SUPPORTED_TARGETS, + Sanitizer::Leak => LSAN_SUPPORTED_TARGETS, + Sanitizer::Memory => MSAN_SUPPORTED_TARGETS, + }; + if !supported_targets.contains(&&*self.sess.opts.target_triple.triple()) { + self.sess.err(&format!("{:?}Sanitizer only works with the `{}` target", + sanitizer, + supported_targets.join("` or `") + )); + return + } + + let any_non_rlib = self.sess.crate_types.borrow().iter().any(|ct| { + *ct != config::CrateType::Rlib + }); + if !any_non_rlib { + info!("sanitizer runtime injection skipped, only generating rlib"); + self.sess.injected_sanitizer_runtime.set(None); + return + } + + let mut uses_std = false; + self.cstore.iter_crate_data(|_, data| { + if data.name == sym::std { + uses_std = true; } + }); - let mut uses_std = false; - self.cstore.iter_crate_data(|_, data| { - if data.name == sym::std { - uses_std = true; - } - }); + if uses_std { + let name = match *sanitizer { + Sanitizer::Address => "rustc_asan", + Sanitizer::Leak => "rustc_lsan", + Sanitizer::Memory => "rustc_msan", + Sanitizer::Thread => "rustc_tsan", + }; + info!("loading sanitizer: {}", name); - if uses_std { - let name = match *sanitizer { - Sanitizer::Address => "rustc_asan", - Sanitizer::Leak => "rustc_lsan", - Sanitizer::Memory => "rustc_msan", - Sanitizer::Thread => "rustc_tsan", - }; - info!("loading sanitizer: {}", name); - - let symbol = Symbol::intern(name); - let dep_kind = DepKind::Explicit; - let (_, data) = - self.resolve_crate(&None, symbol, symbol, None, None, DUMMY_SP, - PathKind::Crate, dep_kind) - .unwrap_or_else(|err| err.report()); - - // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime - if !data.root.sanitizer_runtime { - self.sess.err(&format!("the crate `{}` is not a sanitizer runtime", - name)); - } - } else { - self.sess.err("Must link std to be compiled with `-Z sanitizer`"); + let symbol = Symbol::intern(name); + let dep_kind = DepKind::Implicit; + let (cnum, data) = + self.resolve_crate(&None, symbol, symbol, None, None, DUMMY_SP, + PathKind::Crate, dep_kind) + .unwrap_or_else(|err| err.report()); + + // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime + if !data.root.sanitizer_runtime { + self.sess.err(&format!("the crate `{}` is not a sanitizer runtime", + name)); } + self.sess.injected_sanitizer_runtime.set(Some(cnum)); + } else { + self.sess.err("Must link std to be compiled with `-Z sanitizer`"); } } diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 5334c4dfc68cc..6a7420b31cde2 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -42,6 +42,7 @@ rand = "0.6.1" [target.x86_64-apple-darwin.dependencies] rustc_asan = { path = "../librustc_asan" } +rustc_lsan = { path = "../librustc_lsan" } rustc_tsan = { path = "../librustc_tsan" } [target.x86_64-unknown-linux-gnu.dependencies] diff --git a/src/test/run-make-fulldeps/sanitizer-address/Makefile b/src/test/run-make-fulldeps/sanitizer-address/Makefile index 51d8a4a947adc..4c556a069b3ae 100644 --- a/src/test/run-make-fulldeps/sanitizer-address/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-address/Makefile @@ -5,12 +5,7 @@ LOG := $(TMPDIR)/log.txt # NOTE the address sanitizer only supports x86_64 linux and macOS - -ifeq ($(TARGET),x86_64-apple-darwin) -EXTRA_RUSTFLAG=-C rpath -else ifeq ($(TARGET),x86_64-unknown-linux-gnu) - # Apparently there are very specific Linux kernels, notably the one that's # currently on Travis CI, which contain a buggy commit that triggers failures in # the ASan implementation, detailed at google/sanitizers#837. As noted in @@ -20,7 +15,6 @@ ifeq ($(TARGET),x86_64-unknown-linux-gnu) # flags again. EXTRA_RUSTFLAG=-C relocation-model=dynamic-no-pic endif -endif all: $(RUSTC) -g -Z sanitizer=address -Z print-link-args $(EXTRA_RUSTFLAG) overflow.rs | $(CGREP) librustc_asan diff --git a/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/Makefile b/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/Makefile new file mode 100644 index 0000000000000..99ccaa7ae9768 --- /dev/null +++ b/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/Makefile @@ -0,0 +1,20 @@ +# needs-sanitizer-support +# only-x86_64 +-include ../tools.mk + +ifeq ($(TARGET),x86_64-apple-darwin) +# sanitizers are always built as dylibs on osx +EXTRACFLAGS=-L$(TARGET_RPATH_DIR) -l__rustc__clang_rt.asan_osx_dynamic +LD_LIBRARY_PATH="$(TARGET_RPATH_DIR):$(TMPDIR)" +else +LD_LIBRARY_PATH=$(TMPDIR) +endif + +# This test builds a staticlib, then an executable that links to it. +# The staticlib is compiled with address sanitizer, and we assert that a fault +# in the staticlib is correctly detected. + +all: + $(RUSTC) -g -Z sanitizer=address --crate-type staticlib --target $(TARGET) library.rs + $(CC) program.c $(call STATICLIB,library) $(call OUT_EXE,program) $(EXTRACFLAGS) $(EXTRACXXFLAGS) + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) $(TMPDIR)/program 2>&1 | $(CGREP) stack-buffer-overflow diff --git a/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/library.rs b/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/library.rs new file mode 100644 index 0000000000000..bf11553ea6b17 --- /dev/null +++ b/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/library.rs @@ -0,0 +1,5 @@ +#[no_mangle] +pub extern fn overflow() { + let xs = [0, 1, 2, 3]; + let _y = unsafe { *xs.as_ptr().offset(4) }; +} diff --git a/src/test/run-make-fulldeps/sanitizer-staticlib-link/program.c b/src/test/run-make-fulldeps/sanitizer-c-staticlib-link/program.c similarity index 100% rename from src/test/run-make-fulldeps/sanitizer-staticlib-link/program.c rename to src/test/run-make-fulldeps/sanitizer-c-staticlib-link/program.c diff --git a/src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile b/src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile index 35317dca1e824..b228bc0a7a0b5 100644 --- a/src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile @@ -1,6 +1,5 @@ # needs-sanitizer-support # only-x86_64 -# only-linux -include ../tools.mk @@ -12,7 +11,9 @@ LOG := $(TMPDIR)/log.txt # is correctly detected. # See comment in sanitizer-address/Makefile for why this is here +ifeq ($(TARGET),x86_64-unknown-linux-gnu) EXTRA_RUSTFLAG=-C relocation-model=dynamic-no-pic +endif all: $(RUSTC) -g -Z sanitizer=address --crate-type cdylib --target $(TARGET) $(EXTRA_RUSTFLAG) library.rs diff --git a/src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile b/src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile index 24d2ebd8f48aa..f77524da5c57c 100644 --- a/src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile @@ -1,6 +1,5 @@ # needs-sanitizer-support # only-x86_64 -# only-linux -include ../tools.mk @@ -12,7 +11,9 @@ LOG := $(TMPDIR)/log.txt # is correctly detected. # See comment in sanitizer-address/Makefile for why this is here +ifeq ($(TARGET),x86_64-unknown-linux-gnu) EXTRA_RUSTFLAG=-C relocation-model=dynamic-no-pic +endif all: $(RUSTC) -g -Z sanitizer=address --crate-type dylib --target $(TARGET) $(EXTRA_RUSTFLAG) library.rs diff --git a/src/test/run-make-fulldeps/sanitizer-invalid-cratetype/Makefile b/src/test/run-make-fulldeps/sanitizer-invalid-cratetype/Makefile index 9581ac565ea02..637ba0dabd867 100644 --- a/src/test/run-make-fulldeps/sanitizer-invalid-cratetype/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-invalid-cratetype/Makefile @@ -3,14 +3,9 @@ -include ../tools.mk # NOTE the address sanitizer only supports x86_64 linux and macOS - -ifeq ($(TARGET),x86_64-apple-darwin) -EXTRA_RUSTFLAG=-C rpath -else ifeq ($(TARGET),x86_64-unknown-linux-gnu) EXTRA_RUSTFLAG= endif -endif all: $(RUSTC) -Z sanitizer=address --crate-type proc-macro --target $(TARGET) hello.rs 2>&1 | $(CGREP) '-Z sanitizer' diff --git a/src/test/run-make-fulldeps/sanitizer-invalid-target/Makefile b/src/test/run-make-fulldeps/sanitizer-invalid-target/Makefile index df8afee15ce07..2a23f0fe3d4ef 100644 --- a/src/test/run-make-fulldeps/sanitizer-invalid-target/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-invalid-target/Makefile @@ -2,4 +2,4 @@ all: $(RUSTC) -Z sanitizer=leak --target i686-unknown-linux-gnu hello.rs 2>&1 | \ - $(CGREP) 'LeakSanitizer only works with the `x86_64-unknown-linux-gnu` target' + $(CGREP) 'LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target' diff --git a/src/test/run-make-fulldeps/sanitizer-leak/Makefile b/src/test/run-make-fulldeps/sanitizer-leak/Makefile index 101e8272ab91e..0591f0a6da94b 100644 --- a/src/test/run-make-fulldeps/sanitizer-leak/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-leak/Makefile @@ -1,10 +1,7 @@ -include ../tools.mk # needs-sanitizer-support -# only-linux # only-x86_64 -# ignore-test -# FIXME(#46126) ThinLTO for libstd broke this test all: $(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) librustc_lsan diff --git a/src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile b/src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile index 200dc1be4dee6..94ac6faa2dfb9 100644 --- a/src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile @@ -1,15 +1,12 @@ # needs-sanitizer-support # only-x86_64 -# only-linux - -include ../tools.mk # This test builds a staticlib, then an executable that links to it. -# The staticlib and executable both are compiled with address sanitizer, -# and we assert that a fault in the staticlib is correctly detected. +# The staticlib and executable are compiled with address sanitizer, and we +# assert that a fault in the staticlib is correctly detected. all: $(RUSTC) -g -Z sanitizer=address --crate-type staticlib --target $(TARGET) library.rs - $(CC) program.c $(call STATICLIB,library) $(call OUT_EXE,program) $(EXTRACFLAGS) $(EXTRACXXFLAGS) + $(RUSTC) -g -Z sanitizer=address --crate-type bin --target $(TARGET) $(EXTRA_RUSTFLAG) -llibrary program.rs LD_LIBRARY_PATH=$(TMPDIR) $(TMPDIR)/program 2>&1 | $(CGREP) stack-buffer-overflow - diff --git a/src/test/run-make-fulldeps/sanitizer-staticlib-link/program.rs b/src/test/run-make-fulldeps/sanitizer-staticlib-link/program.rs new file mode 100644 index 0000000000000..3bbbcd9c6f8e6 --- /dev/null +++ b/src/test/run-make-fulldeps/sanitizer-staticlib-link/program.rs @@ -0,0 +1,7 @@ +extern { + fn overflow(); +} + +fn main() { + unsafe { overflow() } +} From b89e8520fc74b0a545c187dc16681974dd8983b8 Mon Sep 17 00:00:00 2001 From: tyler Date: Mon, 15 Jul 2019 12:27:30 -0700 Subject: [PATCH 2/4] report an error when building proc-macro crates with sanitizers. some changes to control flow for readability --- src/librustc_metadata/creader.rs | 61 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index d3148f0f4ff71..9702bd7f8d2a1 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -803,38 +803,55 @@ impl<'a> CrateLoader<'a> { return } + let any_unsupported = self.sess.crate_types.borrow().iter().any(|ct| { + match *ct { + config::CrateType::Executable | + config::CrateType::Staticlib | + config::CrateType::Cdylib | + config::CrateType::Dylib | + config::CrateType::Rlib => false, + _ => true, + } + }); + if any_unsupported { + self.sess.err("Only executables, staticlibs, cdylibs, dylibs and rlibs can be compiled \ + with `-Z sanitizer`"); + self.sess.injected_sanitizer_runtime.set(None); + return + } + let mut uses_std = false; self.cstore.iter_crate_data(|_, data| { if data.name == sym::std { uses_std = true; } }); + if !uses_std { + self.sess.err("Must link std to be compiled with `-Z sanitizer`"); + return + } - if uses_std { - let name = match *sanitizer { - Sanitizer::Address => "rustc_asan", - Sanitizer::Leak => "rustc_lsan", - Sanitizer::Memory => "rustc_msan", - Sanitizer::Thread => "rustc_tsan", - }; - info!("loading sanitizer: {}", name); + let name = match *sanitizer { + Sanitizer::Address => "rustc_asan", + Sanitizer::Leak => "rustc_lsan", + Sanitizer::Memory => "rustc_msan", + Sanitizer::Thread => "rustc_tsan", + }; + info!("loading sanitizer: {}", name); - let symbol = Symbol::intern(name); - let dep_kind = DepKind::Implicit; - let (cnum, data) = - self.resolve_crate(&None, symbol, symbol, None, None, DUMMY_SP, - PathKind::Crate, dep_kind) - .unwrap_or_else(|err| err.report()); + let symbol = Symbol::intern(name); + let dep_kind = DepKind::Implicit; + let (cnum, data) = + self.resolve_crate(&None, symbol, symbol, None, None, DUMMY_SP, + PathKind::Crate, dep_kind) + .unwrap_or_else(|err| err.report()); - // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime - if !data.root.sanitizer_runtime { - self.sess.err(&format!("the crate `{}` is not a sanitizer runtime", - name)); - } - self.sess.injected_sanitizer_runtime.set(Some(cnum)); - } else { - self.sess.err("Must link std to be compiled with `-Z sanitizer`"); + // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime + if !data.root.sanitizer_runtime { + self.sess.err(&format!("the crate `{}` is not a sanitizer runtime", + name)); } + self.sess.injected_sanitizer_runtime.set(Some(cnum)); } fn inject_profiler_runtime(&mut self) { From f33875dfa3c3e22ac382e57401b7ce70abaae994 Mon Sep 17 00:00:00 2001 From: tyler Date: Mon, 29 Jul 2019 12:08:59 -0700 Subject: [PATCH 3/4] slight tweak to sanitizer target detection --- src/librustc_metadata/creader.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 9702bd7f8d2a1..69b939a1f5210 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -803,17 +803,17 @@ impl<'a> CrateLoader<'a> { return } - let any_unsupported = self.sess.crate_types.borrow().iter().any(|ct| { + let all_supported = self.sess.crate_types.borrow().iter().all(|ct| { match *ct { config::CrateType::Executable | config::CrateType::Staticlib | config::CrateType::Cdylib | config::CrateType::Dylib | - config::CrateType::Rlib => false, - _ => true, + config::CrateType::Rlib => true, + _ => false, } }); - if any_unsupported { + if !all_supported { self.sess.err("Only executables, staticlibs, cdylibs, dylibs and rlibs can be compiled \ with `-Z sanitizer`"); self.sess.injected_sanitizer_runtime.set(None); From e85a37e8cd841c60d40a2fd4164c7002a0bd18b4 Mon Sep 17 00:00:00 2001 From: tyler Date: Sun, 11 Aug 2019 09:08:06 -0700 Subject: [PATCH 4/4] [tmp] change azure config to test this pr --- src/ci/azure-pipelines/pr.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ci/azure-pipelines/pr.yml b/src/ci/azure-pipelines/pr.yml index 62e23efe1ef16..a0880f33d5cad 100644 --- a/src/ci/azure-pipelines/pr.yml +++ b/src/ci/azure-pipelines/pr.yml @@ -18,10 +18,8 @@ jobs: - template: steps/run.yml strategy: matrix: - x86_64-gnu-llvm-6.0: - IMAGE: x86_64-gnu-llvm-6.0 - mingw-check: - IMAGE: mingw-check + x86_64-gnu: + IMAGE: x86_64-gnu - job: LinuxTools timeoutInMinutes: 600