Stream: general

Topic: About `global.xxx` in the link test case in wasm-tools


view this post on Zulip lum1n0us (Apr 06 2024 at 08:38):

I'm not sure about that. please feel free to correct me.

I noticed the global.get in lib-foo in link case is:

    local.get 0
    global.get $um
    i32.load offset=16

Because lib-bar will be linked with other wasm modules but run with its own data area ((data $.data (global.get $__memory_base) "\04\00\00\00")). Does it mean its global.get should read from __memory_base + $offsetinstead of $offset, in this case, local.get 0 provides $offset?

CLI and Rust libraries for low-level manipulation of WebAssembly modules - bytecodealliance/wasm-tools

view this post on Zulip Joel Dice (Apr 06 2024 at 15:47):

wasm-tools component link will synthesize an "init" module which is responsible for initializing all GOT.mem global variables based on the computed memory offsets, which means that by the time the global.get and i32.load instructions you linked to are run, the $um global variable has already been updated to point to the correct place in memory. See https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md#imports for more details. See also https://github.com/bytecodealliance/wasm-tools/blob/c85632b22db1fd7a6b9b7146fc1df204e19d5afb/crates/wit-component/src/linking.rs#L675-L697 for where the code initializes the GOT.mem global variables based on the appropriate __memory_base value.

Conventions supporting interoperatibility between tools working with WebAssembly. - WebAssembly/tool-conventions
CLI and Rust libraries for low-level manipulation of WebAssembly modules - bytecodealliance/wasm-tools

view this post on Zulip Joel Dice (Apr 06 2024 at 15:52):

Also, here's the "init" module produced for the test case you linked to above: https://github.com/bytecodealliance/wasm-tools/blob/c85632b22db1fd7a6b9b7146fc1df204e19d5afb/crates/wit-component/tests/components/link/component.wat#L146-L182

CLI and Rust libraries for low-level manipulation of WebAssembly modules - bytecodealliance/wasm-tools

Last updated: Dec 23 2024 at 12:05 UTC