Stream: wasm

Topic: ✔ Editing Globals using Walrus


view this post on Zulip Cwasi4wasm (May 31 2023 at 22:03):

Hello,

I have been working on a tool that edits global variables stored in the wasm and im trying to use Walrus. I'm having a bit of trouble decoding the data in the global to where it would be in the file, I am trying to have this tool replace that data. I'm wondering if there is any repo that I can read for inspiration? I thought Wizer or Javy might help since they both deal at this level. Any other suggestions?

view this post on Zulip Jeff Charles (Jun 01 2023 at 18:19):

In Javy, we use the wasmparser and wasm-encoder crates to add or update custom sections. We don't perform an edit-in-place on the module but rather create a new module with the changes and discard the old module. You may be able to use a similar approach for globals. We also use Wizer for preinitialization.

view this post on Zulip Cwasi4wasm (Jun 02 2023 at 18:22):

Awesome amazing! What is the purpose of the CustomSection in this regard? I see that is where we are putting the source code in a statically linked folder scenario? I read through it on the specifications but not really sure. Will this be used by a compiler?

view this post on Zulip bjorn3 (Jun 02 2023 at 19:05):

Custom sections can contain any kind of data.The wasm runtime will ignore all unknown custom sections. They can be used for many things. For example for storing debug information. And LLVM uses them to store information necessary to have LLD link two wasm object files together.

view this post on Zulip Cwasi4wasm (Jun 05 2023 at 11:32):

Awesome thank you! Is there a guide on Javy? I'm mostly interested on how it manages to inject a new binary with the js code. I thought I would use a global but wondering if there is a better way for this. Similar scenario, I have a python engine in wasm and would like to create a builder using my "bootstrap" wasm file

view this post on Zulip Cwasi4wasm (Jun 05 2023 at 13:24):

Oh, taking a look at it it seems it utilizes wizer and console stdin to create this snapshot that contains the Engine and the source code. Unless I'm looking at this wrong but this would make so much sense

view this post on Zulip Ramon Klass (Jun 05 2023 at 14:04):

yes basically. See the wizer readme, you can write a wizer.init function that sets up global objects the way you want them to be when the component starts and then you use those global objects in your code

view this post on Zulip Ramon Klass (Jun 05 2023 at 14:05):

and it just runs that function and then snapshots the current memory layout into a new component

view this post on Zulip Jeff Charles (Jun 05 2023 at 14:27):

For Javy specifically, the source code section isn't used by a compiler, it's intended for human consumption to help with debugging. If we get a complaint saying a module isn't behaving the way they expect, we have the ability to see the source code. We also update the producers custom section to indicate that Javy and JavaScript is used. We do this since some folks have tools in their hosted Wasm offerings that collect analytics on what source languages are used to produce a module.

view this post on Zulip Cwasi4wasm (Jun 05 2023 at 14:38):

This has been very educational thank you very much. I will resolve this now

view this post on Zulip Notification Bot (Jun 05 2023 at 14:38):

Cwasi4wasm has marked this topic as resolved.


Last updated: Dec 23 2024 at 13:07 UTC