Skip to content

Duplicate JIT debug module registrations with components #9461

@SingleAccretion

Description

@SingleAccretion

Reproduction:

  1. 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
  1. 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'
  1. Observe four (JIT) modules (for each core module in a component). All of them have the exact same content.
> (lldb) image list
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions