Reproduction:
- Compile any component, e. g.
int main()
{
int a = 1;
return a;
}
> & $env:WASI_SDK_PATH/bin/clang main.cpp -o main.wasm -g3 -target wasm32-unknown-wasip2
- Debug with lldb+wasmtime:
> lldb wasmtime -- -D debug-info -O opt-level=0 main.wasm
> (lldb) b main
> (lldb) c ; Until you reach WASM's 'main'
- Observe four
(JIT) modules (for each core module in a component). All of them have the exact same content.
- Also observe that LLDB needed to index the same DWARF info four times. This means that "startup with debugging" is 4x slower if we exclude the time to compile code and transform DWARF.
The bug is somewhere around here:
|
let text = self.text(); |
|
let bytes = crate::debug::create_gdbjit_image( |
|
self.mmap().to_vec(), |
|
(text.as_ptr(), text.len()), |
|
) |
|
.context("failed to create jit image for gdb")?; |
|
let reg = crate::runtime::vm::GdbJitImageRegistration::register(bytes); |
|
self.dbg_jit_registration = Some(reg); |
AFAICT, with components, the generated image is a shared (among core modules) resource, so each Module::from_parts_raw call here:
|
// Convert all information about static core wasm modules into actual |
|
// `Module` instances by converting each `CompiledModuleInfo`, the |
|
// `types` type information, and the code memory to a runtime object. |
|
let static_modules = static_modules |
|
.into_iter() |
|
.map(|(_, info)| Module::from_parts_raw(engine, code.clone(), info, false)) |
|
.collect::<Result<_>>()?; |
Registers the same image.
Reproduction:
(JIT)modules (for each core module in a component). All of them have the exact same content.The bug is somewhere around here:
wasmtime/crates/wasmtime/src/runtime/instantiate.rs
Lines 72 to 79 in 460a4c0
AFAICT, with components, the generated image is a shared (among core modules) resource, so each
Module::from_parts_rawcall here:wasmtime/crates/wasmtime/src/runtime/component/component.rs
Lines 408 to 414 in 460a4c0
Registers the same image.