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):
|
#[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 the target and cranelift_flag_set methods available even when the feature cranelift is not enabled (e.g. in runtime-only mode).
wasmtime::Config should have a setting which mandates that Engine 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.
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 whencfg(compiler):wasmtime/crates/wasmtime/src/module/serialization.rs
Lines 316 to 321 in 8023026
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::Configshould have thetargetandcranelift_flag_setmethods available even when the featurecraneliftis not enabled (e.g. in runtime-only mode).wasmtime::Configshould have a setting which mandates thatEngineconstruction 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.cfg(compiler)is not enabled.