Stream: general

Topic: .wat file field replacement


view this post on Zulip Cwasi4wasm (May 26 2023 at 14:25):

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?

view this post on Zulip bjorn3 (May 26 2023 at 16:11):

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.

view this post on Zulip Cwasi4wasm (May 26 2023 at 17:17):

Awesome thank you!!

view this post on Zulip Cwasi4wasm (May 29 2023 at 20:08):

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?

view this post on Zulip bjorn3 (May 30 2023 at 08:49):

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.

view this post on Zulip bjorn3 (May 30 2023 at 08:50):

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.

view this post on Zulip bjorn3 (May 30 2023 at 08:51):

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: Oct 23 2024 at 20:03 UTC