Skip to content

Commit ffd12f6

Browse files
committed
Auto merge of #2798 - LevitatingLion:master, r=oli-obk
Get Miri working on ARM - Add a shim for `llvm.arm.hint`, which is required by `core::hint::spin_loop` on `arm` targets. The shim simply calls `yield_active_thread` on a YIELD hint, just like the shim for `llvm.aarch64.isb` that's already present. - Change the signature of `miri_host_to_target_path` to use `c_char` instead of `i8`, to make it compatible with `CStr` on targets where `c_char` is unsigned. The implementation of `miri_host_to_target_path` accesses the memory as bytes and does not need to be adjusted. - Enable ARM targets in CI. Specifically, `aarch64-unknown-linux-gnu` and `arm-unknown-linux-gnueabi` on the Linux host. Since all tests also pass for `aarch64-unknown-linux-gnu` I took the liberty of adding that target to CI as well. Fixes #2791
2 parents 81490e1 + 9cb27d2 commit ffd12f6

File tree

9 files changed

+46
-17
lines changed

9 files changed

+46
-17
lines changed

src/tools/miri/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ degree documented below):
213213
- The best-supported target is `x86_64-unknown-linux-gnu`. Miri releases are
214214
blocked on things working with this target. Most other Linux targets should
215215
also work well; we do run the test suite on `i686-unknown-linux-gnu` as a
216-
32bit target and `mips64-unknown-linux-gnuabi64` as a big-endian target.
216+
32bit target and `mips64-unknown-linux-gnuabi64` as a big-endian target, as
217+
well as the ARM targets `aarch64-unknown-linux-gnu` and
218+
`arm-unknown-linux-gnueabi`.
217219
- `x86_64-apple-darwin` should work basically as well as Linux. We also test
218220
`aarch64-apple-darwin`. However, we might ship Miri with a nightly even when
219221
some features on these targets regress.
@@ -590,7 +592,7 @@ extern "Rust" {
590592
/// `out` must point to at least `out_size` many bytes, and the result will be stored there
591593
/// with a null terminator.
592594
/// Returns 0 if the `out` buffer was large enough, and the required size otherwise.
593-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
595+
fn miri_host_to_target_path(path: *const std::ffi::c_char, out: *mut std::ffi::c_char, out_size: usize) -> usize;
594596
}
595597
```
596598

src/tools/miri/ci.sh

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ run_tests
104104
case $HOST_TARGET in
105105
x86_64-unknown-linux-gnu)
106106
MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
107+
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
107108
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
108109
MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
109110
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple atomic data_race env/var
@@ -118,6 +119,7 @@ case $HOST_TARGET in
118119
MIRI_TEST_TARGET=x86_64-pc-windows-msvc run_tests
119120
;;
120121
i686-pc-windows-msvc)
122+
MIRI_TEST_TARGET=arm-unknown-linux-gnueabi run_tests
121123
MIRI_TEST_TARGET=x86_64-unknown-linux-gnu run_tests
122124
MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
123125
;;

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

+13
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
885885
}
886886
}
887887
}
888+
"llvm.arm.hint" if this.tcx.sess.target.arch == "arm" => {
889+
let [arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
890+
let arg = this.read_scalar(arg)?.to_i32()?;
891+
match arg {
892+
// YIELD
893+
1 => {
894+
this.yield_active_thread();
895+
}
896+
_ => {
897+
throw_unsup_format!("unsupported llvm.arm.hint argument {}", arg);
898+
}
899+
}
900+
}
888901

889902
// Platform-specific shims
890903
_ =>

src/tools/miri/test-cargo-miri/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ fn main() {
2323
// (We rely on the test runner to always disable isolation when passing no arguments.)
2424
if std::env::args().len() <= 1 {
2525
fn host_to_target_path(path: String) -> PathBuf {
26-
use std::ffi::{CStr, CString};
26+
use std::ffi::{c_char, CStr, CString};
2727

2828
let path = CString::new(path).unwrap();
2929
let mut out = Vec::with_capacity(1024);
3030

3131
unsafe {
3232
extern "Rust" {
3333
fn miri_host_to_target_path(
34-
path: *const i8,
35-
out: *mut i8,
34+
path: *const c_char,
35+
out: *mut c_char,
3636
out_size: usize,
3737
) -> usize;
3838
}

src/tools/miri/test-cargo-miri/subcrate/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ fn main() {
55
println!("subcrate running");
66

77
fn host_to_target_path(path: String) -> PathBuf {
8-
use std::ffi::{CStr, CString};
8+
use std::ffi::{c_char, CStr, CString};
99

1010
let path = CString::new(path).unwrap();
1111
let mut out = Vec::with_capacity(1024);
1212

1313
unsafe {
1414
extern "Rust" {
1515
fn miri_host_to_target_path(
16-
path: *const i8,
17-
out: *mut i8,
16+
path: *const c_char,
17+
out: *mut c_char,
1818
out_size: usize,
1919
) -> usize;
2020
}

src/tools/miri/test-cargo-miri/subcrate/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ fn main() {
88
println!("subcrate testing");
99

1010
fn host_to_target_path(path: String) -> PathBuf {
11-
use std::ffi::{CStr, CString};
11+
use std::ffi::{c_char, CStr, CString};
1212

1313
let path = CString::new(path).unwrap();
1414
let mut out = Vec::with_capacity(1024);
1515

1616
unsafe {
1717
extern "Rust" {
1818
fn miri_host_to_target_path(
19-
path: *const i8,
20-
out: *mut i8,
19+
path: *const c_char,
20+
out: *mut c_char,
2121
out_size: usize,
2222
) -> usize;
2323
}

src/tools/miri/tests/pass-dep/shims/libc-fs.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(io_error_uncategorized)]
66

77
use std::convert::TryInto;
8-
use std::ffi::{CStr, CString};
8+
use std::ffi::{c_char, CStr, CString};
99
use std::fs::{canonicalize, remove_dir_all, remove_file, File};
1010
use std::io::{Error, ErrorKind, Write};
1111
use std::os::unix::ffi::OsStrExt;
@@ -31,7 +31,11 @@ fn tmp() -> PathBuf {
3131

3232
unsafe {
3333
extern "Rust" {
34-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
34+
fn miri_host_to_target_path(
35+
path: *const c_char,
36+
out: *mut c_char,
37+
out_size: usize,
38+
) -> usize;
3539
}
3640
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
3741
assert_eq!(ret, 0);

src/tools/miri/tests/pass-dep/shims/libc-misc.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::os::unix::io::AsRawFd;
77
use std::path::PathBuf;
88

99
fn tmp() -> PathBuf {
10-
use std::ffi::{CStr, CString};
10+
use std::ffi::{c_char, CStr, CString};
1111

1212
let path = std::env::var("MIRI_TEMP")
1313
.unwrap_or_else(|_| std::env::temp_dir().into_os_string().into_string().unwrap());
@@ -17,7 +17,11 @@ fn tmp() -> PathBuf {
1717

1818
unsafe {
1919
extern "Rust" {
20-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
20+
fn miri_host_to_target_path(
21+
path: *const c_char,
22+
out: *mut c_char,
23+
out_size: usize,
24+
) -> usize;
2125
}
2226
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
2327
assert_eq!(ret, 0);

src/tools/miri/tests/pass/shims/fs.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![feature(is_terminal)]
77

88
use std::collections::HashMap;
9-
use std::ffi::OsString;
9+
use std::ffi::{c_char, OsString};
1010
use std::fs::{
1111
canonicalize, create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename,
1212
File, OpenOptions,
@@ -39,7 +39,11 @@ fn host_to_target_path(path: String) -> PathBuf {
3939

4040
unsafe {
4141
extern "Rust" {
42-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
42+
fn miri_host_to_target_path(
43+
path: *const c_char,
44+
out: *mut c_char,
45+
out_size: usize,
46+
) -> usize;
4347
}
4448
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
4549
assert_eq!(ret, 0);

0 commit comments

Comments
 (0)