1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! The darwin `x86_64` relocation table: each `X86_64_RELOC_*` type mapped to a
//! [`Spec`].
//!
//! Mach-O relocs share the `x86_64` instruction encoding with ELF but use a
//! different type numbering and carry the fixup width in a separate `r_length`
//! field rather than in the type. The width a normal darwin object emits is
//! fixed per type -- `UNSIGNED` is 8 bytes (`r_length = 3`), the PC-relative
//! and branch forms are 4 bytes (`r_length = 2`) -- so each type maps to a
//! single [`WriteKind`]. A width derived from `r_length` by the driver would
//! override the default at apply time; the classification here covers the
//! widths clang actually produces.
//!
//! The addend discipline also differs: Mach-O PC-relative relocs store the
//! displacement from the *end* of the instruction, so the implicit addend is
//! `-(1 << r_length)` plus a small correction for the `_SIGNED_1/2/4` forms.
//! That adjustment is applied when the Mach-O reloc is normalised into a
//! [`crate::reloc::Reloc`] record (a driver-layer concern); the declarative
//! table only fixes the expression and the write kind, so the scan and apply
//! drivers are shared with ELF.
//!
//! `SUBTRACTOR` and `TLV` cannot be reduced to a single portable expression
//! and are routed through [`RelExpr::Escape`]: `SUBTRACTOR` is the first half
//! of a paired `S1 - S2` fixup (a read-modify-write resolved by walking the
//! reloc pair at the driver layer), and `TLV` is a thread-local reference
//! deferred until the TLS models land.
use bytes_of as of;
use crate::;
// --- raw relocation type numbers (darwin x86_64) -------------------------
/// Absolute address: `S + A`. Usually 8 bytes (`r_length = 3`); a 4-byte form
/// exists for low 32-bit absolute references.
pub const X86_64_RELOC_UNSIGNED: u32 = 0;
/// PC-relative 32-bit displacement: `S + A - P`.
pub const X86_64_RELOC_SIGNED: u32 = 1;
/// `CALL`/`JMP` with a 32-bit displacement: `PLT[sym] + A - P` (collapses to
/// `S + A - P` in a static link).
pub const X86_64_RELOC_BRANCH: u32 = 2;
/// `MOVQ` load of a GOT entry: `GOT[sym] + A - P`.
pub const X86_64_RELOC_GOT_LOAD: u32 = 3;
/// Other GOT references: `GOT[sym] + A - P`.
pub const X86_64_RELOC_GOT: u32 = 4;
/// First half of an `S1 - S2` pair; must be followed by `UNSIGNED`. Routed to
/// [`RelExpr::Escape`].
pub const X86_64_RELOC_SUBTRACTOR: u32 = 5;
/// PC-relative 32-bit displacement with a `-1` addend correction.
pub const X86_64_RELOC_SIGNED_1: u32 = 6;
/// PC-relative 32-bit displacement with a `-2` addend correction.
pub const X86_64_RELOC_SIGNED_2: u32 = 7;
/// PC-relative 32-bit displacement with a `-4` addend correction.
pub const X86_64_RELOC_SIGNED_4: u32 = 8;
/// Thread-local variable reference; deferred (Escape).
pub const X86_64_RELOC_TLV: u32 = 9;
/// The 4-byte form of `UNSIGNED` (`r_length = 2`), as a synthetic type.
///
/// Mach-O sizes an absolute fixup through `r_length` rather than through the
/// type, and the declarative table is keyed on the type alone. The reader
/// normalises a 4-byte `UNSIGNED` to this so the table can state the narrow
/// store without the driver growing a width override.
pub const X86_64_RELOC_UNSIGNED_4: u32 = 0x100;
/// The darwin `x86_64` architecture, for use as the `A` type parameter of the
/// drivers.
;