Quiz Entry - updated: 2026.07.10
What is the structure of an ELF relocation entry?
An Elf64_Rela entry records where to patch (offset), how (type), which symbol, and an addend — the linker writes symbol + addend (minus the patch position for PC-relative types).
typedef struct {
// Offset of reference in section
long offset;
// Relocation type (R_X86_64_*)
long type:32,
// Index in symbol table
symbol:32;
// Constant to add to address
long addend;
} Elf64Rela;
How relocation works:
-
Find position to modify:
position = address_of(section) + r.offset -
Calculate value to write:
// For absolute (R_X86_64_64/32): value = address_of(r.symbol) + r.addend // For PC-relative (R_X86_64_PC32): value = address_of(r.symbol) + r.addend - position -
Write value at position (4 or 8 bytes depending on type)
Example from objdump:
Disassembly of section .data.rel:
0000000000000000 <bufp0>:
0: R_X86_64_64 buf [+0]
Go deeper:
elf(5) — Elf64_Rela and relocation entries — the exact struct fields (
r_offset,r_info,r_addend) the linker reads.