diff options
| author | bors <bors@rust-lang.org> | 2019-05-02 07:38:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-02 07:38:36 +0000 |
| commit | 758dc9af504e2fe75813bd362619231ecc727898 (patch) | |
| tree | bba5214e3fd0edcb1e6503afcfcba8f5d93dc5f2 | |
| parent | 92b5e20ad59b183a2e6cd79423f54b8aa7ac9cbf (diff) | |
| parent | 16ad9777b8afd3991b4501e602a04e5e40214b56 (diff) | |
| download | rust-758dc9af504e2fe75813bd362619231ecc727898.tar.gz rust-758dc9af504e2fe75813bd362619231ecc727898.zip | |
Auto merge of #60156 - RalfJung:macos-rand, r=oli-obk,alexcrichton
use SecRandomCopyBytes on macOS in Miri This is a hack to fix https://github.com/rust-lang/miri/issues/686: on macOS, rustc will open `/dev/urandom` to initialize a `HashMap`. That's quite hard to emulate properly in Miri without a full-blown implementation of file descriptors. However, Miri needs an implementation of `SecRandomCopyBytes` anyway to support [getrandom](https://crates.io/crates/getrandom), so using it here should work just as well. This will only have an effect when libstd is compiled specifically for Miri, but that will generally be the case when people use `cargo miri`. This is clearly a hack, so I am opening this to start a discussion about whether we are okay with such a hack or not. Cc @oli-obk
| -rw-r--r-- | src/bootstrap/bin/rustc.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/rand.rs | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 50d170b8a88..821c37dc235 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" { 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; |
