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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//! Parsers for Go runtime structures embedded in compiled binaries.
//!
//! Every Go binary contains several metadata structures that the runtime needs at
//! execution time. These are defined in the Go source tree and populated by the
//! linker (`cmd/link`). This module provides parsers for three key structures:
//!
//! - [`buildid`] -- The Go build ID, a SHA256-derived fingerprint
//! - [`buildinfo`] -- Version, module path, dependencies, and build settings
//! - [`pclntab`] -- The PC/line table: function names, source files, line numbers
//!
//! [`moduledata`] parses the linker-generated master record that ties the rest
//! together, and [`locate`] finds it — by section where the toolchain emits
//! one, and by scanning for its `pcHeader` pointer everywhere else.
//!
//! ## Why These Structures Exist
//!
//! The Go runtime is more self-aware than a typical C runtime. It needs metadata for:
//!
//! - **Stack traces**: function names and line numbers for `panic` output
//! - **Garbage collection**: pointer maps and stack layouts per function
//! - **Goroutine preemption**: safe-point information per PC value
//! - **Interface dispatch**: type descriptors and method tables
//! - **Reflection**: full type information for `reflect.TypeOf` etc.
//!
//! All of this is compiled into the binary and referenced by the `moduledata` struct
//! (defined in `src/runtime/symtab.go:402-450`), which is the linker-generated master
//! record tying everything together.
pub
/// Target architecture, inferred from the pclntab header's `minLC` and `ptrSize` fields.
///
/// The Go pclntab header (see [`pclntab::ParsedPclntab`]) stores two bytes that together
/// identify the target architecture:
///
/// - `minLC` (minimum instruction size, aka "PC quantum"): the smallest possible
/// instruction length. `1` for x86 (variable-length), `2` for s390x, `4` for
/// ARM/MIPS/PPC/RISC-V (fixed-width 32-bit instructions).
/// - `ptrSize`: pointer width in bytes. `4` for 32-bit, `8` for 64-bit.
///
/// ## Mapping Table
///
/// | `minLC` | `ptrSize` | Architecture |
/// |---------|-----------|----------------------------------|
/// | 1 | 4 | x86 (32-bit) |
/// | 1 | 8 | x86_64 / AMD64 |
/// | 4 | 4 | ARM, MIPS32 |
/// | 4 | 8 | ARM64, MIPS64, PPC64, RISC-V 64 |
/// | 2 | 8 | s390x |
/// | 1 | 8 | WebAssembly (wasm) |
///
/// Note: `(4, 8)` is ambiguous between ARM64, MIPS64, PPC64, and RISC-V64.
/// Use build info's `GOARCH` setting for disambiguation.
///
/// Source: `src/internal/abi/symtab.go` (PCQuantum), `src/cmd/internal/obj/link.go`
///
/// # Stability
///
/// Consumers persist this enum into long-lived schemas (database columns,
/// structured logs). The contract:
///
/// - **Variants** — append-only. New architectures appear as new variants;
/// existing variants are never renamed or removed.
/// - **`Display` strings** (and [`Self::as_str`]) — fixed forever once
/// shipped, matching the canonical `GOARCH` values where applicable.
/// - **`Debug` strings** — *not* a stability surface.
/// The pclntab format version, which directly identifies the Go compiler version range.
///
/// The Go toolchain has changed the pclntab format four times. Each change is signaled
/// by a different 4-byte magic number at the start of the `pcHeader` struct. The magic
/// values are intentionally designed to be endianness-invariant: reading them as either
/// little-endian or big-endian produces distinct values, enabling automatic byte-order
/// detection.
///
/// ## Version History
///
/// | Magic (`uint32`) | LE Bytes | Go Versions | Key Changes |
/// |-------------------|---------------------|---------------|--------------------------------|
/// | `0xFFFF_FFFB` | `fb ff ff ff` | 1.2 -- 1.15 | Original format |
/// | `0xFFFF_FFFA` | `fa ff ff ff` | 1.16 -- 1.17 | Added `cutab`, header fields |
/// | `0xFFFF_FFF0` | `f0 ff ff ff` | 1.18 -- 1.19 | Entry PC -> offset from text |
/// | `0xFFFF_FFF1` | `f1 ff ff ff` | 1.20+ | Colon in generated symbol names|
///
/// Source: `src/internal/abi/symtab.go:14-34`
///
/// Design doc: `golang.org/s/go12symtab` (referenced at `src/runtime/runtime2.go:1071`)
///
/// # Stability
///
/// Consumers persist this enum into long-lived schemas (database columns,
/// structured logs). The contract:
///
/// - **Variants** — append-only. New format versions appear as new variants;
/// existing variants are never renamed or removed.
/// - **`Display` strings** (and [`Self::as_str`]) — fixed forever once
/// shipped.
/// - **`Debug` strings** — *not* a stability surface.