Skip to content

Build helper: emit relocatable wasm cores for meld --memory shared (unblocks gust:os buffer/stateful caps, meld#326) #168

Description

@avrabe

Why

meld#326 (dynamic/absolute addresses not rebased under meld fuse --memory shared) is what corrupts the gust:os buffer (log.line list<u8>) and stateful (spawn static mut) capabilities on the qemu-cortex-m3 nodes. A spike (meld#326 comment) settled the fix: meld will relocate a component's addresses into the shared linear memory by consuming its linking + reloc.CODE/reloc.DATA metadata — i.e. meld needs relocatable cores as input. (PIC/dylink is architecturally excluded: wasm-tools component new refuses a core that imports __memory_base/memory as globals.)

The friction

The gust:os cores are built cargo build --release --target wasm32-unknown-unknownwasm-tools component new, which strips relocations (final-linked executable). Producing a relocatable core is not a single cargo flag: rustc hardcodes --export=__heap_base --export=__data_end --gc-sections, which collides with the linker flags that keep relocations:

  • -C link-arg=--relocatablewasm-ld: error: -r and --gc-sections may not be used together
  • -C link-arg=--sharedsymbol exported via --export not found: __heap_base

Ask

A small build helper (xtask / script) for the gust:os driver crates that produces relocatable cores meld can relocate:

  1. rustc --emit=obj (or cargo with -C linker-plugin-lto/object emission) to get the pre-link object with linking + reloc.* intact, then
  2. drive wasm-ld -r manually (bypassing rustc's injected --gc-sections/exports), then
  3. wasm-tools component new (metadata verified to survive byte-for-byte).

Gate: the emitted component still carries linking v2 + reloc.CODE (check with wasm-tools objdump), and meld fuse --memory shared on a two-component composite relocates cleanly once meld's reloc-consumer lands.

Refs

  • meld#326 (the corruption + spike result / contract decision)
  • meld#334 (companion: unify __stack_pointer globals + DCE the dead trampoline — the S1/S2 WAT surgeries build-os-tl.sh does by hand)

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