[lld] [lld][WebAssembly] Add `GOT.mem` for `WASM_MEMORY_ADDR_REL_` of Shared Data (PR #104920)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 10:00:45 PDT 2024
sbc100 wrote:
> > The way this stuff is designed to work is that a given symbol is either accessed via the GOT _or_ via base register.
> > If you are accessing something via `__memory_base` or via `__table_base` then the result is a fixed offset from a dynamic location.
> > If you are accessing something via a GOT entry then each symbol gets its own global (no offset needed).
>
> Thank you for the explanation. I was primarily wondering about the case an importing module would need to perform pointer comparison or arithmetics on that exported data. But maybe this would need explicit GOT entry from the LLVM codegen? I am happy to close this PR if not needed.
Perhaps you could explain in a little more detail? Basically, at codegen time that code generator makes and either or decsion when it need to calculate the address of a symbol:
1. Use a wasm global / GOT entry to hold the address. (i.e. `global.get`)
2. Use an address relative the a base address (i.e. global.get __memory_base + offset)
(1) comes at some cost since it requires O(N) wasm globals whereas (2) only requires a single global, but requires the additional addition of a constant.
(1) is the most conservative option since it will work with any symbol.
(2) only works for symbols that are local to the current DSO (and cannot be interposed / replaced by another DSO). The most commen example I can think of here are `static` C symbols that are file-local. These never need GOT entries. Pretty much all global symbols do need GOT entires.
https://github.com/llvm/llvm-project/pull/104920
More information about the llvm-commits
mailing list