From b5057d89b2872be433072096e4fa40dfad856ea0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 29 Jan 2024 17:17:46 -0600 Subject: [PATCH] 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. --- crates/cranelift/src/func_environ.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index 4e92de21e4..9ae547b9cb 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/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();