From bbea2855beec7231750a90af1adbde6e3f8c044f Mon Sep 17 00:00:00 2001 From: data-pup <16364986+data-pup@users.noreply.github.com> Date: Tue, 26 Nov 2019 12:43:31 -0500 Subject: [PATCH] wip - fix #636, check memory before calculating offset --- crates/jit/src/compiler.rs | 44 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/jit/src/compiler.rs b/crates/jit/src/compiler.rs index 4020baf650..663f56ec8f 100644 --- a/crates/jit/src/compiler.rs +++ b/crates/jit/src/compiler.rs @@ -163,26 +163,30 @@ impl Compiler { 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 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 ofs = VMOffsets::new(target_config.pointer_bytes(), &module); + if ofs.num_defined_memories > 0 { + 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( + triple, + &target_config, + &debug_data, + &module_vmctx_info, + &address_transform, + &value_ranges, + &funcs, + ) + .map_err(|e| SetupError::DebugInfo(e))?; + Some(bytes) + } else { + None + } } else { None };