Skip to content

Commit 5748d79

Browse files
committed
Auto merge of #3554 - RalfJung:freebsd, r=RalfJung
document unofficially supported OSes Also tweak the freeBSD testing a bit.
2 parents 58efad4 + 99c5151 commit 5748d79

File tree

10 files changed

+34
-33
lines changed

10 files changed

+34
-33
lines changed

src/tools/miri/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ degree documented below):
224224
- `s390x-unknown-linux-gnu` is supported as our "big-endian target of choice".
225225
- For every other target with OS `linux`, `macos`, or `windows`, Miri should generally work, but we
226226
make no promises and we don't run tests for such targets.
227-
- For targets on other operating systems, even basic operations such as printing to the standard
228-
output might not work, and Miri might fail before even reaching the `main` function.
227+
- We have unofficial support (not maintained by the Miri team itself) for some further operating systems.
228+
- `freebsd`: **maintainer wanted**. Supports `std::env` and parts of `std::{thread, fs}`, but not `std::sync`.
229+
- `android`: **maintainer wanted**. Support very incomplete, but a basic "hello world" works.
230+
- `wasm`: **maintainer wanted**. Support very incomplete, not even standard output works, but an empty `main` function works.
231+
- For targets on other operating systems, Miri might fail before even reaching the `main` function.
229232

230233
However, even for targets that we do support, the degree of support for accessing platform APIs
231234
(such as the file system) differs between targets: generally, Linux targets have the best support,

src/tools/miri/ci/ci.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ case $HOST_TARGET in
141141
MIRI_TEST_TARGET=arm-unknown-linux-gnueabi run_tests
142142
MIRI_TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
143143
# Partially supported targets (tier 2)
144-
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
145-
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
146-
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
147-
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings wasm
148-
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings wasm
144+
VERY_BASIC="integer vec string btreemap" # common things we test on all of them (if they have std), requires no target-specific shims
145+
BASIC="$VERY_BASIC hello hashmap alloc align" # ensures we have the shims for stdout and basic data structures
146+
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-getentropy libc-getrandom libc-misc fs env num_cpus
147+
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-getentropy libc-getrandom libc-misc fs env num_cpus
148+
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
149+
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
150+
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
149151
MIRI_TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
150152
# Custom target JSON file
151153
MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std

src/tools/miri/src/shims/unix/freebsd/foreign_items.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4747
this.read_scalar(len)?,
4848
)?;
4949
}
50-
"getrandom" => {
51-
let [ptr, len, flags] =
52-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
53-
let ptr = this.read_pointer(ptr)?;
54-
let len = this.read_target_usize(len)?;
55-
let _flags = this.read_scalar(flags)?.to_i32()?;
56-
// flags on freebsd does not really matter
57-
// in practice, GRND_RANDOM does not particularly draw from /dev/random
58-
// since it is the same as to /dev/urandom.
59-
// GRND_INSECURE is only an alias of GRND_NONBLOCK, which
60-
// does not affect the RNG.
61-
// https://man.freebsd.org/cgi/man.cgi?query=getrandom&sektion=2&n=1
62-
this.gen_random(ptr, len)?;
63-
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
64-
}
6550

6651
// File related shims
6752
// For those, we both intercept `func` and `call@FBSD_1.0` symbols cases
@@ -90,7 +75,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9075
this.write_scalar(result, dest)?;
9176
}
9277

93-
// errno
78+
// Miscellaneous
79+
"getrandom" => {
80+
let [ptr, len, flags] =
81+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
82+
let ptr = this.read_pointer(ptr)?;
83+
let len = this.read_target_usize(len)?;
84+
let _flags = this.read_scalar(flags)?.to_i32()?;
85+
// flags on freebsd does not really matter
86+
// in practice, GRND_RANDOM does not particularly draw from /dev/random
87+
// since it is the same as to /dev/urandom.
88+
// GRND_INSECURE is only an alias of GRND_NONBLOCK, which
89+
// does not affect the RNG.
90+
// https://man.freebsd.org/cgi/man.cgi?query=getrandom&sektion=2&n=1
91+
this.gen_random(ptr, len)?;
92+
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
93+
}
9494
"__error" => {
9595
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
9696
let errno_place = this.last_error_place()?;

src/tools/miri/tests/pass/align_offset_symbolic.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ fn test_from_utf8() {
6262
const N: usize = 10;
6363
let vec = vec![0x4141414141414141u64; N];
6464
let content = unsafe { std::slice::from_raw_parts(vec.as_ptr() as *const u8, 8 * N) };
65-
println!("{:?}", std::str::from_utf8(content).unwrap());
65+
assert_eq!(
66+
std::str::from_utf8(content).unwrap(),
67+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
68+
);
6669
}
6770

6871
fn test_u64_array() {

src/tools/miri/tests/pass/align_offset_symbolic.stdout

-1
This file was deleted.

src/tools/miri/tests/pass/vecdeque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ fn main() {
3131
}
3232

3333
// Regression test for Debug impl's
34-
println!("{:?} {:?}", dst, dst.iter());
35-
println!("{:?}", VecDeque::<u32>::new().iter());
34+
format!("{:?} {:?}", dst, dst.iter());
35+
format!("{:?}", VecDeque::<u32>::new().iter());
3636

3737
for a in dst {
3838
assert_eq!(*a, 2);

src/tools/miri/tests/pass/vecdeque.stack.stdout

-2
This file was deleted.

src/tools/miri/tests/pass/vecdeque.tree.stdout

-2
This file was deleted.

src/tools/miri/tests/pass/vecdeque.tree_uniq.stdout

-2
This file was deleted.

0 commit comments

Comments
 (0)