Description
Every wasm module's base address currently defaults to 0 with no way for the crate to override it. This means multiple modules compiled with #![wasm_import_memory]
can't use a single imported memory without clobbering each other's data.
Does it make sense to add a crate attribute like #![wasm_base_address(100)]
to set that module's base address in binaryen's options to 100
? This does mean that the user will have to manually update every crate's base address according to the base addresses of every other crate. So this doesn't work for crates they don't own [1].
The proper solution would be for the compiler to emit relocation information so that a post-processor like wasm-gc
or a loader in the host environment can relocate the modules. As of now that isn't possible, since pointers to static data are indistinguishable from integers.
[1]: Doesn't work for top-level crates (that compile into WASM modules) they don't own that is. rlib dependency crates are fine.