-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
As part of our compiler, we hand-emit a small number of helper methods in pure WASM, of a kind like below:
void helper_11(arg1, arg2) {
extern int compiler_generated_data_symbol_11;
return SomeMethod(&compiler_generated_data_symbol_11, arg1, arg2);
}Historically this was done without the need to consider -fPIC, but recently we've started thinking about supporting that too. However, we would also like to emit code that is "PIC-agnostic" (this is how the compiler works for other targets).
In a non-PIC build, the example from above will emit something like:
000042: 41 80 80 80 80 00 | i32.const 0
000043: R_WASM_MEMORY_ADDR_SLEB 1 <compiler_generated_data_symbol_11>
And that's also what we emit currently (more or less).
For "PIC-agnostic" code, we could emit the same using GOT, like so:
000053: 23 80 80 80 80 00 | global.get 0 <GOT.mem.compiler_generated_data_symbol_11>
000054: R_WASM_GLOBAL_INDEX_LEB 1 <compiler_generated_data_symbol_11>
To keep (roughly) the same code size and runtime performance. However, we will then have a bunch of immutable GOT.* globals that don't really serve much purpose in a non-PIE link.
But this seems avoidable if all the references to these GOT globals could be rewritten in-place to i32.consts with the actual value.