Description
I am thinking about what to do with dtolnay/linkme#62.
My library has a finicky platform-specific behavior that isn't necessarily reasonable for Miri to emulate, based on extern statics and link_name
/link_section
attributes. Miri currently aborts when coming across it.
test readme ... error: unsupported operation: `extern` static `BENCHMARKS::LINKME_START` from crate `example` is not supported by Miri
--> tests/example.rs:22:19
|
22 | for _bench in BENCHMARKS { /* ... */ }
| ^^^^^^^^^^ `extern` static `BENCHMARKS::LINKME_START` from crate `example` is not supported by Miri
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
= note: inside `readme` at tests/example.rs:22:19: 22:29
I'm potentially interested in using cfg(miri)
to provide a stub implementation so that Miri users can still run the rest of their program. However I'm a little hesitant about doing that silently.
What's your impression of augmenting the set of Miri extern functions to include this signature?—
#[cfg(miri)]
extern "Rust" {
fn miri_warn(msg: &str);
}
It would emit a warning in the same style as what you currently get for isolation warnings under -Zmiri-isolation-error=warn
.
warning: operation rejected by isolation
--> .rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/unix/fs.rs:990:36
|
990 | let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `open` was made to return an error due to isolation
|
= note: inside closure at .rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/unix/fs.rs:990:36: 990:84
...
= note: inside `std::fs::File::open::<&str>` at .rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/fs.rs:354:9: 354:58
note: inside `main`
--> src/main.rs:70:5
|
70 | std::fs::File::open("/nonexist").unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I could use this to inform the user and then fall back to my stub implementation which returns a default value (empty slice in my library's case).