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?
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.
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?
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.
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
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
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
and it just runs that function and then snapshots the current memory layout into a new component
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.
This has been very educational thank you very much. I will resolve this now
Cwasi4wasm has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC