From 54aefc6a2d076b74921a8d78c5d8c68c13bfa4a7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 21 Apr 2019 21:38:59 +0200 Subject: [PATCH 1/2] use SecRandomCopyBytes on macOS in Miri --- src/libstd/sys/unix/rand.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 77f1439e17b..e923b9aa29b 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -13,6 +13,7 @@ pub fn hashmap_random_keys() -> (u64, u64) { #[cfg(all(unix, not(target_os = "ios"), + not(all(target_os = "macos", miri)), not(target_os = "openbsd"), not(target_os = "freebsd"), not(target_os = "fuchsia")))] @@ -106,7 +107,9 @@ mod imp { // once per thread in `hashmap_random_keys`. Therefore `SecRandomCopyBytes` is // only used on iOS where direct access to `/dev/urandom` is blocked by the // sandbox. -#[cfg(target_os = "ios")] +// HACK: However, we do use this when running in Miri on macOS; intercepting this is much +// easier than intercepting accesses to /dev/urandom. +#[cfg(any(target_os = "ios", all(target_os = "macos", miri)))] mod imp { use crate::io; use crate::ptr; From 16ad9777b8afd3991b4501e602a04e5e40214b56 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 25 Apr 2019 18:47:36 +0200 Subject: [PATCH 2/2] when testing Miri, compile libstd for Miri --- src/bootstrap/bin/rustc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index a8f0d24ce63..383b3a3cf0a 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -262,6 +262,7 @@ fn main() { // The flags here should be kept in sync with `add_miri_default_args` // in miri's `src/lib.rs`. cmd.arg("-Zalways-encode-mir"); + cmd.arg("--cfg=miri"); // These options are preferred by miri, to be able to perform better validation, // but the bootstrap compiler might not understand them. if stage != "0" {