Format:ELF (Executable and Linkable Format)/Relocations and PLT
x86-64 and AArch64 relocation types an analyst meets in dynamic ELF files, and what the .plt, .plt.sec and .got.plt stubs look like in bytes (classic lazy PLT, Intel IBT and AArch64 BTI/PAC variants).
Dynamic relocations in practice
In a linked executable or shared object the runtime relocations are in .rela.dyn (DT_RELA/RELASZ) and .rela.plt (DT_JMPREL/PLTRELSZ). x86-64 and AArch64 always use RELA (explicit addend). The few types that matter when reading a dynamic table:
| Meaning | x86-64 | AArch64 |
|---|---|---|
| base + addend (no symbol; PIE/so internal pointers) | 8 R_X86_64_RELATIVE | 1027 R_AARCH64_RELATIVE |
| GOT slot for a symbol | 6 R_X86_64_GLOB_DAT | 1025 R_AARCH64_GLOB_DAT |
| PLT slot (lazy import) | 7 R_X86_64_JUMP_SLOT | 1026 R_AARCH64_JUMP_SLOT |
| absolute 64-bit symbol + addend | 1 R_X86_64_64 | 257 R_AARCH64_ABS64 |
| copy data from shared object (non-PIE) | 5 R_X86_64_COPY | 1024 R_AARCH64_COPY |
| IFUNC: call resolver at addend | 37 R_X86_64_IRELATIVE | 1032 R_AARCH64_IRELATIVE |
| TLS module id / offset in module / offset from thread pointer | 16 DTPMOD64 / 17 DTPOFF64 / 18 TPOFF64 | 1028 TLS_DTPMOD / 1029 TLS_DTPREL / 1030 TLS_TPREL |
| TLS descriptor | 36 R_X86_64_TLSDESC | 1031 R_AARCH64_TLSDESC |
Static (link-time) types seen in .o files: x86-64 2 PC32, 4 PLT32 (calls to functions; modern compilers emit it instead of PC32), 9 GOTPCREL, 41 GOTPCRELX and 42 REX_GOTPCRELX (relaxable GOT loads), 10 32, 11 32S; AArch64 283 CALL26 (bl), 282 JUMP26 (b), 275 ADR_PREL_PG_HI21 (adrp), 277 ADD_ABS_LO12_NC, 311 ADR_GOT_PAGE, 312 LD64_GOT_LO12_NC. Note the AArch64 numbers: static types are 257..573, dynamic types start at 1024. A relocation type 0 is R_*_NONE and is a placeholder left by the linker.
DT_RELACOUNT (0x6ffffff9) counts the leading R_*_RELATIVE entries, which linkers sort first.
Lazy PLT, x86-64 (no CET)
.plt starts with a 16-byte header, then 16-byte entries, one per .rela.plt entry, in order:
PLT0: ff 35 <rel32> push GOTPLT+8(%rip) ; link_map
ff 25 <rel32> jmp *GOTPLT+16(%rip) ; _dl_runtime_resolve
0f 1f 40 00 nop
PLTn: ff 25 <rel32> jmp *GOT[n+3](%rip)
68 <idx32> push relocation index
e9 <rel32> jmp PLT0
.got.plt slots 0..2 are reserved (address of _DYNAMIC, link_map, resolver); the slot of an entry first points back at its own push and is overwritten by the resolver. With -z now / DF_BIND_NOW (full RELRO) the slots are filled at load and the binary usually has .plt.got/.got direct calls instead.
x86-64 with IBT (CET)
When -z ibtplt / the GNU property marks IBT, the lazy entries move: .plt holds 16-byte entries f3 0f 1e fa (endbr64) 68 <idx32> e9 <rel32> 66 90, and a second section .plt.sec holds the jump stubs that call sites use:
f3 0f 1e fa endbr64
ff 25 <rel32> jmp *GOT[n](%rip)
66 0f 1f 44 00 00 nopw
So with IBT, call foo@plt targets .plt.sec, and the .got.plt slot initially points into .plt. In a disassembler the stub at .plt.sec is the one to name after the import.
AArch64
PLT0: f0 7b bf a9 stp x16, x30, [sp,#-16]!
10 00 00 90 adrp x16, Page(&.got.plt[2])
11 02 40 f9 ldr x17, [x16, Offset(&.got.plt[2])]
10 02 00 91 add x16, x16, Offset(&.got.plt[2])
20 02 1f d6 br x17
1f 20 03 d5 x3 nop
PLTn: 10 00 00 90 adrp x16, Page(&.got.plt[n])
11 02 40 f9 ldr x17, [x16, Offset]
10 02 00 91 add x16, x16, Offset
20 02 1f d6 br x17
PLT0 is 32 bytes, each entry 16. With BTI the entries start with 5f 24 03 d5 (bti c) and end in a nop; with pointer authentication they use 9f 21 03 d5 (autia1716) before the br x17, or 30 0a 1f d7 (braa x17, x16). DT_AARCH64_BTI_PLT (0x70000001) and DT_AARCH64_PAC_PLT (0x70000003) in the dynamic table say the PLT has them.
Unverified
The exact PLT layout varies by linker (GNU ld, gold, LLD, mold) and version; the bytes above are what LLD writes (llvm-project lld/ELF/Arch/X86_64.cpp and AArch64.cpp). GNU ld uses the same x86-64 instruction sequences but may pad differently (for example .plt.got entries ff 25 <rel32> 66 90 for symbols whose address is taken). Check a real binary with objdump -d -j .plt.
Hooking by overwriting GOT slots (what plthook does): Technique:Function hooking/Unix and mobile.