bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.08k stars 1.26k forks source link

Trying to run MIRI on MacOS #7936

Closed rookieCookies closed 6 months ago

rookieCookies commented 6 months ago

Steps to Reproduce

Expected Results

Miri compiles and runs successfully

Actual Results

Failed to compile because of something inside the crate itself. I looked into the module traphandlers and sure enough there is no function named that

error[E0425]: cannot find function `using_mach_ports` in module `traphandlers`
  --> /Users/macbook/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-runtime-17.0.1/src/traphandlers.rs:52:23
   |
52 |         traphandlers::using_mach_ports(),
   |                       ^^^^^^^^^^^^^^^^ not found in `traphandlers`

For more information about this error, try `rustc --explain E0425`.

Versions and Environment

Wasmtime version or commit: 17.0.1

Operating system: MacOS

Architecture: ARM

bjorn3 commented 6 months ago

Miri is unable to interpret jitted code, so even if this compile error is fixed, you still wouldn't be able to run wasm modules using wasmtime inside miri. It should be possible to compile wasm modules without actually running them though once this error is fixed.

rookieCookies commented 6 months ago

It should be possible to compile wasm modules without actually running them though once this error is fixed.

Why? Can't it run in interpret-only mode?

cfallin commented 6 months ago

Why? Can't it run in interpret-only mode?

Wasmtime doesn't have an interpreter tier, unfortunately; all Wasm execution depends on running native code generated by Cranelift.

rookieCookies commented 6 months ago

Wasmtime doesn't have an interpreter tier, unfortunately; all Wasm execution depends on running native code generated by Cranelift. Ahh, seriously? Bit unrelated to the PR but do you know of any way I can miri wasm?

bjorn3 commented 6 months ago

If you want to run miri on some code you want to compile to wasm, you did have to use cargo miri run --target wasm32-wasi instead of cargo run --target wasm32-wasi. Miri currently doesn't support wasi though afaik. You can't run miri on a wasm module. Miri can only run the MIR intermediate representation of rustc. After compilation to wasm only something like valgrind which uses dynamic instrumentation and heuristics about the source language is possible. It just so happens that wasmtime already has support for something like this behind the -W wmemcheck flag: https://github.com/bytecodealliance/wasmtime/blob/main/docs/wmemcheck.md You will need to recompile wasmtime with the wmemcheck cargo feature enable for this and as I said it uses heuristics and doesn't catch all UB something like miri would catch. For example violations of the stacked borrows rules or invalid values are not catched.