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
[ELF] Emit .reloc annotations and local STT_OBJECT symbols for jump tables
The Linux kernel build system performs static analysis on the ELF
objects to infer whether indirect jumps are truly function pointer
dereferences, or calls via jump tables where the set of possible
destinations is limited and decided at compile-time.
When generating position dependent x86 code for the small code model,
this is usually straight-forward, as the address of the jump table is
encoded as an immediate in the instruction, e.g.,
jmpq *jump_table(, %reg, 8)
and each entry in the table represents the absolute address of a jump
destination.
However, when switching to PIC codegen, or building for load-store
architectures, this usually becomes something like
leaq jump_table(%rip), %reg0
movlsq (%reg0, %reg1, 4), %reg1
addq %reg0, %reg1
jmpq *%reg1
or on arm64
adrp xM, jump_table
add xM, :lo12:jump_table
ldrsw wN, [xM, xN, lsl #2]
add xN, xN, xM
br xN
where there is no obvious correlation between the location of the jump
table and the indirect branch instruction, and where the start of each
jump table has to be known to dereference the 32-bit relative references
correctly, as they are relative to the start of the table rather than
relative to each individual entry.
Make the tooling's job easier by:
- emitting an ELF symbol that covers the jump table, so that its size
can be discovered;
- emitting a BFD_RELOC_NONE allocation that links the symbol to the
indirect branch instruction where the effective jump destination is
consumed.
Signed-off-by: Ard Biesheuvel <[email protected]>
0 commit comments