Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Reimplement passive data segments (#13394)

Alex Crichtonf37fcc9b0cc7
diff --git a/cranelift/codegen/src/isa/pulley_shared/lower.isle b/cranelift/codegen/src/isa/pulley_shared/lower.isle
index 1b4560dca6..abbff7b49b 100644
--- a/cranelift/codegen/src/isa/pulley_shared/lower.isle
+++ b/cranelift/codegen/src/isa/pulley_shared/lower.isle
@@ -1039,35 +1039,49 @@
;; no extension. This should only be used for host-things on wasm and
;; intentionally is minimal at this time as we don't currently need to match
;; all `ExtKind` variants.
-(rule 0 (gen_xload addr offset flags ty (ExtKind.None))
+(rule 0 (gen_xload addr offset flags ty ext)
(if-let true (memflags_nontrapping flags))
(if-let (Endianness.Big) (endianness flags))
- (pulley_xload (amode addr offset) ty flags))
+ (emit_addro32_xload_be (addro32 addr offset) ty ext))
+
+(decl emit_addro32_xload_be (AddrO32 Type ExtKind) XReg)
+(rule (emit_addro32_xload_be addr $I8 ext) (emit_addro32_xload_le addr $I8 ext))
+(rule (emit_addro32_xload_be addr $I16 (ExtKind.None)) (pulley_xload16be_u32_o32 addr))
+(rule (emit_addro32_xload_be addr $I16 (ExtKind.Sign32)) (pulley_xload16be_s32_o32 addr))
+(rule (emit_addro32_xload_be addr $I16 (ExtKind.Zero32)) (pulley_xload16be_u32_o32 addr))
+(rule (emit_addro32_xload_be addr $I16 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload16be_s32_o32 addr)))
+(rule (emit_addro32_xload_be addr $I16 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload16be_u32_o32 addr)))
+(rule (emit_addro32_xload_be addr $I32 (ExtKind.None)) (pulley_xload32be_o32 addr))
+(rule (emit_addro32_xload_be addr $I32 (ExtKind.Sign32)) (pulley_xload32be_o32 addr))
+(rule (emit_addro32_xload_be addr $I32 (ExtKind.Zero32)) (pulley_xload32be_o32 addr))
+(rule (emit_addro32_xload_be addr $I32 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload32be_o32 addr)))
+(rule (emit_addro32_xload_be addr $I32 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload32be_o32 addr)))
+(rule (emit_addro32_xload_be addr $I64 _ext) (pulley_xload64be_o32 addr))
;; Base case: use `*_o32` addressing modes for little-endian and nontrapping
;; loads/stores
(rule 0 (gen_xload addr offset flags ty ext)
(if-let true (memflags_nontrapping flags))
(if-let (Endianness.Little) (endianness flags))
- (emit_addro32_xload (addro32 addr offset) ty ext))
-
-(decl emit_addro32_xload (AddrO32 Type ExtKind) XReg)
-(rule (emit_addro32_xload addr $I8 (ExtKind.None)) (pulley_xload8_u32_o32 addr))
-(rule (emit_addro32_xload addr $I8 (ExtKind.Sign32)) (pulley_xload8_s32_o32 addr))
-(rule (emit_addro32_xload addr $I8 (ExtKind.Zero32)) (pulley_xload8_u32_o32 addr))
-(rule (emit_addro32_xload addr $I8 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload8_s32_o32 addr)))
-(rule (emit_addro32_xload addr $I8 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload8_u32_o32 addr)))
-(rule (emit_addro32_xload addr $I16 (ExtKind.None)) (pulley_xload16le_u32_o32 addr))
-(rule (emit_addro32_xload addr $I16 (ExtKind.Sign32)) (pulley_xload16le_s32_o32 addr))
-(rule (emit_addro32_xload addr $I16 (ExtKind.Zero32)) (pulley_xload16le_u32_o32 addr))
-(rule (emit_addro32_xload addr $I16 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload16le_s32_o32 addr)))
-(rule (emit_addro32_xload addr $I16 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload16le_u32_o32 addr)))
-(rule (emit_addro32_xload addr $I32 (ExtKind.None)) (pulley_xload32le_o32 addr))
-(rule (emit_addro32_xload addr $I32 (ExtKind.Sign32)) (pulley_xload32le_o32 addr))
-(rule (emit_addro32_xload addr $I32 (ExtKind.Zero32)) (pulley_xload32le_o32 addr))
-(rule (emit_addro32_xload addr $I32 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload32le_o32 addr)))
-(rule (emit_addro32_xload addr $I32 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload32le_o32 addr)))
-(rule (emit_addro32_xload addr $I64 _ext) (pulley_xload64le_o32 addr))
+ (emit_addro32_xload_le (addro32 addr offset) ty ext))
+
+(decl emit_addro32_xload_le (AddrO32 Type ExtKind) XReg)
+(rule (emit_addro32_xload_le addr $I8 (ExtKind.None)) (pulley_xload8_u32_o32 addr))
+(rule (emit_addro32_xload_le addr $I8 (ExtKind.Sign32)) (pulley_xload8_s32_o32 addr))
+(rule (emit_addro32_xload_le addr $I8 (ExtKind.Zero32)) (pulley_xload8_u32_o32 addr))
+(rule (emit_addro32_xload_le addr $I8 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload8_s32_o32 addr)))
+(rule (emit_addro32_xload_le addr $I8 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload8_u32_o32 addr)))
+(rule (emit_addro32_xload_le addr $I16 (ExtKind.None)) (pulley_xload16le_u32_o32 addr))
+(rule (emit_addro32_xload_le addr $I16 (ExtKind.Sign32)) (pulley_xload16le_s32_o32 addr))
+(rule (emit_addro32_xload_le addr $I16 (ExtKind.Zero32)) (pulley_xload16le_u32_o32 addr))
+(rule (emit_addro32_xload_le addr $I16 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload16le_s32_o32 addr)))
+(rule (emit_addro32_xload_le addr $I16 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload16le_u32_o32 addr)))
+(rule (emit_addro32_xload_le addr $I32 (ExtKind.None)) (pulley_xload32le_o32 addr))
+(rule (emit_addro32_xload_le addr $I32 (ExtKind.Sign32)) (pulley_xload32le_o32 addr))
+(rule (emit_addro32_xload_le addr $I32 (ExtKind.Zero32)) (pulley_xload32le_o32 addr))
+(rule (emit_addro32_xload_le addr $I32 (ExtKind.Sign64)) (pulley_sext32 (pulley_xload32le_o32 addr)))
+(rule (emit_addro32_xload_le addr $I32 (ExtKind.Zero64)) (pulley_zext32 (pulley_xload32le_o32 addr)))
+(rule (emit_addro32_xload_le addr $I64 _ext) (pulley_xload64le_o32 addr))
;; Special case: trapping loads/stores that map trap use the `*_z` addressing
;; modes which generates a trap for load-from-null.
diff --git a/cranelift/filetests/filetests/isa/pulley64/loadbe.clif b/cranelift/filetests/filetests/isa/pulley64/loadbe.clif
index 9728a7dd99..a3cf0e0e71 100644
--- a/cranelift/filetests/filetests/isa/pulley64/loadbe.clif
+++ b/cranelift/filetests/filetests/isa/pulley64/loadbe.clif
@@ -9,7 +9,7 @@ block0(v0: i64):
; VCode:
; block0:
-; x0 = xload32 x0+0 // flags = notrap
+; xload32be_o32 x0, x0, 0
; ret
;
; Disassembled:
@@ -24,7 +24,7 @@ block0(v0: i64):
; VCode:
; block0:
-; x0 = xload64 x0+0 // flags = notrap
+; xload64be_o32 x0, x0, 0
; ret
;
; Disassembled:
@@ -39,7 +39,7 @@ block0(v0: i64):
; VCode:
; block0:
-; x0 = xload32 x0+4 // flags = notrap
+; xload32be_o32 x0, x0, 4
; ret
;
; Disassembled:
@@ -54,7 +54,7 @@ block0(v0: i64):
; VCode:
; block0:
-; x0 = xload64 x0+8 // flags = notrap
+; xload64be_o32 x0, x0, 8
; ret
;
; Disassembled:
diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs
index dc9fc398ea..0b47093587 100644
--- a/crates/cranelift/src/func_environ.rs
+++ b/crates/cranelift/src/func_environ.rs
@@ -29,9 +29,10 @@ use wasmtime_environ::{
BuiltinFunctionIndex, ComponentPC, DataIndex, DefinedFuncIndex, ElemIndex,
EngineOrModuleTypeIndex, FrameStateSlotBuilder, FrameValType, FuncIndex, FuncKey,
GlobalConstValue, GlobalIndex, IndexType, Memory, MemoryIndex, MemoryTunables, Module,
- ModuleInternedTypeIndex, ModuleTranslation, ModuleTypesBuilder, PtrSize, Table, TableIndex,
- TagIndex, Tunables, TypeConvert, TypeIndex, VMOffsets, WasmCompositeInnerType, WasmFuncType,
- WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmValType,
+ ModuleInternedTypeIndex, ModuleTranslation, ModuleTypesBuilder, PassiveDataIndex, PtrSize,
+ Table, TableIndex, TagIndex, Tunables, TypeConvert, TypeIndex, VMOffsets,
+ WasmCompositeInnerType, WasmFuncType, WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult,
+ WasmValType,
};
use wasmtime_environ::{FUNCREF_INIT_BIT, FUNCREF_MASK};
@@ -2793,20 +2794,14 @@ impl FuncEnvironment<'_> {
data_offset: ir::Value,
len: ir::Value,
) -> WasmResult<ir::Value> {
- let libcall = gc::builtins::array_new_data(self, builder.func)?;
- let vmctx = self.vmctx_val(&mut builder.cursor());
- let interned_type_index = self.module.types[array_type_index].unwrap_module_type_index();
- let interned_type_index = builder
- .ins()
- .iconst(I32, i64::from(interned_type_index.as_u32()));
- let data_index = builder.ins().iconst(I32, i64::from(data_index.as_u32()));
- let call_inst = builder.ins().call(
- libcall,
- &[vmctx, interned_type_index, data_index, data_offset, len],
- );
- let array_ref = builder.func.dfg.first_result(call_inst);
- builder.declare_value_needs_stack_map(array_ref);
- Ok(array_ref)
+ gc::translate_array_new_data(
+ self,
+ builder,
+ array_type_index,
+ data_index,
+ data_offset,
+ len,
+ )
}
pub fn translate_array_new_elem(
@@ -2879,26 +2874,16 @@ impl FuncEnvironment<'_> {
data_offset: ir::Value,
len: ir::Value,
) -> WasmResult<()> {
- let libcall = gc::builtins::array_init_data(self, builder.func)?;
- let vmctx = self.vmctx_val(&mut builder.cursor());
- let interned_type_index = self.module.types[array_type_index].unwrap_module_type_index();
- let interned_type_index = builder
- .ins()
- .iconst(I32, i64::from(interned_type_index.as_u32()));
- let data_index = builder.ins().iconst(I32, i64::from(data_index.as_u32()));
- builder.ins().call(
- libcall,
- &[
- vmctx,
- interned_type_index,
- array,
- dst_index,
- data_index,
- data_offset,
- len,
- ],
- );
- Ok(())
+ gc::translate_array_init_data(
+ self,
+ builder,
+ array_type_index,
+ array,
+ dst_index,
+ data_index,
+ data_offset,
+ len,
+ )
}
pub fn translate_array_init_elem(
@@ -3733,6 +3718,59 @@ impl FuncEnvironment<'_> {
);
}
+ /// Returns a native pointer to the passive data `segment` provided at
+ /// offset `src`.
+ ///
+ /// This will generate a trap if `src + len` is larger than the current
+ /// length of the passive data segment.
+ fn get_passive_data_pointer(
+ &mut self,
+ builder: &mut FunctionBuilder<'_>,
+ segment: PassiveDataIndex,
+ src: ir::Value,
+ len: ir::Value,
+ ) -> ir::Value {
+ assert_eq!(builder.func.dfg.value_type(src), I32);
+ assert_eq!(builder.func.dfg.value_type(len), I32);
+
+ // Test if `src + len` is inbounds for this passive data segment. To do
+ // that the size of the passive data segment is loaded from the
+ // `VMContext`. This is dynamically filled in at instantiation time and
+ // dynamically reset during `data.drop`.
+ //
+ // Note that `src` and `len` here are unconditionally 32-bit and the
+ // bounds check is done in the 64-bit space to ensure there is no
+ // overflow.
+ let vmctx = self.vmctx_val(&mut builder.cursor());
+ let passive_segment_len = builder.ins().uload32(
+ ir::MemFlagsData::trusted(),
+ vmctx,
+ i32::try_from(self.offsets.vmctx_passive_data_length(segment)).unwrap(),
+ );
+ let src64 = builder.ins().uextend(I64, src);
+ let len64 = builder.ins().uextend(I64, len);
+ let segment_end = builder.ins().iadd(src64, len64);
+ let segment_oob =
+ builder
+ .ins()
+ .icmp(IntCC::UnsignedGreaterThan, segment_end, passive_segment_len);
+ self.trapnz(builder, segment_oob, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+
+ // Load the base pointer and offset it by `src` bytes.
+ let passive_segment_base = builder.ins().load(
+ self.pointer_type(),
+ ir::MemFlagsData::trusted(),
+ vmctx,
+ i32::try_from(self.offsets.vmctx_passive_data_base(segment)).unwrap(),
+ );
+ let src_ptr = self.unchecked_cast_wasm_addr_to_native_addr(
+ &mut builder.cursor(),
+ src,
+ IndexType::I32,
+ );
+ builder.ins().iadd(passive_segment_base, src_ptr)
+ }
+
pub fn translate_memory_init(
&mut self,
builder: &mut FunctionBuilder<'_>,
@@ -3742,29 +3780,71 @@ impl FuncEnvironment<'_> {
src: ir::Value,
len: ir::Value,
) -> WasmResult<()> {
- let mut pos = builder.cursor();
- let memory_init = self.builtin_functions.memory_init(&mut pos.func);
-
- let memory_index_arg = pos.ins().iconst(I32, memory_index.index() as i64);
- let seg_index_arg = pos.ins().iconst(I32, seg_index as i64);
-
- let vmctx = self.vmctx_val(&mut pos);
-
- let dst = self.cast_index_to_i64(&mut pos, dst, self.memory(memory_index).idx_type);
+ let seg_index = DataIndex::from_u32(seg_index);
+
+ // First, perform a bounds check to ensure that `dst + len` is inbounds.
+ // Note that `dst` has a type for `memory_index`'s index type, and `len`
+ // always has type i32. For `bounds_check_for_memory_intrinsic` below
+ // they both need to be typed with the memory's type, so cast the length
+ // here appropriately.
+ let len_with_memory_ty = match self.memory(memory_index).idx_type {
+ IndexType::I32 => len,
+ IndexType::I64 => builder.ins().uextend(I64, len),
+ };
+ let raw_dst =
+ self.bounds_check_for_memory_intrinsic(builder, memory_index, dst, len_with_memory_ty);
+
+ // Next see what passive data segment `seg_index` corresponds to. If
+ // this is actually an active data segment then it unconditionally has
+ // length zero. In this situation perform a conditional trap if `src` or
+ // `len` are nonzero, because if they're nonzero then this is out-of-bounds.
+ let raw_src = match self.translation.passive_data_map[seg_index] {
+ Some(idx) => self.get_passive_data_pointer(builder, idx, src, len),
+ None => {
+ self.trapnz(builder, src, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+ self.trapnz(builder, len, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+ return Ok(());
+ }
+ };
- pos.ins().call(
- memory_init,
- &[vmctx, memory_index_arg, seg_index_arg, dst, src, len],
- );
+ // At this point bounds checks have all passed, so it's time to perform
+ // the actual copy by calling the `memory.copy` libcall.
+ let vmctx = self.vmctx_val(&mut builder.cursor());
+ let memory_copy = self.builtin_functions.memory_copy(&mut builder.func);
+ let len_native = match self.pointer_type() {
+ I32 => len,
+ I64 => builder.ins().uextend(I64, len),
+ _ => unreachable!(),
+ };
+ builder
+ .ins()
+ .call(memory_copy, &[vmctx, raw_dst, raw_src, len_native]);
Ok(())
}
pub fn translate_data_drop(&mut self, mut pos: FuncCursor, seg_index: u32) -> WasmResult<()> {
- let data_drop = self.builtin_functions.data_drop(&mut pos.func);
- let seg_index_arg = pos.ins().iconst(I32, seg_index as i64);
+ let seg_index = DataIndex::from_u32(seg_index);
+
+ // Lookup the passive data segment corresponding to this data segment.
+ // If this is an active data segment then it already has length 0 so
+ // there's nothing to do.
+ let passive_index = match self.translation.passive_data_map[seg_index] {
+ Some(idx) => idx,
+ None => return Ok(()),
+ };
+
+ // For passive data segments to implement `data.drop` it's a store of
+ // the value 0 to the `VMContext`'s slot for this passive data segment.
let vmctx = self.vmctx_val(&mut pos);
- pos.ins().call(data_drop, &[vmctx, seg_index_arg]);
+ let new_length = pos.ins().iconst(I32, 0);
+ pos.ins().store(
+ ir::MemFlagsData::trusted(),
+ new_length,
+ vmctx,
+ i32::try_from(self.offsets.vmctx_passive_data_length(passive_index)).unwrap(),
+ );
+
Ok(())
}
diff --git a/crates/cranelift/src/func_environ/gc.rs b/crates/cranelift/src/func_environ/gc.rs
index a445699d5a..570ab7de93 100644
--- a/crates/cranelift/src/func_environ/gc.rs
+++ b/crates/cranelift/src/func_environ/gc.rs
@@ -36,6 +36,9 @@ pub enum ArrayInit<'a> {
/// Initialize the array's elements with `elem` repeated `len` times.
Fill { elem: ir::Value, len: ir::Value },
+
+ /// Don't initialize the elements, just allocate the array.
+ Uninit { len: ir::Value },
}
/// A trait for different collectors to emit any GC barriers they might require.
@@ -208,9 +211,7 @@ pub mod builtins {
define_builtin_accessors! {
table_grow_gc_ref,
table_fill_gc_ref,
- array_new_data,
array_new_elem,
- array_init_data,
array_init_elem,
}
}
diff --git a/crates/cranelift/src/func_environ/gc/disabled.rs b/crates/cranelift/src/func_environ/gc/disabled.rs
index 8ae38e4faf..9b6ad28522 100644
--- a/crates/cranelift/src/func_environ/gc/disabled.rs
+++ b/crates/cranelift/src/func_environ/gc/disabled.rs
@@ -5,7 +5,7 @@ use crate::func_environ::{Extension, FuncEnvironment};
use cranelift_codegen::ir;
use cranelift_frontend::FunctionBuilder;
use smallvec::SmallVec;
-use wasmtime_environ::{TagIndex, TypeIndex, WasmRefType, WasmResult, wasm_unsupported};
+use wasmtime_environ::{DataIndex, TagIndex, TypeIndex, WasmRefType, WasmResult, wasm_unsupported};
fn disabled<T>() -> WasmResult<T> {
Err(wasm_unsupported!(
@@ -177,3 +177,27 @@ pub fn translate_array_copy(
) -> WasmResult<()> {
disabled()
}
+
+pub fn translate_array_new_data(
+ _func_env: &mut FuncEnvironment<'_>,
+ _builder: &mut FunctionBuilder,
+ _array_type_index: TypeIndex,
+ _data_index: DataIndex,
+ _data_offset: ir::Value,
+ _len: ir::Value,
+) -> WasmResult<ir::Value> {
+ disabled()
+}
+
+pub fn translate_array_init_data(
+ _func_env: &mut FuncEnvironment<'_>,
+ _builder: &mut FunctionBuilder,
+ _array_type_index: TypeIndex,
+ _array: ir::Value,
+ _dst_index: ir::Value,
+ _data_index: DataIndex,
+ _data_offset: ir::Value,
+ _len: ir::Value,
+) -> WasmResult<()> {
+ disabled()
+}
diff --git a/crates/cranelift/src/func_environ/gc/enabled.rs b/crates/cranelift/src/func_environ/gc/enabled.rs
index 59474d5854..06775812ea 100644
--- a/crates/cranelift/src/func_environ/gc/enabled.rs
+++ b/crates/cranelift/src/func_environ/gc/enabled.rs
@@ -1,4 +1,5 @@
use super::{ArrayInit, GcCompiler};
+use crate::TRAP_ARRAY_OUT_OF_BOUNDS;
use crate::bounds_checks::BoundsCheck;
use crate::func_environ::{BulkOp, Extension, FuncEnvironment};
use crate::translate::{Heap, HeapData, MemoryKind, StructFieldsVec, TargetEnvironment};
@@ -14,9 +15,10 @@ use cranelift_entity::packed_option::ReservedValue;
use cranelift_frontend::FunctionBuilder;
use smallvec::{SmallVec, smallvec};
use wasmtime_environ::{
- Collector, GcArrayLayout, GcLayout, GcStructLayout, I31_DISCRIMINANT, ModuleInternedTypeIndex,
- PtrSize, TagIndex, TypeIndex, VMGcKind, WasmCompositeInnerType, WasmHeapTopType, WasmHeapType,
- WasmRefType, WasmResult, WasmStorageType, WasmValType, wasm_unsupported,
+ Collector, DataIndex, GcArrayLayout, GcLayout, GcStructLayout, I31_DISCRIMINANT,
+ ModuleInternedTypeIndex, PtrSize, TagIndex, TypeIndex, VMGcKind, WasmCompositeInnerType,
+ WasmHeapTopType, WasmHeapType, WasmRefType, WasmResult, WasmStorageType, WasmValType,
+ wasm_unsupported,
};
#[cfg(feature = "gc-drc")]
@@ -687,7 +689,7 @@ impl ArrayInit<'_> {
)]
fn len(self, pos: &mut FuncCursor) -> ir::Value {
match self {
- ArrayInit::Fill { len, .. } => len,
+ ArrayInit::Fill { len, .. } | ArrayInit::Uninit { len } => len,
ArrayInit::Elems(e) => {
let len = u32::try_from(e.len()).unwrap();
pos.ins().iconst(ir::types::I32, i64::from(len))
@@ -757,6 +759,8 @@ impl ArrayInit<'_> {
},
)?;
}
+
+ ArrayInit::Uninit { .. } => {}
}
log::trace!("initialize_array: finished");
Ok(())
@@ -1167,11 +1171,11 @@ pub fn translate_array_fill(
let len = translate_array_len(func_env, builder, array_ref)?;
// Check that the full range of elements we want to fill is within bounds.
- let end_index = func_env.uadd_overflow_trap(builder, index, n, crate::TRAP_ARRAY_OUT_OF_BOUNDS);
+ let end_index = func_env.uadd_overflow_trap(builder, index, n, TRAP_ARRAY_OUT_OF_BOUNDS);
let out_of_bounds = builder
.ins()
.icmp(IntCC::UnsignedGreaterThan, end_index, len);
- func_env.trapnz(builder, out_of_bounds, crate::TRAP_ARRAY_OUT_OF_BOUNDS);
+ func_env.trapnz(builder, out_of_bounds, TRAP_ARRAY_OUT_OF_BOUNDS);
// Get the address of the first element we want to fill.
let interned_type_index = func_env.module.types[array_type_index].unwrap_module_type_index();
@@ -1327,7 +1331,7 @@ fn array_elem_addr(
let len = translate_array_len(func_env, builder, array_ref).unwrap();
let in_bounds = builder.ins().icmp(IntCC::UnsignedLessThan, index, len);
- func_env.trapz(builder, in_bounds, crate::TRAP_ARRAY_OUT_OF_BOUNDS);
+ func_env.trapz(builder, in_bounds, TRAP_ARRAY_OUT_OF_BOUNDS);
// Compute the size (in bytes) of the whole array object.
let ArraySizeInfo {
@@ -2047,3 +2051,161 @@ fn stack_switching_unsupported<T>() -> WasmResult<T> {
"Stack switching feature not compatible with GC, yet".to_string(),
))
}
+
+pub fn translate_array_new_data(
+ env: &mut FuncEnvironment<'_>,
+ builder: &mut FunctionBuilder,
+ array_type_index: TypeIndex,
+ data_index: DataIndex,
+ data_offset: ir::Value,
+ len: ir::Value,
+) -> WasmResult<ir::Value> {
+ // Before actually allocating this array first do a bounds-check on the
+ // passive data segment itself. This is done by multiplying the length of
+ // the size of the array in the 64-bit integer space to avoid overflow. If
+ // upper bits are set this is definitely out-of-bounds, and otherwise the
+ // low 32-bits are the byte length.
+ let interned_type_index = env.module.types[array_type_index].unwrap_module_type_index();
+ let array_layout = env.array_layout(interned_type_index);
+ let len64 = builder.ins().uextend(ir::types::I64, len);
+ let init_byte_length = builder
+ .ins()
+ .imul_imm(len64, i64::from(array_layout.elem_size));
+ let init_byte_length_upper_bits = builder.ins().ushr_imm(init_byte_length, 32);
+ env.trapnz(
+ builder,
+ init_byte_length_upper_bits,
+ ir::TrapCode::HEAP_OUT_OF_BOUNDS,
+ );
+ let init_byte_length = builder.ins().ireduce(ir::types::I32, init_byte_length);
+
+ let src_addr = match env.translation.passive_data_map[data_index] {
+ Some(idx) => {
+ Some(env.get_passive_data_pointer(builder, idx, data_offset, init_byte_length))
+ }
+ None => {
+ env.trapnz(builder, data_offset, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+ env.trapnz(builder, len, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+ None
+ }
+ };
+ let array =
+ gc_compiler(env)?.alloc_array(env, builder, array_type_index, ArrayInit::Uninit { len })?;
+ if let Some(src_addr) = src_addr {
+ let dst = builder.ins().iconst(ir::types::I32, 0);
+ emit_array_init_data(
+ env,
+ builder,
+ array_type_index,
+ array,
+ len,
+ dst,
+ src_addr,
+ init_byte_length,
+ );
+ }
+ Ok(array)
+}
+
+pub fn translate_array_init_data(
+ env: &mut FuncEnvironment<'_>,
+ builder: &mut FunctionBuilder,
+ array_type_index: TypeIndex,
+ array: ir::Value,
+ dst_index: ir::Value,
+ data_index: DataIndex,
+ data_offset: ir::Value,
+ len: ir::Value,
+) -> WasmResult<()> {
+ // Perform a bounds check and double-check that `dst_index` is in-bounds for
+ // this array. Do this in the 64-bit index space to avoid overflows.
+ let array_len = translate_array_len(env, builder, array)?;
+ let array_len64 = builder.ins().uextend(ir::types::I64, array_len);
+ let dst_index64 = builder.ins().uextend(ir::types::I64, dst_index);
+ let len64 = builder.ins().uextend(ir::types::I64, len);
+ let end_index64 = builder.ins().iadd(dst_index64, len64);
+ let oob = builder
+ .ins()
+ .icmp(IntCC::UnsignedGreaterThan, end_index64, array_len64);
+ env.trapnz(builder, oob, TRAP_ARRAY_OUT_OF_BOUNDS);
+
+ // Note that because `dst_index + len` is in-bounds we know that this won't
+ // overflow, so no need to check for overflow here.
+ let interned_type_index = env.module.types[array_type_index].unwrap_module_type_index();
+ let array_layout = env.array_layout(interned_type_index);
+ let len_in_bytes = builder
+ .ins()
+ .imul_imm(len, i64::from(array_layout.elem_size));
+
+ let src_addr = match env.translation.passive_data_map[data_index] {
+ Some(idx) => env.get_passive_data_pointer(builder, idx, data_offset, len_in_bytes),
+ // If this is an active data segments it's by-definition zero-length so
+ // test the size and then return as we've indeed successfully copied
+ // zero bytes.
+ None => {
+ env.trapnz(builder, data_offset, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+ env.trapnz(builder, len, ir::TrapCode::HEAP_OUT_OF_BOUNDS);
+ return Ok(());
+ }
+ };
+
+ emit_array_init_data(
+ env,
+ builder,
+ array_type_index,
+ array,
+ array_len,
+ dst_index,
+ src_addr,
+ len_in_bytes,
+ );
+
+ Ok(())
+}
+
+/// Shared functionality between `array.new_data` and `array.init_data`.
+///
+/// Assumes the data segment has already been validated and `src_addr` is the
+/// raw host address we're copying from.
+fn emit_array_init_data(
+ env: &mut FuncEnvironment<'_>,
+ builder: &mut FunctionBuilder,
+ array_type_index: TypeIndex,
+ array: ir::Value,
+ array_len: ir::Value,
+ dst_index: ir::Value,
+ src_addr: ir::Value,
+ len_in_bytes: ir::Value,
+) {
+ // Load the destination address for where we're going to write.
+ let interned_type_index = env.module.types[array_type_index].unwrap_module_type_index();
+ let ArraySizeInfo {
+ obj_size,
+ one_elem_size,
+ base_size,
+ } = emit_array_size_info(env, builder, interned_type_index, array_len);
+ let offset_in_elems = builder.ins().imul(dst_index, one_elem_size);
+ let obj_offset = builder.ins().iadd(base_size, offset_in_elems);
+ let dst_elem_addr = env.prepare_gc_ref_access(
+ builder,
+ array,
+ BoundsCheck::DynamicObjectField {
+ offset: obj_offset,
+ object_size: obj_size,
+ },
+ );
+
+ // At this point bounds checks have all passed, so it's time to perform
+ // the actual copy by calling the `memory.copy` libcall.
+ let vmctx = env.vmctx_val(&mut builder.cursor());
+ let memory_copy = env.builtin_functions.memory_copy(&mut builder.func);
+ let len_in_bytes_native = match env.pointer_type() {
+ ir::types::I32 => len_in_bytes,
+ ir::types::I64 => builder.ins().uextend(ir::types::I64, len_in_bytes),
+ _ => unreachable!(),
+ };
+ builder.ins().call(
+ memory_copy,
+ &[vmctx, dst_elem_addr, src_addr, len_in_bytes_native],
+ );
+}
diff --git a/crates/environ/src/builtin.rs b/crates/environ/src/builtin.rs
index 6fe53515b1..688207c9d6 100644
--- a/crates/environ/src/builtin.rs
+++ b/crates/environ/src/builtin.rs
@@ -16,12 +16,8 @@ macro_rules! foreach_builtin_function {
memory_copy(vmctx: vmctx, dst: pointer, src: pointer, len: size);
// Returns an index for wasm's `memory.fill` instruction.
memory_fill(vmctx: vmctx, dst: pointer, val: u32, len: size);
- // Returns an index for wasm's `memory.init` instruction.
- memory_init(vmctx: vmctx, memory: u32, data: u32, dst: u64, src: u32, len: u32) -> bool;
// Returns a value for wasm's `ref.func` instruction.
ref_func(vmctx: vmctx, func: u32) -> pointer;
- // Returns an index for wasm's `data.drop` instruction.
- data_drop(vmctx: vmctx, data: u32) -> bool;
// Returns a table entry after lazily initializing it.
table_get_lazy_init_func_ref(vmctx: vmctx, table: u32, index: u64) -> pointer;
// Returns an index for Wasm's `table.grow` instruction for `funcref`s.
@@ -125,16 +121,6 @@ macro_rules! foreach_builtin_function {
module_interned_type_index: u32
) -> pointer;
- // Builtin implementation of the `array.new_data` instruction.
- #[cfg(feature = "gc")]
- array_new_data(
- vmctx: vmctx,
- array_interned_type_index: u32,
- data_index: u32,
- data_offset: u32,
- len: u32
- ) -> u32;
-
// Builtin implementation of the `array.new_elem` instruction.
#[cfg(feature = "gc")]
array_new_elem(
@@ -145,18 +131,6 @@ macro_rules! foreach_builtin_function {
len: u32
) -> u32;
- // Builtin implementation of the `array.init_data` instruction.
- #[cfg(feature = "gc")]
- array_init_data(
- vmctx: vmctx,
- array_interned_type_index: u32,
- array: u32,
- dst_index: u32,
- data_index: u32,
- data_offset: u32,
- len: u32
- ) -> bool;
-
// Builtin implementation of the `array.init_elem` instruction.
#[cfg(feature = "gc")]
array_init_elem(
@@ -460,6 +434,7 @@ impl BuiltinFunctionIndex {
(@get i8x16_shuffle i8x16) => (return None);
(@get fma_f32x4 f32x4) => (return None);
(@get fma_f64x2 f64x2) => (return None);
+ (@get passive_data_segment_base pointer) => (return None);
(@get cont_new pointer) => (TrapSentinel::Negative);
diff --git a/crates/environ/src/compile/module_artifacts.rs b/crates/environ/src/compile/module_artifacts.rs
index c6c915b75a..ca409dae97 100644
--- a/crates/environ/src/compile/module_artifacts.rs
+++ b/crates/environ/src/compile/module_artifacts.rs
@@ -199,7 +199,7 @@ impl<'a> ObjectBuilder<'a> {
// of this object, after active data in `translation.data`. Update the
// offsets to account prior modules added in addition to active data.
let data_offset = data_offset + u32::try_from(total_data_len).unwrap();
- for (_, range) in module.passive_data_map.iter_mut() {
+ for (_, range) in module.passive_data.iter_mut() {
range.start = range.start.checked_add(data_offset).unwrap();
range.end = range.end.checked_add(data_offset).unwrap();
}
diff --git a/crates/environ/src/compile/module_environ.rs b/crates/environ/src/compile/module_environ.rs
index a4ffbbd04c..ae137d8a94 100644
--- a/crates/environ/src/compile/module_environ.rs
+++ b/crates/environ/src/compile/module_environ.rs
@@ -7,10 +7,10 @@ use crate::prelude::*;
use crate::{
ConstExpr, ConstOp, DataIndex, DefinedFuncIndex, ElemIndex, EngineOrModuleTypeIndex,
EntityIndex, EntityType, FuncIndex, FuncKey, GlobalIndex, IndexType, InitMemory, MemoryIndex,
- ModuleInternedTypeIndex, ModuleTypesBuilder, PanicOnOom as _, PrimaryMap, SizeOverflow,
- StaticMemoryInitializer, StaticModuleIndex, TableIndex, TableInitialValue, Tag, TagIndex,
- Tunables, TypeConvert, TypeIndex, WasmError, WasmHeapTopType, WasmHeapType, WasmResult,
- WasmValType, WasmparserTypeConverter,
+ ModuleInternedTypeIndex, ModuleTypesBuilder, PanicOnOom as _, PassiveDataIndex, PrimaryMap,
+ SizeOverflow, StaticMemoryInitializer, StaticModuleIndex, TableIndex, TableInitialValue, Tag,
+ TagIndex, Tunables, TypeConvert, TypeIndex, WasmError, WasmHeapTopType, WasmHeapType,
+ WasmResult, WasmValType, WasmparserTypeConverter,
};
use cranelift_entity::SecondaryMap;
use cranelift_entity::packed_option::ReservedValue;
@@ -99,6 +99,9 @@ pub struct ModuleTranslation<'data> {
/// an object file into a linear memory.
pub data_align: Option<u64>,
+ /// Map from a data segment to whether it's a passive data segment or not.
+ pub passive_data_map: SecondaryMap<DataIndex, Option<PassiveDataIndex>>,
+
/// Total size of all data pushed onto `data` so far.
total_data: u32,
@@ -137,6 +140,7 @@ impl<'data> ModuleTranslation<'data> {
total_passive_data: 0,
code_index: 0,
types: None,
+ passive_data_map: Default::default(),
}
}
@@ -645,6 +649,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
data,
range: _,
} = entry?;
+ let data_index = DataIndex::from_u32(index.try_into().unwrap());
let mk_range = |total: &mut u32| -> Result<_, WasmError> {
let range = u32::try_from(data.len())
.ok()
@@ -661,7 +666,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
*total += range.end - range.start;
Ok(range)
};
- match kind {
+ let passive_index = match kind {
DataKind::Active {
memory_index,
offset_expr,
@@ -681,17 +686,17 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> {
data: range,
})?;
self.result.data.push(data.into());
+ None
}
DataKind::Passive => {
- let data_index = DataIndex::from_u32(index as u32);
let range = mk_range(&mut self.result.total_passive_data)?;
self.result.passive_data.push(data);
- self.result
- .module
- .passive_data_map
- .insert(data_index, range)?;
+ Some(self.result.module.passive_data.push(range))
}
- }
+ };
+ self.result
+ .passive_data_map
+ .insert(data_index, passive_index);
}
}
diff --git a/crates/environ/src/module.rs b/crates/environ/src/module.rs
index bab65d7a58..5c74d379dc 100644
--- a/crates/environ/src/module.rs
+++ b/crates/environ/src/module.rs
@@ -329,8 +329,8 @@ pub struct Module {
/// index in `passive_elements`.
pub passive_elements_map: TryBTreeMap<ElemIndex, PassiveElemIndex>,
- /// The map from passive data index (data segment index space) to index in `passive_data`.
- pub passive_data_map: TryBTreeMap<DataIndex, Range<u32>>,
+ /// Where passive data segments are located in the module's image.
+ pub passive_data: PrimaryMap<PassiveDataIndex, Range<u32>>,
/// Types declared in the wasm module.
pub types: TryPrimaryMap<TypeIndex, EngineOrModuleTypeIndex>,
@@ -409,7 +409,7 @@ impl Module {
memory_initialization: Default::default(),
passive_elements: Default::default(),
passive_elements_map: Default::default(),
- passive_data_map: Default::default(),
+ passive_data: Default::default(),
types: Default::default(),
num_imported_funcs: Default::default(),
num_imported_tables: Default::default(),
@@ -700,7 +700,7 @@ impl TypeTrace for Module {
memory_initialization: _,
passive_elements: _,
passive_elements_map: _,
- passive_data_map: _,
+ passive_data: _,
types,
num_imported_funcs: _,
num_imported_tables: _,
@@ -752,7 +752,7 @@ impl TypeTrace for Module {
memory_initialization: _,
passive_elements: _,
passive_elements_map: _,
- passive_data_map: _,
+ passive_data: _,
types,
num_imported_funcs: _,
num_imported_tables: _,
diff --git a/crates/environ/src/types.rs b/crates/environ/src/types.rs
index 0e9d11423d..1a4cf09ee4 100644
--- a/crates/environ/src/types.rs
+++ b/crates/environ/src/types.rs
@@ -1691,11 +1691,19 @@ impl Default for VMSharedTypeIndex {
}
}
-/// Index type of a passive data segment inside the WebAssembly module.
+/// Index type of a data segment inside the WebAssembly module.
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
pub struct DataIndex(u32);
entity_impl_with_try_clone!(DataIndex);
+/// Index type of a passive data segment inside the WebAssembly module.
+///
+/// Not a spec-level concept, just used to get dense index spaces for passive
+/// data segments inside of Wasmtime.
+#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
+pub struct PassiveDataIndex(u32);
+entity_impl_with_try_clone!(PassiveDataIndex);
+
/// Index type of an element segment inside the WebAssembly module.
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
pub struct ElemIndex(u32);
diff --git a/crates/environ/src/vmoffsets.rs b/crates/environ/src/vmoffsets.rs
index 5e5b9e7df4..fbca1861fa 100644
--- a/crates/environ/src/vmoffsets.rs
+++ b/crates/environ/src/vmoffsets.rs
@@ -31,11 +31,14 @@
// globals: [VMGlobalDefinition; module.num_defined_globals],
// tags: [VMTagDefinition; module.num_defined_tags],
// func_refs: [VMFuncRef; module.num_escaped_funcs],
+// passive_data_bases: [*const u8; module.num_passive_data],
+// passive_data_lengths: [u32; module.num_passive_data],
// }
use crate::{
DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, DefinedTagIndex, FuncIndex,
- FuncRefIndex, GlobalIndex, MemoryIndex, Module, OwnedMemoryIndex, TableIndex, TagIndex,
+ FuncRefIndex, GlobalIndex, MemoryIndex, Module, OwnedMemoryIndex, PassiveDataIndex, TableIndex,
+ TagIndex,
};
use cranelift_entity::packed_option::ReservedValue;
@@ -87,6 +90,8 @@ pub struct VMOffsets<P> {
/// The number of escaped functions in the module, the size of the func_refs
/// array.
pub num_escaped_funcs: u32,
+ /// The number of passive data segments in the module.
+ pub num_passive_data: u32,
// precalculated offsets of various member fields
imported_functions: u32,
@@ -100,6 +105,8 @@ pub struct VMOffsets<P> {
defined_globals: u32,
defined_tags: u32,
defined_func_refs: u32,
+ passive_data_bases: u32,
+ passive_data_lengths: u32,
size: u32,
}
@@ -566,6 +573,8 @@ pub struct VMOffsetsFields<P> {
/// The number of escaped functions in the module, the size of the function
/// references array.
pub num_escaped_funcs: u32,
+ /// The number of passive data segments in the module.
+ pub num_passive_data: u32,
}
impl<P: PtrSize> VMOffsets<P> {
@@ -592,6 +601,7 @@ impl<P: PtrSize> VMOffsets<P> {
num_defined_globals: cast_to_u32(module.globals.len() - module.num_imported_globals),
num_defined_tags: cast_to_u32(module.tags.len() - module.num_imported_tags),
num_escaped_funcs: cast_to_u32(module.num_escaped_funcs),
+ num_passive_data: cast_to_u32(module.passive_data.len()),
})
}
@@ -623,6 +633,7 @@ impl<P: PtrSize> VMOffsets<P> {
num_defined_tags: _,
num_owned_memories: _,
num_escaped_funcs: _,
+ num_passive_data: _,
// used as the initial size below
size,
@@ -651,6 +662,8 @@ impl<P: PtrSize> VMOffsets<P> {
}
calculate_sizes! {
+ passive_data_lengths: "passive data lengths",
+ passive_data_bases: "passive data base pointers",
defined_func_refs: "module functions",
defined_tags: "defined tags",
defined_globals: "defined globals",
@@ -681,6 +694,7 @@ impl<P: PtrSize> From<VMOffsetsFields<P>> for VMOffsets<P> {
num_defined_globals: fields.num_defined_globals,
num_defined_tags: fields.num_defined_tags,
num_escaped_funcs: fields.num_escaped_funcs,
+ num_passive_data: fields.num_passive_data,
imported_functions: 0,
imported_tables: 0,
imported_memories: 0,
@@ -692,6 +706,8 @@ impl<P: PtrSize> From<VMOffsetsFields<P>> for VMOffsets<P> {
defined_globals: 0,
defined_tags: 0,
defined_func_refs: 0,
+ passive_data_bases: 0,
+ passive_data_lengths: 0,
size: 0,
};
@@ -750,6 +766,8 @@ impl<P: PtrSize> From<VMOffsetsFields<P>> for VMOffsets<P> {
ret.num_escaped_funcs,
ret.ptr.size_of_vm_func_ref(),
),
+ size(passive_data_bases) = cmul(ret.num_passive_data, ret.ptr.size()),
+ size(passive_data_lengths) = cmul(ret.num_passive_data, 4),
}
ret.size = next_field_offset;
@@ -998,6 +1016,18 @@ impl<P: PtrSize> VMOffsets<P> {
self.defined_func_refs
}
+ /// The offset of the `passive_data_bases` array.
+ #[inline]
+ pub fn vmctx_passive_data_bases_begin(&self) -> u32 {
+ self.passive_data_bases
+ }
+
+ /// The offset of the `passive_data_lengths` array.
+ #[inline]
+ pub fn vmctx_passive_data_lengths_begin(&self) -> u32 {
+ self.passive_data_lengths
+ }
+
/// Return the size of the `VMContext` allocation.
#[inline]
pub fn size_of_vmctx(&self) -> u32 {
@@ -1090,6 +1120,22 @@ impl<P: PtrSize> VMOffsets<P> {
self.vmctx_func_refs_begin() + index.as_u32() * u32::from(self.ptr.size_of_vm_func_ref())
}
+ /// Return the offset to the base of the passive data segment at `index`.
+ #[inline]
+ pub fn vmctx_passive_data_base(&self, index: PassiveDataIndex) -> u32 {
+ assert!(!index.is_reserved_value());
+ assert!(index.as_u32() < self.num_passive_data);
+ self.vmctx_passive_data_bases_begin() + index.as_u32() * u32::from(self.ptr.size())
+ }
+
+ /// Return the offset to the length of the passive data segment at `index`.
+ #[inline]
+ pub fn vmctx_passive_data_length(&self, index: PassiveDataIndex) -> u32 {
+ assert!(!index.is_reserved_value());
+ assert!(index.as_u32() < self.num_passive_data);
+ self.vmctx_passive_data_lengths_begin() + index.as_u32() * 4
+ }
+
/// Return the offset to the `wasm_call` field in `*const VMFunctionBody` index `index`.
#[inline]
pub fn vmctx_vmfunction_import_wasm_call(&self, index: FuncIndex) -> u32 {
diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rs
index 3bf776c671..93051b7921 100644
--- a/crates/wasmtime/src/runtime/types.rs
+++ b/crates/wasmtime/src/runtime/types.rs
@@ -1712,24 +1712,6 @@ impl StorageType {
Self::ValType(v) => WasmStorageType::Val(v.to_wasm_type()),
}
}
-
- /// The byte size of this type, if it has a defined size in the spec.
- ///
- /// See
- /// https://webassembly.github.io/gc/core/syntax/types.html#bitwidth-fieldtype
- /// and
- /// https://webassembly.github.io/gc/core/syntax/types.html#bitwidth-valtype
- #[cfg(feature = "gc")]
- pub(crate) fn data_byte_size(&self) -> Option<u32> {
- match self {
- StorageType::I8 => Some(1),
- StorageType::I16 => Some(2),
- StorageType::ValType(ValType::I32 | ValType::F32) => Some(4),
- StorageType::ValType(ValType::I64 | ValType::F64) => Some(8),
- StorageType::ValType(ValType::V128) => Some(16),
- StorageType::ValType(ValType::Ref(_)) => None,
- }
- }
}
/// The type of a `struct` field or an `array`'s elements.
diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs
index ac76c470dd..a2f91e326c 100644
--- a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs
+++ b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs
@@ -1243,6 +1243,7 @@ mod tests {
num_defined_globals: 0,
num_defined_tags: 0,
num_escaped_funcs: 0,
+ num_passive_data: 0,
});
assert_eq!(
diff --git a/crates/wasmtime/src/runtime/vm/instance.rs b/crates/wasmtime/src/runtime/vm/instance.rs
index 670c07a017..18b39654cd 100644
--- a/crates/wasmtime/src/runtime/vm/instance.rs
+++ b/crates/wasmtime/src/runtime/vm/instance.rs
@@ -35,10 +35,10 @@ use core::{mem, ptr};
use wasmtime_environ::ModuleInternedTypeIndex;
use wasmtime_environ::error::OutOfMemory;
use wasmtime_environ::{
- DataIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, DefinedTagIndex,
- ElemIndex, EntityIndex, EntityRef, FuncIndex, GlobalIndex, HostPtr, MemoryIndex, PtrSize,
- TableIndex, TableInitialValue, TagIndex, Trap, VMCONTEXT_MAGIC, VMOffsets, VMSharedTypeIndex,
- WasmRefType, packed_option::ReservedValue,
+ DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, DefinedTagIndex, ElemIndex,
+ EntityIndex, EntityRef, FuncIndex, GlobalIndex, HostPtr, MemoryIndex, PassiveDataIndex,
+ PtrSize, TableIndex, TableInitialValue, TagIndex, Trap, VMCONTEXT_MAGIC, VMOffsets,
+ VMSharedTypeIndex, WasmRefType, packed_option::ReservedValue,
};
#[cfg(feature = "wmemcheck")]
use wasmtime_wmemcheck::Wmemcheck;
@@ -135,10 +135,6 @@ pub struct Instance {
// but that type is currently footgun-y / isn't actually OOM-safe yet.
passive_elements: TryVec<PassiveElementSegment>,
- /// Stores the dropped passive data segments in this instantiation by index.
- /// If the index is present in the set, the segment has been dropped.
- dropped_data: TryEntitySet<DataIndex>,
-
// TODO: add support for multiple memories; `wmemcheck_state` corresponds to
// memory 0.
#[cfg(feature = "wmemcheck")]
@@ -175,7 +171,6 @@ impl Instance {
let module = req.runtime_info.env_module();
let memory_tys = &module.memories;
let passive_elements = TryVec::with_capacity(module.passive_elements.len())?;
- let dropped_data = TryEntitySet::with_capacity(module.passive_data_map.len())?;
#[cfg(feature = "wmemcheck")]
let wmemcheck_state = if req.store.engine().config().wmemcheck {
@@ -199,7 +194,6 @@ impl Instance {
memories,
tables,
passive_elements,
- dropped_data,
#[cfg(feature = "wmemcheck")]
wmemcheck_state,
store: None,
@@ -1030,27 +1024,6 @@ impl Instance {
}
}
- fn validate_inbounds(&self, max: usize, ptr: u64, len: u64) -> Result<usize, Trap> {
- let oob = || Trap::MemoryOutOfBounds;
- let end = ptr
- .checked_add(len)
- .and_then(|i| usize::try_from(i).ok())
- .ok_or_else(oob)?;
- if end > max {
- Err(oob())
- } else {
- Ok(ptr.try_into().unwrap())
- }
- }
-
- /// Get the internal storage range of a particular Wasm data segment.
- pub(crate) fn wasm_data_range(&self, index: DataIndex) -> Range<u32> {
- match self.env_module().passive_data_map.get(index) {
- Some(range) if !self.dropped_data.contains(index) => range.clone(),
- _ => 0..0,
- }
- }
-
/// Given an internal storage range of a Wasm data segment (or subset of a
/// Wasm data segment), get the data's raw bytes.
pub(crate) fn wasm_data(&self, range: Range<u32>) -> &[u8] {
@@ -1059,63 +1032,17 @@ impl Instance {
&self.runtime_info.wasm_data()[start..end]
}
- /// Performs the `memory.init` operation.
+ /// Returns the data for the passive segment identified by `index`
///
- /// # Errors
+ /// Does not take into account the dynamic size of the data pointed to by
+ /// `index`, always returns the raw data from the module itself.
///
- /// Returns a `Trap` error if the destination range is out of this module's
- /// memory's bounds or if the source range is outside the data segment's
- /// bounds.
- pub(crate) fn memory_init(
- self: Pin<&mut Self>,
- memory_index: MemoryIndex,
- data_index: DataIndex,
- dst: u64,
- src: u32,
- len: u32,
- ) -> Result<(), Trap> {
- let range = self.wasm_data_range(data_index);
- self.memory_init_segment(memory_index, range, dst, src, len)
- }
-
- pub(crate) fn memory_init_segment(
- self: Pin<&mut Self>,
- memory_index: MemoryIndex,
- range: Range<u32>,
- dst: u64,
- src: u32,
- len: u32,
- ) -> Result<(), Trap> {
- // https://webassembly.github.io/bulk-memory-operations/core/exec/instructions.html#exec-memory-init
-
- let memory = self.get_memory(memory_index);
- let data = self.wasm_data(range);
- let dst = self.validate_inbounds(memory.current_length(), dst, len.into())?;
- let src = self.validate_inbounds(data.len(), src.into(), len.into())?;
- let len = len as usize;
-
- unsafe {
- let src_start = data.as_ptr().add(src);
- let dst_start = memory.base.as_ptr().add(dst);
- // FIXME audit whether this is safe in the presence of shared memory
- // (https://github.com/bytecodealliance/wasmtime/issues/4203).
- ptr::copy_nonoverlapping(src_start, dst_start, len);
- }
-
- Ok(())
- }
-
- /// Drop the given data segment, truncating its length to zero.
- pub(crate) fn data_drop(
- self: Pin<&mut Self>,
- data_index: DataIndex,
- ) -> Result<(), OutOfMemory> {
- self.dropped_data_mut().insert(data_index)?;
-
- // Note that we don't check that we actually removed a segment because
- // dropping a non-passive segment is a no-op (not a trap).
-
- Ok(())
+ /// # Panics
+ ///
+ /// Panics if `index` is out-of-bounds.
+ fn passive_data(&self, index: PassiveDataIndex) -> &[u8] {
+ let range = self.env_module().passive_data[index].clone();
+ self.wasm_data(range)
}
/// Get a table by index regardless of whether it is locally-defined
@@ -1419,6 +1346,26 @@ impl Instance {
ptr = ptr.add(1);
}
}
+
+ // Initialize the lengths of passive data segments.
+ //
+ // SAFETY: it's safe to initialize these lengths during initialization
+ // here and the various types of pointers and such here should all be
+ // valid.
+ unsafe {
+ let offsets = instance.runtime_info.offsets();
+ let mut lengths =
+ instance.vmctx_plus_offset_raw(offsets.vmctx_passive_data_lengths_begin());
+ let mut bases =
+ instance.vmctx_plus_offset_raw(offsets.vmctx_passive_data_bases_begin());
+ for i in module.passive_data.keys() {
+ let data = instance.passive_data(i);
+ lengths.write(u32::try_from(data.len()).unwrap());
+ lengths = lengths.add(1);
+ bases.write(VmPtr::from(NonNull::from(data).cast::<u8>()));
+ bases = bases.add(1);
+ }
+ }
}
/// Attempts to convert from the host `addr` specified to a WebAssembly
@@ -1517,11 +1464,6 @@ impl Instance {
unsafe { &mut self.get_unchecked_mut().store }
}
- fn dropped_data_mut(self: Pin<&mut Self>) -> &mut TryEntitySet<DataIndex> {
- // SAFETY: see `store_mut` above.
- unsafe { &mut self.get_unchecked_mut().dropped_data }
- }
-
fn memories_mut(
self: Pin<&mut Self>,
) -> &mut TryPrimaryMap<DefinedMemoryIndex, (MemoryAllocationIndex, Memory)> {
diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rs
index 7681aaef2a..6e1dca3fba 100644
--- a/crates/wasmtime/src/runtime/vm/libcalls.rs
+++ b/crates/wasmtime/src/runtime/vm/libcalls.rs
@@ -72,8 +72,7 @@ use core::ptr::NonNull;
use core::time::Duration;
use wasmtime_core::math::WasmFloat;
use wasmtime_environ::{
- CompiledTrap, DataIndex, DefinedMemoryIndex, DefinedTableIndex, ElemIndex, FuncIndex,
- MemoryIndex, TableIndex, Trap,
+ CompiledTrap, DefinedMemoryIndex, DefinedTableIndex, ElemIndex, FuncIndex, TableIndex, Trap,
};
#[cfg(feature = "wmemcheck")]
use wasmtime_wmemcheck::AccessError::{
@@ -567,23 +566,6 @@ unsafe fn memory_fill(
}
}
-// Implementation of `memory.init`.
-fn memory_init(
- store: &mut dyn VMStore,
- instance: InstanceId,
- memory_index: u32,
- data_index: u32,
- dst: u64,
- src: u32,
- len: u32,
-) -> Result<(), Trap> {
- let memory_index = MemoryIndex::from_u32(memory_index);
- let data_index = DataIndex::from_u32(data_index);
- store
- .instance_mut(instance)
- .memory_init(memory_index, data_index, dst, src, len)
-}
-
// Implementation of `ref.func`.
fn ref_func(store: &mut dyn VMStore, instance: InstanceId, func_index: u32) -> NonNull<u8> {
let (instance, registry) = store.instance_and_module_registry_mut(instance);
@@ -593,13 +575,6 @@ fn ref_func(store: &mut dyn VMStore, instance: InstanceId, func_index: u32) -> N
.cast()
}
-// Implementation of `data.drop`.
-fn data_drop(store: &mut dyn VMStore, instance: InstanceId, data_index: u32) -> Result<()> {
- let data_index = DataIndex::from_u32(data_index);
- store.instance_mut(instance).data_drop(data_index)?;
- Ok(())
-}
-
// Returns a table entry after lazily initializing it.
fn table_get_lazy_init_func_ref(
store: &mut dyn VMStore,
@@ -794,163 +769,6 @@ fn get_interned_func_ref(
func_ref.map_or(core::ptr::null_mut(), |f| f.as_ptr().cast())
}
-/// Implementation of the `array.new_data` instruction.
-#[cfg(feature = "gc")]
-fn array_new_data(
- store: &mut dyn VMStore,
- instance_id: InstanceId,
- array_type_index: u32,
- data_index: u32,
- src: u32,
- len: u32,
-) -> Result<core::num::NonZeroU32> {
- use crate::ArrayType;
- use wasmtime_environ::ModuleInternedTypeIndex;
-
- let (mut limiter, store) = store.resource_limiter_and_store_opaque();
- block_on!(store, async |store, asyncness| {
- let array_type_index = ModuleInternedTypeIndex::from_u32(array_type_index);
- let data_index = DataIndex::from_u32(data_index);
- let instance = store.instance(instance_id);
-
- // Calculate the byte-length of the data (as opposed to the element-length
- // of the array).
- let data_range = instance.wasm_data_range(data_index);
- let shared_ty = instance.engine_type_index(array_type_index);
- let array_ty = ArrayType::from_shared_type_index(store.engine(), shared_ty);
- let one_elem_size = array_ty
- .element_type()
- .data_byte_size()
- .expect("Wasm validation ensures that this type have a defined byte size");
- let byte_len = len
- .checked_mul(one_elem_size)
- .and_then(|x| usize::try_from(x).ok())
- .ok_or_else(|| Trap::MemoryOutOfBounds)?;
-
- // Get the data from the segment, checking bounds.
- let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds)?;
- instance
- .wasm_data(data_range.clone())
- .get(src..)
- .and_then(|d| d.get(..byte_len))
- .ok_or_else(|| Trap::MemoryOutOfBounds)?;
-
- // Allocate the (uninitialized) array.
- let gc_layout = store
- .engine()
- .signatures()
- .layout(shared_ty)
- .expect("array types have GC layouts");
- let array_layout = gc_layout.unwrap_array();
- let array_ref = store
- .retry_after_gc_async(limiter.as_mut(), (), asyncness, |store, ()| {
- store
- .unwrap_gc_store_mut()
- .alloc_uninit_array(shared_ty, len, &array_layout)?
- .map_err(|bytes_needed| crate::GcHeapOutOfMemory::new((), bytes_needed).into())
- })
- .await?;
-
- let (gc_store, instance) = store.optional_gc_store_and_instance_mut(instance_id);
- let gc_store = gc_store.unwrap();
- let data = &instance.wasm_data(data_range)[src..][..byte_len];
-
- // Copy the data into the array, initializing it.
- gc_store
- .gc_object_data(array_ref.as_gc_ref())
- .copy_from_slice(array_layout.base_size, data);
-
- // Return the array to Wasm!
- let raw = gc_store.expose_gc_ref_to_wasm(array_ref.into());
- Ok(raw)
- })?
-}
-
-/// Implementation of the `array.init_data` instruction.
-#[cfg(feature = "gc")]
-fn array_init_data(
- store: &mut dyn VMStore,
- instance_id: InstanceId,
- array_type_index: u32,
- array: u32,
- dst: u32,
- data_index: u32,
- src: u32,
- len: u32,
-) -> Result<()> {
- use crate::ArrayType;
- use wasmtime_environ::ModuleInternedTypeIndex;
-
- let array_type_index = ModuleInternedTypeIndex::from_u32(array_type_index);
- let data_index = DataIndex::from_u32(data_index);
- let instance = store.instance(instance_id);
-
- log::trace!(
- "array.init_data(array={array:#x}, dst={dst}, data_index={data_index:?}, src={src}, len={len})",
- );
-
- // Null check the array.
- let gc_ref = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference)?;
- let array = gc_ref
- .into_arrayref(&*store.unwrap_gc_store().gc_heap)
- .expect("gc ref should be an array");
-
- let dst = usize::try_from(dst).map_err(|_| Trap::MemoryOutOfBounds)?;
- let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds)?;
- let len = usize::try_from(len).map_err(|_| Trap::MemoryOutOfBounds)?;
-
- // Bounds check the array.
- let array_len = array.len(store.store_opaque());
- let array_len = usize::try_from(array_len).map_err(|_| Trap::ArrayOutOfBounds)?;
- if dst.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > array_len {
- return Err(Trap::ArrayOutOfBounds.into());
- }
-
- // Calculate the byte length from the array length.
- let shared_ty = instance.engine_type_index(array_type_index);
- let array_ty = ArrayType::from_shared_type_index(store.engine(), shared_ty);
- let one_elem_size = array_ty
- .element_type()
- .data_byte_size()
- .expect("Wasm validation ensures that this type have a defined byte size");
- let data_len = len
- .checked_mul(usize::try_from(one_elem_size).unwrap())
- .ok_or_else(|| Trap::MemoryOutOfBounds)?;
-
- // Get the data from the segment, checking its bounds.
- let data_range = instance.wasm_data_range(data_index);
- instance
- .wasm_data(data_range.clone())
- .get(src..)
- .and_then(|d| d.get(..data_len))
- .ok_or_else(|| Trap::MemoryOutOfBounds)?;
-
- // Copy the data into the array.
-
- let dst_offset = u32::try_from(dst)
- .unwrap()
- .checked_mul(one_elem_size)
- .unwrap();
-
- let array_layout = store
- .engine()
- .signatures()
- .layout(shared_ty)
- .expect("array types have GC layouts");
- let array_layout = array_layout.unwrap_array();
-
- let obj_offset = array_layout.base_size.checked_add(dst_offset).unwrap();
-
- let (gc_store, instance) = store.optional_gc_store_and_instance_mut(instance_id);
- let gc_store = gc_store.unwrap();
- let data = &instance.wasm_data(data_range)[src..][..data_len];
- gc_store
- .gc_object_data(array.as_gc_ref())
- .copy_from_slice(obj_offset, data);
-
- Ok(())
-}
-
#[cfg(feature = "gc")]
fn array_new_elem(
store: &mut dyn VMStore,
diff --git a/tests/disas/array-fill-funcref.wat b/tests/disas/array-fill-funcref.wat
index bdd6a27f89..6bb8a7ccb1 100644
--- a/tests/disas/array-fill-funcref.wat
+++ b/tests/disas/array-fill-funcref.wat
@@ -29,7 +29,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:28 sig0
+;; fn0 = colocated u805306368:26 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i64, v5: i32):
@@ -155,8 +155,8 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32) -> i64 tail
;; sig1 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:7 sig0
-;; fn1 = colocated u805306368:28 sig1
+;; fn0 = colocated u805306368:6 sig0
+;; fn1 = colocated u805306368:26 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32):
diff --git a/tests/disas/call-indirect.wat b/tests/disas/call-indirect.wat
index 728a32da4a..e528475fd1 100644
--- a/tests/disas/call-indirect.wat
+++ b/tests/disas/call-indirect.wat
@@ -16,7 +16,7 @@
;; gv5 = load.i64 notrap aligned gv3+56
;; sig0 = (i64 vmctx, i64, i32) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
diff --git a/tests/disas/component-may-leave-without-signals-based-traps.wat b/tests/disas/component-may-leave-without-signals-based-traps.wat
index d3851bc76e..e3811e244b 100644
--- a/tests/disas/component-may-leave-without-signals-based-traps.wat
+++ b/tests/disas/component-may-leave-without-signals-based-traps.wat
@@ -44,7 +44,7 @@
;; retq
;; 129: movq %rbx, %rsi
;; 12c: movq 0x10(%rsi), %rax
-;; 130: movq 0x190(%rax), %rax
+;; 130: movq 0x170(%rax), %rax
;; 137: movq %rbx, %rdi
;; 13a: callq *%rax
;; 13c: ud2
diff --git a/tests/disas/debug.wat b/tests/disas/debug.wat
index cbfa40c8f1..90d14de9b3 100644
--- a/tests/disas/debug.wat
+++ b/tests/disas/debug.wat
@@ -128,7 +128,7 @@
;; popq %rbp
;; retq
;; 17a: movq 0x10(%rbx), %rax
-;; 17e: movq 0x190(%rax), %rax
+;; 17e: movq 0x170(%rax), %rax
;; 185: movq %rbx, %rdi
;; 188: callq *%rax
;; 18a: ud2
@@ -143,7 +143,7 @@
;; movq 8(%r10), %r11
;; movq %r11, 0x38(%r9)
;; movq 0x10(%rdi), %r11
-;; movq 0x188(%r11), %r11
+;; movq 0x168(%r11), %r11
;; movzbq %sil, %rsi
;; callq *%r11
;; movq %rbp, %rsp
@@ -160,7 +160,7 @@
;; movq 8(%r9), %r9
;; movq %r9, 0x38(%r8)
;; movq 0x10(%rdi), %r9
-;; movq 0x190(%r9), %r9
+;; movq 0x170(%r9), %r9
;; callq *%r9
;; movq %rbp, %rsp
;; popq %rbp
@@ -203,7 +203,7 @@
;; movq 8(%r11), %rax
;; movq %rax, 0x38(%r10)
;; movq 0x10(%rdi), %rax
-;; movq 0x1c0(%rax), %rcx
+;; movq 0x1a0(%rax), %rcx
;; movq %rdi, %rbx
;; callq *%rcx
;; testb %al, %al
@@ -239,7 +239,7 @@
;; popq %rbp
;; retq
;; 3af: movq 0x10(%rbx), %rax
-;; 3b3: movq 0x190(%rax), %rax
+;; 3b3: movq 0x170(%rax), %rax
;; 3ba: movq %rbx, %rdi
;; 3bd: callq *%rax
;; 3bf: ud2
diff --git a/tests/disas/duplicate-function-types.wat b/tests/disas/duplicate-function-types.wat
index 0682b67449..239d4405cb 100644
--- a/tests/disas/duplicate-function-types.wat
+++ b/tests/disas/duplicate-function-types.wat
@@ -26,7 +26,7 @@
;; gv6 = load.i64 notrap aligned gv4+8
;; sig0 = (i64 vmctx, i64) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/epoch-interruption.wat b/tests/disas/epoch-interruption.wat
index db17fe360b..9df8914937 100644
--- a/tests/disas/epoch-interruption.wat
+++ b/tests/disas/epoch-interruption.wat
@@ -11,7 +11,7 @@
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; sig0 = (i64 vmctx) -> i64 tail
-;; fn0 = colocated u805306368:16 sig0
+;; fn0 = colocated u805306368:14 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/gc/array-copy-with-fuel.wat b/tests/disas/gc/array-copy-with-fuel.wat
index 1c02b98809..844af77e8e 100644
--- a/tests/disas/gc/array-copy-with-fuel.wat
+++ b/tests/disas/gc/array-copy-with-fuel.wat
@@ -20,7 +20,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx) -> i8 tail
-;; fn0 = colocated u805306368:15 sig0
+;; fn0 = colocated u805306368:13 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32):
diff --git a/tests/disas/gc/array-init-data.wat b/tests/disas/gc/array-init-data.wat
new file mode 100644
index 0000000000..c1e264aee5
--- /dev/null
+++ b/tests/disas/gc/array-init-data.wat
@@ -0,0 +1,67 @@
+;;! target = "x86_64"
+;;! test = 'optimize'
+;;! flags = '-Wgc'
+
+(module
+ (data $passive "this is a passive data segment")
+ (type $a (array (mut i8)))
+
+ (func $a (param (ref $a) i32 i32 i32)
+ local.get 0
+ local.get 1
+ local.get 2
+ local.get 3
+ array.init_data $a $passive)
+)
+;; function u0:0(i64 vmctx, i64, i32, i32, i32, i32) tail {
+;; gv0 = vmctx
+;; gv1 = load.i64 notrap aligned readonly gv0+8
+;; gv2 = load.i64 notrap aligned gv1+24
+;; gv3 = vmctx
+;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
+;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
+;; gv6 = load.i64 notrap aligned gv4+40
+;; sig0 = (i64 vmctx, i64, i64, i64) tail
+;; fn0 = colocated u805306368:4 sig0
+;; stack_limit = gv2
+;;
+;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
+;; @002a trapz v2, user16
+;; @002a v50 = load.i64 notrap aligned readonly can_move v0+8
+;; @002a v7 = load.i64 notrap aligned readonly can_move v50+32
+;; @002a v6 = uextend.i64 v2
+;; @002a v8 = iadd v7, v6
+;; @002a v9 = iconst.i64 24
+;; @002a v10 = iadd v8, v9 ; v9 = 24
+;; @002a v11 = load.i32 user2 readonly v10
+;; @002a v13 = uextend.i64 v3
+;; @002a v14 = uextend.i64 v5
+;; @002a v15 = iadd v13, v14
+;; @002a v12 = uextend.i64 v11
+;; @002a v16 = icmp ugt v15, v12
+;; @002a trapnz v16, user17
+;; @002a v19 = uload32 notrap aligned v0+56
+;; @002a v20 = uextend.i64 v4
+;; @002a v22 = iadd v20, v14
+;; @002a v23 = icmp ugt v22, v19
+;; @002a trapnz v23, heap_oob
+;; @002a v24 = load.i64 notrap aligned v0+48
+;; v48 = iconst.i64 32
+;; @002a v30 = ushr v12, v48 ; v48 = 32
+;; @002a trapnz v30, user2
+;; @002a v32 = iconst.i32 28
+;; @002a v33 = uadd_overflow_trap v11, v32, user2 ; v32 = 28
+;; @002a v37 = uadd_overflow_trap v2, v33, user2
+;; @002a v38 = uextend.i64 v37
+;; @002a v40 = iadd v7, v38
+;; v58 = iadd v3, v32 ; v32 = 28
+;; @002a v41 = isub v33, v58
+;; @002a v42 = uextend.i64 v41
+;; @002a v43 = isub v40, v42
+;; @002a v26 = iadd v24, v20
+;; @002a call fn0(v0, v43, v26, v14)
+;; @002e jump block1
+;;
+;; block1:
+;; @002e return
+;; }
diff --git a/tests/disas/gc/array-new-data.wat b/tests/disas/gc/array-new-data.wat
new file mode 100644
index 0000000000..f18d74e6f7
--- /dev/null
+++ b/tests/disas/gc/array-new-data.wat
@@ -0,0 +1,138 @@
+;;! target = "x86_64"
+;;! test = 'optimize'
+;;! flags = '-Wgc'
+
+(module
+ (data $passive "this is a passive data segment")
+ (type $a (array i8))
+
+ (func $a (param i32 i32) (result (ref $a))
+ local.get 0
+ local.get 1
+ array.new_data $a $passive)
+)
+;; function u0:0(i64 vmctx, i64, i32, i32) -> i32 tail {
+;; ss0 = explicit_slot 4, align = 4
+;; gv0 = vmctx
+;; gv1 = load.i64 notrap aligned readonly gv0+8
+;; gv2 = load.i64 notrap aligned gv1+24
+;; gv3 = vmctx
+;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
+;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
+;; gv6 = load.i64 notrap aligned gv4+40
+;; sig0 = (i64 vmctx, i32, i32, i32) -> i64 tail
+;; sig1 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
+;; sig2 = (i64 vmctx, i64, i64, i64) tail
+;; fn0 = colocated u805306368:6 sig0
+;; fn1 = colocated u805306368:26 sig1
+;; fn2 = colocated u805306368:4 sig2
+;; stack_limit = gv2
+;;
+;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
+;; @0025 v5 = uextend.i64 v3
+;; v72 = iconst.i64 32
+;; @0025 v7 = ushr v5, v72 ; v72 = 32
+;; @0025 trapnz v7, heap_oob
+;; @0025 v10 = uload32 notrap aligned v0+48
+;; @0025 v11 = uextend.i64 v2
+;; @0025 v13 = iadd v11, v5
+;; @0025 v14 = icmp ugt v13, v10
+;; @0025 trapnz v14, heap_oob
+;; @0025 v15 = iconst.i32 0
+;; @0025 v16 = call fn0(v0, v15, v2, v3) ; v15 = 0
+;; @0025 trapnz v7, user18
+;; @0025 v17 = iconst.i32 28
+;; @0025 v22 = uadd_overflow_trap v17, v3, user18 ; v17 = 28
+;; @0025 v24 = iconst.i32 -1476395008
+;; @0025 v26 = load.i64 notrap aligned readonly can_move v0+40
+;; @0025 v27 = load.i32 notrap aligned readonly can_move v26
+;; @0025 v28 = iconst.i32 8
+;; @0025 v29 = call fn1(v0, v24, v27, v22, v28) ; v24 = -1476395008, v28 = 8
+;; v69 = stack_addr.i64 ss0
+;; store notrap v29, v69
+;; @0025 v67 = load.i64 notrap aligned readonly can_move v0+8
+;; @0025 v30 = load.i64 notrap aligned readonly can_move v67+32
+;; @0025 v31 = uextend.i64 v29
+;; @0025 v32 = iadd v30, v31
+;; v65 = iconst.i64 24
+;; @0025 v33 = iadd v32, v65 ; v65 = 24
+;; @0025 store user2 v3, v33
+;; @0025 v41 = ushr v5, v72 ; v72 = 32
+;; @0025 trapnz v41, user2
+;; @0025 v44 = uadd_overflow_trap v3, v17, user2 ; v17 = 28
+;; v58 = load.i32 notrap v69
+;; @0025 v48 = uadd_overflow_trap v58, v44, user2
+;; @0025 v49 = uextend.i64 v48
+;; @0025 v51 = iadd v30, v49
+;; @0025 v52 = isub v44, v17 ; v17 = 28
+;; @0025 v53 = uextend.i64 v52
+;; @0025 v54 = isub v51, v53
+;; @0025 call fn2(v0, v54, v16, v5), stack_map=[i32 @ ss0+0]
+;; v57 = load.i32 notrap v69
+;; @0029 jump block1
+;;
+;; block1:
+;; @0029 return v57
+;; }
+
+;; function u0:0(i64 vmctx, i64, i32, i32) -> i32 tail {
+;; ss0 = explicit_slot 4, align = 4
+;; gv0 = vmctx
+;; gv1 = load.i64 notrap aligned readonly gv0+8
+;; gv2 = load.i64 notrap aligned gv1+24
+;; gv3 = vmctx
+;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
+;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
+;; gv6 = load.i64 notrap aligned gv4+40
+;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
+;; sig1 = (i64 vmctx, i64, i64, i64) tail
+;; fn0 = colocated u805306368:25 sig0
+;; fn1 = colocated u805306368:4 sig1
+;; stack_limit = gv2
+;;
+;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
+;; @0025 v5 = uextend.i64 v3
+;; v73 = iconst.i64 32
+;; @0025 v7 = ushr v5, v73 ; v73 = 32
+;; @0025 trapnz v7, heap_oob
+;; @0025 v10 = uload32 notrap aligned v0+56
+;; @0025 v11 = uextend.i64 v2
+;; @0025 v13 = iadd v11, v5
+;; @0025 v14 = icmp ugt v13, v10
+;; @0025 trapnz v14, heap_oob
+;; @0025 v15 = load.i64 notrap aligned v0+48
+;; @0025 trapnz v7, user18
+;; @0025 v18 = iconst.i32 28
+;; @0025 v23 = uadd_overflow_trap v18, v3, user18 ; v18 = 28
+;; @0025 v25 = iconst.i32 -1476395008
+;; @0025 v27 = load.i64 notrap aligned readonly can_move v0+40
+;; @0025 v28 = load.i32 notrap aligned readonly can_move v27
+;; @0025 v29 = iconst.i32 8
+;; @0025 v30 = call fn0(v0, v25, v28, v23, v29) ; v25 = -1476395008, v29 = 8
+;; v70 = stack_addr.i64 ss0
+;; store notrap v30, v70
+;; @0025 v68 = load.i64 notrap aligned readonly can_move v0+8
+;; @0025 v31 = load.i64 notrap aligned readonly can_move v68+32
+;; @0025 v32 = uextend.i64 v30
+;; @0025 v33 = iadd v31, v32
+;; v66 = iconst.i64 24
+;; @0025 v34 = iadd v33, v66 ; v66 = 24
+;; @0025 store user2 v3, v34
+;; @0025 v42 = ushr v5, v73 ; v73 = 32
+;; @0025 trapnz v42, user2
+;; @0025 v45 = uadd_overflow_trap v3, v18, user2 ; v18 = 28
+;; v59 = load.i32 notrap v70
+;; @0025 v49 = uadd_overflow_trap v59, v45, user2
+;; @0025 v50 = uextend.i64 v49
+;; @0025 v52 = iadd v31, v50
+;; @0025 v53 = isub v45, v18 ; v18 = 28
+;; @0025 v54 = uextend.i64 v53
+;; @0025 v55 = isub v52, v54
+;; @0025 v17 = iadd v15, v11
+;; @0025 call fn1(v0, v55, v17, v5), stack_map=[i32 @ ss0+0]
+;; v58 = load.i32 notrap v70
+;; @0029 jump block1
+;;
+;; block1:
+;; @0029 return v58
+;; }
diff --git a/tests/disas/gc/array-new-default-anyref.wat b/tests/disas/gc/array-new-default-anyref.wat
index d0c7285cc8..bd0a83169c 100644
--- a/tests/disas/gc/array-new-default-anyref.wat
+++ b/tests/disas/gc/array-new-default-anyref.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-exnref.wat b/tests/disas/gc/array-new-default-exnref.wat
index 65768119c0..67674b7288 100644
--- a/tests/disas/gc/array-new-default-exnref.wat
+++ b/tests/disas/gc/array-new-default-exnref.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-externref.wat b/tests/disas/gc/array-new-default-externref.wat
index 5daacd3389..b9d15a9161 100644
--- a/tests/disas/gc/array-new-default-externref.wat
+++ b/tests/disas/gc/array-new-default-externref.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-f32.wat b/tests/disas/gc/array-new-default-f32.wat
index 9368a71346..c2eb20f17c 100644
--- a/tests/disas/gc/array-new-default-f32.wat
+++ b/tests/disas/gc/array-new-default-f32.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-f64.wat b/tests/disas/gc/array-new-default-f64.wat
index 0b9bd83d2f..1b3d7d217f 100644
--- a/tests/disas/gc/array-new-default-f64.wat
+++ b/tests/disas/gc/array-new-default-f64.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-funcref.wat b/tests/disas/gc/array-new-default-funcref.wat
index 40b74290ad..c14c38edcf 100644
--- a/tests/disas/gc/array-new-default-funcref.wat
+++ b/tests/disas/gc/array-new-default-funcref.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-i16.wat b/tests/disas/gc/array-new-default-i16.wat
index 97fc473f4a..268b9eaa53 100644
--- a/tests/disas/gc/array-new-default-i16.wat
+++ b/tests/disas/gc/array-new-default-i16.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-i32.wat b/tests/disas/gc/array-new-default-i32.wat
index 2c47f2f099..4eacd42ae7 100644
--- a/tests/disas/gc/array-new-default-i32.wat
+++ b/tests/disas/gc/array-new-default-i32.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-i64.wat b/tests/disas/gc/array-new-default-i64.wat
index 3d71303b2d..50db279c33 100644
--- a/tests/disas/gc/array-new-default-i64.wat
+++ b/tests/disas/gc/array-new-default-i64.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/array-new-default-i8.wat b/tests/disas/gc/array-new-default-i8.wat
index db6ebbd99d..70e564e7e4 100644
--- a/tests/disas/gc/array-new-default-i8.wat
+++ b/tests/disas/gc/array-new-default-i8.wat
@@ -20,7 +20,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32, i64) tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; fn1 = colocated u805306368:5 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/copying/array-new-fixed-of-gc-refs.wat b/tests/disas/gc/copying/array-new-fixed-of-gc-refs.wat
index 64ea216cc8..890b2db4b3 100644
--- a/tests/disas/gc/copying/array-new-fixed-of-gc-refs.wat
+++ b/tests/disas/gc/copying/array-new-fixed-of-gc-refs.wat
@@ -19,7 +19,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32):
diff --git a/tests/disas/gc/copying/array-new-fixed.wat b/tests/disas/gc/copying/array-new-fixed.wat
index 8ef742dbd7..7e44a3607e 100644
--- a/tests/disas/gc/copying/array-new-fixed.wat
+++ b/tests/disas/gc/copying/array-new-fixed.wat
@@ -16,7 +16,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i64, v4: i64):
diff --git a/tests/disas/gc/copying/array-new.wat b/tests/disas/gc/copying/array-new.wat
index 6d827f9f27..c642d976ce 100644
--- a/tests/disas/gc/copying/array-new.wat
+++ b/tests/disas/gc/copying/array-new.wat
@@ -16,7 +16,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i32):
diff --git a/tests/disas/gc/copying/br-on-cast-fail.wat b/tests/disas/gc/copying/br-on-cast-fail.wat
index 845bd5a27f..2d29f12290 100644
--- a/tests/disas/gc/copying/br-on-cast-fail.wat
+++ b/tests/disas/gc/copying/br-on-cast-fail.wat
@@ -26,7 +26,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/copying/br-on-cast.wat b/tests/disas/gc/copying/br-on-cast.wat
index 518ba235e3..8d8f2ad865 100644
--- a/tests/disas/gc/copying/br-on-cast.wat
+++ b/tests/disas/gc/copying/br-on-cast.wat
@@ -26,7 +26,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/copying/call-indirect-and-subtyping.wat b/tests/disas/gc/copying/call-indirect-and-subtyping.wat
index 88f1c18cfb..7f8df50e4f 100644
--- a/tests/disas/gc/copying/call-indirect-and-subtyping.wat
+++ b/tests/disas/gc/copying/call-indirect-and-subtyping.wat
@@ -24,8 +24,8 @@
;; sig0 = (i64 vmctx, i64) tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
;; sig2 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:9 sig1
-;; fn1 = colocated u805306368:34 sig2
+;; fn0 = colocated u805306368:7 sig1
+;; fn1 = colocated u805306368:30 sig2
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/copying/funcref-in-gc-heap-get.wat b/tests/disas/gc/copying/funcref-in-gc-heap-get.wat
index bb3c5b6de0..c7d82d046a 100644
--- a/tests/disas/gc/copying/funcref-in-gc-heap-get.wat
+++ b/tests/disas/gc/copying/funcref-in-gc-heap-get.wat
@@ -17,7 +17,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:29 sig0
+;; fn0 = colocated u805306368:27 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/copying/funcref-in-gc-heap-new.wat b/tests/disas/gc/copying/funcref-in-gc-heap-new.wat
index 3f6df13873..3b4b034690 100644
--- a/tests/disas/gc/copying/funcref-in-gc-heap-new.wat
+++ b/tests/disas/gc/copying/funcref-in-gc-heap-new.wat
@@ -18,8 +18,8 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:27 sig0
-;; fn1 = colocated u805306368:28 sig1
+;; fn0 = colocated u805306368:25 sig0
+;; fn1 = colocated u805306368:26 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
diff --git a/tests/disas/gc/copying/funcref-in-gc-heap-set.wat b/tests/disas/gc/copying/funcref-in-gc-heap-set.wat
index 2e9835209c..592d529b61 100644
--- a/tests/disas/gc/copying/funcref-in-gc-heap-set.wat
+++ b/tests/disas/gc/copying/funcref-in-gc-heap-set.wat
@@ -17,7 +17,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:28 sig0
+;; fn0 = colocated u805306368:26 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i64):
diff --git a/tests/disas/gc/copying/ref-cast.wat b/tests/disas/gc/copying/ref-cast.wat
index 1be0c3bbd0..9d5acdcf9e 100644
--- a/tests/disas/gc/copying/ref-cast.wat
+++ b/tests/disas/gc/copying/ref-cast.wat
@@ -17,7 +17,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/copying/ref-test-concrete-func-type.wat b/tests/disas/gc/copying/ref-test-concrete-func-type.wat
index 4bc0f9e62b..f37ad0ff7f 100644
--- a/tests/disas/gc/copying/ref-test-concrete-func-type.wat
+++ b/tests/disas/gc/copying/ref-test-concrete-func-type.wat
@@ -13,7 +13,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
diff --git a/tests/disas/gc/copying/ref-test-concrete-type.wat b/tests/disas/gc/copying/ref-test-concrete-type.wat
index 6f3e0ba068..e2a436d070 100644
--- a/tests/disas/gc/copying/ref-test-concrete-type.wat
+++ b/tests/disas/gc/copying/ref-test-concrete-type.wat
@@ -16,7 +16,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/copying/struct-new-default.wat b/tests/disas/gc/copying/struct-new-default.wat
index 85484358d0..d0bd916e37 100644
--- a/tests/disas/gc/copying/struct-new-default.wat
+++ b/tests/disas/gc/copying/struct-new-default.wat
@@ -18,7 +18,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/gc/copying/struct-new.wat b/tests/disas/gc/copying/struct-new.wat
index b362928cde..769e80b235 100644
--- a/tests/disas/gc/copying/struct-new.wat
+++ b/tests/disas/gc/copying/struct-new.wat
@@ -19,7 +19,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: f32, v3: i32, v4: i32):
diff --git a/tests/disas/gc/drc/array-new-fixed-of-gc-refs.wat b/tests/disas/gc/drc/array-new-fixed-of-gc-refs.wat
index 4a823efb3f..1c15fb71da 100644
--- a/tests/disas/gc/drc/array-new-fixed-of-gc-refs.wat
+++ b/tests/disas/gc/drc/array-new-fixed-of-gc-refs.wat
@@ -21,7 +21,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32):
diff --git a/tests/disas/gc/drc/array-new-fixed.wat b/tests/disas/gc/drc/array-new-fixed.wat
index 985c630a7f..67ddb29871 100644
--- a/tests/disas/gc/drc/array-new-fixed.wat
+++ b/tests/disas/gc/drc/array-new-fixed.wat
@@ -17,7 +17,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i64, v4: i64):
diff --git a/tests/disas/gc/drc/array-new.wat b/tests/disas/gc/drc/array-new.wat
index 513ec4378a..e379647b3c 100644
--- a/tests/disas/gc/drc/array-new.wat
+++ b/tests/disas/gc/drc/array-new.wat
@@ -17,7 +17,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+8
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i32):
diff --git a/tests/disas/gc/drc/br-on-cast-fail.wat b/tests/disas/gc/drc/br-on-cast-fail.wat
index c761cfbc99..6adc158fe5 100644
--- a/tests/disas/gc/drc/br-on-cast-fail.wat
+++ b/tests/disas/gc/drc/br-on-cast-fail.wat
@@ -27,7 +27,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/br-on-cast.wat b/tests/disas/gc/drc/br-on-cast.wat
index e014d6d4bb..a62b6f56a5 100644
--- a/tests/disas/gc/drc/br-on-cast.wat
+++ b/tests/disas/gc/drc/br-on-cast.wat
@@ -27,7 +27,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/call-indirect-and-subtyping.wat b/tests/disas/gc/drc/call-indirect-and-subtyping.wat
index ad12f0d2f0..974536af5b 100644
--- a/tests/disas/gc/drc/call-indirect-and-subtyping.wat
+++ b/tests/disas/gc/drc/call-indirect-and-subtyping.wat
@@ -25,8 +25,8 @@
;; sig0 = (i64 vmctx, i64) tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
;; sig2 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:9 sig1
-;; fn1 = colocated u805306368:34 sig2
+;; fn0 = colocated u805306368:7 sig1
+;; fn1 = colocated u805306368:30 sig2
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/externref-globals.wat b/tests/disas/gc/drc/externref-globals.wat
index 0140179474..961d89163f 100644
--- a/tests/disas/gc/drc/externref-globals.wat
+++ b/tests/disas/gc/drc/externref-globals.wat
@@ -78,7 +78,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u805306368:25 sig0
+;; fn0 = colocated u805306368:23 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/funcref-in-gc-heap-get.wat b/tests/disas/gc/drc/funcref-in-gc-heap-get.wat
index 710db4657e..6b55171b88 100644
--- a/tests/disas/gc/drc/funcref-in-gc-heap-get.wat
+++ b/tests/disas/gc/drc/funcref-in-gc-heap-get.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:29 sig0
+;; fn0 = colocated u805306368:27 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/funcref-in-gc-heap-new.wat b/tests/disas/gc/drc/funcref-in-gc-heap-new.wat
index 5f9c18aebd..5c80af41ed 100644
--- a/tests/disas/gc/drc/funcref-in-gc-heap-new.wat
+++ b/tests/disas/gc/drc/funcref-in-gc-heap-new.wat
@@ -19,8 +19,8 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:27 sig0
-;; fn1 = colocated u805306368:28 sig1
+;; fn0 = colocated u805306368:25 sig0
+;; fn1 = colocated u805306368:26 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
diff --git a/tests/disas/gc/drc/funcref-in-gc-heap-set.wat b/tests/disas/gc/drc/funcref-in-gc-heap-set.wat
index d5b4fbae5f..889ac7fc49 100644
--- a/tests/disas/gc/drc/funcref-in-gc-heap-set.wat
+++ b/tests/disas/gc/drc/funcref-in-gc-heap-set.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:28 sig0
+;; fn0 = colocated u805306368:26 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i64):
diff --git a/tests/disas/gc/drc/ref-cast.wat b/tests/disas/gc/drc/ref-cast.wat
index fb473992d6..1a57afb8b1 100644
--- a/tests/disas/gc/drc/ref-cast.wat
+++ b/tests/disas/gc/drc/ref-cast.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/ref-test-concrete-func-type.wat b/tests/disas/gc/drc/ref-test-concrete-func-type.wat
index 54b1268c10..5549f38b4e 100644
--- a/tests/disas/gc/drc/ref-test-concrete-func-type.wat
+++ b/tests/disas/gc/drc/ref-test-concrete-func-type.wat
@@ -14,7 +14,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
diff --git a/tests/disas/gc/drc/ref-test-concrete-type.wat b/tests/disas/gc/drc/ref-test-concrete-type.wat
index 6d0266369e..bed86d88e1 100644
--- a/tests/disas/gc/drc/ref-test-concrete-type.wat
+++ b/tests/disas/gc/drc/ref-test-concrete-type.wat
@@ -17,7 +17,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/drc/struct-new-default.wat b/tests/disas/gc/drc/struct-new-default.wat
index 64b21df0c9..fb4a67db46 100644
--- a/tests/disas/gc/drc/struct-new-default.wat
+++ b/tests/disas/gc/drc/struct-new-default.wat
@@ -20,7 +20,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/gc/drc/struct-new.wat b/tests/disas/gc/drc/struct-new.wat
index af99ad5a57..908bd5d967 100644
--- a/tests/disas/gc/drc/struct-new.wat
+++ b/tests/disas/gc/drc/struct-new.wat
@@ -21,7 +21,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: f32, v3: i32, v4: i32):
diff --git a/tests/disas/gc/drc/struct-set.wat b/tests/disas/gc/drc/struct-set.wat
index 4a14e9b353..a416612cf4 100644
--- a/tests/disas/gc/drc/struct-set.wat
+++ b/tests/disas/gc/drc/struct-set.wat
@@ -78,7 +78,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u805306368:25 sig0
+;; fn0 = colocated u805306368:23 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
diff --git a/tests/disas/gc/null/array-new-fixed-of-gc-refs.wat b/tests/disas/gc/null/array-new-fixed-of-gc-refs.wat
index c5f3eaaca8..72bc75fa94 100644
--- a/tests/disas/gc/null/array-new-fixed-of-gc-refs.wat
+++ b/tests/disas/gc/null/array-new-fixed-of-gc-refs.wat
@@ -21,7 +21,7 @@
;; gv5 = load.i64 notrap aligned gv4+40
;; gv6 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u805306368:26 sig0
+;; fn0 = colocated u805306368:24 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32):
diff --git a/tests/disas/gc/null/array-new-fixed.wat b/tests/disas/gc/null/array-new-fixed.wat
index 888e1d9652..afd09881e6 100644
--- a/tests/disas/gc/null/array-new-fixed.wat
+++ b/tests/disas/gc/null/array-new-fixed.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned gv4+40
;; gv6 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u805306368:26 sig0
+;; fn0 = colocated u805306368:24 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i64, v4: i64):
diff --git a/tests/disas/gc/null/array-new.wat b/tests/disas/gc/null/array-new.wat
index 5202973846..e8a99a9d49 100644
--- a/tests/disas/gc/null/array-new.wat
+++ b/tests/disas/gc/null/array-new.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned gv4+40
;; gv6 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u805306368:26 sig0
+;; fn0 = colocated u805306368:24 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i32):
diff --git a/tests/disas/gc/null/br-on-cast-fail.wat b/tests/disas/gc/null/br-on-cast-fail.wat
index 102674f7d2..9a49f354f2 100644
--- a/tests/disas/gc/null/br-on-cast-fail.wat
+++ b/tests/disas/gc/null/br-on-cast-fail.wat
@@ -27,7 +27,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/null/br-on-cast.wat b/tests/disas/gc/null/br-on-cast.wat
index 84ba976d8f..4ad6c8c097 100644
--- a/tests/disas/gc/null/br-on-cast.wat
+++ b/tests/disas/gc/null/br-on-cast.wat
@@ -27,7 +27,7 @@
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/null/call-indirect-and-subtyping.wat b/tests/disas/gc/null/call-indirect-and-subtyping.wat
index 36b5114a88..89d80ee7ab 100644
--- a/tests/disas/gc/null/call-indirect-and-subtyping.wat
+++ b/tests/disas/gc/null/call-indirect-and-subtyping.wat
@@ -25,8 +25,8 @@
;; sig0 = (i64 vmctx, i64) tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
;; sig2 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:9 sig1
-;; fn1 = colocated u805306368:34 sig2
+;; fn0 = colocated u805306368:7 sig1
+;; fn1 = colocated u805306368:30 sig2
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/null/funcref-in-gc-heap-get.wat b/tests/disas/gc/null/funcref-in-gc-heap-get.wat
index a77b333749..42fa52d8dc 100644
--- a/tests/disas/gc/null/funcref-in-gc-heap-get.wat
+++ b/tests/disas/gc/null/funcref-in-gc-heap-get.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:29 sig0
+;; fn0 = colocated u805306368:27 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/null/funcref-in-gc-heap-new.wat b/tests/disas/gc/null/funcref-in-gc-heap-new.wat
index a2ac811af6..73e66b9b0d 100644
--- a/tests/disas/gc/null/funcref-in-gc-heap-new.wat
+++ b/tests/disas/gc/null/funcref-in-gc-heap-new.wat
@@ -19,8 +19,8 @@
;; gv6 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i64) -> i8 tail
;; sig1 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:26 sig0
-;; fn1 = colocated u805306368:28 sig1
+;; fn0 = colocated u805306368:24 sig0
+;; fn1 = colocated u805306368:26 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
diff --git a/tests/disas/gc/null/funcref-in-gc-heap-set.wat b/tests/disas/gc/null/funcref-in-gc-heap-set.wat
index 9d062b9911..334d5ac14f 100644
--- a/tests/disas/gc/null/funcref-in-gc-heap-set.wat
+++ b/tests/disas/gc/null/funcref-in-gc-heap-set.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u805306368:28 sig0
+;; fn0 = colocated u805306368:26 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i64):
diff --git a/tests/disas/gc/null/ref-cast.wat b/tests/disas/gc/null/ref-cast.wat
index d62c24edd8..7a5a570d0b 100644
--- a/tests/disas/gc/null/ref-cast.wat
+++ b/tests/disas/gc/null/ref-cast.wat
@@ -18,7 +18,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/null/ref-test-concrete-func-type.wat b/tests/disas/gc/null/ref-test-concrete-func-type.wat
index 9120b465ea..9c560b0820 100644
--- a/tests/disas/gc/null/ref-test-concrete-func-type.wat
+++ b/tests/disas/gc/null/ref-test-concrete-func-type.wat
@@ -14,7 +14,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
diff --git a/tests/disas/gc/null/ref-test-concrete-type.wat b/tests/disas/gc/null/ref-test-concrete-type.wat
index a18a4cbfdd..03132d9e10 100644
--- a/tests/disas/gc/null/ref-test-concrete-type.wat
+++ b/tests/disas/gc/null/ref-test-concrete-type.wat
@@ -17,7 +17,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:34 sig0
+;; fn0 = colocated u805306368:30 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/gc/null/struct-new-default.wat b/tests/disas/gc/null/struct-new-default.wat
index 1e340d1bcd..9c8bebf167 100644
--- a/tests/disas/gc/null/struct-new-default.wat
+++ b/tests/disas/gc/null/struct-new-default.wat
@@ -20,7 +20,7 @@
;; gv5 = load.i64 notrap aligned gv4+40
;; gv6 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u805306368:26 sig0
+;; fn0 = colocated u805306368:24 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/gc/null/struct-new.wat b/tests/disas/gc/null/struct-new.wat
index eac3f343c8..d5815fc0cf 100644
--- a/tests/disas/gc/null/struct-new.wat
+++ b/tests/disas/gc/null/struct-new.wat
@@ -21,7 +21,7 @@
;; gv5 = load.i64 notrap aligned gv4+40
;; gv6 = load.i64 notrap aligned readonly can_move gv4+32
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u805306368:26 sig0
+;; fn0 = colocated u805306368:24 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: f32, v3: i32, v4: i32):
diff --git a/tests/disas/gc/struct-new-default.wat b/tests/disas/gc/struct-new-default.wat
index 7bf876a97b..5ae04e74c6 100644
--- a/tests/disas/gc/struct-new-default.wat
+++ b/tests/disas/gc/struct-new-default.wat
@@ -21,7 +21,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/struct-new.wat b/tests/disas/gc/struct-new.wat
index 3997852121..45a393d4f7 100644
--- a/tests/disas/gc/struct-new.wat
+++ b/tests/disas/gc/struct-new.wat
@@ -21,7 +21,7 @@
;; gv5 = load.i64 notrap aligned readonly can_move gv4+32
;; gv6 = load.i64 notrap aligned gv4+40
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:27 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: f32, v3: i32, v4: i32):
diff --git a/tests/disas/icall-loop.wat b/tests/disas/icall-loop.wat
index 3918c54295..5874570b9e 100644
--- a/tests/disas/icall-loop.wat
+++ b/tests/disas/icall-loop.wat
@@ -30,7 +30,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
@@ -78,7 +78,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/icall-simd.wat b/tests/disas/icall-simd.wat
index 749c30e870..563cc990b7 100644
--- a/tests/disas/icall-simd.wat
+++ b/tests/disas/icall-simd.wat
@@ -16,7 +16,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64, i8x16) -> i8x16 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i8x16):
diff --git a/tests/disas/icall.wat b/tests/disas/icall.wat
index d84d2b7c72..df8447bf12 100644
--- a/tests/disas/icall.wat
+++ b/tests/disas/icall.wat
@@ -16,7 +16,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64, f32) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: f32):
diff --git a/tests/disas/indirect-call-no-caching.wat b/tests/disas/indirect-call-no-caching.wat
index 3f7e14f6a1..6d4322dc7f 100644
--- a/tests/disas/indirect-call-no-caching.wat
+++ b/tests/disas/indirect-call-no-caching.wat
@@ -70,7 +70,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/memory-copy-epochs.wat b/tests/disas/memory-copy-epochs.wat
index 3628a8ffb6..2ce8e0d348 100644
--- a/tests/disas/memory-copy-epochs.wat
+++ b/tests/disas/memory-copy-epochs.wat
@@ -18,7 +18,7 @@
;; gv6 = load.i64 notrap aligned readonly can_move gv3+56
;; sig0 = (i64 vmctx) -> i64 tail
;; sig1 = (i64 vmctx, i64, i64, i64) tail
-;; fn0 = colocated u805306368:16 sig0
+;; fn0 = colocated u805306368:14 sig0
;; fn1 = colocated u805306368:4 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/memory-copy-fuel.wat b/tests/disas/memory-copy-fuel.wat
index c0933b52b1..fcbc25e8ae 100644
--- a/tests/disas/memory-copy-fuel.wat
+++ b/tests/disas/memory-copy-fuel.wat
@@ -18,7 +18,7 @@
;; gv6 = load.i64 notrap aligned readonly can_move gv3+56
;; sig0 = (i64 vmctx) -> i8 tail
;; sig1 = (i64 vmctx, i64, i64, i64) tail
-;; fn0 = colocated u805306368:15 sig0
+;; fn0 = colocated u805306368:13 sig0
;; fn1 = colocated u805306368:4 sig1
;; stack_limit = gv2
;;
diff --git a/tests/disas/metadata-for-internal-asserts.wat b/tests/disas/metadata-for-internal-asserts.wat
index 4dd6039b51..a101aa8829 100644
--- a/tests/disas/metadata-for-internal-asserts.wat
+++ b/tests/disas/metadata-for-internal-asserts.wat
@@ -39,7 +39,7 @@
;; popq %rbp
;; retq
;; 5e: movq 0x10(%rbx), %rax
-;; 62: movq 0x190(%rax), %rax
+;; 62: movq 0x170(%rax), %rax
;; 69: movq %rbx, %rdi
;; 6c: callq *%rax
;; 6e: ud2
diff --git a/tests/disas/passive-data.wat b/tests/disas/passive-data.wat
index da2c547278..ba894ce058 100644
--- a/tests/disas/passive-data.wat
+++ b/tests/disas/passive-data.wat
@@ -20,15 +20,31 @@
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+64
;; gv5 = load.i64 notrap aligned readonly can_move gv3+56
-;; sig0 = (i64 vmctx, i32, i32, i64, i32, i32) -> i8 tail
-;; fn0 = colocated u805306368:6 sig0
+;; sig0 = (i64 vmctx, i64, i64, i64) tail
+;; fn0 = colocated u805306368:4 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32):
-;; @003d v5 = iconst.i32 0
-;; @003d v6 = iconst.i32 0
-;; @003d v8 = uextend.i64 v2
-;; @003d v9 = call fn0(v0, v5, v6, v8, v3, v4) ; v5 = 0, v6 = 0
+;; @003d v6 = load.i64 notrap aligned v0+64
+;; @003d v7 = uextend.i64 v2
+;; @003d v8 = uextend.i64 v4
+;; @003d v9 = iadd v7, v8
+;; @003d v10 = icmp ule v9, v6
+;; @003d trapz v10, heap_oob
+;; @003d v11 = uextend.i64 v2
+;; @003d v12 = load.i64 notrap aligned readonly can_move v0+56
+;; @003d v13 = iadd v12, v11
+;; @003d v15 = uload32 notrap aligned v0+152
+;; @003d v16 = uextend.i64 v3
+;; @003d v17 = uextend.i64 v4
+;; @003d v18 = iadd v16, v17
+;; @003d v19 = icmp ugt v18, v15
+;; @003d trapnz v19, heap_oob
+;; @003d v20 = load.i64 notrap aligned v0+144
+;; @003d v21 = uextend.i64 v3
+;; @003d v22 = iadd v20, v21
+;; @003d v24 = uextend.i64 v4
+;; @003d call fn0(v0, v13, v22, v24)
;; @0041 jump block1
;;
;; block1:
@@ -40,13 +56,11 @@
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
-;; sig0 = (i64 vmctx, i32) -> i8 tail
-;; fn0 = colocated u805306368:8 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
-;; @0044 v2 = iconst.i32 0
-;; @0044 v4 = call fn0(v0, v2) ; v2 = 0
+;; @0044 v3 = iconst.i32 0
+;; @0044 store notrap aligned v3, v0+152 ; v3 = 0
;; @0047 jump block1
;;
;; block1:
diff --git a/tests/disas/readonly-funcrefs.wat b/tests/disas/readonly-funcrefs.wat
index 8e70e114b1..a2895d7b6a 100644
--- a/tests/disas/readonly-funcrefs.wat
+++ b/tests/disas/readonly-funcrefs.wat
@@ -39,7 +39,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64) tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/riscv64-component-builtins-asm.wat b/tests/disas/riscv64-component-builtins-asm.wat
index adb9364fa3..157502d1cf 100644
--- a/tests/disas/riscv64-component-builtins-asm.wat
+++ b/tests/disas/riscv64-component-builtins-asm.wat
@@ -54,7 +54,7 @@
;; ret
;; mv a1, s5
;; ld a0, 0x10(a1)
-;; ld a2, 0x190(a0)
+;; ld a2, 0x170(a0)
;; mv a0, a1
;; jalr a2
;; .byte 0x00, 0x00, 0x00, 0x00
diff --git a/tests/disas/riscv64-component-builtins.wat b/tests/disas/riscv64-component-builtins.wat
index e1ab366a08..8a96cab8de 100644
--- a/tests/disas/riscv64-component-builtins.wat
+++ b/tests/disas/riscv64-component-builtins.wat
@@ -34,7 +34,7 @@
;;
;; block1 cold:
;; v15 = load.i64 notrap aligned readonly v1+16
-;; v16 = load.i64 notrap aligned readonly v15+400
+;; v16 = load.i64 notrap aligned readonly v15+368
;; call_indirect sig1, v16(v1)
;; trap user1
;;
diff --git a/tests/disas/stack-switching/resume-suspend-data-passing.wat b/tests/disas/stack-switching/resume-suspend-data-passing.wat
index 148afc8ec5..3e88a77156 100644
--- a/tests/disas/stack-switching/resume-suspend-data-passing.wat
+++ b/tests/disas/stack-switching/resume-suspend-data-passing.wat
@@ -152,8 +152,8 @@
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32) -> i64 tail
;; sig1 = (i64 vmctx, i64, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:7 sig0
-;; fn1 = colocated u805306368:51 sig1
+;; fn0 = colocated u805306368:6 sig0
+;; fn1 = colocated u805306368:47 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/stack-switching/resume-suspend.wat b/tests/disas/stack-switching/resume-suspend.wat
index 96430f7297..e7656ac8ae 100644
--- a/tests/disas/stack-switching/resume-suspend.wat
+++ b/tests/disas/stack-switching/resume-suspend.wat
@@ -113,8 +113,8 @@
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32) -> i64 tail
;; sig1 = (i64 vmctx, i64, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:7 sig0
-;; fn1 = colocated u805306368:51 sig1
+;; fn0 = colocated u805306368:6 sig0
+;; fn1 = colocated u805306368:47 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/stack-switching/symmetric-switch.wat b/tests/disas/stack-switching/symmetric-switch.wat
index 578e0f1cb7..1c6036ee47 100644
--- a/tests/disas/stack-switching/symmetric-switch.wat
+++ b/tests/disas/stack-switching/symmetric-switch.wat
@@ -33,8 +33,8 @@
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32) -> i64 tail
;; sig1 = (i64 vmctx, i64, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:7 sig0
-;; fn1 = colocated u805306368:51 sig1
+;; fn0 = colocated u805306368:6 sig0
+;; fn1 = colocated u805306368:47 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
@@ -248,8 +248,8 @@
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32) -> i64 tail
;; sig1 = (i64 vmctx, i64, i32, i32) -> i64 tail
-;; fn0 = colocated u805306368:7 sig0
-;; fn1 = colocated u805306368:51 sig1
+;; fn0 = colocated u805306368:6 sig0
+;; fn1 = colocated u805306368:47 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/table-set-fixed-size.wat b/tests/disas/table-set-fixed-size.wat
index 15af7f10f6..5a6bafedb9 100644
--- a/tests/disas/table-set-fixed-size.wat
+++ b/tests/disas/table-set-fixed-size.wat
@@ -26,7 +26,7 @@
;; gv6 = load.i64 notrap aligned readonly can_move gv5+32
;; gv7 = load.i64 notrap aligned gv5+40
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u805306368:25 sig0
+;; fn0 = colocated u805306368:23 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
@@ -123,7 +123,7 @@
;; gv6 = load.i64 notrap aligned readonly can_move gv5+32
;; gv7 = load.i64 notrap aligned gv5+40
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u805306368:25 sig0
+;; fn0 = colocated u805306368:23 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
diff --git a/tests/disas/table-set.wat b/tests/disas/table-set.wat
index 9b2b4b4a70..fd5bdf64e3 100644
--- a/tests/disas/table-set.wat
+++ b/tests/disas/table-set.wat
@@ -27,7 +27,7 @@
;; gv7 = load.i64 notrap aligned readonly can_move gv6+32
;; gv8 = load.i64 notrap aligned gv6+40
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u805306368:25 sig0
+;; fn0 = colocated u805306368:23 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
@@ -126,7 +126,7 @@
;; gv7 = load.i64 notrap aligned readonly can_move gv6+32
;; gv8 = load.i64 notrap aligned gv6+40
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u805306368:25 sig0
+;; fn0 = colocated u805306368:23 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
diff --git a/tests/disas/typed-funcrefs.wat b/tests/disas/typed-funcrefs.wat
index 0adf87debc..6257f9de10 100644
--- a/tests/disas/typed-funcrefs.wat
+++ b/tests/disas/typed-funcrefs.wat
@@ -134,7 +134,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i32, i64) -> i64 tail
;; sig1 = (i64 vmctx, i64, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u805306368:9 sig0
+;; fn0 = colocated u805306368:7 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
@@ -188,7 +188,7 @@
;; gv4 = load.i64 notrap aligned readonly can_move gv3+48
;; sig0 = (i64 vmctx, i64, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i32, i64) -> i64 tail
-;; fn0 = colocated u805306368:9 sig1
+;; fn0 = colocated u805306368:7 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
diff --git a/tests/disas/x64-simd-round-without-sse41.wat b/tests/disas/x64-simd-round-without-sse41.wat
index cca72da966..c31b00715e 100644
--- a/tests/disas/x64-simd-round-without-sse41.wat
+++ b/tests/disas/x64-simd-round-without-sse41.wat
@@ -17,7 +17,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u805306368:37 sig0
+;; fn0 = colocated u805306368:33 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -49,7 +49,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u805306368:39 sig0
+;; fn0 = colocated u805306368:35 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -81,7 +81,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u805306368:41 sig0
+;; fn0 = colocated u805306368:37 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -113,7 +113,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u805306368:43 sig0
+;; fn0 = colocated u805306368:39 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -145,7 +145,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u805306368:38 sig0
+;; fn0 = colocated u805306368:34 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -171,7 +171,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u805306368:40 sig0
+;; fn0 = colocated u805306368:36 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -197,7 +197,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u805306368:42 sig0
+;; fn0 = colocated u805306368:38 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -223,7 +223,7 @@
;; gv2 = load.i64 notrap aligned gv1+24
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u805306368:44 sig0
+;; fn0 = colocated u805306368:40 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
diff --git a/tests/misc_testsuite/memory_init.wast b/tests/misc_testsuite/memory_init.wast
new file mode 100644
index 0000000000..70d18bc799
--- /dev/null
+++ b/tests/misc_testsuite/memory_init.wast
@@ -0,0 +1,123 @@
+;;! multi_memory = true
+;;! bulk_memory = true
+;;! memory64 = true
+
+;; A test about the trapping behavior of `memory.init`
+
+(module
+ (memory $m32 1)
+ (memory $m64 i64 1)
+
+ (data $d "hi")
+ (data $a (i32.const 0) "hi2")
+
+ (func (export "init32-d") (param i32 i32 i32)
+ local.get 0
+ local.get 1
+ local.get 2
+ memory.init $m32 $d)
+
+ (func (export "init64-d") (param i64 i32 i32)
+ local.get 0
+ local.get 1
+ local.get 2
+ memory.init $m64 $d)
+
+ (func (export "drop-d") data.drop $d)
+
+ (func (export "init32-a") (param i32 i32 i32)
+ local.get 0
+ local.get 1
+ local.get 2
+ memory.init $m32 $a)
+
+ (func (export "init64-a") (param i64 i32 i32)
+ local.get 0
+ local.get 1
+ local.get 2
+ memory.init $m64 $a)
+)
+
+(assert_return (invoke "init32-d" (i32.const 0) (i32.const 0) (i32.const 0)))
+(assert_return (invoke "init32-d" (i32.const 10) (i32.const 1) (i32.const 1)))
+(assert_return (invoke "init32-d" (i32.const 100) (i32.const 0) (i32.const 2)))
+(assert_return (invoke "init32-d" (i32.const 65536) (i32.const 2) (i32.const 0)))
+(assert_return (invoke "init32-d" (i32.const 65535) (i32.const 1) (i32.const 1)))
+(assert_return (invoke "init32-d" (i32.const 65534) (i32.const 0) (i32.const 2)))
+(assert_trap (invoke "init32-d" (i32.const 0) (i32.const 0) (i32.const 3)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 0) (i32.const 3) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 65537) (i32.const 0) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const -1) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 1) (i32.const -1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 1) (i32.const 1) (i32.const -1)) "out of bounds")
+
+(assert_return (invoke "init64-d" (i64.const 0) (i32.const 0) (i32.const 0)))
+(assert_return (invoke "init64-d" (i64.const 10) (i32.const 1) (i32.const 1)))
+(assert_return (invoke "init64-d" (i64.const 100) (i32.const 0) (i32.const 2)))
+(assert_return (invoke "init64-d" (i64.const 65536) (i32.const 2) (i32.const 0)))
+(assert_return (invoke "init64-d" (i64.const 65535) (i32.const 1) (i32.const 1)))
+(assert_return (invoke "init64-d" (i64.const 65534) (i32.const 0) (i32.const 2)))
+(assert_trap (invoke "init64-d" (i64.const 0) (i32.const 0) (i32.const 3)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 0) (i32.const 3) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 65537) (i32.const 0) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const -1) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 1) (i32.const -1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 1) (i32.const 1) (i32.const -1)) "out of bounds")
+
+(assert_return (invoke "drop-d"))
+
+(assert_return (invoke "init32-d" (i32.const 0) (i32.const 0) (i32.const 0)))
+(assert_return (invoke "init32-d" (i32.const 65536) (i32.const 0) (i32.const 0)))
+(assert_trap (invoke "init32-d" (i32.const 10) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 100) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 65536) (i32.const 2) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 65535) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 65534) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 0) (i32.const 0) (i32.const 3)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 0) (i32.const 3) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 65537) (i32.const 0) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const -1) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 1) (i32.const -1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-d" (i32.const 1) (i32.const 1) (i32.const -1)) "out of bounds")
+
+(assert_return (invoke "init64-d" (i64.const 0) (i32.const 0) (i32.const 0)))
+(assert_return (invoke "init64-d" (i64.const 65536) (i32.const 0) (i32.const 0)))
+(assert_trap (invoke "init64-d" (i64.const 10) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 100) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 65536) (i32.const 2) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 65535) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 65534) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 0) (i32.const 0) (i32.const 3)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 0) (i32.const 3) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 65537) (i32.const 0) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const -1) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 1) (i32.const -1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-d" (i64.const 1) (i32.const 1) (i32.const -1)) "out of bounds")
+
+(assert_return (invoke "init32-a" (i32.const 0) (i32.const 0) (i32.const 0)))
+(assert_return (invoke "init32-a" (i32.const 65536) (i32.const 0) (i32.const 0)))
+(assert_trap (invoke "init32-a" (i32.const 10) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 100) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 65536) (i32.const 2) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 65535) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 65534) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 0) (i32.const 0) (i32.const 3)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 0) (i32.const 3) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 65537) (i32.const 0) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const -1) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 1) (i32.const -1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init32-a" (i32.const 1) (i32.const 1) (i32.const -1)) "out of bounds")
+
+(assert_return (invoke "init64-a" (i64.const 0) (i32.const 0) (i32.const 0)))
+(assert_return (invoke "init64-a" (i64.const 65536) (i32.const 0) (i32.const 0)))
+(assert_trap (invoke "init64-a" (i64.const 10) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 100) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 65536) (i32.const 2) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 65535) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 65534) (i32.const 0) (i32.const 2)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 0) (i32.const 0) (i32.const 3)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 0) (i32.const 3) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 65537) (i32.const 0) (i32.const 0)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const -1) (i32.const 1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 1) (i32.const -1) (i32.const 1)) "out of bounds")
+(assert_trap (invoke "init64-a" (i64.const 1) (i32.const 1) (i32.const -1)) "out of bounds")
diff --git a/winch/codegen/src/codegen/mod.rs b/winch/codegen/src/codegen/mod.rs
index f0a34b163c..e4fb855316 100644
--- a/winch/codegen/src/codegen/mod.rs
+++ b/winch/codegen/src/codegen/mod.rs
@@ -24,8 +24,8 @@ use wasmparser::{
};
use wasmtime_cranelift::{TRAP_BAD_SIGNATURE, TRAP_HEAP_MISALIGNED, TRAP_TABLE_OUT_OF_BOUNDS};
use wasmtime_environ::{
- FUNCREF_MASK, GlobalIndex, MemoryIndex, MemoryKind, MemoryTunables, PtrSize, TableIndex,
- Tunables, TypeIndex, WasmHeapType, WasmValType,
+ DataIndex, FUNCREF_MASK, GlobalIndex, MemoryIndex, MemoryKind, MemoryTunables, PtrSize,
+ TableIndex, Tunables, TypeIndex, WasmHeapType, WasmValType,
};
mod context;
@@ -1289,6 +1289,124 @@ where
Ok(())
}
+ /// Emit the `memory.init` operation.
+ pub fn emit_memory_init(&mut self, segment: DataIndex, mem: MemoryIndex) -> Result<()> {
+ let dst_heap = self.env.resolve_heap(mem);
+
+ let len = self.context.pop_to_reg(self.masm, None)?;
+ let src = self.context.pop_to_reg(self.masm, None)?;
+ let dst = self.context.pop_to_reg(self.masm, None)?;
+
+ // Make sure `len` is zero extended within its register ensuring that
+ // the full 64-bits of the register are defined. This assists in
+ // situations like cross-memory copies where one memory is 32-bit and
+ // one is 64-bit and the same register can be used for the length in
+ // both bounds checks below.
+ self.masm.extend(
+ writable!(len.reg),
+ len.reg,
+ Extend::<Zero>::I64Extend32.into(),
+ )?;
+
+ let dst_raw_addr = self.context.any_gpr(self.masm)?;
+ self.emit_bounds_check_and_compute_addr(&dst_heap, dst_raw_addr, dst.reg, len.reg)?;
+ self.context.free_reg(dst);
+
+ let passive_data_index = match self.env.translation.passive_data_map[segment] {
+ Some(i) => i,
+
+ // Active data segments always have length zero, so this is only
+ // valid of src and len are both zero.
+ None => {
+ self.masm.cmp(src.reg, RegImm::i32(0), OperandSize::S32)?;
+ self.masm
+ .trapif(IntCmpKind::Ne, TrapCode::HEAP_OUT_OF_BOUNDS)?;
+ self.masm.cmp(len.reg, RegImm::i32(0), OperandSize::S32)?;
+ self.masm
+ .trapif(IntCmpKind::Ne, TrapCode::HEAP_OUT_OF_BOUNDS)?;
+ self.context.free_reg(dst_raw_addr);
+ self.context.free_reg(src);
+ self.context.free_reg(len);
+ return Ok(());
+ }
+ };
+
+ // Bounds check this passive data segment. Load its
+ // dynamically-specified length and see if that's in the range
+ // of `src+len`.
+ let data_segment_length_offset = self
+ .env
+ .vmoffsets
+ .vmctx_passive_data_length(passive_data_index);
+ let tmp1 = self.context.any_gpr(self.masm)?;
+ let tmp2 = self.context.any_gpr(self.masm)?;
+ self.masm.load(
+ self.masm.address_at_vmctx(data_segment_length_offset)?,
+ writable!(tmp1),
+ OperandSize::S32,
+ )?;
+ self.masm
+ .mov(writable!(tmp2), src.reg.into(), OperandSize::S32)?;
+ self.masm.checked_uadd(
+ writable!(tmp2),
+ tmp2,
+ len.reg.into(),
+ OperandSize::S32,
+ TrapCode::HEAP_OUT_OF_BOUNDS,
+ )?;
+ self.masm.cmp(tmp2, tmp1.into(), OperandSize::S32)?;
+ self.masm
+ .trapif(IntCmpKind::GtU, TrapCode::HEAP_OUT_OF_BOUNDS)?;
+ self.context.free_reg(tmp2);
+
+ // Calculate the src pointer by loading the base of the passive segment
+ // and adding in the `src` offset.
+ let data_segment_base_offset = self
+ .env
+ .vmoffsets
+ .vmctx_passive_data_base(passive_data_index);
+ self.masm.load(
+ self.masm.address_at_vmctx(data_segment_base_offset)?,
+ writable!(tmp1),
+ OperandSize::S64,
+ )?;
+ self.masm.add_uextend(
+ writable!(tmp1),
+ tmp1,
+ src.reg,
+ OperandSize::S32,
+ OperandSize::S64,
+ )?;
+ self.context.free_reg(src);
+
+ // And finally, the final step is calling the `memory_copy` libcall.
+ self.context.stack.push(TypedReg::i64(dst_raw_addr).into());
+ self.context.stack.push(TypedReg::i64(tmp1).into());
+ self.context.stack.push(len.into());
+ let builtin = self.env.builtins.memory_copy::<M::ABI>()?;
+ FnCall::emit::<M>(
+ &mut self.env,
+ self.masm,
+ &mut self.context,
+ Callee::Builtin(builtin),
+ )?;
+ Ok(())
+ }
+
+ pub fn emit_data_drop(&mut self, data_index: DataIndex) -> Result<()> {
+ let passive_data_index = match self.env.translation.passive_data_map[data_index] {
+ Some(idx) => idx,
+ // Active data segments do nothing when dropped, so this is a noop.
+ None => return Ok(()),
+ };
+ let data_segment_offset = self
+ .env
+ .vmoffsets
+ .vmctx_passive_data_length(passive_data_index);
+ let len_addr = self.masm.address_at_vmctx(data_segment_offset)?;
+ self.masm.store(RegImm::i32(0), len_addr, OperandSize::S32)
+ }
+
/// Checks if fuel consumption is enabled and emits a series of instructions
/// that check the current fuel usage by performing a zero-comparison with
/// the number of units stored in `VMStoreContext`.
diff --git a/winch/codegen/src/visitor.rs b/winch/codegen/src/visitor.rs
index f908379b5e..8d1f131d54 100644
--- a/winch/codegen/src/visitor.rs
+++ b/winch/codegen/src/visitor.rs
@@ -28,8 +28,8 @@ use wasmparser::{
};
use wasmtime_cranelift::TRAP_INDIRECT_CALL_TO_NULL;
use wasmtime_environ::{
- FUNCREF_INIT_BIT, FuncIndex, GlobalIndex, IndexType, MemoryIndex, TableIndex, TypeIndex,
- WasmHeapType, WasmValType,
+ DataIndex, FUNCREF_INIT_BIT, FuncIndex, GlobalIndex, IndexType, MemoryIndex, TableIndex,
+ TypeIndex, WasmHeapType, WasmValType,
};
/// A macro to define unsupported WebAssembly operators.
@@ -1876,18 +1876,7 @@ where
}
fn visit_memory_init(&mut self, data_index: u32, mem: u32) -> Self::Output {
- let at = self.context.stack.ensure_index_at(3)?;
- self.context
- .stack
- .insert_many(at, &[mem.try_into()?, data_index.try_into()?]);
- let builtin = self.env.builtins.memory_init::<M::ABI>()?;
- FnCall::emit::<M>(
- &mut self.env,
- self.masm,
- &mut self.context,
- Callee::Builtin(builtin),
- )?;
- self.context.pop_and_free(self.masm)
+ self.emit_memory_init(DataIndex::from_u32(data_index), MemoryIndex::from_u32(mem))
}
fn visit_memory_copy(&mut self, dst_mem: u32, src_mem: u32) -> Self::Output {
@@ -1936,16 +1925,7 @@ where
}
fn visit_data_drop(&mut self, data_index: u32) -> Self::Output {
- self.context.stack.extend([data_index.try_into()?]);
-
- let builtin = self.env.builtins.data_drop::<M::ABI>()?;
- FnCall::emit::<M>(
- &mut self.env,
- self.masm,
- &mut self.context,
- Callee::Builtin(builtin),
- )?;
- self.context.pop_and_free(self.masm)
+ self.emit_data_drop(DataIndex::from_u32(data_index))
}
fn visit_nop(&mut self) -> Self::Output {