A relocation entry tells a linker to adjust the bytes at some place. Object files
keep them per section, at each section’s reloff and nreloc.
A linked image that keeps any has them in LC_DYSYMTAB’s external and local tables;
today’s linked files use dyld info or
chained fixups instead.
relocation_info
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | r_address | Offset of the bytes to fix, from the start of the section (in an object file). Bit 31 set means this is a scattered entry. |
| 4 | 4 | the rest | Bit-fields, below. |
In a little-endian file the bit-fields, from the low bit, are:
| Bits | Field | Meaning |
|---|---|---|
| 0–23 | r_symbolnum | A symbol index if r_extern is set, otherwise the ordinal of a section. |
| 24 | r_pcrel | Set if the value is relative to the program counter. |
| 25–26 | r_length | 0 a byte, 1 a word, 2 a long, 3 a quad. |
| 27 | r_extern | Set when r_symbolnum is a symbol. |
| 28–31 | r_type | The kind, below; 0 is the plain case. |
In a big-endian file the bit-fields are laid out from the top of the word instead: r_symbolnum in bits 8 to 31, r_pcrel in bit 7, r_length in bits 5 and 6, r_extern in bit 4, and r_type in bits 0 to 3.
scattered_relocation_info
Used in 32-bit object files, when the target address must be kept. Its first word,
with the top bit set, packs r_address (24 bits), r_type
(4 bits), r_length (2 bits) and r_pcrel (1 bit). The second
word is r_value, the address the entry refers to.
Relocation types
| Value | x86-64 | ARM64 |
|---|---|---|
| 0 | X86_64_RELOC_UNSIGNED | ARM64_RELOC_UNSIGNED |
| 1 | X86_64_RELOC_SIGNED | ARM64_RELOC_SUBTRACTOR |
| 2 | X86_64_RELOC_BRANCH | ARM64_RELOC_BRANCH26 |
| 3 | X86_64_RELOC_GOT_LOAD | ARM64_RELOC_PAGE21 |
| 4 | X86_64_RELOC_GOT | ARM64_RELOC_PAGEOFF12 |
| 5 | X86_64_RELOC_SUBTRACTOR | ARM64_RELOC_GOT_LOAD_PAGE21 |
| 6 | X86_64_RELOC_SIGNED_1 | ARM64_RELOC_GOT_LOAD_PAGEOFF12 |
| 7 | X86_64_RELOC_SIGNED_2 | ARM64_RELOC_POINTER_TO_GOT |
| 8 | X86_64_RELOC_SIGNED_4 | ARM64_RELOC_TLVP_LOAD_PAGE21 |
| 9 | X86_64_RELOC_TLV | ARM64_RELOC_TLVP_LOAD_PAGEOFF12 |
| 10 | ARM64_RELOC_ADDEND | |
| 11 | ARM64_RELOC_AUTHENTICATED_POINTER |
| Value | x86 | ARM |
|---|---|---|
| 0 | GENERIC_RELOC_VANILLA | ARM_RELOC_VANILLA |
| 1 | GENERIC_RELOC_PAIR | ARM_RELOC_PAIR |
| 2 | GENERIC_RELOC_SECTDIFF | ARM_RELOC_SECTDIFF |
| 3 | GENERIC_RELOC_PB_LA_PTR | ARM_RELOC_LOCAL_SECTDIFF |
| 4 | GENERIC_RELOC_LOCAL_SECTDIFF | ARM_RELOC_PB_LA_PTR |
| 5 | GENERIC_RELOC_TLV | ARM_RELOC_BR24 |
| 6 | ARM_THUMB_RELOC_BR22 | |
| 7 | ARM_THUMB_32BIT_BRANCH | |
| 8 | ARM_RELOC_HALF | |
| 9 | ARM_RELOC_HALF_SECTDIFF |
An ARM64_RELOC_PAGE21, PAGEOFF12 or BRANCH26 entry that needs an addend is preceded by an ARM64_RELOC_ADDEND entry, with the addend in r_symbolnum.