diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index 5f710c4357..a476c37131 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -19,3 +19,6 @@ log = "0.4.8" wasmparser = "0.42.1" wasmprinter = "0.2.0" wasmtime-jit = { path = "../jit" } + +[dev-dependencies] +wat = "1.0" diff --git a/crates/fuzzing/tests/regressions.rs b/crates/fuzzing/tests/regressions.rs index c463e1422e..8576cd6c86 100644 --- a/crates/fuzzing/tests/regressions.rs +++ b/crates/fuzzing/tests/regressions.rs @@ -7,3 +7,9 @@ #[allow(unused_imports)] // Until we actually have some regression tests... use wasmtime_fuzzing::*; + +#[test] +fn instantiate_empty_module() { + let data = wat::parse_str(include_str!("./regressions/empty.wat")).unwrap(); + oracles::instantiate(&data, wasmtime_jit::CompilationStrategy::Auto); +} diff --git a/crates/fuzzing/tests/regressions/empty.wat b/crates/fuzzing/tests/regressions/empty.wat new file mode 100644 index 0000000000..3af8f25454 --- /dev/null +++ b/crates/fuzzing/tests/regressions/empty.wat @@ -0,0 +1 @@ +(module) diff --git a/crates/jit/src/compiler.rs b/crates/jit/src/compiler.rs index 4020baf650..ff30bc71eb 100644 --- a/crates/jit/src/compiler.rs +++ b/crates/jit/src/compiler.rs @@ -156,33 +156,36 @@ impl Compiler { let dbg = if let Some(debug_data) = debug_data { let target_config = self.isa.frontend_config(); - let triple = self.isa.triple().clone(); - let mut funcs = Vec::new(); - for (i, allocated) in allocated_functions.into_iter() { - let ptr = (*allocated) as *const u8; - let body_len = compilation.get(i).body.len(); - funcs.push((ptr, body_len)); - } - let module_vmctx_info = { - let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); - let memory_offset = - ofs.vmctx_vmmemory_definition_base(DefinedMemoryIndex::new(0)) as i64; - ModuleVmctxInfo { - memory_offset, - stack_slots, + let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); + if ofs.num_defined_memories > 0 { + let mut funcs = Vec::new(); + for (i, allocated) in allocated_functions.into_iter() { + let ptr = (*allocated) as *const u8; + let body_len = compilation.get(i).body.len(); + funcs.push((ptr, body_len)); } - }; - let bytes = emit_debugsections_image( - triple, - &target_config, - &debug_data, - &module_vmctx_info, - &address_transform, - &value_ranges, - &funcs, - ) - .map_err(|e| SetupError::DebugInfo(e))?; - Some(bytes) + let module_vmctx_info = { + let memory_offset = + ofs.vmctx_vmmemory_definition_base(DefinedMemoryIndex::new(0)) as i64; + ModuleVmctxInfo { + memory_offset, + stack_slots, + } + }; + let bytes = emit_debugsections_image( + self.isa.triple().clone(), + &target_config, + &debug_data, + &module_vmctx_info, + &address_transform, + &value_ranges, + &funcs, + ) + .map_err(|e| SetupError::DebugInfo(e))?; + Some(bytes) + } else { + None + } } else { None };