Skip to content

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

Debug: implement breakpoints and single-stepping. (#12133)

Chris Fallin17fbd3c632fe
diff --git a/Cargo.lock b/Cargo.lock
index b79bd18164..edd8d32378 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4588,6 +4588,7 @@ dependencies = [
"serde_derive",
"serde_json",
"similar",
+ "smallvec",
"target-lexicon",
"tempfile",
"termcolor",
diff --git a/Cargo.toml b/Cargo.toml
index c3dc9d9fce..c06d8eddae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -79,6 +79,7 @@ capstone = { workspace = true, optional = true }
termcolor = { workspace = true, optional = true }
gimli = { workspace = true, optional = true }
pulley-interpreter = { workspace = true, optional = true }
+smallvec = { workspace = true }
async-trait = { workspace = true }
bytes = { workspace = true }
diff --git a/cranelift/codegen/src/inline.rs b/cranelift/codegen/src/inline.rs
index 1ca82203f3..4332012221 100644
--- a/cranelift/codegen/src/inline.rs
+++ b/cranelift/codegen/src/inline.rs
@@ -227,6 +227,14 @@ pub(crate) fn do_inlining(
// Can't inline indirect calls; need to have some earlier
// pass rewrite them into direct calls first, when possible.
}
+ ir::InstructionData::Call {
+ opcode: ir::Opcode::PatchableCall,
+ ..
+ } => {
+ // Can't inline patchable calls; they need to
+ // remain patchable and inlining the whole body is
+ // decidedly *not* patchable!
+ }
_ => {
debug_assert!(
!cursor.func.dfg.insts[inst].opcode().is_call(),
@@ -497,7 +505,19 @@ fn inline_one(
call_opcode == ir::Opcode::TryCall,
call_exception_table.is_some()
);
- if call_opcode == ir::Opcode::TryCall {
+ // Note that we do not fix up patchable calls
+ // inlined at a try-call to a try-call, because
+ // the "patchable ABI" does not support catching
+ // exceptions. This does mean that we cannot have
+ // an exception-throw propagate out of a
+ // breakpoint when we use patchable calls to set
+ // up breakpoints, but we don't expect that to
+ // occur.
+ //
+ // FIXME: consider making patchability an aspect
+ // of any call; then we can remove this special
+ // case.
+ if call_opcode == ir::Opcode::TryCall && opcode != ir::Opcode::PatchableCall {
allocs
.calls_needing_exception_table_fixup
.push(inlined_inst);
diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rs
index f8c8b997cc..04717a5e39 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs
@@ -1111,8 +1111,8 @@ impl MachInst for Inst {
Inst::Nop4
}
- fn gen_nop_unit() -> SmallVec<[u8; 8]> {
- smallvec![0x1f, 0x20, 0x03, 0xd5]
+ fn gen_nop_units() -> Vec<Vec<u8>> {
+ vec![vec![0x1f, 0x20, 0x03, 0xd5]]
}
fn rc_for_type(ty: Type) -> CodegenResult<(&'static [RegClass], &'static [Type])> {
diff --git a/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs b/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
index bc7082ee6e..a75eca5ff3 100644
--- a/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
+++ b/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
@@ -10,6 +10,8 @@ use crate::isa::pulley_shared::abi::PulleyMachineDeps;
use crate::{CodegenError, CodegenResult, settings};
use crate::{machinst::*, trace};
use alloc::string::{String, ToString};
+use alloc::vec;
+use alloc::vec::Vec;
use regalloc2::RegClass;
use smallvec::SmallVec;
@@ -535,14 +537,14 @@ where
todo!()
}
- fn gen_nop_unit() -> SmallVec<[u8; 8]> {
- let mut bytes = smallvec::smallvec![];
+ fn gen_nop_units() -> Vec<Vec<u8>> {
+ let mut bytes = vec![];
let nop = pulley_interpreter::op::Nop {};
nop.encode(&mut bytes);
// NOP needs to be a 1-byte opcode so it can be used to
// overwrite a callsite of any length.
assert_eq!(bytes.len(), 1);
- bytes
+ vec![bytes]
}
fn rc_for_type(ty: Type) -> CodegenResult<(&'static [RegClass], &'static [Type])> {
diff --git a/cranelift/codegen/src/isa/riscv64/inst/mod.rs b/cranelift/codegen/src/isa/riscv64/inst/mod.rs
index 1d2d5f6fdb..c461a86729 100644
--- a/cranelift/codegen/src/isa/riscv64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/riscv64/inst/mod.rs
@@ -811,8 +811,8 @@ impl MachInst for Inst {
Inst::Nop4
}
- fn gen_nop_unit() -> SmallVec<[u8; 8]> {
- smallvec![0x13, 0x00, 0x00, 0x00]
+ fn gen_nop_units() -> Vec<Vec<u8>> {
+ vec![vec![0x13, 0x00, 0x00, 0x00]]
}
fn rc_for_type(ty: Type) -> CodegenResult<(&'static [RegClass], &'static [Type])> {
diff --git a/cranelift/codegen/src/isa/s390x/inst/mod.rs b/cranelift/codegen/src/isa/s390x/inst/mod.rs
index d960e6eba0..c82183a5bd 100644
--- a/cranelift/codegen/src/isa/s390x/inst/mod.rs
+++ b/cranelift/codegen/src/isa/s390x/inst/mod.rs
@@ -1164,8 +1164,8 @@ impl MachInst for Inst {
}
}
- fn gen_nop_unit() -> SmallVec<[u8; 8]> {
- smallvec::smallvec![0x07, 0x07]
+ fn gen_nop_units() -> Vec<Vec<u8>> {
+ vec![vec![0x07, 0x07]]
}
fn rc_for_type(ty: Type) -> CodegenResult<(&'static [RegClass], &'static [Type])> {
diff --git a/cranelift/codegen/src/isa/x64/inst/mod.rs b/cranelift/codegen/src/isa/x64/inst/mod.rs
index 1d96403d28..0cb6c7494d 100644
--- a/cranelift/codegen/src/isa/x64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/x64/inst/mod.rs
@@ -11,6 +11,8 @@ use crate::isa::{CallConv, FunctionAlignment};
use crate::{CodegenError, CodegenResult, settings};
use crate::{machinst::*, trace};
use alloc::boxed::Box;
+use alloc::vec;
+use alloc::vec::Vec;
use core::slice;
use cranelift_assembler_x64 as asm;
use smallvec::{SmallVec, smallvec};
@@ -1308,6 +1310,7 @@ impl MachInst for Inst {
match self {
Inst::CallKnown { .. }
| Inst::CallUnknown { .. }
+ | Inst::PatchableCallKnown { .. }
| Inst::ElfTlsGetAddr { .. }
| Inst::MachOTlsGetAddr { .. } => CallType::Regular,
@@ -1391,8 +1394,13 @@ impl MachInst for Inst {
Inst::nop(std::cmp::min(preferred_size, 9) as u8)
}
- fn gen_nop_unit() -> SmallVec<[u8; 8]> {
- smallvec![0x90]
+ fn gen_nop_units() -> Vec<Vec<u8>> {
+ vec![
+ // Standard 1-byte NOP.
+ vec![0x90],
+ // 5-byte NOP useful for patching out patchable calls.
+ vec![0x0f, 0x1f, 0x44, 0x00, 0x00],
+ ]
}
fn rc_for_type(ty: Type) -> CodegenResult<(&'static [RegClass], &'static [Type])> {
diff --git a/cranelift/codegen/src/machinst/buffer.rs b/cranelift/codegen/src/machinst/buffer.rs
index c003ee18f7..f386e2af50 100644
--- a/cranelift/codegen/src/machinst/buffer.rs
+++ b/cranelift/codegen/src/machinst/buffer.rs
@@ -355,7 +355,7 @@ impl MachBufferFinalized<Stencil> {
unwind_info: self.unwind_info,
alignment: self.alignment,
frame_layout: self.frame_layout,
- nop: self.nop,
+ nop_units: self.nop_units,
}
}
}
@@ -406,7 +406,10 @@ pub struct MachBufferFinalized<T: CompilePhase> {
/// This allows a consumer of a `MachBufferFinalized` to disable
/// patchable call sites (which are enabled by default) without
/// specific knowledge of the target ISA.
- pub nop: SmallVec<[u8; 8]>,
+ ///
+ /// Each entry is one form of nop, and these are required to be
+ /// sorted in ascending-size order.
+ pub nop_units: Vec<Vec<u8>>,
}
const UNKNOWN_LABEL_OFFSET: CodeOffset = 0xffff_ffff;
@@ -1586,7 +1589,7 @@ impl<I: VCodeInst> MachBuffer<I> {
unwind_info: self.unwind_info,
alignment,
frame_layout: self.frame_layout,
- nop: I::gen_nop_unit(),
+ nop_units: I::gen_nop_units(),
}
}
@@ -1841,6 +1844,12 @@ impl<T: CompilePhase> MachBufferFinalized<T> {
&self.data[..]
}
+ /// Get a mutable slice of the code bytes, allowing patching
+ /// post-passes.
+ pub fn data_mut(&mut self) -> &mut [u8] {
+ &mut self.data[..]
+ }
+
/// Get the list of external relocations for this code.
pub fn relocs(&self) -> &[FinalizedMachReloc] {
&self.relocs[..]
@@ -1900,10 +1909,7 @@ impl<T: CompilePhase> MachBufferFinalized<T> {
/// region is guaranteed to be an integer multiple of that NOP
/// unit size.)
pub fn patchable_call_sites(&self) -> impl Iterator<Item = &MachPatchableCallSite> + '_ {
- self.patchable_call_sites.iter().map(|call_site| {
- debug_assert!(call_site.len as usize % self.nop.len() == 0);
- call_site
- })
+ self.patchable_call_sites.iter()
}
}
diff --git a/cranelift/codegen/src/machinst/mod.rs b/cranelift/codegen/src/machinst/mod.rs
index 15d8ed55c6..f534ddb87a 100644
--- a/cranelift/codegen/src/machinst/mod.rs
+++ b/cranelift/codegen/src/machinst/mod.rs
@@ -177,9 +177,9 @@ pub trait MachInst: Clone + Debug {
/// the instruction must have a nonzero size if preferred_size is nonzero.
fn gen_nop(preferred_size: usize) -> Self;
- /// The smallest possible NOP, as a unit that can be used to patch
- /// out code.
- fn gen_nop_unit() -> SmallVec<[u8; 8]>;
+ /// The various kinds of NOP, with size, sorted in ascending-size
+ /// order.
+ fn gen_nop_units() -> Vec<Vec<u8>>;
/// Align a basic block offset (from start of function). By default, no
/// alignment occurs.
diff --git a/crates/cranelift/src/compiled_function.rs b/crates/cranelift/src/compiled_function.rs
index ac1da86765..451b41f3ab 100644
--- a/crates/cranelift/src/compiled_function.rs
+++ b/crates/cranelift/src/compiled_function.rs
@@ -1,3 +1,5 @@
+use std::ops::Range;
+
use crate::{Relocation, mach_reloc_to_reloc, mach_trap_to_trap};
use cranelift_codegen::{
Final, MachBufferFinalized, MachBufferFrameLayout, MachSrcLoc, ValueLabelsRanges, ir,
@@ -65,6 +67,8 @@ pub struct CompiledFunction {
metadata: CompiledFunctionMetadata,
/// Debug metadata for the top-level function's state slot.
pub debug_slot_descriptor: Option<FrameStateSlotBuilder>,
+ /// Debug breakpoint patches: Wasm PC, offset range in buffer.
+ pub breakpoint_patch_points: Vec<(u32, Range<u32>)>,
}
impl CompiledFunction {
@@ -76,12 +80,58 @@ impl CompiledFunction {
name_map: PrimaryMap<ir::UserExternalNameRef, ir::UserExternalName>,
alignment: u32,
) -> Self {
- Self {
+ let mut this = Self {
buffer,
name_map,
alignment,
metadata: Default::default(),
debug_slot_descriptor: None,
+ breakpoint_patch_points: vec![],
+ };
+ this.finalize_breakpoints();
+
+ this
+ }
+
+ /// Finalize breakpoint patches: edit the buffer to have NOPs by
+ /// default, and place patch data in the debug breakpoint data
+ /// tables.
+ fn finalize_breakpoints(&mut self) {
+ // Traverse debug tags and patchable callsites together. All
+ // patchable callsites should have debug tags. Given both, we
+ // can know the Wasm PC and we can emit a breakpoint record.
+ let mut tags = self.buffer.debug_tags().peekable();
+ let mut patchable_callsites = self.buffer.patchable_call_sites().peekable();
+
+ while let (Some(tag), Some(patchable_callsite)) = (tags.peek(), patchable_callsites.peek())
+ {
+ if tag.offset > patchable_callsite.ret_addr {
+ patchable_callsites.next();
+ continue;
+ }
+ if patchable_callsite.ret_addr > tag.offset {
+ tags.next();
+ continue;
+ }
+ assert_eq!(tag.offset, patchable_callsite.ret_addr);
+
+ // Tag format used by our Wasm-to-CLIF format is
+ // (stackslot, wasm_pc, stack_shape). Taking the
+ // second-to-last tag will get the innermost Wasm PC (if
+ // there are multiple nested frames due to inlining).
+ assert!(tag.tags.len() >= 3);
+ let ir::DebugTag::User(wasm_pc) = tag.tags[tag.tags.len() - 2] else {
+ panic!("invalid tag")
+ };
+
+ let patchable_start = patchable_callsite.ret_addr - patchable_callsite.len;
+ let patchable_end = patchable_callsite.ret_addr;
+
+ self.breakpoint_patch_points
+ .push((wasm_pc, patchable_start..patchable_end));
+
+ tags.next();
+ patchable_callsites.next();
}
}
@@ -164,6 +214,13 @@ impl CompiledFunction {
.frame_layout()
.expect("Single-function MachBuffer must have frame layout information")
}
+
+ /// Returns an iterator over breakpoint patches for this function.
+ ///
+ /// Each tuple is (wasm PC, buffer offset range).
+ pub fn breakpoint_patches(&self) -> impl Iterator<Item = (u32, Range<u32>)> + '_ {
+ self.breakpoint_patch_points.iter().cloned()
+ }
}
// Collects an iterator of `InstructionAddressMap` into a `Vec` for insertion
diff --git a/crates/cranelift/src/compiler.rs b/crates/cranelift/src/compiler.rs
index c0edc72a98..a2d384bb0f 100644
--- a/crates/cranelift/src/compiler.rs
+++ b/crates/cranelift/src/compiler.rs
@@ -9,6 +9,7 @@ use cranelift_codegen::binemit::CodeOffset;
use cranelift_codegen::inline::InlineCommand;
use cranelift_codegen::ir::condcodes::IntCC;
use cranelift_codegen::ir::{self, InstBuilder, MemFlags, UserExternalName, UserFuncName, Value};
+use cranelift_codegen::isa::CallConv;
use cranelift_codegen::isa::{
OwnedTargetIsa, TargetIsa,
unwind::{UnwindInfo, UnwindInfoKind},
@@ -490,6 +491,9 @@ impl wasmtime_environ::Compiler for Compiler {
}
}
+ let mut breakpoint_table = Vec::new();
+ let mut nop_units = None;
+
let mut ret = Vec::with_capacity(funcs.len());
for (i, (sym, _key, func)) in funcs.iter().enumerate() {
let (sym_id, range) = builder.append_func(&sym, func, |idx| resolve_reloc(i, idx));
@@ -523,6 +527,14 @@ impl wasmtime_environ::Compiler for Compiler {
&frame_descriptors,
)?;
}
+ if self.tunables.debug_guest {
+ clif_to_env_breakpoints(
+ range.clone(),
+ func.breakpoint_patches(),
+ &mut breakpoint_table,
+ )?;
+ nop_units.get_or_insert_with(|| func.buffer.nop_units.clone());
+ }
builder.append_padding(self.linkopts.padding_between_functions);
let info = FunctionLoc {
@@ -532,7 +544,37 @@ impl wasmtime_environ::Compiler for Compiler {
ret.push((sym_id, info));
}
- builder.finish();
+ // Sort breakpoints by Wasm PC now. Note that the same Wasm PC
+ // may appear in multiple functions (due to inlining) so it is
+ // only now that we can aggregate all appearances of a PC
+ // together for breakpoint metadata indexed by that PC.
+ breakpoint_table.sort_by_key(|(wasm_pc, _text_range)| *wasm_pc);
+
+ builder.finish(|text| {
+ if !breakpoint_table.is_empty() {
+ let nop_units = nop_units.as_ref().unwrap();
+ let fill_with_nops = |mut slice: &mut [u8]| {
+ while !slice.is_empty() {
+ let nop_unit = nop_units
+ .iter()
+ .rev()
+ .find(|u| u.len() <= slice.len())
+ .expect("no NOP is small enough for remaining slice");
+ let (nop_sized_chunk, rest) = slice.split_at_mut(nop_unit.len());
+ nop_sized_chunk.copy_from_slice(&nop_unit);
+ slice = rest;
+ }
+ };
+
+ for (wasm_pc, text_range) in &breakpoint_table {
+ let start = usize::try_from(text_range.start).unwrap();
+ let end = usize::try_from(text_range.end).unwrap();
+ let text = &mut text[start..end];
+ frame_tables.add_breakpoint_patch(*wasm_pc, text_range.start, text);
+ fill_with_nops(text);
+ }
+ }
+ });
if self.tunables.generate_address_map {
addrs.append_to(obj);
@@ -674,8 +716,19 @@ impl wasmtime_environ::Compiler for Compiler {
let ptr_size = isa.pointer_bytes();
let pointer_type = isa.pointer_type();
let sigs = BuiltinFunctionSignatures::new(self);
- let builtin_func_index = key.unwrap_wasm_to_builtin_trampoline();
- let wasm_sig = sigs.wasm_signature(builtin_func_index);
+
+ let (builtin_func_index, wasm_sig) = match key {
+ FuncKey::WasmToBuiltinTrampoline(builtin) => (builtin, sigs.wasm_signature(builtin)),
+ FuncKey::PatchableToBuiltinTrampoline(builtin) => {
+ let mut sig = sigs.wasm_signature(builtin);
+ // Patchable-ABI functions cannot return anything. We
+ // raise any errors that occur below so this is fine.
+ sig.returns.clear();
+ sig.call_conv = CallConv::Patchable;
+ (builtin, sig)
+ }
+ _ => unreachable!(),
+ };
let host_sig = sigs.host_signature(builtin_func_index);
let mut compiler = self.function_compiler();
@@ -736,7 +789,11 @@ impl wasmtime_environ::Compiler for Compiler {
}
// And finally, return all the results of this libcall.
- builder.ins().return_(&results);
+ if !wasm_sig.returns.is_empty() {
+ builder.ins().return_(&results);
+ } else {
+ builder.ins().return_(&[]);
+ }
builder.finalize();
Ok(CompiledFunctionBody {
@@ -885,6 +942,7 @@ impl InliningCompiler for Compiler {
None => Cow::Borrowed(symbol),
Some(Abi::Wasm) => Cow::Owned(format!("{symbol}_wasm_call")),
Some(Abi::Array) => Cow::Owned(format!("{symbol}_array_call")),
+ Some(Abi::Patchable) => Cow::Owned(format!("{symbol}_patchable_call")),
};
let compiled_func = if let Some(input) = input {
@@ -1581,6 +1639,21 @@ fn clif_to_env_frame_tables<'a>(
Ok(())
}
+/// Convert from Cranelift's representation of breakpoint patches to
+/// Wasmtime's serialized metadata.
+fn clif_to_env_breakpoints(
+ range: Range<u64>,
+ breakpoint_patches: impl Iterator<Item = (u32, Range<u32>)>,
+ patch_table: &mut Vec<(u32, Range<u32>)>,
+) -> anyhow::Result<()> {
+ patch_table.extend(breakpoint_patches.map(|(wasm_pc, offset_range)| {
+ let start = offset_range.start + u32::try_from(range.start).unwrap();
+ let end = offset_range.end + u32::try_from(range.start).unwrap();
+ (wasm_pc, start..end)
+ }));
+ Ok(())
+}
+
fn save_last_wasm_entry_context(
builder: &mut FunctionBuilder,
pointer_type: ir::Type,
diff --git a/crates/cranelift/src/compiler/component.rs b/crates/cranelift/src/compiler/component.rs
index 707e2cd7b7..18c2b6086c 100644
--- a/crates/cranelift/src/compiler/component.rs
+++ b/crates/cranelift/src/compiler/component.rs
@@ -1420,6 +1420,10 @@ impl ComponentCompiler for Compiler {
wasmtime_environ::component::VMCOMPONENT_MAGIC,
)?);
}
+
+ Abi::Patchable => unreachable!(
+ "We should not be compiling a patchable-ABI trampoline for a component function"
+ ),
}
let mut compiler = self.function_compiler();
@@ -1499,6 +1503,12 @@ impl ComponentCompiler for Compiler {
wasmtime_environ::component::VMCOMPONENT_MAGIC,
)?);
}
+
+ Abi::Patchable => {
+ unreachable!(
+ "We should not be compiling a patchable trampoline for a component intrinsic"
+ )
+ }
}
let mut compiler = self.function_compiler();
diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs
index e5196037d0..0ec63d7e4a 100644
--- a/crates/cranelift/src/func_environ.rs
+++ b/crates/cranelift/src/func_environ.rs
@@ -14,7 +14,7 @@ use cranelift_codegen::ir::pcc::Fact;
use cranelift_codegen::ir::{self, BlockArg, ExceptionTableData, ExceptionTableItem, types};
use cranelift_codegen::ir::{ArgumentPurpose, ConstantData, Function, InstBuilder, MemFlags};
use cranelift_codegen::ir::{Block, types::*};
-use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa};
+use cranelift_codegen::isa::{CallConv, TargetFrontendConfig, TargetIsa};
use cranelift_entity::packed_option::{PackedOption, ReservedValue};
use cranelift_entity::{EntityRef, PrimaryMap, SecondaryMap};
use cranelift_frontend::Variable;
@@ -45,6 +45,7 @@ pub(crate) struct BuiltinFunctions {
types: BuiltinFunctionSignatures,
builtins: [Option<ir::FuncRef>; BuiltinFunctionIndex::len() as usize],
+ breakpoint_trampoline: Option<ir::FuncRef>,
}
impl BuiltinFunctions {
@@ -52,6 +53,7 @@ impl BuiltinFunctions {
Self {
types: BuiltinFunctionSignatures::new(compiler),
builtins: [None; BuiltinFunctionIndex::len() as usize],
+ breakpoint_trampoline: None,
}
}
@@ -74,6 +76,26 @@ impl BuiltinFunctions {
*cache = Some(f);
f
}
+
+ pub(crate) fn patchable_breakpoint(&mut self, func: &mut Function) -> ir::FuncRef {
+ *self.breakpoint_trampoline.get_or_insert_with(|| {
+ let mut signature = ir::Signature::new(CallConv::Patchable);
+ signature
+ .params
+ .push(ir::AbiParam::new(self.types.pointer_type));
+ let signature = func.import_signature(signature);
+ let key = FuncKey::PatchableToBuiltinTrampoline(BuiltinFunctionIndex::breakpoint());
+ let (namespace, index) = key.into_raw_parts();
+ let name = ir::ExternalName::User(
+ func.declare_imported_user_function(ir::UserExternalName { namespace, index }),
+ );
+ func.import_function(ir::ExtFuncData {
+ name,
+ signature,
+ colocated: true,
+ })
+ })
+ }
}
// Generate helper methods on `BuiltinFunctions` above for each named builtin
@@ -85,6 +107,7 @@ macro_rules! declare_function_signatures {
)*) => {
$(impl BuiltinFunctions {
$( #[$attr] )*
+ #[allow(dead_code, reason = "debug breakpoint libcall not used in host ABI, only patchable ABI")]
pub(crate) fn $name(&mut self, func: &mut Function) -> ir::FuncRef {
self.load_builtin(func, BuiltinFunctionIndex::$name())
}
@@ -3741,7 +3764,9 @@ impl FuncEnvironment<'_> {
self.fuel_before_op(op, builder, self.is_reachable());
}
if self.is_reachable() && self.state_slot.is_some() {
- let inst = builder.ins().sequence_point();
+ let builtin = self.builtin_functions.patchable_breakpoint(builder.func);
+ let vmctx = self.vmctx_val(&mut builder.cursor());
+ let inst = builder.ins().patchable_call(builtin, &[vmctx]);
let tags = self.debug_tags(builder.srcloc());
builder.func.debug_tags.set(inst, tags);
}
diff --git a/crates/cranelift/src/obj.rs b/crates/cranelift/src/obj.rs
index cd3142abeb..2d968995bc 100644
--- a/crates/cranelift/src/obj.rs
+++ b/crates/cranelift/src/obj.rs
@@ -218,9 +218,12 @@ impl<'a> ModuleTextBuilder<'a> {
///
/// Note that this will also write out the unwind information sections if
/// necessary.
- pub fn finish(mut self) {
+ pub fn finish(mut self, postprocess_text: impl FnOnce(&mut [u8])) {
// Finish up the text section now that we're done adding functions.
- let text = self.text.finish(&mut self.ctrl_plane);
+ let mut text = self.text.finish(&mut self.ctrl_plane);
+
+ postprocess_text(&mut text[..]);
+
self.obj
.section_mut(self.text_section)
.set_data(text, text_align(self.compiler));
diff --git a/crates/environ/src/builtin.rs b/crates/environ/src/builtin.rs
index a2b6e029a4..8422dce5a7 100644
--- a/crates/environ/src/builtin.rs
+++ b/crates/environ/src/builtin.rs
@@ -247,6 +247,9 @@ macro_rules! foreach_builtin_function {
// Throw an exception.
#[cfg(feature = "gc")]
throw_ref(vmctx: vmctx, exnref: u32) -> bool;
+
+ // Process a debug breakpoint.
+ breakpoint(vmctx: vmctx) -> bool;
}
};
}
diff --git a/crates/environ/src/compile/frame_table.rs b/crates/environ/src/compile/frame_table.rs
index 3191ae7ca1..489e990c9a 100644
--- a/crates/environ/src/compile/frame_table.rs
+++ b/crates/environ/src/compile/frame_table.rs
@@ -196,8 +196,10 @@ impl FrameStateSlotBuilder {
///
/// - `num_slot_descriptors`: u32
/// - `num_progpoints`: u32
+/// - `num_breakpoints`: u32
/// - `frame_descriptor_pool_length`: u32
-/// - `progpoint_descriptor_pool_length`; U32
+/// - `progpoint_descriptor_pool_length`: u32
+/// - `breakpoint_patch_pool_length`: u32
/// - `num_slot_descriptors` times:
/// - frame descriptor offset: u32
/// - length: u32
@@ -208,12 +210,22 @@ impl FrameStateSlotBuilder {
/// - encoded as (pc << 1) | post_pre_bit
/// - `num_progpoints` times:
/// - progpoint descriptor offset: u32
+/// - `num_breakpoints` times:
+/// - Wasm PC: u32 (sorted order; may repeat)
+/// - `num_breakpoints` times:
+/// - patch offset in text: u32
+/// - `num_breakpoints` times:
+/// - end of breakpoint patch data in pool: u32
+/// (find the start by end of previous; patches are in the
+/// pool in order and this saves storing redundant start/end values)
/// - frame descriptors (format described above; `frame_descriptor_pool_length` bytes)
/// - progpoint descriptors (`progpoint_descriptor_pool_length` bytes)
/// - each descriptor: sequence of frames
/// - Wasm PC: u32 (high bit set to indicate a parent frame)
/// - slot descriptor index: u32
/// - stack shape index: u32 (or u32::MAX for none)
+/// - breakpoint patch pool (`breakpoint_patch_pool_length` bytes)
+/// - freeform slices of machine-code bytes to patch in
#[derive(Default)]
pub struct FrameTableBuilder {
/// (offset, length) pairs into `frame_descriptor_data`, indexed
@@ -227,6 +239,12 @@ pub struct FrameTableBuilder {
progpoint_pcs: Vec<U32Bytes<LittleEndian>>,
progpoint_descriptor_offsets: Vec<U32Bytes<LittleEndian>>,
progpoint_descriptor_data: Vec<U32Bytes<LittleEndian>>,
+
+ breakpoint_pcs: Vec<U32Bytes<LittleEndian>>,
+ breakpoint_patch_offsets: Vec<U32Bytes<LittleEndian>>,
+ breakpoint_patch_data_ends: Vec<U32Bytes<LittleEndian>>,
+
+ breakpoint_patch_data: Vec<u8>,
}
impl FrameTableBuilder {
@@ -295,8 +313,20 @@ impl FrameTableBuilder {
}
}
- /// Serialize the exception-handler data section, taking a closure
- /// to consume slices.
+ /// Add one breakpoint patch.
+ pub fn add_breakpoint_patch(&mut self, wasm_pc: u32, patch_start_native_pc: u32, patch: &[u8]) {
+ self.breakpoint_pcs
+ .push(U32Bytes::new(LittleEndian, wasm_pc));
+ self.breakpoint_patch_offsets
+ .push(U32Bytes::new(LittleEndian, patch_start_native_pc));
+ self.breakpoint_patch_data.extend(patch.iter().cloned());
+ let end = u32::try_from(self.breakpoint_patch_data.len()).unwrap();
+ self.breakpoint_patch_data_ends
+ .push(U32Bytes::new(LittleEndian, end));
+ }
+
+ /// Serialize the framd-table data section, taking a closure to
+ /// consume slices.
pub fn serialize<F: FnMut(&[u8])>(&mut self, mut f: F) {
// Pad `frame_descriptor_data` to a multiple of 4 bytes so
// `progpoint_descriptor_data` is aligned as well.
@@ -308,18 +338,26 @@ impl FrameTableBuilder {
f(&num_frame_descriptors.to_le_bytes());
let num_prog_points = u32::try_from(self.progpoint_pcs.len()).unwrap();
f(&num_prog_points.to_le_bytes());
+ let num_breakpoints = u32::try_from(self.breakpoint_pcs.len()).unwrap();
+ f(&num_breakpoints.to_le_bytes());
let frame_descriptor_pool_length = u32::try_from(self.frame_descriptor_data.len()).unwrap();
f(&frame_descriptor_pool_length.to_le_bytes());
let progpoint_descriptor_pool_length =
u32::try_from(self.progpoint_descriptor_data.len()).unwrap();
f(&progpoint_descriptor_pool_length.to_le_bytes());
+ let breakpoint_patch_pool_length = u32::try_from(self.breakpoint_patch_data.len()).unwrap();
+ f(&breakpoint_patch_pool_length.to_le_bytes());
f(object::bytes_of_slice(&self.frame_descriptor_ranges));
f(object::bytes_of_slice(&self.frame_descriptor_fp_offsets));
f(object::bytes_of_slice(&self.progpoint_pcs));
f(object::bytes_of_slice(&self.progpoint_descriptor_offsets));
+ f(object::bytes_of_slice(&self.breakpoint_pcs));
+ f(object::bytes_of_slice(&self.breakpoint_patch_offsets));
+ f(object::bytes_of_slice(&self.breakpoint_patch_data_ends));
f(&self.frame_descriptor_data);
f(object::bytes_of_slice(&self.progpoint_descriptor_data));
+ f(&self.breakpoint_patch_data);
}
}
diff --git a/crates/environ/src/frame_table.rs b/crates/environ/src/frame_table.rs
index 1c58e1710f..3fe0bfa8ed 100644
--- a/crates/environ/src/frame_table.rs
+++ b/crates/environ/src/frame_table.rs
@@ -52,12 +52,19 @@ pub struct FrameTable<'a> {
progpoint_pcs: &'a [U32Bytes<LittleEndian>],
progpoint_descriptor_offsets: &'a [U32Bytes<LittleEndian>],
progpoint_descriptor_data: &'a [U32Bytes<LittleEndian>],
+
+ breakpoint_pcs: &'a [U32Bytes<LittleEndian>],
+ breakpoint_patch_offsets: &'a [U32Bytes<LittleEndian>],
+ breakpoint_patch_data_ends: &'a [U32Bytes<LittleEndian>],
+ breakpoint_patch_data: &'a [u8],
+
+ original_text: &'a [u8],
}
impl<'a> FrameTable<'a> {
/// Parse a frame table section from a byte-slice as produced by
/// [`crate::compile::frame_table::FrameTableBuilder`].
- pub fn parse(data: &'a [u8]) -> anyhow::Result<FrameTable<'a>> {
+ pub fn parse(data: &'a [u8], original_text: &'a [u8]) -> anyhow::Result<FrameTable<'a>> {
let mut data = Bytes(data);
let num_frame_descriptors = data
.read::<U32Bytes<LittleEndian>>()
@@ -68,6 +75,11 @@ impl<'a> FrameTable<'a> {
.map_err(|_| anyhow::anyhow!("Unable to read progpoint descriptor count prefix"))?;
let num_progpoint_descriptors =
usize::try_from(num_progpoint_descriptors.get(LittleEndian))?;
+ let num_breakpoints = data
+ .read::<U32Bytes<LittleEndian>>()
+ .map_err(|_| anyhow::anyhow!("Unable to read breakpoint count prefix"))?;
+ let num_breakpoints = usize::try_from(num_breakpoints.get(LittleEndian))?;
+
let frame_descriptor_pool_length = data
.read::<U32Bytes<LittleEndian>>()
.map_err(|_| anyhow::anyhow!("Unable to read frame descriptor pool length"))?;
@@ -78,6 +90,11 @@ impl<'a> FrameTable<'a> {
.map_err(|_| anyhow::anyhow!("Unable to read progpoint descriptor pool length"))?;
let progpoint_descriptor_pool_length =
usize::try_from(progpoint_descriptor_pool_length.get(LittleEndian))?;
+ let breakpoint_patch_pool_length = data
+ .read::<U32Bytes<LittleEndian>>()
+ .map_err(|_| anyhow::anyhow!("Unable to read breakpoint patch pool length"))?;
+ let breakpoint_patch_pool_length =
+ usize::try_from(breakpoint_patch_pool_length.get(LittleEndian))?;
let (frame_descriptor_ranges, data) =
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data.0, 2 * num_frame_descriptors)
@@ -92,17 +109,30 @@ impl<'a> FrameTable<'a> {
let (progpoint_descriptor_offsets, data) =
object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, num_progpoint_descriptors)
.map_err(|_| anyhow::anyhow!("Unable to read progpoint descriptor offset slice"))?;
+ let (breakpoint_pcs, data) =
+ object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, num_breakpoints)
+ .map_err(|_| anyhow::anyhow!("Unable to read breakpoint PC slice"))?;
+ let (breakpoint_patch_offsets, data) =
+ object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, num_breakpoints)
+ .map_err(|_| anyhow::anyhow!("Unable to read breakpoint patch offsets slice"))?;
+ let (breakpoint_patch_data_ends, data) =
+ object::slice_from_bytes::<U32Bytes<LittleEndian>>(data, num_breakpoints)
+ .map_err(|_| anyhow::anyhow!("Unable to read breakpoint patch data ends slice"))?;
let (frame_descriptor_data, data) = data
.split_at_checked(frame_descriptor_pool_length)
.ok_or_else(|| anyhow::anyhow!("Unable to read frame descriptor pool"))?;
- let (progpoint_descriptor_data, _) = object::slice_from_bytes::<U32Bytes<LittleEndian>>(
+ let (progpoint_descriptor_data, data) = object::slice_from_bytes::<U32Bytes<LittleEndian>>(
data,
progpoint_descriptor_pool_length,
)
.map_err(|_| anyhow::anyhow!("Unable to read progpoint descriptor pool"))?;
+ let (breakpoint_patch_data, _) = data
+ .split_at_checked(breakpoint_patch_pool_length)
+ .ok_or_else(|| anyhow::anyhow!("Unable to read breakpoint patch pool"))?;
+
Ok(FrameTable {
frame_descriptor_ranges,
frame_descriptor_data,
@@ -110,6 +140,11 @@ impl<'a> FrameTable<'a> {
progpoint_pcs,
progpoint_descriptor_offsets,
progpoint_descriptor_data,
+ breakpoint_pcs,
+ breakpoint_patch_offsets,
+ breakpoint_patch_data_ends,
+ breakpoint_patch_data,
+ original_text,
})
}
@@ -206,6 +241,85 @@ impl<'a> FrameTable<'a> {
Some((wasm_pc, frame_descriptor, stack_shape))
})
}
+
+ /// For a given breakpoint index, return the patch offset in text,
+ /// the patch data, and the original data.
+ fn breakpoint_patch(&self, i: usize) -> FrameTableBreakpointData<'_> {
+ let patch_pool_start = if i == 0 {
+ 0
+ } else {
+ self.breakpoint_patch_data_ends[i - 1].get(LittleEndian)
+ };
+ let patch_pool_end = self.breakpoint_patch_data_ends[i].get(LittleEndian);
+ let patch_pool_start = usize::try_from(patch_pool_start).unwrap();
+ let patch_pool_end = usize::try_from(patch_pool_end).unwrap();
+ let len = patch_pool_end - patch_pool_start;
+ let offset = self.breakpoint_patch_offsets[i].get(LittleEndian);
+ let offset = usize::try_from(offset).unwrap();
+ let original_data = &self.original_text[offset..offset + len];
+ FrameTableBreakpointData {
+ offset,
+ enable: &self.breakpoint_patch_data[patch_pool_start..patch_pool_end],
+ disable: original_data,
+ }
+ }
+
+ /// Find a list of breakpoint patches for a given Wasm PC.
+ pub fn lookup_breakpoint_patches_by_pc(
+ &self,
+ pc: u32,
+ ) -> impl Iterator<Item = FrameTableBreakpointData<'_>> + '_ {
+ // Find *some* entry with a matching Wasm PC. Note that there
+ // may be multiple entries for one PC.
+ let range = match self
+ .breakpoint_pcs
+ .binary_search_by_key(&pc, |p| p.get(LittleEndian))
+ {
+ Ok(mut i) => {
+ // Scan backward to first index with this PC.
+ while i > 0 && self.breakpoint_pcs[i - 1].get(LittleEndian) == pc {
+ i -= 1;
+ }
+
+ // Scan forward to find the end of the range.
+ let mut end = i;
+ while end < self.breakpoint_pcs.len()
+ && self.breakpoint_pcs[end].get(LittleEndian) == pc
+ {
+ end += 1;
+ }
+
+ i..end
+ }
+ Err(_) => 0..0,
+ };
+
+ range.map(|i| self.breakpoint_patch(i))
+ }
+
+ /// Return an iterator over all breakpoint patches.
+ ///
+ /// Returned tuples are (Wasm PC, breakpoint data).
+ pub fn breakpoint_patches(
+ &self,
+ ) -> impl Iterator<Item = (u32, FrameTableBreakpointData<'_>)> + '_ {
+ self.breakpoint_pcs.iter().enumerate().map(|(i, wasm_pc)| {
+ let wasm_pc = wasm_pc.get(LittleEndian);
+ let data = self.breakpoint_patch(i);
+ (wasm_pc, data)
+ })
+ }
+}
+
+/// Data describing how to patch code to enable or disable one
+/// breakpoint.
+pub struct FrameTableBreakpointData<'a> {
+ /// Offset in the code image's text section.
+ pub offset: usize,
+ /// Code bytes to patch in to enable the breakpoint.
+ pub enable: &'a [u8],
+ /// Code bytes to patch in to disable the breakpoint.
+ pub disable: &'a [u8],
}
/// An instruction position for a program point.
diff --git a/crates/environ/src/key.rs b/crates/environ/src/key.rs
index 190b0979ab..8f0fd0e794 100644
--- a/crates/environ/src/key.rs
+++ b/crates/environ/src/key.rs
@@ -18,31 +18,34 @@ use serde_derive::{Deserialize, Serialize};
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
pub enum FuncKeyKind {
/// A Wasm-defined function.
- DefinedWasmFunction = FuncKey::new_kind(0b000),
+ DefinedWasmFunction = FuncKey::new_kind(0b0000),
/// A trampoline from an array-caller to the given Wasm-callee.
- ArrayToWasmTrampoline = FuncKey::new_kind(0b001),
+ ArrayToWasmTrampoline = FuncKey::new_kind(0b0001),
/// A trampoline from a Wasm-caller to an array-callee of the given type.
- WasmToArrayTrampoline = FuncKey::new_kind(0b010),
+ WasmToArrayTrampoline = FuncKey::new_kind(0b0010),
/// A trampoline from a Wasm-caller to the given builtin.
- WasmToBuiltinTrampoline = FuncKey::new_kind(0b011),
+ WasmToBuiltinTrampoline = FuncKey::new_kind(0b0011),
+
+ /// A trampoline from the patchable ABI to the given builtin.
+ PatchableToBuiltinTrampoline = FuncKey::new_kind(0b0100),
/// A Pulley-specific host call.
- PulleyHostCall = FuncKey::new_kind(0b100),
+ PulleyHostCall = FuncKey::new_kind(0b0101),
/// A Wasm-caller to component builtin trampoline.
#[cfg(feature = "component-model")]
- ComponentTrampoline = FuncKey::new_kind(0b101),
+ ComponentTrampoline = FuncKey::new_kind(0b0110),
/// A Wasm-caller to array-callee `resource.drop` trampoline.
#[cfg(feature = "component-model")]
- ResourceDropTrampoline = FuncKey::new_kind(0b110),
+ ResourceDropTrampoline = FuncKey::new_kind(0b0111),
/// A Wasmtime unsafe intrinsic function.
#[cfg(feature = "component-model")]
- UnsafeIntrinsic = FuncKey::new_kind(0b111),
+ UnsafeIntrinsic = FuncKey::new_kind(0b1000),
}
impl From<FuncKeyKind> for u32 {
@@ -66,6 +69,9 @@ impl FuncKeyKind {
x if x == Self::ArrayToWasmTrampoline.into() => Self::ArrayToWasmTrampoline,
x if x == Self::WasmToArrayTrampoline.into() => Self::WasmToArrayTrampoline,
x if x == Self::WasmToBuiltinTrampoline.into() => Self::WasmToBuiltinTrampoline,
+ x if x == Self::PatchableToBuiltinTrampoline.into() => {
+ Self::PatchableToBuiltinTrampoline
+ }
x if x == Self::PulleyHostCall.into() => Self::PulleyHostCall,
#[cfg(feature = "component-model")]
@@ -122,6 +128,7 @@ impl FuncKeyNamespace {
FuncKeyKind::DefinedWasmFunction | FuncKeyKind::ArrayToWasmTrampoline => Self(raw),
FuncKeyKind::WasmToArrayTrampoline
| FuncKeyKind::WasmToBuiltinTrampoline
+ | FuncKeyKind::PatchableToBuiltinTrampoline
| FuncKeyKind::PulleyHostCall => {
assert_eq!(raw & FuncKey::MODULE_MASK, 0);
Self(raw)
@@ -192,6 +199,10 @@ pub enum Abi {
Wasm = 0,
/// The "array" ABI, or suitable to be an `array_call` field.
Array = 1,
+ /// The "patchable" ABI. Signature same as Wasm ABI, but
+ /// Cranelift-level (machine-level) ABI is different (no
+ /// clobbers).
+ Patchable = 2,
}
#[cfg(feature = "component-model")]
@@ -200,6 +211,7 @@ impl Abi {
match raw {
x if x == Self::Wasm.into_raw() => Self::Wasm,
x if x == Self::Array.into_raw() => Self::Array,
+ x if x == Self::Patchable.into_raw() => Self::Patchable,
_ => panic!("invalid raw representation passed to `Abi::from_raw`: {raw}"),
}
}
@@ -228,6 +240,9 @@ pub enum FuncKey {
/// A Pulley-specific host call.
PulleyHostCall(HostCall),
+ /// A trampoline from the patchable ABI to the given builtin.
+ PatchableToBuiltinTrampoline(BuiltinFunctionIndex),
+
/// A Wasm-caller to component builtin trampoline.
#[cfg(feature = "component-model")]
ComponentTrampoline(Abi, component::TrampolineIndex),
@@ -258,7 +273,7 @@ impl PartialOrd for FuncKey {
}
impl FuncKey {
- const KIND_BITS: u32 = 3;
+ const KIND_BITS: u32 = 4;
const KIND_OFFSET: u32 = 32 - Self::KIND_BITS;
const KIND_MASK: u32 = ((1 << Self::KIND_BITS) - 1) << Self::KIND_OFFSET;
const MODULE_MASK: u32 = !Self::KIND_MASK;
@@ -294,6 +309,11 @@ impl FuncKey {
let index = builtin.index();
(namespace, index)
}
+ FuncKey::PatchableToBuiltinTrampoline(builtin) => {
+ let namespace = FuncKeyKind::PatchableToBuiltinTrampoline.into_raw();
+ let index = builtin.index();
+ (namespace, index)
+ }
FuncKey::PulleyHostCall(host_call) => {
let namespace = FuncKeyKind::PulleyHostCall.into_raw();
let index = host_call.index();
@@ -341,13 +361,14 @@ impl FuncKey {
self.into_parts().1
}
- /// Get ABI of the function that this key is definining.
+ /// Get ABI of the function that this key is defining.
pub fn abi(self) -> Abi {
match self {
FuncKey::DefinedWasmFunction(_, _) => Abi::Wasm,
FuncKey::ArrayToWasmTrampoline(_, _) => Abi::Array,
FuncKey::WasmToArrayTrampoline(_) => Abi::Wasm,
FuncKey::WasmToBuiltinTrampoline(_) => Abi::Wasm,
+ FuncKey::PatchableToBuiltinTrampoline(_) => Abi::Patchable,
FuncKey::PulleyHostCall(_) => Abi::Wasm,
#[cfg(feature = "component-model")]
FuncKey::ComponentTrampoline(abi, _) => abi,
@@ -412,6 +433,11 @@ impl FuncKey {
let builtin = BuiltinFunctionIndex::from_u32(b);
Self::WasmToBuiltinTrampoline(builtin)
}
+ FuncKeyKind::PatchableToBuiltinTrampoline => {
+ assert_eq!(a & Self::MODULE_MASK, 0);
+ let builtin = BuiltinFunctionIndex::from_u32(b);
+ Self::PatchableToBuiltinTrampoline(builtin)
+ }
FuncKeyKind::PulleyHostCall => {
assert_eq!(a & Self::MODULE_MASK, 0);
let host_call = HostCall::from_index(b);
@@ -533,6 +559,7 @@ impl FuncKey {
Self::DefinedWasmFunction(..) | Self::ArrayToWasmTrampoline(..) => false,
Self::WasmToArrayTrampoline(..)
| Self::WasmToBuiltinTrampoline(..)
+ | Self::PatchableToBuiltinTrampoline(..)
| Self::PulleyHostCall(..) => true,
#[cfg(feature = "component-model")]
Self::ComponentTrampoline(..)
diff --git a/crates/environ/src/module_artifacts.rs b/crates/environ/src/module_artifacts.rs
index c5c0643c43..a5d3b4c81c 100644
--- a/crates/environ/src/module_artifacts.rs
+++ b/crates/environ/src/module_artifacts.rs
@@ -506,7 +506,9 @@ impl CompiledFunctionsTable {
| FuncKeyKind::WasmToArrayTrampoline
| FuncKeyKind::PulleyHostCall => true,
- FuncKeyKind::ArrayToWasmTrampoline | FuncKeyKind::WasmToBuiltinTrampoline => false,
+ FuncKeyKind::ArrayToWasmTrampoline
+ | FuncKeyKind::WasmToBuiltinTrampoline
+ | FuncKeyKind::PatchableToBuiltinTrampoline => false,
#[cfg(feature = "component-model")]
FuncKeyKind::ComponentTrampoline
@@ -522,6 +524,7 @@ impl CompiledFunctionsTable {
FuncKeyKind::ArrayToWasmTrampoline
| FuncKeyKind::WasmToArrayTrampoline
| FuncKeyKind::WasmToBuiltinTrampoline
+ | FuncKeyKind::PatchableToBuiltinTrampoline
| FuncKeyKind::PulleyHostCall => false,
#[cfg(feature = "component-model")]
FuncKeyKind::ComponentTrampoline
diff --git a/crates/jit-icache-coherence/src/libc.rs b/crates/jit-icache-coherence/src/libc.rs
index bac0a68d19..c61f4bb26a 100644
--- a/crates/jit-icache-coherence/src/libc.rs
+++ b/crates/jit-icache-coherence/src/libc.rs
@@ -139,17 +139,45 @@ fn riscv_flush_icache(start: u64, end: u64) -> Result<()> {
}
}
+#[cfg(target_arch = "aarch64")]
+fn aarch64_flush_icache(start: u64, end: u64) {
+ use core::arch::asm;
+
+ // See `sys_icache_invalidate` implementation in Darwin at
+ // https://github.com/apple/darwin-libplatform/blob/main/src/cachecontrol/arm64/cache.s. It
+ // turns out that all of these instructions work in userspace, so
+ // we can do this portably without having to rely on OS-specific
+ // syscalls like `sys_cache_invalidate()` on macOS or something
+ // equivalent on Linux.
+ const CACHE_LINE_SIZE: u64 = 64;
+ // For each cache line, flush the icache.
+ // Round down the start and round up the end.
+ let mut start = (start - CACHE_LINE_SIZE + 1).next_multiple_of(CACHE_LINE_SIZE);
+ let end = end.next_multiple_of(CACHE_LINE_SIZE);
+ while start < end {
+ unsafe {
+ asm!("ic ivau, {}", in(reg) start);
+ }
+ start += CACHE_LINE_SIZE;
+ }
+
+ // Flush the dcache, and then issue an instruction barrier so
+ // fetch can't restart until that's done. All cache lines we are
+ // about to execute (in the flushed range) are now guaranteed to
+ // see the new data.
+ unsafe {
+ asm!("dsb ish"); // Flush dcache.
+ asm!("isb"); // Instruction fetch barrier.
+ }
+}
+
pub(crate) use details::*;
/// See docs on [crate::clear_cache] for a description of what this function is trying to do.
#[inline]
pub(crate) fn clear_cache(_ptr: *const c_void, _len: usize) -> Result<()> {
- // TODO: On AArch64 we currently rely on the `mprotect` call that switches the memory from W+R
- // to R+X to do this for us, however that is an implementation detail and should not be relied
- // upon.
- // We should call some implementation of `clear_cache` here.
- //
- // See: https://github.com/bytecodealliance/wasmtime/issues/3310
+ #[cfg(target_arch = "aarch64")]
+ aarch64_flush_icache(_ptr as u64, (_ptr as u64) + (_len as u64));
#[cfg(all(target_arch = "riscv64", target_os = "linux"))]
riscv_flush_icache(_ptr as u64, (_ptr as u64) + (_len as u64))?;
Ok(())
diff --git a/crates/wasmtime/src/compile.rs b/crates/wasmtime/src/compile.rs
index 5e63afcc90..726a5bfc44 100644
--- a/crates/wasmtime/src/compile.rs
+++ b/crates/wasmtime/src/compile.rs
@@ -32,11 +32,10 @@ use call_graph::CallGraph;
#[cfg(feature = "component-model")]
use wasmtime_environ::component::Translator;
use wasmtime_environ::{
- Abi, BuiltinFunctionIndex, CompiledFunctionBody, CompiledFunctionsTable,
- CompiledFunctionsTableBuilder, CompiledModuleInfo, Compiler, DefinedFuncIndex, FilePos,
- FinishedObject, FuncKey, FunctionBodyData, InliningCompiler, IntraModuleInlining,
- ModuleEnvironment, ModuleTranslation, ModuleTypes, ModuleTypesBuilder, ObjectKind, PrimaryMap,
- StaticModuleIndex, Tunables,
+ Abi, CompiledFunctionBody, CompiledFunctionsTable, CompiledFunctionsTableBuilder,
+ CompiledModuleInfo, Compiler, DefinedFuncIndex, FilePos, FinishedObject, FuncKey,
+ FunctionBodyData, InliningCompiler, IntraModuleInlining, ModuleEnvironment, ModuleTranslation,
+ ModuleTypes, ModuleTypesBuilder, ObjectKind, PrimaryMap, StaticModuleIndex, Tunables,
};
mod call_graph;
@@ -306,6 +305,7 @@ impl<'a> CompileInputs<'a> {
match abi {
Abi::Wasm => "wasm-call",
Abi::Array => "array-call",
+ Abi::Patchable => "patchable-call",
},
intrinsic.name(),
);
@@ -334,6 +334,7 @@ impl<'a> CompileInputs<'a> {
match abi {
Abi::Wasm => "wasm-call",
Abi::Array => "array-call",
+ Abi::Patchable => "patchable-call",
},
trampoline.symbol_name(),
);
@@ -626,7 +627,8 @@ the use case.
// in their own call frames.
FuncKey::ArrayToWasmTrampoline(..)
| FuncKey::WasmToArrayTrampoline(..)
- | FuncKey::WasmToBuiltinTrampoline(..) => false,
+ | FuncKey::WasmToBuiltinTrampoline(..)
+ | FuncKey::PatchableToBuiltinTrampoline(..) => false,
#[cfg(feature = "component-model")]
FuncKey::ComponentTrampoline(..) | FuncKey::ResourceDropTrampoline => false,
@@ -917,10 +919,17 @@ fn compile_required_builtins(engine: &Engine, raw_outputs: &mut Vec<CompileOutpu
let mut builtins = HashSet::new();
let mut new_inputs: Vec<CompileInput<'_>> = Vec::new();
- let compile_builtin = |builtin: BuiltinFunctionIndex| {
+ let compile_builtin = |key: FuncKey| {
Box::new(move |compiler: &dyn Compiler| {
- let key = FuncKey::WasmToBuiltinTrampoline(builtin);
- let symbol = format!("wasmtime_builtin_{}", builtin.name());
+ let symbol = match key {
+ FuncKey::WasmToBuiltinTrampoline(builtin) => {
+ format!("wasmtime_builtin_{}", builtin.name())
+ }
+ FuncKey::PatchableToBuiltinTrampoline(builtin) => {
+ format!("wasmtime_patchable_builtin_{}", builtin.name())
+ }
+ _ => unreachable!(),
+ };
let mut function = compiler
.compile_wasm_to_builtin(key, &symbol)
.with_context(|| format!("failed to compile `{symbol}`"))?;
@@ -940,10 +949,14 @@ fn compile_required_builtins(engine: &Engine, raw_outputs: &mut Vec<CompileOutpu
for output in raw_outputs.iter() {
for reloc in compiler.compiled_function_relocation_targets(&*output.function.code) {
- if let FuncKey::WasmToBuiltinTrampoline(builtin) = reloc {
- if builtins.insert(builtin) {
- new_inputs.push(compile_builtin(builtin));
+ match reloc {
+ FuncKey::WasmToBuiltinTrampoline(builtin)
+ | FuncKey::PatchableToBuiltinTrampoline(builtin) => {
+ if builtins.insert(builtin) {
+ new_inputs.push(compile_builtin(reloc));
+ }
}
+ _ => {}
}
}
}
diff --git a/crates/wasmtime/src/runtime/code.rs b/crates/wasmtime/src/runtime/code.rs
index 4fabb195db..203b5128cf 100644
--- a/crates/wasmtime/src/runtime/code.rs
+++ b/crates/wasmtime/src/runtime/code.rs
@@ -461,7 +461,7 @@ impl<'a> ModuleWithCode<'a> {
/// Get the text offset (relative PC) for a given absolute PC in
/// this module.
- #[cfg(any(feature = "gc", feature = "debug"))]
+ #[cfg(feature = "gc")]
pub(crate) fn text_offset(&self, pc: usize) -> Option<u32> {
StoreCodePC::offset_of(self.store_code.text_range(), pc)
.map(|offset| u32::try_from(offset).expect("Module larger than 4GiB"))
diff --git a/crates/wasmtime/src/runtime/code_memory.rs b/crates/wasmtime/src/runtime/code_memory.rs
index 4659ec85f2..622a9bc6ce 100644
--- a/crates/wasmtime/src/runtime/code_memory.rs
+++ b/crates/wasmtime/src/runtime/code_memory.rs
@@ -22,6 +22,7 @@ pub struct CodeMemory {
#[cfg(feature = "debug-builtins")]
debug_registration: Option<crate::runtime::vm::GdbJitImageRegistration>,
published: bool,
+ registered: bool,
enable_branch_protection: bool,
needs_executable: bool,
#[cfg(feature = "debug-builtins")]
@@ -46,6 +47,10 @@ impl Drop for CodeMemory {
fn drop(&mut self) {
// If there is a custom code memory handler, restore the
// original (non-executable) state of the memory.
+ //
+ // We do this rather than invoking `unpublish()` because we
+ // want to skip the mprotect() if we natively own the mmap and
+ // are going to munmap soon anyway.
if let Some(mem) = self.custom_code_memory.as_ref() {
if self.published && self.needs_executable {
let text = self.text();
@@ -207,6 +212,7 @@ impl CodeMemory {
#[cfg(feature = "debug-builtins")]
debug_registration: None,
published: false,
+ registered: false,
enable_branch_protection: enable_branch_protection
.ok_or_else(|| anyhow!("missing `{}` section", obj::ELF_WASM_BTI))?,
needs_executable,
@@ -303,15 +309,20 @@ impl CodeMemory {
/// Publishes the internal ELF image to be ready for execution.
///
- /// This method can only be called once and will panic if called twice. This
- /// will parse the ELF image from the original `MmapVec` and do everything
- /// necessary to get it ready for execution, including:
+ /// This method can only be when the image is not published (its
+ /// default state) and will panic if called when already
+ /// published. This will parse the ELF image from the original
+ /// `MmapVec` and do everything necessary to get it ready for
+ /// execution, including:
///
/// * Change page protections from read/write to read/execute.
/// * Register unwinding information with the OS
/// * Register this image with the debugger if native DWARF is present
///
/// After this function executes all JIT code should be ready to execute.
+ ///
+ /// The action may be reversed by calling [`unpublish`], as long
+ /// as that method's safety requirements are upheld.
pub fn publish(&mut self) -> Result<()> {
assert!(!self.published);
self.published = true;
@@ -358,14 +369,17 @@ impl CodeMemory {
}
}
- // With all our memory set up use the platform-specific
- // `UnwindRegistration` implementation to inform the general
- // runtime that there's unwinding information available for all
- // our just-published JIT functions.
- self.register_unwind_info()?;
+ if !self.registered {
+ // With all our memory set up use the platform-specific
+ // `UnwindRegistration` implementation to inform the general
+ // runtime that there's unwinding information available for all
+ // our just-published JIT functions.
+ self.register_unwind_info()?;
- #[cfg(feature = "debug-builtins")]
- self.register_debug_image()?;
+ #[cfg(feature = "debug-builtins")]
+ self.register_debug_image()?;
+ self.registered = true;
+ }
}
Ok(())
@@ -394,6 +408,78 @@ impl CodeMemory {
}
}
+ /// "Unpublish" code memory (transition it from executable to read/writable).
+ ///
+ /// This may be used to edit the code image, as long as the
+ /// overall size of the memory remains the same. Note the hazards
+ /// inherent in editing code that may have been executed: any
+ /// stack frames with PC still active in this code must be
+ /// suspended (e.g., called into a hostcall that is then invoking
+ /// this method, or async-yielded) and any active PC values must
+ /// point to valid instructions. Thus this is mostly useful for
+ /// patching in-place at particular sites, such as by the use of
+ /// Cranelift's `patchable_call` instruction.
+ ///
+ /// If this fails, then the memory remains executable.
+ pub fn unpublish(&mut self) -> Result<()> {
+ assert!(self.published);
+ self.published = false;
+
+ if self.text().is_empty() {
+ return Ok(());
+ }
+
+ if self.custom_unpublish()? {
+ return Ok(());
+ }
+
+ if !self.mmap.supports_virtual_memory() {
+ bail!("this target requires virtual memory to be enabled");
+ }
+
+ // SAFETY: we are guaranteed by our own safety conditions that
+ // we have exclusive access to this code and can change its
+ // permissions (removing the execute bit) without causing
+ // problems.
+ #[cfg(has_virtual_memory)]
+ unsafe {
+ self.mmap.make_readwrite(0..self.mmap.len())?;
+ }
+
+ // Note that we do *not* unregister: we expect unpublish
+ // to be used for temporary edits, so we want the
+ // registration to "stick" after the initial publish and
+ // not toggle in subsequent unpublish/publish cycles.
+
+ Ok(())
+ }
+
+ fn custom_unpublish(&mut self) -> Result<bool> {
+ if let Some(mem) = self.custom_code_memory.as_ref() {
+ let text = self.text();
+ mem.unpublish_executable(text.as_ptr(), text.len())?;
+ Ok(true)
+ } else {
+ Ok(false)
+ }
+ }
+
+ /// Return a mutable borrow to the code, suitable for editing.
+ ///
+ /// Must not be published.
+ ///
+ /// # Panics
+ ///
+ /// This method panics if the code has been published (and not
+ /// subsequently unpublished).
+ pub fn text_mut(&mut self) -> &mut [u8] {
+ assert!(!self.published);
+ // SAFETY: we assert !published, which means we either have
+ // not yet applied readonly + execute permissinos, or we have
+ // undone that and flipped back to read-write via unpublish.
+ unsafe { &mut self.mmap.as_mut_slice()[self.text.clone()] }
+ }
+
unsafe fn register_unwind_info(&mut self) -> Result<()> {
if self.unwind.len() == 0 {
return Ok(());
diff --git a/crates/wasmtime/src/runtime/debug.rs b/crates/wasmtime/src/runtime/debug.rs
index f6b4730bf4..e256b886ba 100644
--- a/crates/wasmtime/src/runtime/debug.rs
+++ b/crates/wasmtime/src/runtime/debug.rs
@@ -1,19 +1,23 @@
//! Debugging API.
use crate::{
- AnyRef, AsContext, AsContextMut, ExnRef, ExternRef, Func, Instance, Module, OwnedRooted,
- StoreContext, StoreContextMut, Val,
+ AnyRef, AsContext, AsContextMut, CodeMemory, ExnRef, ExternRef, Func, Instance, Module,
+ OwnedRooted, StoreContext, StoreContextMut, Val,
+ code::StoreCodePC,
+ module::ModuleRegistry,
store::{AutoAssertNoGc, StoreOpaque},
- vm::{CurrentActivationBacktrace, VMContext},
+ vm::{CompiledModuleId, CurrentActivationBacktrace, VMContext},
};
+use alloc::collections::BTreeSet;
use alloc::vec;
use alloc::vec::Vec;
+use anyhow::Result;
use core::{ffi::c_void, ptr::NonNull};
#[cfg(feature = "gc")]
use wasmtime_environ::FrameTable;
use wasmtime_environ::{
DefinedFuncIndex, FrameInstPos, FrameStackShape, FrameStateSlot, FrameStateSlotOffset,
- FrameTableDescriptorIndex, FrameValType, FuncKey, Trap,
+ FrameTableBreakpointData, FrameTableDescriptorIndex, FrameValType, FuncKey, Trap,
};
use wasmtime_unwinder::Frame;
@@ -53,6 +57,34 @@ impl<'a, T> StoreContextMut<'a, T> {
view.move_to_parent(); // Load the first frame.
Some(view)
}
+
+ /// Start an edit session to update breakpoints.
+ pub fn edit_breakpoints(self) -> Option<BreakpointEdit<'a>> {
+ if !self.engine().tunables().debug_guest {
+ return None;
+ }
+
+ let (breakpoints, registry) = self.0.breakpoints_and_registry_mut();
+ Some(breakpoints.edit(registry))
+ }
+}
+
+impl<'a, T> StoreContext<'a, T> {
+ /// Return all breakpoints.
+ pub fn breakpoints(self) -> Option<impl Iterator<Item = Breakpoint> + 'a> {
+ if !self.engine().tunables().debug_guest {
+ return None;
+ }
+
+ let (breakpoints, registry) = self.0.breakpoints_and_registry();
+ Some(breakpoints.breakpoints(registry))
+ }
+
+ /// Indicate whether single-step mode is enabled.
+ pub fn is_single_step(&self) -> bool {
+ let (breakpoints, _) = self.0.breakpoints_and_registry();
+ breakpoints.is_single_step()
+ }
}
/// A view of an active stack frame, with the ability to move up the
@@ -458,6 +490,8 @@ pub enum DebugEvent<'a> {
UncaughtExceptionThrown(OwnedRooted<ExnRef>),
/// A Wasm trap occurred.
Trap(Trap),
+ /// A breakpoint was reached.
+ Breakpoint,
}
/// A handler for debug events.
@@ -516,3 +550,238 @@ pub trait DebugHandler: Clone + Send + Sync + 'static {
event: DebugEvent<'_>,
) -> impl Future<Output = ()> + Send;
}
+
+/// Breakpoint state for modules within a store.
+#[derive(Default)]
+pub(crate) struct BreakpointState {
+ /// Single-step mode.
+ single_step: bool,
+ /// Breakpoints added individually.
+ breakpoints: BTreeSet<BreakpointKey>,
+}
+
+/// A breakpoint.
+pub struct Breakpoint {
+ /// Reference to the module in which we are setting the breakpoint.
+ pub module: Module,
+ /// Wasm PC offset within the module.
+ pub pc: u32,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
+struct BreakpointKey(CompiledModuleId, u32);
+
+impl BreakpointKey {
+ fn from_raw(module: &Module, pc: u32) -> BreakpointKey {
+ BreakpointKey(module.id(), pc)
+ }
+
+ fn get(&self, registry: &ModuleRegistry) -> Breakpoint {
+ let module = registry
+ .module_by_compiled_id(self.0)
+ .expect("Module should not have been removed from Store")
+ .clone();
+ Breakpoint { module, pc: self.1 }
+ }
+}
+
+/// A breakpoint-editing session.
+///
+/// This enables updating breakpoint state (setting or unsetting
+/// individual breakpoints or the store-global single-step flag) in a
+/// batch. It is more efficient to batch these updates because
+/// "re-publishing" the newly patched code, with update breakpoint
+/// settings, typically requires a syscall to re-enable execute
+/// permissions.
+pub struct BreakpointEdit<'a> {
+ state: &'a mut BreakpointState,
+ registry: &'a mut ModuleRegistry,
+ /// Modules that have been edited.
+ ///
+ /// Invariant: each of these modules' CodeMemory objects is
+ /// *unpublished* when in the dirty set.
+ dirty_modules: BTreeSet<StoreCodePC>,
+}
+
+impl BreakpointState {
+ pub(crate) fn edit<'a>(&'a mut self, registry: &'a mut ModuleRegistry) -> BreakpointEdit<'a> {
+ BreakpointEdit {
+ state: self,
+ registry,
+ dirty_modules: BTreeSet::new(),
+ }
+ }
+
+ pub(crate) fn breakpoints<'a>(
+ &'a self,
+ registry: &'a ModuleRegistry,
+ ) -> impl Iterator<Item = Breakpoint> + 'a {
+ self.breakpoints.iter().map(|key| key.get(registry))
+ }
+
+ pub(crate) fn is_single_step(&self) -> bool {
+ self.single_step
+ }
+}
+
+impl<'a> BreakpointEdit<'a> {
+ fn get_code_memory<'b>(
+ registry: &'b mut ModuleRegistry,
+ dirty_modules: &mut BTreeSet<StoreCodePC>,
+ module: &Module,
+ ) -> Result<&'b mut CodeMemory> {
+ let store_code_pc = registry.store_code_base_or_register(module)?;
+ let code_memory = registry
+ .store_code_mut(store_code_pc)
+ .expect("Just checked presence above")
+ .code_memory_mut()
+ .expect("Must have unique ownership of StoreCode in guest-debug mode");
+ if dirty_modules.insert(store_code_pc) {
+ code_memory.unpublish()?;
+ }
+ Ok(code_memory)
+ }
+
+ fn patch<'b>(
+ patches: impl Iterator<Item = FrameTableBreakpointData<'b>> + 'b,
+ mem: &mut CodeMemory,
+ enable: bool,
+ ) {
+ let mem = mem.text_mut();
+ for patch in patches {
+ let data = if enable { patch.enable } else { patch.disable };
+ let mem = &mut mem[patch.offset..patch.offset + data.len()];
+ log::trace!(
+ "patch: offset 0x{:x} with enable={enable}: data {data:?} replacing {mem:?}",
+ patch.offset
+ );
+ mem.copy_from_slice(data);
+ }
+ }
+
+ /// Add a breakpoint in the given module at the given PC in that
+ /// module.
+ ///
+ /// No effect if the breakpoint is already set.
+ pub fn add_breakpoint(&mut self, module: &Module, pc: u32) -> Result<()> {
+ let key = BreakpointKey::from_raw(module, pc);
+ self.state.breakpoints.insert(key);
+ log::trace!("patching in breakpoint {key:?}");
+ let mem = Self::get_code_memory(self.registry, &mut self.dirty_modules, module)?;
+ let frame_table = module
+ .frame_table()
+ .expect("Frame table must be present when guest-debug is enabled");
+ let patches = frame_table.lookup_breakpoint_patches_by_pc(pc);
+ Self::patch(patches, mem, true);
+ Ok(())
+ }
+
+ /// Remove a breakpoint in the given module at the given PC in
+ /// that module.
+ ///
+ /// No effect if the breakpoint was not set.
+ pub fn remove_breakpoint(&mut self, module: &Module, pc: u32) -> Result<()> {
+ let key = BreakpointKey::from_raw(module, pc);
+ self.state.breakpoints.remove(&key);
+ if !self.state.single_step {
+ let mem = Self::get_code_memory(self.registry, &mut self.dirty_modules, module)?;
+ let frame_table = module
+ .frame_table()
+ .expect("Frame table must be present when guest-debug is enabled");
+ let patches = frame_table.lookup_breakpoint_patches_by_pc(pc);
+ Self::patch(patches, mem, false);
+ }
+ Ok(())
+ }
+
+ /// Turn on or off single-step mode.
+ ///
+ /// In single-step mode, a breakpoint event is emitted at every
+ /// Wasm PC.
+ pub fn single_step(&mut self, enabled: bool) -> Result<()> {
+ log::trace!(
+ "single_step({enabled}) with breakpoint set {:?}",
+ self.state.breakpoints
+ );
+ let modules = self.registry.all_modules().cloned().collect::<Vec<_>>();
+ for module in modules {
+ let mem = Self::get_code_memory(self.registry, &mut self.dirty_modules, &module)?;
+ let table = module
+ .frame_table()
+ .expect("Frame table must be present when guest-debug is enabled");
+ for (wasm_pc, patch) in table.breakpoint_patches() {
+ let key = BreakpointKey::from_raw(&module, wasm_pc);
+ let this_enabled = enabled || self.state.breakpoints.contains(&key);
+ log::trace!(
+ "single_step: enabled {enabled} key {key:?} -> this_enabled {this_enabled}"
+ );
+ Self::patch(core::iter::once(patch), mem, this_enabled);
+ }
+ }
+
+ self.state.single_step = enabled;
+
+ Ok(())
+ }
+}
+
+impl<'a> Drop for BreakpointEdit<'a> {
+ fn drop(&mut self) {
+ for &store_code_base in &self.dirty_modules {
+ let store_code = self.registry.store_code_mut(store_code_base).unwrap();
+ if let Err(e) = store_code
+ .code_memory_mut()
+ .expect("Must have unique ownership of StoreCode in guest-debug mode")
+ .publish()
+ {
+ abort_on_republish_error(e);
+ }
+ }
+ }
+}
+
+/// Abort when we cannot re-publish executable code.
+///
+/// Note that this puts us in quite a conundrum. Typically we will
+/// have been editing breakpoints from within a hostcall context
+/// (e.g. inside a debugger hook while execution is paused) with JIT
+/// code on the stack. Wasmtime's usual path to return errors is back
+/// through that JIT code: we do not panic-unwind across the JIT code,
+/// we return into the exit trampoline and that then re-enters the
+/// raise libcall to use a Cranelift exception-throw to cross most of
+/// the JIT frames to the entry trampoline. When even trampolines are
+/// no longer executable, we have no way out. Even an ordinary
+/// `panic!` cannot work, because we catch panics and carry them
+/// across JIT code using that trampoline-based error path. Our only
+/// way out is to directly abort the whole process.
+///
+/// This is not without precedent: other engines have similar failure
+/// paths. For example, SpiderMonkey directly aborts the process when
+/// failing to re-apply executable permissions (see [1]).
+///
+/// Note that we don't really expect to ever hit this case in
+/// practice: it's unlikely that `mprotect` applying `PROT_EXEC` would
+/// fail due to, e.g., resource exhaustion in the kernel, because we
+/// will have the same net number of virtual memory areas before and
+/// after the permissions change. Nevertheless, we have to account for
+/// the possibility of error.
+///
+/// [1]: https://searchfox.org/firefox-main/rev/7496c8515212669451d7e775a00c2be07da38ca5/js/src/jit/AutoWritableJitCode.h#26-56
+#[cfg(feature = "std")]
+fn abort_on_republish_error(e: anyhow::Error) -> ! {
+ log::error!(
+ "Failed to re-publish executable code: {e:?}. Wasmtime cannot return through JIT code on the stack and cannot even panic; aborting the process."
+ );
+ std::process::abort();
+}
+
+/// In the `no_std` case, we don't have a concept of a "process
+/// abort", so rely on `panic!`. Typically an embedded scenario that
+/// uses `no_std` will build with `panic=abort` so the effect is the
+/// same. If it doesn't, there is truly nothing we can do here so
+/// let's panic anyway; the panic propagation through the trampolines
+/// will at least deterministically crash.
+#[cfg(not(feature = "std"))]
+fn abort_on_republish_error(e: anyhow::Error) -> ! {
+ panic!("Failed to re-publish executable code: {e:?}");
+}
diff --git a/crates/wasmtime/src/runtime/module.rs b/crates/wasmtime/src/runtime/module.rs
index 36366a5387..82bf6eab50 100644
--- a/crates/wasmtime/src/runtime/module.rs
+++ b/crates/wasmtime/src/runtime/module.rs
@@ -1149,9 +1149,29 @@ impl Module {
if data.is_empty() {
None
} else {
- Some(FrameTable::parse(data).expect("Frame tables were validated on module load"))
+ let orig_text = self.inner.code.text();
+ Some(
+ FrameTable::parse(data, orig_text)
+ .expect("Frame tables were validated on module load"),
+ )
}
}
+
+ /// Is this `Module` the same as another?
+ ///
+ /// Ordinarily, module identity does not matter: a Wasmtime user
+ /// will create or obtain a module from some source and
+ /// instantiate it, and any two `Module` objects created from the
+ /// same source module are interchangeable. However, introspecting
+ /// module identity may be useful when examining Wasm VM state,
+ /// e.g. via debug APIs. It is guaranteed that `Module::same`
+ /// returns true for `Module` objects that reference the same
+ /// underlying module (e.g., one created via a `clone` of the
+ /// other).
+ #[inline]
+ pub fn same(a: &Module, b: &Module) -> bool {
+ Arc::ptr_eq(&a.inner, &b.inner)
+ }
}
/// Describes a function for a given module.
diff --git a/crates/wasmtime/src/runtime/module/registry.rs b/crates/wasmtime/src/runtime/module/registry.rs
index eba6e9a833..e7d5bce632 100644
--- a/crates/wasmtime/src/runtime/module/registry.rs
+++ b/crates/wasmtime/src/runtime/module/registry.rs
@@ -106,6 +106,11 @@ impl ModuleRegistry {
self.modules.get(&id)
}
+ /// Get a module by CompiledModuleId, if present.
+ pub fn module_by_compiled_id(&self, id: CompiledModuleId) -> Option<&Module> {
+ self.modules.get(&RegisteredModuleId(id))
+ }
+
/// Fetches a registered StoreCode and module and an offset within
/// it given a program counter value.
pub fn module_and_code_by_pc<'a>(&'a self, pc: usize) -> Option<(ModuleWithCode<'a>, usize)> {
@@ -121,13 +126,38 @@ impl ModuleRegistry {
/// Fetches the `StoreCode` for a given `EngineCode`.
pub fn store_code(&self, engine_code: &EngineCode) -> Option<&StoreCode> {
- let store_code_pc = *self.store_code.get(&engine_code.text_range().start)?;
+ let store_code_pc = self.store_code_base(engine_code)?;
let (_, code) = self.loaded_code.range(store_code_pc..).next()?;
Some(&code.code)
}
+ /// Fetches the base `StoreCodePC` for a given `EngineCode`.
+ pub fn store_code_base(&self, engine_code: &EngineCode) -> Option<StoreCodePC> {
+ self.store_code
+ .get(&engine_code.text_range().start)
+ .cloned()
+ }
+
+ /// Fetches the base `StoreCodePC` for a given `EngineCode` with
+ /// `Module`, registering the module if not already registered.
+ pub fn store_code_base_or_register(&mut self, module: &Module) -> Result<StoreCodePC> {
+ let key = module.engine_code().text_range().start;
+ if !self.store_code.contains_key(&key) {
+ let engine = module.engine().clone();
+ self.register_module(module, &engine)?;
+ }
+ Ok(*self.store_code.get(&key).unwrap())
+ }
+
+ /// Fetches a mutable `StoreCode` for a given base `StoreCodePC`.
+ pub fn store_code_mut(&mut self, store_code_base: StoreCodePC) -> Option<&mut StoreCode> {
+ let (_, code) = self.loaded_code.range_mut(store_code_base..).next()?;
+ assert_eq!(code.code.text_range().start, store_code_base);
+ Some(&mut code.code)
+ }
+
/// Gets an iterator over all modules in the registry.
- #[cfg(feature = "coredump")]
+ #[cfg(any(feature = "coredump", feature = "debug"))]
pub fn all_modules(&self) -> impl Iterator<Item = &'_ Module> + '_ {
self.modules.values()
}
diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rs
index 19d9edc401..ddd06be3cc 100644
--- a/crates/wasmtime/src/runtime/store.rs
+++ b/crates/wasmtime/src/runtime/store.rs
@@ -76,8 +76,6 @@
//! contents of `StoreOpaque`. This is an invariant that we, as the authors of
//! `wasmtime`, must uphold for the public interface to be safe.
-#[cfg(feature = "debug")]
-use crate::DebugHandler;
#[cfg(all(feature = "gc", feature = "debug"))]
use crate::OwnedRooted;
use crate::RootSet;
@@ -103,6 +101,8 @@ use crate::runtime::vm::{
VMStoreContext,
};
use crate::trampoline::VMHostGlobalContext;
+#[cfg(feature = "debug")]
+use crate::{BreakpointState, DebugHandler};
use crate::{Engine, Module, Val, ValRaw, module::ModuleRegistry};
#[cfg(feature = "gc")]
use crate::{ExnRef, Rooted};
@@ -550,6 +550,20 @@ pub struct StoreOpaque {
/// For example if Pulley is enabled and configured then this will store a
/// Pulley interpreter.
executor: Executor,
+
+ /// The debug breakpoint state for this store.
+ ///
+ /// When guest debugging is enabled, a given store may have a set
+ /// of breakpoints defined, denoted by module and Wasm PC within
+ /// that module. Or alternately, it may be in "single-step" mode,
+ /// where every possible breakpoint is logically enabled.
+ ///
+ /// When execution of any instance in this store hits any defined
+ /// breakpoint, a `Breakpoint` debug event is emitted and the
+ /// handler defined above, if any, has a chance to perform some
+ /// logic before returning to allow execution to resume.
+ #[cfg(feature = "debug")]
+ breakpoints: BreakpointState,
}
/// Self-pointer to `StoreInner<T>` from within a `StoreOpaque` which is chiefly
@@ -758,6 +772,8 @@ impl<T> Store<T> {
executor: Executor::new(engine),
#[cfg(feature = "component-model")]
concurrent_state: Default::default(),
+ #[cfg(feature = "debug")]
+ breakpoints: Default::default(),
};
let mut inner = Box::new(StoreInner {
inner,
@@ -1252,6 +1268,24 @@ impl<T> Store<T> {
self.as_context_mut().debug_frames()
}
+ /// Start an edit session to update breakpoints.
+ #[cfg(feature = "debug")]
+ pub fn edit_breakpoints(&mut self) -> Option<crate::BreakpointEdit<'_>> {
+ self.as_context_mut().edit_breakpoints()
+ }
+
+ /// Return all breakpoints.
+ #[cfg(feature = "debug")]
+ pub fn breakpoints(&self) -> Option<impl Iterator<Item = crate::Breakpoint> + '_> {
+ self.as_context().breakpoints()
+ }
+
+ /// Indicate whether single-step mode is enabled.
+ #[cfg(feature = "debug")]
+ pub fn is_single_step(&self) -> bool {
+ self.as_context().is_single_step()
+ }
+
/// Set the debug callback on this store.
///
/// See [`crate::DebugHandler`] for more documentation.
@@ -1621,6 +1655,18 @@ impl StoreOpaque {
(&mut self.store_data, &self.modules)
}
+ #[cfg(feature = "debug")]
+ pub(crate) fn breakpoints_and_registry_mut(
+ &mut self,
+ ) -> (&mut BreakpointState, &mut ModuleRegistry) {
+ (&mut self.breakpoints, &mut self.modules)
+ }
+
+ #[cfg(feature = "debug")]
+ pub(crate) fn breakpoints_and_registry(&self) -> (&BreakpointState, &ModuleRegistry) {
+ (&self.breakpoints, &self.modules)
+ }
+
#[inline]
pub(crate) fn modules(&self) -> &ModuleRegistry {
&self.modules
diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rs
index 70d5856f43..bf44e96329 100644
--- a/crates/wasmtime/src/runtime/vm/libcalls.rs
+++ b/crates/wasmtime/src/runtime/vm/libcalls.rs
@@ -1704,3 +1704,14 @@ fn throw_ref(
store.set_pending_exception(exnref);
Err(TrapReason::Exception)
}
+
+fn breakpoint(store: &mut dyn VMStore, _instance: InstanceId) -> Result<()> {
+ #[cfg(feature = "debug")]
+ {
+ log::trace!("hit breakpoint");
+ store.block_on_debug_handler(crate::DebugEvent::Breakpoint)?;
+ }
+ // Avoid unused-argument warning in no-debugger builds.
+ let _ = store;
+ Ok(())
+}
diff --git a/crates/wasmtime/src/runtime/vm/mmap.rs b/crates/wasmtime/src/runtime/vm/mmap.rs
index a3174e8d86..8054a786f8 100644
--- a/crates/wasmtime/src/runtime/vm/mmap.rs
+++ b/crates/wasmtime/src/runtime/vm/mmap.rs
@@ -349,6 +349,30 @@ impl<T> Mmap<T> {
.context("failed to make memory readonly")
}
}
+
+ /// Makes the specified `range` within this `Mmap` to be read-write.
+ pub unsafe fn make_readwrite(&self, range: Range<usize>) -> Result<()> {
+ assert!(range.start <= self.len());
+ assert!(range.end <= self.len());
+ assert!(range.start <= range.end);
+ assert!(
+ range.start % crate::runtime::vm::host_page_size() == 0,
+ "changing of protections isn't page-aligned",
+ );
+
+ if range.start == range.end {
+ // A zero-sized mprotect (or equivalent) is allowed on some
+ // platforms but not others (notably Windows). Treat it as a no-op
+ // everywhere.
+ return Ok(());
+ }
+
+ unsafe {
+ self.sys
+ .make_readwrite(range)
+ .context("failed to make memory read-write")
+ }
+ }
}
fn _assert() {
diff --git a/crates/wasmtime/src/runtime/vm/mmap_vec.rs b/crates/wasmtime/src/runtime/vm/mmap_vec.rs
index 9bebbf4d72..5900cb3104 100644
--- a/crates/wasmtime/src/runtime/vm/mmap_vec.rs
+++ b/crates/wasmtime/src/runtime/vm/mmap_vec.rs
@@ -226,6 +226,21 @@ impl MmapVec {
unsafe { mmap.make_readonly(range.start..range.end) }
}
+ /// Makes the specified `range` within this `mmap` to be
+ /// read-write (and not executable).
+ #[cfg(has_virtual_memory)]
+ pub unsafe fn make_readwrite(&self, range: Range<usize>) -> Result<()> {
+ let (mmap, len) = match self {
+ MmapVec::Mmap { mmap, len } => (mmap, *len),
+ MmapVec::ExternallyOwned { .. } => {
+ bail!("Unable to make externally owned memory read-write");
+ }
+ };
+ assert!(range.start <= range.end);
+ assert!(range.end <= len);
+ unsafe { mmap.make_readwrite(range.start..range.end) }
+ }
+
/// Returns the underlying file that this mmap is mapping, if present.
#[cfg(feature = "std")]
pub fn original_file(&self) -> Option<&Arc<File>> {
diff --git a/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs
index 19db107b80..2b4bc8bdcd 100644
--- a/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs
+++ b/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs
@@ -109,6 +109,20 @@ impl Mmap {
Ok(())
}
+ pub unsafe fn make_readwrite(&self, range: Range<usize>) -> Result<()> {
+ unsafe {
+ let base = self.memory.as_ptr().byte_add(range.start).cast();
+ let len = range.end - range.start;
+
+ cvt(capi::wasmtime_mprotect(
+ base,
+ len,
+ capi::PROT_READ | capi::PROT_WRITE,
+ ))?;
+ }
+ Ok(())
+ }
+
pub unsafe fn map_image_at(
&self,
image_source: &MemoryImageSource,
diff --git a/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
index 4243b7f7c3..3e3145886f 100644
--- a/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
+++ b/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
@@ -114,6 +114,10 @@ impl Mmap {
Ok(())
}
+ pub unsafe fn make_readwrite(&self, _range: Range<usize>) -> Result<()> {
+ Ok(())
+ }
+
pub unsafe fn map_image_at(
&self,
image_source: &MemoryImageSource,
diff --git a/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs
index 3463c3b1b6..477a1309f5 100644
--- a/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs
+++ b/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs
@@ -201,6 +201,17 @@ impl Mmap {
Ok(())
}
+ pub unsafe fn make_readwrite(&self, range: Range<usize>) -> Result<()> {
+ let base = unsafe { self.memory.as_ptr().byte_add(range.start).cast() };
+ let len = range.end - range.start;
+
+ unsafe {
+ mprotect(base, len, MprotectFlags::READ | MprotectFlags::WRITE)?;
+ }
+
+ Ok(())
+ }
+
pub unsafe fn map_image_at(
&self,
image_source: &MemoryImageSource,
diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs
index 736bcc938a..54ca2686eb 100644
--- a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs
+++ b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs
@@ -248,6 +248,18 @@ impl Mmap {
Ok(())
}
+ pub unsafe fn make_readwrite(&self, range: Range<usize>) -> Result<()> {
+ let mut old = 0;
+ unsafe {
+ let base = self.as_send_sync_ptr().as_ptr().add(range.start).cast();
+ let result = VirtualProtect(base, range.end - range.start, PAGE_READWRITE, &mut old);
+ if result == 0 {
+ bail!(io::Error::last_os_error());
+ }
+ }
+ Ok(())
+ }
+
pub unsafe fn map_image_at(
&self,
image_source: &MemoryImageSource,
diff --git a/src/commands/objdump.rs b/src/commands/objdump.rs
index 60e595b395..b439cb2da5 100644
--- a/src/commands/objdump.rs
+++ b/src/commands/objdump.rs
@@ -9,6 +9,7 @@ use object::read::elf::ElfFile64;
use object::{Architecture, Endianness, FileFlags, Object, ObjectSection, ObjectSymbol};
use pulley_interpreter::decode::{Decoder, DecodingError, OpVisitor};
use pulley_interpreter::disas::Disassembler;
+use smallvec::SmallVec;
use std::io::{IsTerminal, Read, Write};
use std::iter::{self, Peekable};
use std::path::{Path, PathBuf};
@@ -137,6 +138,20 @@ impl ObjdumpCommand {
.context("missing .text section")?;
let text = text.data()?;
+ let frame_table_descriptors = elf
+ .section_by_name(obj::ELF_WASMTIME_FRAMES)
+ .and_then(|section| section.data().ok())
+ .and_then(|bytes| FrameTable::parse(bytes, text).ok());
+
+ let mut breakpoints = frame_table_descriptors
+ .iter()
+ .flat_map(|ftd| ftd.breakpoint_patches())
+ .map(|(wasm_pc, patch)| (wasm_pc, patch.offset, SmallVec::from(patch.enable)))
+ .collect::<Vec<_>>();
+ breakpoints.sort_by_key(|(_wasm_pc, native_offset, _patch)| *native_offset);
+ let breakpoints: Box<dyn Iterator<Item = _>> = Box::new(breakpoints.into_iter());
+ let breakpoints = breakpoints.peekable();
+
// Build the helper that'll get used to attach decorations/annotations
// to various instructions.
let mut decorator = Decorator {
@@ -164,14 +179,13 @@ impl ObjdumpCommand {
frame_tables: elf
.section_by_name(obj::ELF_WASMTIME_FRAMES)
.and_then(|section| section.data().ok())
- .and_then(|bytes| FrameTable::parse(bytes).ok())
+ .and_then(|bytes| FrameTable::parse(bytes, text).ok())
.map(|table| table.into_program_points())
.map(|i| (Box::new(i) as Box<dyn Iterator<Item = _>>).peekable()),
- frame_table_descriptors: elf
- .section_by_name(obj::ELF_WASMTIME_FRAMES)
- .and_then(|section| section.data().ok())
- .and_then(|bytes| FrameTable::parse(bytes).ok()),
+ breakpoints,
+
+ frame_table_descriptors,
objdump: &self,
};
@@ -186,7 +200,9 @@ impl ObjdumpCommand {
};
let bytes = &text[sym.address() as usize..][..sym.size() as usize];
- let kind = if name.starts_with("wasmtime_builtin") {
+ let kind = if name.starts_with("wasmtime_builtin")
+ || name.starts_with("wasmtime_patchable_builtin")
+ {
Func::Builtin
} else if name.contains("]::function[") {
Func::Wasm
@@ -565,6 +581,11 @@ struct Decorator<'a> {
>,
>,
+ // Breakpoint table, sorted by native offset instead so we can
+ // display inline with disassembly (the table in the image is
+ // sorted by Wasm PC).
+ breakpoints: Peekable<Box<dyn Iterator<Item = (u32, usize, SmallVec<[u8; 8]>)>>>,
+
frame_table_descriptors: Option<FrameTable<'a>>,
}
@@ -575,6 +596,7 @@ impl Decorator<'_> {
self.stack_maps(address, post_list);
self.exception_table(address, pre_list);
self.frame_table(address, pre_list, post_list);
+ self.breakpoints(address, pre_list);
}
fn addrmap(&mut self, address: u64, list: &mut Vec<String>) {
@@ -713,6 +735,19 @@ impl Decorator<'_> {
}
}
+ fn breakpoints(&mut self, address: u64, list: &mut Vec<String>) {
+ while let Some((wasm_pc, addr, patch)) = self.breakpoints.next_if(|(_, addr, patch)| {
+ u64::try_from(*addr).unwrap() + u64::try_from(patch.len()).unwrap() <= address
+ }) {
+ if u64::try_from(addr).unwrap() + u64::try_from(patch.len()).unwrap() != address {
+ continue;
+ }
+ list.push(format!(
+ "breakpoint patch: wasm PC {wasm_pc}, patch bytes {patch:?}"
+ ));
+ }
+ }
+
fn describe_local_shape(desc: &FrameStateSlot<'_>) -> String {
let mut parts = vec![];
for (offset, ty) in desc.locals() {
diff --git a/tests/all/debug.rs b/tests/all/debug.rs
index 092da7fe5c..0bbe64c191 100644
--- a/tests/all/debug.rs
+++ b/tests/all/debug.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use wasmtime::{
AsContextMut, Caller, Config, DebugEvent, DebugHandler, Engine, Extern, Func, Instance, Module,
- Store, StoreContextMut,
+ Store, StoreContextMut, Val,
};
#[test]
@@ -453,3 +453,212 @@ async fn hostcall_error_events() -> anyhow::Result<()> {
assert_eq!(counter.load(Ordering::Relaxed), 1);
Ok(())
}
+
+#[tokio::test]
+#[cfg_attr(miri, ignore)]
+async fn breakpoint_events() -> anyhow::Result<()> {
+ let _ = env_logger::try_init();
+
+ let (module, mut store) = get_module_and_store(
+ |config| {
+ config.async_support(true);
+ config.wasm_exceptions(true);
+ },
+ r#"
+ (module
+ (func (export "main") (param i32 i32) (result i32)
+ local.get 0
+ local.get 1
+ i32.add))
+ "#,
+ )?;
+
+ debug_event_checker!(
+ D, store,
+ { 0 ;
+ wasmtime::DebugEvent::Breakpoint => {
+ let mut stack = store.debug_frames().expect("frame cursor must be available");
+ assert!(!stack.done());
+ assert_eq!(stack.num_locals(), 2);
+ assert_eq!(stack.local(0).unwrap_i32(), 1);
+ assert_eq!(stack.local(1).unwrap_i32(), 2);
+ let (func, pc) = stack.wasm_function_index_and_pc().unwrap();
+ assert_eq!(func.as_u32(), 0);
+ assert_eq!(pc, 0x28);
+ stack.move_to_parent();
+ assert!(stack.done());
+ }
+ }
+ );
+
+ let (handler, counter) = D::new_and_counter();
+ store.set_debug_handler(handler);
+ store
+ .edit_breakpoints()
+ .unwrap()
+ .add_breakpoint(&module, 0x28)?;
+
+ let instance = Instance::new_async(&mut store, &module, &[]).await?;
+ let func = instance.get_func(&mut store, "main").unwrap();
+ let mut results = [Val::I32(0)];
+ func.call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
+ .await?;
+ assert_eq!(counter.load(Ordering::Relaxed), 1);
+ assert_eq!(results[0].unwrap_i32(), 3);
+
+ let breakpoints = store.breakpoints().unwrap().collect::<Vec<_>>();
+ assert_eq!(breakpoints.len(), 1);
+ assert!(Module::same(&breakpoints[0].module, &module));
+ assert_eq!(breakpoints[0].pc, 0x28);
+
+ store
+ .edit_breakpoints()
+ .unwrap()
+ .remove_breakpoint(&module, 0x28)?;
+ func.call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
+ .await?;
+ assert_eq!(counter.load(Ordering::Relaxed), 1); // Should not have incremented from above.
+ assert_eq!(results[0].unwrap_i32(), 3);
+
+ // Enable single-step mode (on top of the breakpoint already enabled).
+ assert!(!store.is_single_step());
+ store.edit_breakpoints().unwrap().single_step(true).unwrap();
+ assert!(store.is_single_step());
+
+ debug_event_checker!(
+ D2, store,
+ { 0 ;
+ wasmtime::DebugEvent::Breakpoint => {
+ let stack = store.debug_frames().unwrap();
+ assert!(!stack.done());
+ let (_, pc) = stack.wasm_function_index_and_pc().unwrap();
+ assert_eq!(pc, 0x24);
+ }
+ },
+ {
+ 1 ;
+ wasmtime::DebugEvent::Breakpoint => {
+ let stack = store.debug_frames().unwrap();
+ assert!(!stack.done());
+ let (_, pc) = stack.wasm_function_index_and_pc().unwrap();
+ assert_eq!(pc, 0x26);
+ }
+ },
+ {
+ 2 ;
+ wasmtime::DebugEvent::Breakpoint => {
+ let stack = store.debug_frames().unwrap();
+ assert!(!stack.done());
+ let (_, pc) = stack.wasm_function_index_and_pc().unwrap();
+ assert_eq!(pc, 0x28);
+ }
+ },
+ {
+ 3 ;
+ wasmtime::DebugEvent::Breakpoint => {
+ let stack = store.debug_frames().unwrap();
+ assert!(!stack.done());
+ let (_, pc) = stack.wasm_function_index_and_pc().unwrap();
+ assert_eq!(pc, 0x29);
+ }
+ }
+ );
+
+ let (handler, counter) = D2::new_and_counter();
+ store.set_debug_handler(handler);
+
+ func.call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
+ .await?;
+ assert_eq!(counter.load(Ordering::Relaxed), 4);
+
+ // Re-enable individual breakpoint.
+ store
+ .edit_breakpoints()
+ .unwrap()
+ .add_breakpoint(&module, 0x28)
+ .unwrap();
+
+ // Now disable single-stepping. The single breakpoint set above
+ // should still remain.
+ store
+ .edit_breakpoints()
+ .unwrap()
+ .single_step(false)
+ .unwrap();
+
+ let (handler, counter) = D::new_and_counter();
+ store.set_debug_handler(handler);
+
+ func.call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
+ .await?;
+ assert_eq!(counter.load(Ordering::Relaxed), 1);
+
+ Ok(())
+}
+
+#[tokio::test]
+#[cfg_attr(miri, ignore)]
+async fn breakpoints_in_inlined_code() -> anyhow::Result<()> {
+ let _ = env_logger::try_init();
+
+ let (module, mut store) = get_module_and_store(
+ |config| {
+ config.async_support(true);
+ config.wasm_exceptions(true);
+ config.compiler_inlining(true);
+ unsafe {
+ config.cranelift_flag_set("wasmtime_inlining_intra_module", "true");
+ }
+ },
+ r#"
+ (module
+ (func $f (export "f") (param i32 i32) (result i32)
+ local.get 0
+ local.get 1
+ i32.add)
+
+ (func (export "main") (param i32 i32) (result i32)
+ local.get 0
+ local.get 1
+ call $f))
+ "#,
+ )?;
+
+ debug_event_checker!(
+ D, store,
+ { 0 ;
+ wasmtime::DebugEvent::Breakpoint => {}
+ },
+ { 1 ;
+ wasmtime::DebugEvent::Breakpoint => {}
+ }
+ );
+
+ let (handler, counter) = D::new_and_counter();
+ store.set_debug_handler(handler);
+ store
+ .edit_breakpoints()
+ .unwrap()
+ .add_breakpoint(&module, 0x2d)?; // `i32.add` in `$f`.
+
+ let instance = Instance::new_async(&mut store, &module, &[]).await?;
+ let func_main = instance.get_func(&mut store, "main").unwrap();
+ let func_f = instance.get_func(&mut store, "f").unwrap();
+ let mut results = [Val::I32(0)];
+ // Breakpoint in `$f` should have been hit in `main` even if it
+ // was inlined.
+ func_main
+ .call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
+ .await?;
+ assert_eq!(counter.load(Ordering::Relaxed), 1);
+ assert_eq!(results[0].unwrap_i32(), 3);
+
+ // Breakpoint in `$f` should be hit when called directly, too.
+ func_f
+ .call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
+ .await?;
+ assert_eq!(counter.load(Ordering::Relaxed), 2);
+ assert_eq!(results[0].unwrap_i32(), 3);
+
+ Ok(())
+}
diff --git a/tests/disas/call-indirect.wat b/tests/disas/call-indirect.wat
index 02b046ebfb..0f2e06916d 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
diff --git a/tests/disas/component-model/inlining-and-unsafe-intrinsics.wat b/tests/disas/component-model/inlining-and-unsafe-intrinsics.wat
index 128e913579..9743c270d7 100644
--- a/tests/disas/component-model/inlining-and-unsafe-intrinsics.wat
+++ b/tests/disas/component-model/inlining-and-unsafe-intrinsics.wat
@@ -50,9 +50,9 @@
;; sig0 = (i64 vmctx, i64) -> i64 tail
;; sig1 = (i64 vmctx, i64, i64) -> i32 tail
;; sig2 = (i64 vmctx, i64, i64, i32) tail
-;; fn0 = colocated u3758096384:0 sig0
-;; fn1 = colocated u3758096384:1 sig1
-;; fn2 = colocated u3758096384:2 sig2
+;; fn0 = colocated u2147483648:0 sig0
+;; fn1 = colocated u2147483648:1 sig1
+;; fn2 = colocated u2147483648:2 sig2
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/debug-exceptions.wat b/tests/disas/debug-exceptions.wat
index ad4a17cf6b..9b1abb072e 100644
--- a/tests/disas/debug-exceptions.wat
+++ b/tests/disas/debug-exceptions.wat
@@ -30,74 +30,100 @@
;; ldr x3, [x3, #0x10]
;; mov x4, sp
;; cmp x4, x3
-;; b.lo #0x15c
+;; b.lo #0x190
;; 44: stur x2, [sp]
+;; mov x0, x2
;; stur x2, [sp, #0x10]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 53, slot at FP-0xc0, locals , stack
+;; ╰─╼ breakpoint patch: wasm PC 53, patch bytes [29, 1, 0, 148]
+;; ldur x0, [sp, #0x10]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 55, slot at FP-0xc0, locals , stack
+;; ╰─╼ breakpoint patch: wasm PC 55, patch bytes [27, 1, 0, 148]
+;; ldur x0, [sp, #0x10]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 61, slot at FP-0xc0, locals , stack
+;; ╰─╼ breakpoint patch: wasm PC 61, patch bytes [25, 1, 0, 148]
;; mov w22, #0x2a
-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 61, slot at FP-0xc0, locals , stack
;; stur w22, [sp, #8]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 63, slot at FP-0xc0, locals , stack I32 @ slot+0x8
+;; ╰─╼ breakpoint patch: wasm PC 63, patch bytes [22, 1, 0, 148]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 64, slot at FP-0xc0, locals , stack
+;; ╰─╼ breakpoint patch: wasm PC 64, patch bytes [21, 1, 0, 148]
;; stur w22, [sp, #8]
-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 64, slot at FP-0xc0, locals , stack
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 66, slot at FP-0xc0, locals , stack I32 @ slot+0x8
+;; ╰─╼ breakpoint patch: wasm PC 66, patch bytes [19, 1, 0, 148]
;; ldur x2, [sp, #0x10]
-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 66, slot at FP-0xc0, locals , stack I32 @ slot+0x8
-;; bl #0x3f0
-;; 60: mov x24, x2
+;; bl #0x424
+;; 84: mov x24, x2
;; mov w3, #0x4000000
;; mov w4, #2
;; mov w5, #0x28
;; mov w6, #8
;; ldur x2, [sp, #0x10]
-;; bl #0x310
-;; 7c: ldur x13, [sp, #0x10]
-;; ldr x5, [x13, #8]
+;; bl #0x344
+;; a0: ldur x0, [sp, #0x10]
+;; ldr x5, [x0, #8]
;; ldr x6, [x5, #0x18]
;; stur x5, [sp, #0x20]
;; add x15, x6, #0x20
;; str w22, [x15, w2, uxtw]
;; add x3, x6, #0x18
-;; mov x7, x24
-;; str w7, [x3, w2, uxtw]
+;; mov x1, x24
+;; str w1, [x3, w2, uxtw]
;; mov w3, #0
;; add x4, x6, #0x1c
;; stur x6, [sp, #0x18]
;; str w3, [x4, w2, uxtw]
;; mov x3, x2
;; ldur x2, [sp, #0x10]
-;; bl #0x428
+;; bl #0x45c
;; ├─╼ exception frame offset: SP = FP - 0xc0
-;; ╰─╼ exception handler: tag=0, context at [SP+0x10], handler=0xd4
-;; bc: mov w3, #9
+;; ╰─╼ exception handler: tag=0, context at [SP+0x10], handler=0xf8
+;; e0: mov w3, #9
;; ldur x2, [sp, #0x10]
-;; bl #0x384
-;; c8: ldur x2, [sp, #0x10]
-;; bl #0x3bc
-;; d0: .byte 0x1f, 0xc1, 0x00, 0x00
-;; mov x15, x0
-;; mov w6, w15
+;; bl #0x3b8
+;; ec: ldur x2, [sp, #0x10]
+;; bl #0x3f0
+;; f4: .byte 0x1f, 0xc1, 0x00, 0x00
+;; mov x9, x0
+;; mov w6, w9
;; mov x7, #0x28
;; adds x5, x6, x7
;; cset x7, hs
;; uxtb w6, w7
-;; cbnz x6, #0x174
-;; f0: ldur x12, [sp, #0x20]
-;; ldr x8, [x12, #0x20]
+;; cbnz x6, #0x1a8
+;; 114: ldur x4, [sp, #0x20]
+;; ldr x8, [x4, #0x20]
;; cmp x5, x8
-;; cset x9, hi
-;; uxtb w9, w9
-;; cbnz x9, #0x178
-;; 108: ldur x6, [sp, #0x18]
+;; cset x10, hi
+;; uxtb w10, w10
+;; cbnz x10, #0x1ac
+;; 12c: ldur x6, [sp, #0x18]
;; add x10, x6, #0x20
-;; ldr w12, [x10, w15, uxtw]
+;; ldr w12, [x10, w9, uxtw]
;; stur w12, [sp, #8]
-;; ldur x2, [sp, #0x10]
-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xc0, locals , stack I32 @ slot+0x8
-;; ldr x14, [x2, #0x30]
-;; ldr x2, [x2, #0x40]
+;; ldur x0, [sp, #0x10]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xc0, locals , stack I32 @ slot+0x8
+;; ╰─╼ breakpoint patch: wasm PC 72, patch bytes [225, 0, 0, 148]
+;; ldr x14, [x0, #0x30]
+;; ldr x2, [x0, #0x40]
;; ldur x3, [sp, #0x10]
;; blr x14
;; ╰─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xc0, locals , stack I32 @ slot+0x8
-;; 12c: add sp, sp, #0x30
-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 75, slot at FP-0xc0, locals , stack
+;; 154: ldur x0, [sp, #0x10]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 74, slot at FP-0xc0, locals , stack I32 @ slot+0x8
+;; ╰─╼ breakpoint patch: wasm PC 74, patch bytes [219, 0, 0, 148]
+;; nop
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 75, slot at FP-0xc0, locals , stack
+;; ╰─╼ breakpoint patch: wasm PC 75, patch bytes [218, 0, 0, 148]
+;; add sp, sp, #0x30
;; ldp d8, d9, [sp], #0x10
;; ldp d10, d11, [sp], #0x10
;; ldp d12, d13, [sp], #0x10
@@ -109,11 +135,11 @@
;; ldp x27, x28, [sp], #0x10
;; ldp x29, x30, [sp], #0x10
;; ret
-;; 15c: stur x2, [sp, #0x10]
-;; 160: mov w3, #0
-;; 164: bl #0x384
-;; 168: ldur x2, [sp, #0x10]
-;; 16c: bl #0x3bc
-;; 170: .byte 0x1f, 0xc1, 0x00, 0x00
-;; 174: .byte 0x1f, 0xc1, 0x00, 0x00
-;; 178: .byte 0x1f, 0xc1, 0x00, 0x00
+;; 190: stur x2, [sp, #0x10]
+;; 194: mov w3, #0
+;; 198: bl #0x3b8
+;; 19c: ldur x2, [sp, #0x10]
+;; 1a0: bl #0x3f0
+;; 1a4: .byte 0x1f, 0xc1, 0x00, 0x00
+;; 1a8: .byte 0x1f, 0xc1, 0x00, 0x00
+;; 1ac: .byte 0x1f, 0xc1, 0x00, 0x00
diff --git a/tests/disas/debug.wat b/tests/disas/debug.wat
new file mode 100644
index 0000000000..5b5e68fffe
--- /dev/null
+++ b/tests/disas/debug.wat
@@ -0,0 +1,242 @@
+;;! target = "x86_64"
+;;! test = "compile"
+;;! flags = ["-Dguest-debug=yes"]
+;;! objdump = "--funcs all"
+
+(module
+ (func (export "main") (param i32 i32) (result i32)
+ local.get 0
+ local.get 1
+ i32.add))
+;; wasm[0]::function[0]:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; subq $0x30, %rsp
+;; movq %rbx, 0x20(%rsp)
+;; movl %edx, 8(%rsp)
+;; movl %ecx, 0xc(%rsp)
+;; movq 8(%rdi), %rax
+;; movq 0x10(%rax), %rax
+;; movq %rsp, %r8
+;; cmpq %rax, %r8
+;; jb 0x62
+;; 29: movq %rdi, (%rsp)
+;; nopl (%rax, %rax)
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 36, slot at FP-0x30, locals I32 @ slot+0x8, I32 @ slot+0xc, stack
+;; ╰─╼ breakpoint patch: wasm PC 36, patch bytes [232, 176, 1, 0, 0]
+;; movl %edx, 0x10(%rsp)
+;; nopl (%rax, %rax)
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 38, slot at FP-0x30, locals I32 @ slot+0x8, I32 @ slot+0xc, stack I32 @ slot+0x10
+;; ╰─╼ breakpoint patch: wasm PC 38, patch bytes [232, 167, 1, 0, 0]
+;; movl %ecx, 0x14(%rsp)
+;; nopl (%rax, %rax)
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 40, slot at FP-0x30, locals I32 @ slot+0x8, I32 @ slot+0xc, stack I32 @ slot+0x10, I32 @ slot+0x14
+;; ╰─╼ breakpoint patch: wasm PC 40, patch bytes [232, 158, 1, 0, 0]
+;; leal (%rdx, %rcx), %eax
+;; movl %eax, 0x10(%rsp)
+;; nopl (%rax, %rax)
+;; ├─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 41, slot at FP-0x30, locals I32 @ slot+0x8, I32 @ slot+0xc, stack I32 @ slot+0x10
+;; ╰─╼ breakpoint patch: wasm PC 41, patch bytes [232, 146, 1, 0, 0]
+;; movl %eax, 0x10(%rsp)
+;; movq 0x20(%rsp), %rbx
+;; addq $0x30, %rsp
+;; movq %rbp, %rsp
+;; popq %rbp
+;; retq
+;; 62: movq %rdi, %rbx
+;; 65: xorl %esi, %esi
+;; 67: callq 0x186
+;; 6c: movq %rbx, %rdi
+;; 6f: callq 0x1b6
+;; 74: ud2
+;;
+;; wasm[0]::array_to_wasm_trampoline[0]:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; subq $0x40, %rsp
+;; movq %rbx, 0x10(%rsp)
+;; movq %r12, 0x18(%rsp)
+;; movq %r13, 0x20(%rsp)
+;; movq %r14, 0x28(%rsp)
+;; movq %r15, 0x30(%rsp)
+;; movl (%rdx), %r10d
+;; movl 0x10(%rdx), %ecx
+;; movq %rdx, (%rsp)
+;; movq 8(%rdi), %r11
+;; movq %rbp, %rax
+;; movq %rax, 0x40(%r11)
+;; movq %rsp, %rax
+;; movq %rax, 0x38(%r11)
+;; leaq 0x39(%rip), %rax
+;; movq %rax, 0x48(%r11)
+;; movq %r10, %rdx
+;; callq 0
+;; ├─╼ exception frame offset: SP = FP - 0x40
+;; ╰─╼ exception handler: default handler, no dynamic context, handler=0xf3
+;; movq (%rsp), %rdx
+;; movl %eax, (%rdx)
+;; movl $1, %eax
+;; movq 0x10(%rsp), %rbx
+;; movq 0x18(%rsp), %r12
+;; movq 0x20(%rsp), %r13
+;; movq 0x28(%rsp), %r14
+;; movq 0x30(%rsp), %r15
+;; addq $0x40, %rsp
+;; movq %rbp, %rsp
+;; popq %rbp
+;; retq
+;; f3: xorl %eax, %eax
+;; f5: movq 0x10(%rsp), %rbx
+;; fa: movq 0x18(%rsp), %r12
+;; ff: movq 0x20(%rsp), %r13
+;; 104: movq 0x28(%rsp), %r14
+;; 109: movq 0x30(%rsp), %r15
+;; 10e: addq $0x40, %rsp
+;; 112: movq %rbp, %rsp
+;; 115: popq %rbp
+;; 116: retq
+;;
+;; signatures[0]::wasm_to_array_trampoline:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; subq $0x30, %rsp
+;; movq %r14, 0x20(%rsp)
+;; movq %rdx, %rax
+;; movq 8(%rsi), %r9
+;; movq %rbp, %r10
+;; movq %r10, 0x28(%r9)
+;; movq %rbp, %r10
+;; movq 8(%r10), %r11
+;; movq %r11, 0x30(%r9)
+;; leaq (%rsp), %rdx
+;; movq %rax, %r11
+;; movl %r11d, (%rsp)
+;; movl %ecx, 0x10(%rsp)
+;; movq 8(%rdi), %r8
+;; movl $2, %ecx
+;; movq %rsi, %r14
+;; callq *%r8
+;; testb %al, %al
+;; je 0x174
+;; 163: movl (%rsp), %eax
+;; movq 0x20(%rsp), %r14
+;; addq $0x30, %rsp
+;; movq %rbp, %rsp
+;; popq %rbp
+;; retq
+;; 174: movq 0x10(%r14), %rcx
+;; 178: movq 0x198(%rcx), %rcx
+;; 17f: movq %r14, %rdi
+;; 182: callq *%rcx
+;; 184: ud2
+;;
+;; wasmtime_builtin_trap:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; movq 8(%rdi), %rax
+;; movq %rbp, %rcx
+;; movq %rcx, 0x28(%rax)
+;; movq %rbp, %rcx
+;; movq 8(%rcx), %rcx
+;; movq %rcx, 0x30(%rax)
+;; movq 0x10(%rdi), %rax
+;; movq 0x190(%rax), %rax
+;; movzbq %sil, %rsi
+;; callq *%rax
+;; movq %rbp, %rsp
+;; popq %rbp
+;; retq
+;;
+;; wasmtime_builtin_raise:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; movq 8(%rdi), %r10
+;; movq %rbp, %r11
+;; movq %r11, 0x28(%r10)
+;; movq %rbp, %r11
+;; movq 8(%r11), %rsi
+;; movq %rsi, 0x30(%r10)
+;; movq 0x10(%rdi), %rsi
+;; movq 0x198(%rsi), %rsi
+;; callq *%rsi
+;; movq %rbp, %rsp
+;; popq %rbp
+;; retq
+;;
+;; wasmtime_patchable_builtin_breakpoint:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; subq $0x150, %rsp
+;; movq %rax, (%rsp)
+;; movq %rcx, 8(%rsp)
+;; movq %rdx, 0x10(%rsp)
+;; movq %rbx, 0x18(%rsp)
+;; movq %rsi, 0x20(%rsp)
+;; movq %rdi, 0x28(%rsp)
+;; movq %r8, 0x30(%rsp)
+;; movq %r9, 0x38(%rsp)
+;; movq %r10, 0x40(%rsp)
+;; movq %r11, 0x48(%rsp)
+;; movdqu %xmm0, 0x50(%rsp)
+;; movdqu %xmm1, 0x60(%rsp)
+;; movdqu %xmm2, 0x70(%rsp)
+;; movdqu %xmm3, 0x80(%rsp)
+;; movdqu %xmm4, 0x90(%rsp)
+;; movdqu %xmm5, 0xa0(%rsp)
+;; movdqu %xmm6, 0xb0(%rsp)
+;; movdqu %xmm7, 0xc0(%rsp)
+;; movdqu %xmm8, 0xd0(%rsp)
+;; movdqu %xmm9, 0xe0(%rsp)
+;; movdqu %xmm10, 0xf0(%rsp)
+;; movdqu %xmm11, 0x100(%rsp)
+;; movdqu %xmm12, 0x110(%rsp)
+;; movdqu %xmm13, 0x120(%rsp)
+;; movdqu %xmm14, 0x130(%rsp)
+;; movdqu %xmm15, 0x140(%rsp)
+;; movq 8(%rdi), %rax
+;; movq %rbp, %rcx
+;; movq %rcx, 0x28(%rax)
+;; movq %rbp, %rcx
+;; movq 8(%rcx), %rcx
+;; movq %rcx, 0x30(%rax)
+;; movq 0x10(%rdi), %rcx
+;; movq 0x1c8(%rcx), %rcx
+;; movq %rdi, %rbx
+;; callq *%rcx
+;; testb %al, %al
+;; je 0x3a7
+;; 2db: movq (%rsp), %rax
+;; movq 8(%rsp), %rcx
+;; movq 0x10(%rsp), %rdx
+;; movq 0x18(%rsp), %rbx
+;; movq 0x20(%rsp), %rsi
+;; movq 0x28(%rsp), %rdi
+;; movq 0x30(%rsp), %r8
+;; movq 0x38(%rsp), %r9
+;; movq 0x40(%rsp), %r10
+;; movq 0x48(%rsp), %r11
+;; movdqu 0x50(%rsp), %xmm0
+;; movdqu 0x60(%rsp), %xmm1
+;; movdqu 0x70(%rsp), %xmm2
+;; movdqu 0x80(%rsp), %xmm3
+;; movdqu 0x90(%rsp), %xmm4
+;; movdqu 0xa0(%rsp), %xmm5
+;; movdqu 0xb0(%rsp), %xmm6
+;; movdqu 0xc0(%rsp), %xmm7
+;; movdqu 0xd0(%rsp), %xmm8
+;; movdqu 0xe0(%rsp), %xmm9
+;; movdqu 0xf0(%rsp), %xmm10
+;; movdqu 0x100(%rsp), %xmm11
+;; movdqu 0x110(%rsp), %xmm12
+;; movdqu 0x120(%rsp), %xmm13
+;; movdqu 0x130(%rsp), %xmm14
+;; movdqu 0x140(%rsp), %xmm15
+;; addq $0x150, %rsp
+;; movq %rbp, %rsp
+;; popq %rbp
+;; retq
+;; 3a7: movq 0x10(%rbx), %r8
+;; 3ab: movq 0x198(%r8), %r8
+;; 3b2: movq %rbx, %rdi
+;; 3b5: callq *%r8
+;; 3b8: ud2
diff --git a/tests/disas/duplicate-function-types.wat b/tests/disas/duplicate-function-types.wat
index cf2139672b..3976f808e5 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 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 f4dcffaa3e..4b9dfd41dc 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 u1610612736:16 sig0
+;; fn0 = colocated u805306368:16 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
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 955f3571e4..31cbaf7fc6 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 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 dd7a899e89..9f8e985bd7 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+24
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 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 274b4d5f54..f2edee849f 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+24
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 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 6ca19404ff..fc5d97c033 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+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 7adb9bdf25..cdc1fcaf3e 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+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 9669191c5e..68391822d8 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 u1610612736:9 sig1
-;; fn1 = colocated u1610612736:35 sig2
+;; fn0 = colocated u805306368:9 sig1
+;; fn1 = colocated u805306368:35 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 c84be143fb..44ad9c2831 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:25 sig0
+;; fn0 = colocated u805306368:25 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 226609b2e7..a0752b7806 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32) -> i64 tail
-;; fn0 = colocated u1610612736:29 sig0
+;; fn0 = colocated u805306368:29 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 87e548958b..0d1ad8a3ef 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+24
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u1610612736:27 sig0
-;; fn1 = colocated u1610612736:28 sig1
+;; fn0 = colocated u805306368:27 sig0
+;; fn1 = colocated u805306368:28 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 511596b093..2cd534a9a2 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u1610612736:28 sig0
+;; fn0 = colocated u805306368:28 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 63d833f3fe..83fad1e6c0 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 b1a38fbb5f..bc034f636e 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+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 25f7897c75..bf4405a5e4 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 feb660998b..42f735a4be 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 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 c8ea45a89d..9794d0fe87 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 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 1a2b233c6b..a762954a46 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:25 sig0
+;; fn0 = colocated u805306368:25 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 27ac8470a3..59623535ef 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+32
;; gv6 = load.i64 notrap aligned readonly can_move gv4+24
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u1610612736:26 sig0
+;; fn0 = colocated u805306368:26 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 834eb9e5ee..4c96c8c34f 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+32
;; gv6 = load.i64 notrap aligned readonly can_move gv4+24
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u1610612736:26 sig0
+;; fn0 = colocated u805306368:26 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 4a28f086e8..d7d430bfe8 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+32
;; gv6 = load.i64 notrap aligned readonly can_move gv4+24
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u1610612736:26 sig0
+;; fn0 = colocated u805306368:26 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 e16a70c390..6cda7d3895 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+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 b8340d6373..4ced43b49a 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+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64) tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 f1bff51d65..5766332c56 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 u1610612736:9 sig1
-;; fn1 = colocated u1610612736:35 sig2
+;; fn0 = colocated u805306368:9 sig1
+;; fn1 = colocated u805306368:35 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 a12beba91d..417531ae00 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32) -> i64 tail
-;; fn0 = colocated u1610612736:29 sig0
+;; fn0 = colocated u805306368:29 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 658c4d8337..d2f8b7f83c 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+24
;; sig0 = (i64 vmctx, i64) -> i8 tail
;; sig1 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u1610612736:26 sig0
-;; fn1 = colocated u1610612736:28 sig1
+;; fn0 = colocated u805306368:26 sig0
+;; fn1 = colocated u805306368:28 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 97dba164e1..aeed15a95b 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i64) -> i64 tail
-;; fn0 = colocated u1610612736:28 sig0
+;; fn0 = colocated u805306368:28 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 451898878d..12e19ab587 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 30b06b4805..9438b3f2e4 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+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 89809a3752..a0f18bbc6c 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:35 sig0
+;; fn0 = colocated u805306368:35 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 c67db4ca42..537dbde6d0 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+32
;; gv6 = load.i64 notrap aligned readonly can_move gv4+24
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u1610612736:26 sig0
+;; fn0 = colocated u805306368:26 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 36b5e1ad28..6797807015 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+32
;; gv6 = load.i64 notrap aligned readonly can_move gv4+24
;; sig0 = (i64 vmctx, i64) -> i8 tail
-;; fn0 = colocated u1610612736:26 sig0
+;; fn0 = colocated u805306368:26 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 3141cfb7d6..ad4851ed15 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
diff --git a/tests/disas/gc/struct-new.wat b/tests/disas/gc/struct-new.wat
index 7f59fc1297..82adb310ad 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+24
;; gv6 = load.i64 notrap aligned gv4+32
;; sig0 = (i64 vmctx, i32, i32, i32, i32) -> i32 tail
-;; fn0 = colocated u1610612736:27 sig0
+;; fn0 = colocated u805306368:27 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 ac63bc9be5..74442cb427 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/icall-simd.wat b/tests/disas/icall-simd.wat
index 6733afce4c..c820284359 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 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 aeb4cb467d..ae5822604c 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 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 a30b25af54..a69e77623c 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/passive-data.wat b/tests/disas/passive-data.wat
index 21de22f461..7b51f04ef1 100644
--- a/tests/disas/passive-data.wat
+++ b/tests/disas/passive-data.wat
@@ -21,7 +21,7 @@
;; gv4 = load.i64 notrap aligned gv3+64
;; gv5 = load.i64 notrap aligned readonly can_move checked gv3+56
;; sig0 = (i64 vmctx, i32, i32, i64, i32, i32) -> i8 tail
-;; fn0 = colocated u1610612736:6 sig0
+;; fn0 = colocated u805306368:6 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32):
@@ -41,7 +41,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:8 sig0
+;; fn0 = colocated u805306368:8 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/readonly-funcrefs.wat b/tests/disas/readonly-funcrefs.wat
index 6091c33e9d..d9300bb09e 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
diff --git a/tests/disas/stack-switching/resume-suspend-data-passing.wat b/tests/disas/stack-switching/resume-suspend-data-passing.wat
index d1009a509e..b24ba2288e 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 u1610612736:7 sig0
-;; fn1 = colocated u1610612736:52 sig1
+;; fn0 = colocated u805306368:7 sig0
+;; fn1 = colocated u805306368:52 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 4fe2578e49..1f09b66632 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 u1610612736:7 sig0
-;; fn1 = colocated u1610612736:52 sig1
+;; fn0 = colocated u805306368:7 sig0
+;; fn1 = colocated u805306368:52 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 2609cda7a1..666fcd8406 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 u1610612736:7 sig0
-;; fn1 = colocated u1610612736:52 sig1
+;; fn0 = colocated u805306368:7 sig0
+;; fn1 = colocated u805306368:52 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 u1610612736:7 sig0
-;; fn1 = colocated u1610612736:52 sig1
+;; fn0 = colocated u805306368:7 sig0
+;; fn1 = colocated u805306368:52 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
diff --git a/tests/disas/table-copy.wat b/tests/disas/table-copy.wat
index 05d8fcde4e..05dd9e62cd 100644
--- a/tests/disas/table-copy.wat
+++ b/tests/disas/table-copy.wat
@@ -68,7 +68,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32, i64, i64, i64) -> i8 tail
-;; fn0 = colocated u1610612736:1 sig0
+;; fn0 = colocated u805306368:1 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
@@ -90,7 +90,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, i32, i32, i64, i64, i64) -> i8 tail
-;; fn0 = colocated u1610612736:1 sig0
+;; fn0 = colocated u805306368:1 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32, v4: i32, v5: i32):
diff --git a/tests/disas/table-set-fixed-size.wat b/tests/disas/table-set-fixed-size.wat
index 86e57ff332..d35111f901 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+24
;; gv7 = load.i64 notrap aligned gv5+32
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:25 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
@@ -123,7 +123,7 @@
;; gv6 = load.i64 notrap aligned readonly can_move gv5+24
;; gv7 = load.i64 notrap aligned gv5+32
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:25 sig0
+;; fn0 = colocated u805306368:25 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 ee30fbc370..ceb3a92b71 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+24
;; gv8 = load.i64 notrap aligned gv6+32
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:25 sig0
+;; fn0 = colocated u805306368:25 sig0
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
@@ -126,7 +126,7 @@
;; gv7 = load.i64 notrap aligned readonly can_move gv6+24
;; gv8 = load.i64 notrap aligned gv6+32
;; sig0 = (i64 vmctx, i32) tail
-;; fn0 = colocated u1610612736:25 sig0
+;; fn0 = colocated u805306368:25 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 310334996a..32082555f2 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 u1610612736:9 sig0
+;; fn0 = colocated u805306368:9 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 u1610612736:9 sig1
+;; fn0 = colocated u805306368:9 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 c3dd36b467..2473e6c325 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+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u1610612736:38 sig0
+;; fn0 = colocated u805306368:38 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -49,7 +49,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u1610612736:40 sig0
+;; fn0 = colocated u805306368:40 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -81,7 +81,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u1610612736:42 sig0
+;; fn0 = colocated u805306368:42 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -113,7 +113,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f32) -> f32 tail
-;; fn0 = colocated u1610612736:44 sig0
+;; fn0 = colocated u805306368:44 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -145,7 +145,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u1610612736:39 sig0
+;; fn0 = colocated u805306368:39 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -171,7 +171,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u1610612736:41 sig0
+;; fn0 = colocated u805306368:41 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -197,7 +197,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u1610612736:43 sig0
+;; fn0 = colocated u805306368:43 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;
@@ -223,7 +223,7 @@
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx, f64) -> f64 tail
-;; fn0 = colocated u1610612736:45 sig0
+;; fn0 = colocated u805306368:45 sig0
;; const0 = 0x00000000000000000000000000000000
;; stack_limit = gv2
;;