From 91f0b28ecc780f291ed716c9126719b0f3110f92 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Fri, 30 Nov 2018 17:05:37 +0100 Subject: [PATCH 1/3] Skip testing targets that don't ship libstd --- tests/compiletest.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 7aa55ef66340..859890aba9f2 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -124,16 +124,33 @@ fn is_target_dir>(path: P) -> bool { path.metadata().map(|m| m.is_dir()).unwrap_or(false) } -fn for_all_targets(sysroot: &Path, mut f: F) { +fn target_has_std>(path: P) -> bool { + let mut path = path.into(); + path.push("lib"); + std::fs::read_dir(path) + .expect("invalid target") + .map(|entry| entry.unwrap()) + .filter(|entry| entry.file_type().unwrap().is_file()) + .filter_map(|entry| entry.file_name().into_string().ok()) + .any(|file_name| file_name.starts_with("libstd") && file_name.ends_with(".rlib")) +} + + +fn for_all_targets(sysroot: &Path, f: F) { let target_dir = sysroot.join("lib").join("rustlib"); - for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") { - let entry = entry.unwrap(); - if !is_target_dir(entry.path()) { - continue; - } - let target = entry.file_name().into_string().unwrap(); - f(target); + let mut targets = std::fs::read_dir(target_dir) + .expect("invalid sysroot") + .map(|entry| entry.unwrap()) + .filter(|entry| is_target_dir(entry.path())) + .filter(|entry| target_has_std(entry.path())) + .map(|entry| entry.file_name().into_string().unwrap()) + .peekable(); + + if targets.peek().is_none() { + panic!("No valid targets found"); } + + targets.for_each(f); } fn get_sysroot() -> PathBuf { From e12d4bc70c018e366e0ac896f60b456019e63986 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 2 Dec 2018 14:03:29 +0100 Subject: [PATCH 2/3] build libstd with minimal features --- src/bin/cargo-miri.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 4c83c5bd3dc0..2dc6eee5de9d 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -155,6 +155,9 @@ fn setup(ask_user: bool) { File::create(dir.join("Xargo.toml")).unwrap() .write_all(br#" [dependencies.std] +default_features = false +# We need the `panic_unwind` feature because we use the `unwind` panic strategy. +# Using `abort` works for libstd, but then libtest will not compile. features = ["panic_unwind"] [dependencies.test] From 6df89de68a21f538173fa833f5965ac4d5da7f23 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 2 Dec 2018 17:18:25 +0100 Subject: [PATCH 3/3] we don't need no whitelist --- src/lib.rs | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9739a7a95b6d..ec4e621a24a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -310,26 +310,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { const STATIC_KIND: Option = Some(MiriMemoryKind::MutStatic); + #[inline(always)] fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool { - if !ecx.machine.validate { - return false; - } - - // Some functions are whitelisted until we figure out how to fix them. - // We walk up the stack a few frames to also cover their callees. - const WHITELIST: &[(&str, &str)] = &[ - // Uses mem::uninitialized - ("std::sys::windows::mutex::Mutex::", ""), - ]; - for frame in ecx.stack().iter() - .rev().take(3) - { - let name = frame.instance.to_string(); - if WHITELIST.iter().any(|(prefix, suffix)| name.starts_with(prefix) && name.ends_with(suffix)) { - return false; - } - } - true + ecx.machine.validate } /// Returns Ok() when the function was handled, fail otherwise