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?
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.
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
Last updated: Dec 06 2025 at 05:03 UTC