Stream: wasmtime

Topic: ISA-safety of precompiled modules


view this post on Zulip Simonas (nagisa) (Sep 25 2025 at 15:10):

(relatively related ref: #wasmtime > Selecting Cranelift ISA in wasmtime::Config)

I have a couple of questions with regards to module precompilation and CPU feature detection. I can see that precompiled+serialized modules hash to different values between my local machine and what's generated on the CI, and in my mind the most likely cause is the auto-detection of host cpu features. Host CPU feature detection is actually somewhat a desired behaviour for me, I want the generated code to run as fast as the hardware allows. At the same time, though, I save these precompiled modules onto a disk with a hash (of certain input information such as hash of wasm code) for a name. And the system should continue working correctly if these files are made available on a different machine with a different set of CPU features.

This means that I need to mix into the filename hash additional information that can affect the validity of the modules, and I need to do so from the information that's available with an Engine (or anything that leads to it.) I see that cranelift's flags struct(s) have a hashing function, but I can't find any API at wasmtime level to obtain the hash or, alternatively, relevant hashable structures. Is there perhaps a straightforward API I'm missing here?

view this post on Zulip Simonas (nagisa) (Sep 25 2025 at 15:11):

A side question is: does anybody know off top of their heads what would happen if a precompiled module that was compiled with, say, AVX512, were to be loaded on a machine without it? SIGILL? An instantiation-time result? Something else?

view this post on Zulip Alex Crichton (Sep 25 2025 at 19:48):

We check enabled features at compile time are also available at runtime when a module is loaded -- https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/src/config.rs#L3705 which if I understand right means that if you load a precompiled module with more features than the host platform some sort of error should pop out. That's the intention at least and this has grown over time so it may not be bulletproof necessarily, so if you notice an issue let us know!

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Alex Crichton (Sep 25 2025 at 19:50):

For hashing does this work? https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/src/engine.rs#L819

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Alex Crichton (Sep 25 2025 at 19:50):

IIRC that contains compiler flags enabled but I am also on a phone so can't say for certain

view this post on Zulip Simonas (nagisa) (Sep 25 2025 at 22:09):

Thank you, yeah I'll look into it. For some reason I didn't see when scrolling through Engine's API earlier today :sweat_smile:


Last updated: Dec 06 2025 at 06:05 UTC