Skip to content

Preserve relocation locations #4429

Open
@jkelleyrtp

Description

@jkelleyrtp

Motivation

To build new advanced tools like wasm-split and wasm binary patching, keeping relocation information is crucial to building an accurate call graph (calling through vtables).

However, wasm-bindgen invalidates all relocation information during its transform passes.

In my wasm-split implementation, I actually load the original pre-bindgen module into memory, build the call-graph, and then attempt to revive the callgraph using symbol names in the post-bindgen module.

https://github.com/DioxusLabs/dioxus/blob/9c02eeb52ad5aac31eb353edd94d4ef754ab9d78/packages/wasm-split/wasm-split-cli/src/lib.rs#L1025-L1121

https://github.com/DioxusLabs/dioxus/blob/9c02eeb52ad5aac31eb353edd94d4ef754ab9d78/packages/wasm-split/wasm-split-cli/src/lib.rs#L236-L242

Ideally, any relocation data passed through the wasm-bindgen transform could actually be preserved, meaning anyone could build a proper call graph just from the wasm-bindgen output directly.

Proposed Solution

It seems that I could actually just graft in my solution that translates the relocations in wasm-bindgen itself. We could implement this by using the symbols names (giving them one if they don't already have one) or by using the indicies.

In the final emit phase, we'd simply write a new TypedRelocation section using the IdsToIndicies and IndiciesToIds, fixing up the relocations using the LocId of the instructions.

Alternatives

Currently to get relocations preserved you need to load the original module, which does work, but it's just messy and hard to extend.

Additional Context

I have a proper wasm-split implementation working with dioxus and have posted it on twitter.

https://x.com/dioxuslabs/status/1889016319670137123

To be able to release it as a general tool we would need a bit more support from wasm-bindgen itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions