I'm looking to build a program that replaces static globals in a wat file and then eventually output a wasm file. Is wast the best crate for this?
Walrus is a library for modifying wasm files. I don't think it supports wat files, but you can always compile them to wasm files and afterwards decompile to wat files.
Awesome thank you!!
How does the .data section reference the $.rodata? My global has a number that points to a data section I thought i would find my string static there but it is stored in the rodata. But not sure how to make sense of what's in the .data so that I can get the text in the string. Any ideas?
For wasm modules all relocations are resolved already. There is nothing left to indicate which bytes are pointers and which aren't. You need the source wasm object files if you need relocations.
By the way wasm doesn't have a distinction between .data and .rodata. Everything is inside a single segment and the entire linear memory is writable.
Also are you using C strings or Rust strings. In case of C strings you just need to follow an extra pointer indirection to get the actual string data. The global points to the location of the static, which likely is a const char *
pointer. For Rust strings the layout doesn't have any guarantees.
Last updated: Nov 22 2024 at 16:03 UTC