You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
;tldr; should we use globals hold data addresses, even in non-PIC object files.
The current tooling conventions for object files (and the default used by llvm) is to represent data and functions address only in relocations.
Taking the address or a data symbol or function symbol results in the following code:
i32.const <reloc>
Where the reloc exists only in the linking section and is either a R_WASM_MEMORY_ADDRESS_LEB (for data symbols) or R_WASM_FUNCTION_INDEX_LEB (for function symbols).
With the experimental PIC ABI used by emscripten these address are instead model as wasm globals and produces the following pattern.
global.get <reloc>
In this case the relocation type is R_WASM_GLOBAL_INDEX_LEB.
When linking object built with -fPIC into static binaries that linker creates internal immutable globals that represent the static address of the symbol. Because the global is internal and immutable wasm-opt can then completely eliminate the global and replace the global.get with an i32.const. This can be though of as form of linker relaxation that happen in the post-link optimizer. With a little work we could teach wasm-ld to perform this relaxation directly.
My suggestion is to use globals in similar fashion by default and even when -fPIC is not specified. Here are some of the advantages, as I see them:
It simplifies llvm, having just one way to get symbol addresses.
It means more comaptability between object files. (-fPIC object need no longer be special)
We can use the name section to name wasm globals (Add initial support for extended names sections wabt#1554) which means that inspecting object files will give much clearer results. The llvm symbol names can appear the output of normal wasm disassemblers such as wasm2wat and wasmdis, whereas this information was previously hidden in the relocation data.
Undefined data symbols can now be represented as imports by the linker. Previously there is now way for the linker to turn an undefined data symbol into an import which is why --allow-undefined doesn't do what most people think it does WRT to data symbols.
Downsides:
Unoptimized builds with a lot of global data symbols or address taken functions will have extra wasm globals. (wasm-opt can remove all of these).
;tldr; should we use globals hold data addresses, even in non-PIC object files.
The current tooling conventions for object files (and the default used by llvm) is to represent data and functions address only in relocations.
Taking the address or a data symbol or function symbol results in the following code:
Where the reloc exists only in the linking section and is either a
R_WASM_MEMORY_ADDRESS_LEB(for data symbols) orR_WASM_FUNCTION_INDEX_LEB(for function symbols).With the experimental PIC ABI used by emscripten these address are instead model as wasm globals and produces the following pattern.
In this case the relocation type is
R_WASM_GLOBAL_INDEX_LEB.When linking object built with
-fPICinto static binaries that linker creates internal immutable globals that represent the static address of the symbol. Because the global is internal and immutablewasm-optcan then completely eliminate the global and replace theglobal.getwith ani32.const. This can be though of as form of linker relaxation that happen in the post-link optimizer. With a little work we could teach wasm-ld to perform this relaxation directly.My suggestion is to use globals in similar fashion by default and even when
-fPICis not specified. Here are some of the advantages, as I see them:It simplifies llvm, having just one way to get symbol addresses.-fPICobject need no longer be special)wasm2watandwasmdis, whereas this information was previously hidden in the relocation data.--allow-undefineddoesn't do what most people think it does WRT to data symbols.Downsides: