Browse Source

Handle defined shared memories in dwarf processing (#8750)

This commit resolves an assert in the dwarf generating of core wasm
modules when the module has a defined linear memory which is flagged
`shared`. This is represented slightly differently in the `VMContext`
than owned memories that aren't `shared`, and looks more like an
imported memory. With support in #8740 it's now much easier to support
this.

Closes #8652
pull/8753/head
Alex Crichton 5 months ago
committed by GitHub
parent
commit
cdb59304c3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      crates/cranelift/src/debug.rs
  2. 2
      crates/test-programs/artifacts/build.rs
  3. 2
      crates/test-programs/build.rs
  4. 1
      crates/test-programs/src/bin/dwarf_shared_memory.rs
  5. 6
      tests/all/debug/lldb.rs

28
crates/cranelift/src/debug.rs

@ -5,8 +5,8 @@ use cranelift_codegen::isa::TargetIsa;
use object::write::SymbolId;
use std::collections::HashMap;
use wasmtime_environ::{
DefinedFuncIndex, EntityRef, MemoryIndex, ModuleTranslation, OwnedMemoryIndex, PrimaryMap,
PtrSize, StaticModuleIndex, Tunables, VMOffsets,
DefinedFuncIndex, DefinedMemoryIndex, EntityRef, MemoryIndex, ModuleTranslation,
OwnedMemoryIndex, PrimaryMap, PtrSize, StaticModuleIndex, Tunables, VMOffsets,
};
/// Memory definition offset in the VMContext structure.
@ -88,25 +88,21 @@ impl<'a> Compilation<'a> {
);
let memory_offset = if ofs.num_imported_memories > 0 {
let index = MemoryIndex::new(0);
ModuleMemoryOffset::Imported {
offset_to_vm_memory_definition: ofs.vmctx_vmmemory_import(MemoryIndex::new(0))
offset_to_vm_memory_definition: ofs.vmctx_vmmemory_import(index)
+ u32::from(ofs.vmmemory_import_from()),
offset_to_memory_base: ofs.ptr.vmmemory_definition_base().into(),
}
} else if ofs.num_owned_memories > 0 {
let index = OwnedMemoryIndex::new(0);
ModuleMemoryOffset::Defined(ofs.vmctx_vmmemory_definition_base(index))
} else if ofs.num_defined_memories > 0 {
// The addition of shared memory makes the following assumption,
// "owned memory index = 0", possibly false. If the first memory
// is a shared memory, the base pointer will not be stored in
// the `owned_memories` array. The following code should
// eventually be fixed to not only handle shared memories but
// also multiple memories.
assert_eq!(
ofs.num_defined_memories, ofs.num_owned_memories,
"the memory base pointer may be incorrect due to sharing memory"
);
ModuleMemoryOffset::Defined(
ofs.vmctx_vmmemory_definition_base(OwnedMemoryIndex::new(0)),
)
let index = DefinedMemoryIndex::new(0);
ModuleMemoryOffset::Imported {
offset_to_vm_memory_definition: ofs.vmctx_vmmemory_pointer(index),
offset_to_memory_base: ofs.ptr.vmmemory_definition_base().into(),
}
} else {
ModuleMemoryOffset::None
};

2
crates/test-programs/artifacts/build.rs

@ -90,7 +90,7 @@ fn build_and_generate_tests() {
}
// Generate a component from each test.
if kind == "nn" || target == "dwarf_imported_memory" {
if kind == "nn" || target == "dwarf_imported_memory" || target == "dwarf_shared_memory" {
continue;
}
let adapter = match target.as_str() {

2
crates/test-programs/build.rs

@ -1,4 +1,6 @@
fn main() {
println!("cargo:rustc-link-arg-bin=dwarf_imported_memory=--import-memory");
println!("cargo:rustc-link-arg-bin=dwarf_imported_memory=--export-memory");
println!("cargo:rustc-link-arg-bin=dwarf_shared_memory=--no-check-features");
println!("cargo:rustc-link-arg-bin=dwarf_shared_memory=--shared-memory");
}

1
crates/test-programs/src/bin/dwarf_shared_memory.rs

@ -0,0 +1 @@
include!("./dwarf_simple.rs");

6
tests/all/debug/lldb.rs

@ -370,4 +370,10 @@ check: exited with status = 0
&["--preload=env=./tests/all/debug/satisfy_memory_import.wat"],
)
}
#[test]
#[ignore]
fn dwarf_shared_memory() -> Result<()> {
test_dwarf_simple(DWARF_SHARED_MEMORY, &[])
}
}

Loading…
Cancel
Save