Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve relocation locations #4429

Open
jkelleyrtp opened this issue Feb 11, 2025 · 0 comments
Open

Preserve relocation locations #4429

jkelleyrtp opened this issue Feb 11, 2025 · 0 comments

Comments

@jkelleyrtp
Copy link

jkelleyrtp commented Feb 11, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant