Browse Source

Fix funcrefs cross-compiled between architectures (#7842)

Currently translation of Wasm code uses the `FUNCREF_MASK` constant
which has type `usize` but this type is not always appropriate in
cross-compiled situations. This commit fixes the usage of `FUNCREF_MASK`
by using the platform-independent value (a negative value) along with
some extra asserts and an explantation of how to update if necessary.
pull/7846/head
Alex Crichton 9 months ago
committed by GitHub
parent
commit
b5057d89b2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      crates/cranelift/src/func_environ.rs

10
crates/cranelift/src/func_environ.rs

@ -870,10 +870,12 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
let value = builder.ins().load(pointer_type, flags, table_entry_addr, 0);
// Mask off the "initialized bit". See documentation on
// FUNCREF_INIT_BIT in crates/environ/src/ref_bits.rs for more
// details.
let value_masked = builder
.ins()
.band_imm(value, Imm64::from(FUNCREF_MASK as i64));
// details. Note that `FUNCREF_MASK` has type `usize` which may not be
// appropriate for the target architecture. Right now its value is
// always -2 so assert that part doesn't change and then thread through
// -2 as the immediate.
assert_eq!(FUNCREF_MASK as isize, -2);
let value_masked = builder.ins().band_imm(value, Imm64::from(-2));
let null_block = builder.create_block();
let continuation_block = builder.create_block();

Loading…
Cancel
Save