Fix a panic with Func::new and reference types (#2039)

Currently `Func::new` will panic if one of the arguments of the function
is a reference type and the `Store` doesn't have reference types
enabled. This happens because cranelift isn't configure to enable stack
maps but the register allocators expects them to exist when reference
types are seen.

The fix here is to always enable reference types in cranelift for our
trampoline generation and `Func::new`. This should hopefully ensure that
trampolines are generated correctly and they'll just not be able to get
hooked up to an `Instance` because validation will prevent reference
types from being used elsewhere.
This commit is contained in:
Alex Crichton
2020-07-17 12:05:42 -05:00
committed by GitHub
parent 8dd4ab2f1e
commit c3ff0754d4
3 changed files with 25 additions and 1 deletions

View File

@@ -206,7 +206,10 @@ pub fn create_handle_with_function(
func: Box<dyn Fn(*mut VMContext, *mut u128) -> Result<(), Trap>>,
store: &Store,
) -> Result<(StoreInstanceHandle, VMTrampoline)> {
let isa = store.engine().config().target_isa();
// Note that we specifically enable reference types here in our ISA because
// `Func::new` is intended to be infallible, but our signature may use
// reference types which requires safepoints.
let isa = store.engine().config().target_isa_with_reference_types();
let pointer_type = isa.pointer_type();
let sig = ft.get_wasmtime_signature(pointer_type);