LOGBOOK

HELP

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:

  1. Find position to modify:

    position = address_of(section) + r.offset
    
  2. 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
    
  3. 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:

From Quiz: REVE1 / Program Execution | Updated: Jul 10, 2026