-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Loading a compiled module into wasmtime may mean the Module was compiled on a different machine. Wasmtime does not provide a mechanism to make sure the set of flags on a compiled module is compatible with the CPU that the compiled module will be executed on.
Presently, when wasmtime loads a compiled Module
(e.g. Module::deserialize_file
), the isa flags in the loaded module are only checked when cfg(compiler)
:
wasmtime/crates/wasmtime/src/module/serialization.rs
Lines 316 to 321 in 8023026
#[cfg(compiler)] | |
{ | |
let compiler = engine.compiler(); | |
self.check_shared_flags(compiler)?; | |
self.check_isa_flags(compiler)?; | |
} |
This check doesn't even perform precisely what we want - it will determine if the Engine's flags are compatible with the loaded module, which do not necessarily match the host cpu.
So, I propose the following additions to wasmtime:
wasmtime::Config
should have thetarget
andcranelift_flag_set
methods available even when the featurecranelift
is not enabled (e.g. in runtime-only mode).wasmtime::Config
should have a setting which mandates thatEngine
construction validates those target and cranelift flags against the host cpu. This needs to be configable so that an engine Engine can be used for cross-compilation.- When loading a compiled Module, the isa flags should be checked against the Engine settings even when
cfg(compiler)
is not enabled.