1//! Executable and Linkable Format.
2
3const std = @import("std.zig");
4const Io = std.Io;
5const math = std.math;
6const mem = std.mem;
7const assert = std.debug.assert;
8const Endian = std.builtin.Endian;
9const native_endian = @import("builtin").target.cpu.arch.endian();
10
11pub const AT_NULL = 0;
12pub const AT_IGNORE = 1;
13pub const AT_EXECFD = 2;
14pub const AT_PHDR = 3;
15pub const AT_PHENT = 4;
16pub const AT_PHNUM = 5;
17pub const AT_PAGESZ = 6;
18pub const AT_BASE = 7;
19pub const AT_FLAGS = 8;
20pub const AT_ENTRY = 9;
21pub const AT_NOTELF = 10;
22pub const AT_UID = 11;
23pub const AT_EUID = 12;
24pub const AT_GID = 13;
25pub const AT_EGID = 14;
26pub const AT_CLKTCK = 17;
27pub const AT_PLATFORM = 15;
28pub const AT_HWCAP = 16;
29pub const AT_FPUCW = 18;
30pub const AT_DCACHEBSIZE = 19;
31pub const AT_ICACHEBSIZE = 20;
32pub const AT_UCACHEBSIZE = 21;
33pub const AT_IGNOREPPC = 22;
34pub const AT_SECURE = 23;
35pub const AT_BASE_PLATFORM = 24;
36pub const AT_RANDOM = 25;
37pub const AT_HWCAP2 = 26;
38pub const AT_EXECFN = 31;
39pub const AT_SYSINFO = 32;
40pub const AT_SYSINFO_EHDR = 33;
41pub const AT_L1I_CACHESHAPE = 34;
42pub const AT_L1D_CACHESHAPE = 35;
43pub const AT_L2_CACHESHAPE = 36;
44pub const AT_L3_CACHESHAPE = 37;
45pub const AT_L1I_CACHESIZE = 40;
46pub const AT_L1I_CACHEGEOMETRY = 41;
47pub const AT_L1D_CACHESIZE = 42;
48pub const AT_L1D_CACHEGEOMETRY = 43;
49pub const AT_L2_CACHESIZE = 44;
50pub const AT_L2_CACHEGEOMETRY = 45;
51pub const AT_L3_CACHESIZE = 46;
52pub const AT_L3_CACHEGEOMETRY = 47;
53pub const AT_MINSIGSTKSZ = 51;
54
55pub const DT_NULL = 0;
56pub const DT_NEEDED = 1;
57pub const DT_PLTRELSZ = 2;
58pub const DT_PLTGOT = 3;
59pub const DT_HASH = 4;
60pub const DT_STRTAB = 5;
61pub const DT_SYMTAB = 6;
62pub const DT_RELA = 7;
63pub const DT_RELASZ = 8;
64pub const DT_RELAENT = 9;
65pub const DT_STRSZ = 10;
66pub const DT_SYMENT = 11;
67pub const DT_INIT = 12;
68pub const DT_FINI = 13;
69pub const DT_SONAME = 14;
70pub const DT_RPATH = 15;
71pub const DT_SYMBOLIC = 16;
72pub const DT_REL = 17;
73pub const DT_RELSZ = 18;
74pub const DT_RELENT = 19;
75pub const DT_PLTREL = 20;
76pub const DT_DEBUG = 21;
77pub const DT_TEXTREL = 22;
78pub const DT_JMPREL = 23;
79pub const DT_BIND_NOW = 24;
80pub const DT_INIT_ARRAY = 25;
81pub const DT_FINI_ARRAY = 26;
82pub const DT_INIT_ARRAYSZ = 27;
83pub const DT_FINI_ARRAYSZ = 28;
84pub const DT_RUNPATH = 29;
85pub const DT_FLAGS = 30;
86pub const DT_ENCODING = 32;
87pub const DT_PREINIT_ARRAY = 32;
88pub const DT_PREINIT_ARRAYSZ = 33;
89pub const DT_SYMTAB_SHNDX = 34;
90pub const DT_RELRSZ = 35;
91pub const DT_RELR = 36;
92pub const DT_RELRENT = 37;
93pub const DT_NUM = 38;
94pub const DT_LOOS = 0x6000000d;
95pub const DT_HIOS = 0x6ffff000;
96pub const DT_LOPROC = 0x70000000;
97pub const DT_HIPROC = 0x7fffffff;
98pub const DT_PROCNUM = DT_MIPS_NUM;
99
100pub const DT_VALRNGLO = 0x6ffffd00;
101pub const DT_GNU_PRELINKED = 0x6ffffdf5;
102pub const DT_GNU_CONFLICTSZ = 0x6ffffdf6;
103pub const DT_GNU_LIBLISTSZ = 0x6ffffdf7;
104pub const DT_CHECKSUM = 0x6ffffdf8;
105pub const DT_PLTPADSZ = 0x6ffffdf9;
106pub const DT_MOVEENT = 0x6ffffdfa;
107pub const DT_MOVESZ = 0x6ffffdfb;
108pub const DT_FEATURE_1 = 0x6ffffdfc;
109pub const DT_POSFLAG_1 = 0x6ffffdfd;
110
111pub const DT_SYMINSZ = 0x6ffffdfe;
112pub const DT_SYMINENT = 0x6ffffdff;
113pub const DT_VALRNGHI = 0x6ffffdff;
114pub const DT_VALNUM = 12;
115
116pub const DT_ADDRRNGLO = 0x6ffffe00;
117pub const DT_GNU_HASH = 0x6ffffef5;
118pub const DT_TLSDESC_PLT = 0x6ffffef6;
119pub const DT_TLSDESC_GOT = 0x6ffffef7;
120pub const DT_GNU_CONFLICT = 0x6ffffef8;
121pub const DT_GNU_LIBLIST = 0x6ffffef9;
122pub const DT_CONFIG = 0x6ffffefa;
123pub const DT_DEPAUDIT = 0x6ffffefb;
124pub const DT_AUDIT = 0x6ffffefc;
125pub const DT_PLTPAD = 0x6ffffefd;
126pub const DT_MOVETAB = 0x6ffffefe;
127pub const DT_SYMINFO = 0x6ffffeff;
128pub const DT_ADDRRNGHI = 0x6ffffeff;
129pub const DT_ADDRNUM = 11;
130
131pub const DT_VERSYM = 0x6ffffff0;
132
133pub const DT_RELACOUNT = 0x6ffffff9;
134pub const DT_RELCOUNT = 0x6ffffffa;
135
136pub const DT_FLAGS_1 = 0x6ffffffb;
137pub const DT_VERDEF = 0x6ffffffc;
138
139pub const DT_VERDEFNUM = 0x6ffffffd;
140pub const DT_VERNEED = 0x6ffffffe;
141
142pub const DT_VERNEEDNUM = 0x6fffffff;
143pub const DT_VERSIONTAGNUM = 16;
144
145pub const DT_AUXILIARY = 0x7ffffffd;
146pub const DT_FILTER = 0x7fffffff;
147pub const DT_EXTRANUM = 3;
148
149pub const DT_SPARC_REGISTER = 0x70000001;
150pub const DT_SPARC_NUM = 2;
151
152pub const DT_MIPS_RLD_VERSION = 0x70000001;
153pub const DT_MIPS_TIME_STAMP = 0x70000002;
154pub const DT_MIPS_ICHECKSUM = 0x70000003;
155pub const DT_MIPS_IVERSION = 0x70000004;
156pub const DT_MIPS_FLAGS = 0x70000005;
157pub const DT_MIPS_BASE_ADDRESS = 0x70000006;
158pub const DT_MIPS_MSYM = 0x70000007;
159pub const DT_MIPS_CONFLICT = 0x70000008;
160pub const DT_MIPS_LIBLIST = 0x70000009;
161pub const DT_MIPS_LOCAL_GOTNO = 0x7000000a;
162pub const DT_MIPS_CONFLICTNO = 0x7000000b;
163pub const DT_MIPS_LIBLISTNO = 0x70000010;
164pub const DT_MIPS_SYMTABNO = 0x70000011;
165pub const DT_MIPS_UNREFEXTNO = 0x70000012;
166pub const DT_MIPS_GOTSYM = 0x70000013;
167pub const DT_MIPS_HIPAGENO = 0x70000014;
168pub const DT_MIPS_RLD_MAP = 0x70000016;
169pub const DT_MIPS_DELTA_CLASS = 0x70000017;
170pub const DT_MIPS_DELTA_CLASS_NO = 0x70000018;
171
172pub const DT_MIPS_DELTA_INSTANCE = 0x70000019;
173pub const DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a;
174
175pub const DT_MIPS_DELTA_RELOC = 0x7000001b;
176pub const DT_MIPS_DELTA_RELOC_NO = 0x7000001c;
177
178pub const DT_MIPS_DELTA_SYM = 0x7000001d;
179
180pub const DT_MIPS_DELTA_SYM_NO = 0x7000001e;
181
182pub const DT_MIPS_DELTA_CLASSSYM = 0x70000020;
183
184pub const DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021;
185
186pub const DT_MIPS_CXX_FLAGS = 0x70000022;
187pub const DT_MIPS_PIXIE_INIT = 0x70000023;
188pub const DT_MIPS_SYMBOL_LIB = 0x70000024;
189pub const DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025;
190pub const DT_MIPS_LOCAL_GOTIDX = 0x70000026;
191pub const DT_MIPS_HIDDEN_GOTIDX = 0x70000027;
192pub const DT_MIPS_PROTECTED_GOTIDX = 0x70000028;
193pub const DT_MIPS_OPTIONS = 0x70000029;
194pub const DT_MIPS_INTERFACE = 0x7000002a;
195pub const DT_MIPS_DYNSTR_ALIGN = 0x7000002b;
196pub const DT_MIPS_INTERFACE_SIZE = 0x7000002c;
197pub const DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d;
198
199pub const DT_MIPS_PERF_SUFFIX = 0x7000002e;
200
201pub const DT_MIPS_COMPACT_SIZE = 0x7000002f;
202pub const DT_MIPS_GP_VALUE = 0x70000030;
203pub const DT_MIPS_AUX_DYNAMIC = 0x70000031;
204
205pub const DT_MIPS_PLTGOT = 0x70000032;
206
207pub const DT_MIPS_RWPLT = 0x70000034;
208pub const DT_MIPS_RLD_MAP_REL = 0x70000035;
209pub const DT_MIPS_NUM = 0x36;
210
211pub const DT_ALPHA_PLTRO = (DT_LOPROC + 0);
212pub const DT_ALPHA_NUM = 1;
213
214pub const DT_PPC_GOT = (DT_LOPROC + 0);
215pub const DT_PPC_OPT = (DT_LOPROC + 1);
216pub const DT_PPC_NUM = 2;
217
218pub const DT_PPC64_GLINK = (DT_LOPROC + 0);
219pub const DT_PPC64_OPD = (DT_LOPROC + 1);
220pub const DT_PPC64_OPDSZ = (DT_LOPROC + 2);
221pub const DT_PPC64_OPT = (DT_LOPROC + 3);
222pub const DT_PPC64_NUM = 4;
223
224pub const DT_IA_64_PLT_RESERVE = (DT_LOPROC + 0);
225pub const DT_IA_64_NUM = 1;
226
227pub const DT_XTENSA_GOT_LOC_OFF = 0x70000000;
228pub const DT_XTENSA_GOT_LOC_SZ = 0x70000001;
229
230pub const DT_NIOS2_GP = 0x70000002;
231
232pub const DF_ORIGIN = 0x00000001;
233pub const DF_SYMBOLIC = 0x00000002;
234pub const DF_TEXTREL = 0x00000004;
235pub const DF_BIND_NOW = 0x00000008;
236pub const DF_STATIC_TLS = 0x00000010;
237
238pub const DF_1_NOW = 0x00000001;
239pub const DF_1_GLOBAL = 0x00000002;
240pub const DF_1_GROUP = 0x00000004;
241pub const DF_1_NODELETE = 0x00000008;
242pub const DF_1_LOADFLTR = 0x00000010;
243pub const DF_1_INITFIRST = 0x00000020;
244pub const DF_1_NOOPEN = 0x00000040;
245pub const DF_1_ORIGIN = 0x00000080;
246pub const DF_1_DIRECT = 0x00000100;
247pub const DF_1_TRANS = 0x00000200;
248pub const DF_1_INTERPOSE = 0x00000400;
249pub const DF_1_NODEFLIB = 0x00000800;
250pub const DF_1_NODUMP = 0x00001000;
251pub const DF_1_CONFALT = 0x00002000;
252pub const DF_1_ENDFILTEE = 0x00004000;
253pub const DF_1_DISPRELDNE = 0x00008000;
254pub const DF_1_DISPRELPND = 0x00010000;
255pub const DF_1_NODIRECT = 0x00020000;
256pub const DF_1_IGNMULDEF = 0x00040000;
257pub const DF_1_NOKSYMS = 0x00080000;
258pub const DF_1_NOHDR = 0x00100000;
259pub const DF_1_EDITED = 0x00200000;
260pub const DF_1_NORELOC = 0x00400000;
261pub const DF_1_SYMINTPOSE = 0x00800000;
262pub const DF_1_GLOBAUDIT = 0x01000000;
263pub const DF_1_SINGLETON = 0x02000000;
264pub const DF_1_STUB = 0x04000000;
265pub const DF_1_PIE = 0x08000000;
266
267pub const Versym = packed struct(u16) {
268 VERSION: u15,
269 HIDDEN: bool,
270
271 pub const LOCAL: Versym = @bitCast(@backingInt(VER_NDX.LOCAL));
272 pub const GLOBAL: Versym = @bitCast(@backingInt(VER_NDX.GLOBAL));
273};
274
275pub const VER_NDX = enum(u16) {
276 /// Symbol is local
277 LOCAL = 0,
278 /// Symbol is global
279 GLOBAL = 1,
280 /// Beginning of reserved entries
281 LORESERVE = 0xff00,
282 /// Symbol is to be eliminated
283 ELIMINATE = 0xff01,
284 UNSPECIFIED = 0xffff,
285 _,
286};
287
288/// Version definition of the file itself
289pub const VER_FLG_BASE = 1;
290/// Weak version identifier
291pub const VER_FLG_WEAK = 2;
292
293pub const PN_XNUM = 0xffff;
294
295/// Deprecated, use `@intFromEnum(std.elf.SHT.NULL)`
296pub const SHT_NULL = @backingInt(std.elf.SHT.NULL);
297/// Deprecated, use `@intFromEnum(std.elf.SHT.PROGBITS)`
298pub const SHT_PROGBITS = @backingInt(std.elf.SHT.PROGBITS);
299/// Deprecated, use `@intFromEnum(std.elf.SHT.SYMTAB)`
300pub const SHT_SYMTAB = @backingInt(std.elf.SHT.SYMTAB);
301/// Deprecated, use `@intFromEnum(std.elf.SHT.STRTAB)`
302pub const SHT_STRTAB = @backingInt(std.elf.SHT.STRTAB);
303/// Deprecated, use `@intFromEnum(std.elf.SHT.RELA)`
304pub const SHT_RELA = @backingInt(std.elf.SHT.RELA);
305/// Deprecated, use `@intFromEnum(std.elf.SHT.HASH)`
306pub const SHT_HASH = @backingInt(std.elf.SHT.HASH);
307/// Deprecated, use `@intFromEnum(std.elf.SHT.DYNAMIC)`
308pub const SHT_DYNAMIC = @backingInt(std.elf.SHT.DYNAMIC);
309/// Deprecated, use `@intFromEnum(std.elf.SHT.NOTE)`
310pub const SHT_NOTE = @backingInt(std.elf.SHT.NOTE);
311/// Deprecated, use `@intFromEnum(std.elf.SHT.NOBITS)`
312pub const SHT_NOBITS = @backingInt(std.elf.SHT.NOBITS);
313/// Deprecated, use `@intFromEnum(std.elf.SHT.REL)`
314pub const SHT_REL = @backingInt(std.elf.SHT.REL);
315/// Deprecated, use `@intFromEnum(std.elf.SHT.SHLIB)`
316pub const SHT_SHLIB = @backingInt(std.elf.SHT.SHLIB);
317/// Deprecated, use `@intFromEnum(std.elf.SHT.DYNSYM)`
318pub const SHT_DYNSYM = @backingInt(std.elf.SHT.DYNSYM);
319/// Deprecated, use `@intFromEnum(std.elf.SHT.INIT_ARRAY)`
320pub const SHT_INIT_ARRAY = @backingInt(std.elf.SHT.INIT_ARRAY);
321/// Deprecated, use `@intFromEnum(std.elf.SHT.FINI_ARRAY)`
322pub const SHT_FINI_ARRAY = @backingInt(std.elf.SHT.FINI_ARRAY);
323/// Deprecated, use `@intFromEnum(std.elf.SHT.PREINIT_ARRAY)`
324pub const SHT_PREINIT_ARRAY = @backingInt(std.elf.SHT.PREINIT_ARRAY);
325/// Deprecated, use `@intFromEnum(std.elf.SHT.GROUP)`
326pub const SHT_GROUP = @backingInt(std.elf.SHT.GROUP);
327/// Deprecated, use `@intFromEnum(std.elf.SHT.SYMTAB_SHNDX)`
328pub const SHT_SYMTAB_SHNDX = @backingInt(std.elf.SHT.SYMTAB_SHNDX);
329/// Deprecated, use `@intFromEnum(std.elf.SHT.RELR)`
330pub const SHT_RELR = @backingInt(std.elf.SHT.RELR);
331/// Deprecated, use `std.elf.SHT.NUM`.
332pub const SHT_NUM = SHT.NUM;
333/// Deprecated, use `@intFromEnum(std.elf.SHT.LOOS)`
334pub const SHT_LOOS = @backingInt(std.elf.SHT.LOOS);
335/// Deprecated, use `@intFromEnum(std.elf.SHT.LLVM_ADDRSIG)`
336pub const SHT_LLVM_ADDRSIG = @backingInt(std.elf.SHT.LLVM_ADDRSIG);
337/// Deprecated, use `@intFromEnum(std.elf.SHT.GNU_HASH)`
338pub const SHT_GNU_HASH = @backingInt(std.elf.SHT.GNU_HASH);
339/// Deprecated, use `@intFromEnum(std.elf.SHT.GNU_VERDEF)`
340pub const SHT_GNU_VERDEF = @backingInt(std.elf.SHT.GNU_VERDEF);
341/// Deprecated, use `@intFromEnum(std.elf.SHT.GNU_VERNEED)`
342pub const SHT_GNU_VERNEED = @backingInt(std.elf.SHT.GNU_VERNEED);
343/// Deprecated, use `@intFromEnum(std.elf.SHT.GNU_VERSYM)`
344pub const SHT_GNU_VERSYM = @backingInt(std.elf.SHT.GNU_VERSYM);
345/// Deprecated, use `@intFromEnum(std.elf.SHT.HIOS)`
346pub const SHT_HIOS = @backingInt(std.elf.SHT.HIOS);
347/// Deprecated, use `@intFromEnum(std.elf.SHT.LOPROC)`
348pub const SHT_LOPROC = @backingInt(std.elf.SHT.LOPROC);
349/// Deprecated, use `@intFromEnum(std.elf.SHT.X86_64_UNWIND)`
350pub const SHT_X86_64_UNWIND = @backingInt(std.elf.SHT.X86_64_UNWIND);
351/// Deprecated, use `@intFromEnum(std.elf.SHT.HIPROC)`
352pub const SHT_HIPROC = @backingInt(std.elf.SHT.HIPROC);
353/// Deprecated, use `@intFromEnum(std.elf.SHT.LOUSER)`
354pub const SHT_LOUSER = @backingInt(std.elf.SHT.LOUSER);
355/// Deprecated, use `@intFromEnum(std.elf.SHT.HIUSER)`
356pub const SHT_HIUSER = @backingInt(std.elf.SHT.HIUSER);
357
358// Note type for .note.gnu.build_id
359pub const NT_GNU_BUILD_ID = 3;
360
361/// Deprecated, use `@intFromEnum(std.elf.STB.LOCAL)`
362pub const STB_LOCAL = @backingInt(STB.LOCAL);
363/// Deprecated, use `@intFromEnum(std.elf.STB.GLOBAL)`
364pub const STB_GLOBAL = @backingInt(STB.GLOBAL);
365/// Deprecated, use `@intFromEnum(std.elf.STB.WEAK)`
366pub const STB_WEAK = @backingInt(STB.WEAK);
367/// Deprecated, use `std.elf.STB.NUM`
368pub const STB_NUM = STB.NUM;
369/// Deprecated, use `@intFromEnum(std.elf.STB.LOOS)`
370pub const STB_LOOS = @backingInt(STB.LOOS);
371/// Deprecated, use `@intFromEnum(std.elf.STB.GNU_UNIQUE)`
372pub const STB_GNU_UNIQUE = @backingInt(STB.GNU_UNIQUE);
373/// Deprecated, use `@intFromEnum(std.elf.STB.HIOS)`
374pub const STB_HIOS = @backingInt(STB.HIOS);
375/// Deprecated, use `@intFromEnum(std.elf.STB.LOPROC)`
376pub const STB_LOPROC = @backingInt(STB.LOPROC);
377/// Deprecated, use `@intFromEnum(std.elf.STB.HIPROC)`
378pub const STB_HIPROC = @backingInt(STB.HIPROC);
379
380/// Deprecated, use `@intFromEnum(std.elf.STB.MIPS_SPLIT_COMMON)`
381pub const STB_MIPS_SPLIT_COMMON = @backingInt(STB.MIBS_SPLIT_COMMON);
382
383/// Deprecated, use `@intFromEnum(std.elf.STT.NOTYPE)`
384pub const STT_NOTYPE = @backingInt(STT.NOTYPE);
385/// Deprecated, use `@intFromEnum(std.elf.STT.OBJECT)`
386pub const STT_OBJECT = @backingInt(STT.OBJECT);
387/// Deprecated, use `@intFromEnum(std.elf.STT.FUNC)`
388pub const STT_FUNC = @backingInt(STT.FUNC);
389/// Deprecated, use `@intFromEnum(std.elf.STT.SECTION)`
390pub const STT_SECTION = @backingInt(STT.SECTION);
391/// Deprecated, use `@intFromEnum(std.elf.STT.FILE)`
392pub const STT_FILE = @backingInt(STT.FILE);
393/// Deprecated, use `@intFromEnum(std.elf.STT.COMMON)`
394pub const STT_COMMON = @backingInt(STT.COMMON);
395/// Deprecated, use `@intFromEnum(std.elf.STT.TLS)`
396pub const STT_TLS = @backingInt(STT.TLS);
397/// Deprecated, use `std.elf.STT.NUM`
398pub const STT_NUM = STT.NUM;
399/// Deprecated, use `@intFromEnum(std.elf.STT.LOOS)`
400pub const STT_LOOS = @backingInt(STT.LOOS);
401/// Deprecated, use `@intFromEnum(std.elf.STT.GNU_IFUNC)`
402pub const STT_GNU_IFUNC = @backingInt(STT.GNU_IFUNC);
403/// Deprecated, use `@intFromEnum(std.elf.STT.HIOS)`
404pub const STT_HIOS = @backingInt(STT.HIOS);
405/// Deprecated, use `@intFromEnum(std.elf.STT.LOPROC)`
406pub const STT_LOPROC = @backingInt(STT.LOPROC);
407/// Deprecated, use `@intFromEnum(std.elf.STT.HIPROC)`
408pub const STT_HIPROC = @backingInt(STT.HIPROC);
409
410/// Deprecated, use `@intFromEnum(std.elf.STT.SPARC_REGISTER)`
411pub const STT_SPARC_REGISTER = @backingInt(STT.SPARC_REGISTER);
412
413/// Deprecated, use `@intFromEnum(std.elf.STT.PARISC_MILLICODE)`
414pub const STT_PARISC_MILLICODE = @backingInt(STT.PARISC_MILLICODE);
415
416/// Deprecated, use `@intFromEnum(std.elf.STT.HP_OPAQUE)`
417pub const STT_HP_OPAQUE = @backingInt(STT.HP_OPAQUE);
418/// Deprecated, use `@intFromEnum(std.elf.STT.HP_STUB)`
419pub const STT_HP_STUB = @backingInt(STT.HP_STUB);
420
421/// Deprecated, use `@intFromEnum(std.elf.STT.ARM_TFUNC)`
422pub const STT_ARM_TFUNC = @backingInt(STT.ARM_TFUNC);
423/// Deprecated, use `@intFromEnum(std.elf.STT.ARM_16BIT)`
424pub const STT_ARM_16BIT = @backingInt(STT.ARM_16BIT);
425
426pub const PT = enum(Word) {
427 /// Program header table entry unused
428 NULL = 0,
429 /// Loadable program segment
430 LOAD = 1,
431 /// Dynamic linking information
432 DYNAMIC = 2,
433 /// Program interpreter
434 INTERP = 3,
435 /// Auxiliary information
436 NOTE = 4,
437 /// Reserved
438 SHLIB = 5,
439 /// Entry for header table itself
440 PHDR = 6,
441 /// Thread-local storage segment
442 TLS = 7,
443 _,
444
445 /// Number of defined types
446 pub const NUM = @typeInfo(PT).@"enum".field_names.len;
447
448 /// Start of OS-specific
449 pub const LOOS: PT = @fromBackingInt(@intCast(0x60000000));
450 /// End of OS-specific
451 pub const HIOS: PT = @fromBackingInt(@intCast(0x6fffffff));
452
453 /// GCC .eh_frame_hdr segment
454 pub const GNU_EH_FRAME: PT = @fromBackingInt(@intCast(0x6474e550));
455 /// Indicates stack executability
456 pub const GNU_STACK: PT = @fromBackingInt(@intCast(0x6474e551));
457 /// Read-only after relocation
458 pub const GNU_RELRO: PT = @fromBackingInt(@intCast(0x6474e552));
459
460 pub const LOSUNW: PT = @fromBackingInt(@intCast(0x6ffffffa));
461 pub const HISUNW: PT = @fromBackingInt(@intCast(0x6fffffff));
462
463 /// Sun specific segment
464 pub const SUNWBSS: PT = @fromBackingInt(@intCast(0x6ffffffa));
465 /// Stack segment
466 pub const SUNWSTACK: PT = @fromBackingInt(@intCast(0x6ffffffb));
467
468 /// Start of processor-specific
469 pub const LOPROC: PT = @fromBackingInt(@intCast(0x70000000));
470 /// End of processor-specific
471 pub const HIPROC: PT = @fromBackingInt(@intCast(0x7fffffff));
472};
473
474pub const SHT = enum(Word) {
475 /// Section header table entry unused
476 NULL = 0,
477 /// Program data
478 PROGBITS = 1,
479 /// Symbol table
480 SYMTAB = 2,
481 /// String table
482 STRTAB = 3,
483 /// Relocation entries with addends
484 RELA = 4,
485 /// Symbol hash table
486 HASH = 5,
487 /// Dynamic linking information
488 DYNAMIC = 6,
489 /// Notes
490 NOTE = 7,
491 /// Program space with no data (bss)
492 NOBITS = 8,
493 /// Relocation entries, no addends
494 REL = 9,
495 /// Reserved
496 SHLIB = 10,
497 /// Dynamic linker symbol table
498 DYNSYM = 11,
499 /// Array of constructors
500 INIT_ARRAY = 14,
501 /// Array of destructors
502 FINI_ARRAY = 15,
503 /// Array of pre-constructors
504 PREINIT_ARRAY = 16,
505 /// Section group
506 GROUP = 17,
507 /// Extended section indices
508 SYMTAB_SHNDX = 18,
509 /// RELR relative relocations
510 RELR = 19,
511 _,
512
513 /// Number of defined types
514 pub const NUM = @typeInfo(SHT).@"enum".field_names.len;
515
516 /// Start of OS-specific
517 pub const LOOS: SHT = @fromBackingInt(@intCast(0x60000000));
518 /// End of OS-specific
519 pub const HIOS: SHT = @fromBackingInt(@intCast(0x6fffffff));
520
521 /// LLVM address-significance table
522 pub const LLVM_ADDRSIG: SHT = @fromBackingInt(@intCast(0x6fff4c03));
523
524 /// GNU hash table
525 pub const GNU_HASH: SHT = @fromBackingInt(@intCast(0x6ffffff6));
526 /// GNU version definition table
527 pub const GNU_VERDEF: SHT = @fromBackingInt(@intCast(0x6ffffffd));
528 /// GNU needed versions table
529 pub const GNU_VERNEED: SHT = @fromBackingInt(@intCast(0x6ffffffe));
530 /// GNU symbol version table
531 pub const GNU_VERSYM: SHT = @fromBackingInt(@intCast(0x6fffffff));
532
533 /// Start of processor-specific
534 pub const LOPROC: SHT = @fromBackingInt(@intCast(0x70000000));
535 /// End of processor-specific
536 pub const HIPROC: SHT = @fromBackingInt(@intCast(0x7fffffff));
537
538 /// Unwind information
539 pub const X86_64_UNWIND: SHT = @fromBackingInt(@intCast(0x70000001));
540
541 /// Start of application-specific
542 pub const LOUSER: SHT = @fromBackingInt(@intCast(0x80000000));
543 /// End of application-specific
544 pub const HIUSER: SHT = @fromBackingInt(@intCast(0xffffffff));
545};
546
547pub const STB = enum(u4) {
548 /// Local symbol
549 LOCAL = 0,
550 /// Global symbol
551 GLOBAL = 1,
552 /// Weak symbol
553 WEAK = 2,
554 _,
555
556 /// Number of defined types
557 pub const NUM = @typeInfo(STB).@"enum".field_names.len;
558
559 /// Start of OS-specific
560 pub const LOOS: STB = @fromBackingInt(@intCast(10));
561 /// End of OS-specific
562 pub const HIOS: STB = @fromBackingInt(@intCast(12));
563
564 /// Unique symbol
565 pub const GNU_UNIQUE: STB = @fromBackingInt(@intCast(@backingInt(LOOS) + 0));
566
567 /// Start of processor-specific
568 pub const LOPROC: STB = @fromBackingInt(@intCast(13));
569 /// End of processor-specific
570 pub const HIPROC: STB = @fromBackingInt(@intCast(15));
571
572 pub const MIPS_SPLIT_COMMON: STB = @fromBackingInt(@intCast(@backingInt(LOPROC) + 0));
573};
574
575pub const STT = enum(u4) {
576 /// Symbol type is unspecified
577 NOTYPE = 0,
578 /// Symbol is a data object
579 OBJECT = 1,
580 /// Symbol is a code object
581 FUNC = 2,
582 /// Symbol associated with a section
583 SECTION = 3,
584 /// Symbol's name is file name
585 FILE = 4,
586 /// Symbol is a common data object
587 COMMON = 5,
588 /// Symbol is thread-local data object
589 TLS = 6,
590 _,
591
592 /// Number of defined types
593 pub const NUM = @typeInfo(STT).@"enum".field_names.len;
594
595 /// Start of OS-specific
596 pub const LOOS: STT = @fromBackingInt(@intCast(10));
597 /// End of OS-specific
598 pub const HIOS: STT = @fromBackingInt(@intCast(12));
599
600 /// Symbol is indirect code object
601 pub const GNU_IFUNC: STT = @fromBackingInt(@intCast(@backingInt(LOOS) + 0));
602
603 pub const HP_OPAQUE: STT = @fromBackingInt(@intCast(@backingInt(LOOS) + 1));
604 pub const HP_STUB: STT = @fromBackingInt(@intCast(@backingInt(LOOS) + 2));
605
606 /// Start of processor-specific
607 pub const LOPROC: STT = @fromBackingInt(@intCast(13));
608 /// End of processor-specific
609 pub const HIPROC: STT = @fromBackingInt(@intCast(15));
610
611 pub const SPARC_REGISTER: STT = @fromBackingInt(@intCast(@backingInt(LOPROC) + 0));
612
613 pub const PARISC_MILLICODE: STT = @fromBackingInt(@intCast(@backingInt(LOPROC) + 0));
614
615 pub const ARM_TFUNC: STT = @fromBackingInt(@intCast(@backingInt(LOPROC) + 0));
616 pub const ARM_16BIT: STT = @fromBackingInt(@intCast(@backingInt(HIPROC) + 2));
617};
618
619pub const STV = enum(u3) {
620 DEFAULT = 0,
621 INTERNAL = 1,
622 HIDDEN = 2,
623 PROTECTED = 3,
624};
625
626pub const MAGIC = "\x7fELF";
627
628/// File types
629pub const ET = enum(u16) {
630 /// No file type
631 NONE = 0,
632
633 /// Relocatable file
634 REL = 1,
635
636 /// Executable file
637 EXEC = 2,
638
639 /// Shared object file
640 DYN = 3,
641
642 /// Core file
643 CORE = 4,
644
645 _,
646
647 /// Beginning of OS-specific codes
648 pub const LOOS = 0xfe00;
649
650 /// End of OS-specific codes
651 pub const HIOS = 0xfeff;
652
653 /// Beginning of processor-specific codes
654 pub const LOPROC = 0xff00;
655
656 /// End of processor-specific codes
657 pub const HIPROC = 0xffff;
658};
659
660/// All integers are native endian.
661pub const Header = struct {
662 is_64: bool,
663 endian: Endian,
664 os_abi: OSABI,
665 /// The meaning of this value depends on `os_abi`.
666 abi_version: u8,
667 type: ET,
668 machine: EM,
669 entry: u64,
670 phoff: u64,
671 shoff: u64,
672 phentsize: u16,
673 phnum: u16,
674 shentsize: u16,
675 shnum: u16,
676 shstrndx: u16,
677
678 pub fn iterateProgramHeaders(h: *const Header, file_reader: *Io.File.Reader) ProgramHeaderIterator {
679 return .{
680 .is_64 = h.is_64,
681 .endian = h.endian,
682 .phnum = h.phnum,
683 .phoff = h.phoff,
684 .file_reader = file_reader,
685 };
686 }
687
688 pub fn iterateProgramHeadersBuffer(h: *const Header, buf: []const u8) ProgramHeaderBufferIterator {
689 return .{
690 .is_64 = h.is_64,
691 .endian = h.endian,
692 .phnum = h.phnum,
693 .phoff = h.phoff,
694 .buf = buf,
695 };
696 }
697
698 pub fn iterateSectionHeaders(h: *const Header, file_reader: *Io.File.Reader) SectionHeaderIterator {
699 return .{
700 .is_64 = h.is_64,
701 .endian = h.endian,
702 .shnum = h.shnum,
703 .shoff = h.shoff,
704 .file_reader = file_reader,
705 };
706 }
707
708 pub fn iterateSectionHeadersBuffer(h: *const Header, buf: []const u8) SectionHeaderBufferIterator {
709 return .{
710 .is_64 = h.is_64,
711 .endian = h.endian,
712 .shnum = h.shnum,
713 .shoff = h.shoff,
714 .buf = buf,
715 };
716 }
717
718 pub fn iterateDynamicSection(
719 h: *const Header,
720 file_reader: *Io.File.Reader,
721 offset: u64,
722 size: u64,
723 ) DynamicSectionIterator {
724 return .{
725 .is_64 = h.is_64,
726 .endian = h.endian,
727 .offset = offset,
728 .end_offset = offset + size,
729 .file_reader = file_reader,
730 };
731 }
732
733 pub fn iterateDynamicSectionBuffer(
734 h: *const Header,
735 buf: []const u8,
736 offset: u64,
737 size: u64,
738 ) DynamicSectionBufferIterator {
739 return .{
740 .is_64 = h.is_64,
741 .endian = h.endian,
742 .offset = offset,
743 .end_offset = offset + size,
744 .buf = buf,
745 };
746 }
747
748 pub const ReadError = Io.Reader.Error || error{
749 InvalidElfMagic,
750 InvalidElfVersion,
751 InvalidElfClass,
752 InvalidElfEndian,
753 };
754
755 /// If this function fails, seek position of `r` is unchanged.
756 pub fn read(r: *Io.Reader) ReadError!Header {
757 const buf = try r.peek(@sizeOf(Elf64_Ehdr));
758
759 if (!mem.eql(u8, buf[0..4], MAGIC)) return error.InvalidElfMagic;
760 if (buf[EI.VERSION] != 1) return error.InvalidElfVersion;
761
762 const endian: Endian = switch (buf[EI.DATA]) {
763 ELFDATA2LSB => .little,
764 ELFDATA2MSB => .big,
765 else => return error.InvalidElfEndian,
766 };
767
768 return switch (buf[EI.CLASS]) {
769 ELFCLASS32 => .init(try r.takeStruct(Elf32_Ehdr, endian), endian),
770 ELFCLASS64 => .init(try r.takeStruct(Elf64_Ehdr, endian), endian),
771 else => return error.InvalidElfClass,
772 };
773 }
774
775 pub fn init(hdr: anytype, endian: Endian) Header {
776 // Converting integers to exhaustive enums using `@enumFromInt` could cause a panic.
777 comptime assert(@typeInfo(OSABI).@"enum".mode == .nonexhaustive);
778 return .{
779 .is_64 = switch (@TypeOf(hdr)) {
780 Elf32_Ehdr => false,
781 Elf64_Ehdr => true,
782 else => @compileError("bad type"),
783 },
784 .endian = endian,
785 .os_abi = @fromBackingInt(@intCast(hdr.e_ident[EI.OSABI])),
786 .abi_version = hdr.e_ident[EI.ABIVERSION],
787 .type = hdr.e_type,
788 .machine = hdr.e_machine,
789 .entry = hdr.e_entry,
790 .phoff = hdr.e_phoff,
791 .shoff = hdr.e_shoff,
792 .phentsize = hdr.e_phentsize,
793 .phnum = hdr.e_phnum,
794 .shentsize = hdr.e_shentsize,
795 .shnum = hdr.e_shnum,
796 .shstrndx = hdr.e_shstrndx,
797 };
798 }
799};
800
801pub const ProgramHeaderIterator = struct {
802 is_64: bool,
803 endian: Endian,
804 phnum: u16,
805 phoff: u64,
806
807 file_reader: *Io.File.Reader,
808 index: usize = 0,
809
810 pub fn next(it: *ProgramHeaderIterator) !?Elf64.Phdr {
811 if (it.index >= it.phnum) return null;
812 defer it.index += 1;
813
814 const size: u64 = if (it.is_64) @sizeOf(Elf64.Phdr) else @sizeOf(Elf32.Phdr);
815 const offset = it.phoff + size * it.index;
816 try it.file_reader.seekTo(offset);
817
818 return try takeProgramHeader(&it.file_reader.interface, it.is_64, it.endian);
819 }
820};
821
822pub const ProgramHeaderBufferIterator = struct {
823 is_64: bool,
824 endian: Endian,
825 phnum: u16,
826 phoff: u64,
827
828 buf: []const u8,
829 index: usize = 0,
830
831 pub fn next(it: *ProgramHeaderBufferIterator) !?Elf64.Phdr {
832 if (it.index >= it.phnum) return null;
833 defer it.index += 1;
834
835 const size: usize = if (it.is_64) @sizeOf(Elf64.Phdr) else @sizeOf(Elf32.Phdr);
836 const offset = @as(usize, @intCast(it.phoff)) + size * it.index;
837 var reader = Io.Reader.fixed(it.buf[offset..]);
838
839 return try takeProgramHeader(&reader, it.is_64, it.endian);
840 }
841};
842
843pub fn takeProgramHeader(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64.Phdr {
844 if (is_64) {
845 const phdr = try reader.takeStruct(Elf64.Phdr, endian);
846 return phdr;
847 }
848
849 const phdr = try reader.takeStruct(Elf32.Phdr, endian);
850 return .{
851 .type = phdr.type,
852 .offset = phdr.offset,
853 .vaddr = phdr.vaddr,
854 .paddr = phdr.paddr,
855 .filesz = phdr.filesz,
856 .memsz = phdr.memsz,
857 .flags = phdr.flags,
858 .@"align" = phdr.@"align",
859 };
860}
861
862pub const SectionHeaderIterator = struct {
863 is_64: bool,
864 endian: Endian,
865 shnum: u16,
866 shoff: u64,
867
868 file_reader: *Io.File.Reader,
869 index: usize = 0,
870
871 pub fn next(it: *SectionHeaderIterator) !?Elf64_Shdr {
872 if (it.index >= it.shnum) return null;
873 defer it.index += 1;
874
875 const size: u64 = if (it.is_64) @sizeOf(Elf64_Shdr) else @sizeOf(Elf32_Shdr);
876 const offset = it.shoff + size * it.index;
877 try it.file_reader.seekTo(offset);
878
879 return try takeSectionHeader(&it.file_reader.interface, it.is_64, it.endian);
880 }
881};
882
883pub const SectionHeaderBufferIterator = struct {
884 is_64: bool,
885 endian: Endian,
886 shnum: u16,
887 shoff: u64,
888
889 buf: []const u8,
890 index: usize = 0,
891
892 pub fn next(it: *SectionHeaderBufferIterator) !?Elf64_Shdr {
893 if (it.index >= it.shnum) return null;
894 defer it.index += 1;
895
896 const size: u64 = if (it.is_64) @sizeOf(Elf64_Shdr) else @sizeOf(Elf32_Shdr);
897 const offset = it.shoff + size * it.index;
898 if (offset > it.buf.len) return error.EndOfStream;
899 var reader = Io.Reader.fixed(it.buf[@intCast(offset)..]);
900
901 return try takeSectionHeader(&reader, it.is_64, it.endian);
902 }
903};
904
905pub fn takeSectionHeader(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Shdr {
906 if (is_64) {
907 const shdr = try reader.takeStruct(Elf64_Shdr, endian);
908 return shdr;
909 }
910
911 const shdr = try reader.takeStruct(Elf32_Shdr, endian);
912 return .{
913 .sh_name = shdr.sh_name,
914 .sh_type = shdr.sh_type,
915 .sh_flags = shdr.sh_flags,
916 .sh_addr = shdr.sh_addr,
917 .sh_offset = shdr.sh_offset,
918 .sh_size = shdr.sh_size,
919 .sh_link = shdr.sh_link,
920 .sh_info = shdr.sh_info,
921 .sh_addralign = shdr.sh_addralign,
922 .sh_entsize = shdr.sh_entsize,
923 };
924}
925
926pub const DynamicSectionIterator = struct {
927 is_64: bool,
928 endian: Endian,
929 offset: u64,
930 end_offset: u64,
931
932 file_reader: *Io.File.Reader,
933
934 pub fn next(it: *DynamicSectionIterator) !?Elf64_Dyn {
935 if (it.offset >= it.end_offset) return null;
936 const size: u64 = if (it.is_64) @sizeOf(Elf64_Dyn) else @sizeOf(Elf32_Dyn);
937 defer it.offset += size;
938 try it.file_reader.seekTo(it.offset);
939 return try takeDynamicSection(&it.file_reader.interface, it.is_64, it.endian);
940 }
941};
942
943pub const DynamicSectionBufferIterator = struct {
944 is_64: bool,
945 endian: Endian,
946 offset: u64,
947 end_offset: u64,
948
949 buf: []const u8,
950
951 pub fn next(it: *DynamicSectionBufferIterator) !?Elf64_Dyn {
952 if (it.offset >= it.end_offset) return null;
953 const size: u64 = if (it.is_64) @sizeOf(Elf64_Dyn) else @sizeOf(Elf32_Dyn);
954 defer it.offset += size;
955 var reader: std.Io.Reader = .fixed(it.buf[it.offset..]);
956 return try takeDynamicSection(&reader, it.is_64, it.endian);
957 }
958};
959
960pub fn takeDynamicSection(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Dyn {
961 if (is_64) {
962 const dyn = try reader.takeStruct(Elf64_Dyn, endian);
963 return dyn;
964 }
965
966 const dyn = try reader.takeStruct(Elf32_Dyn, endian);
967 return .{
968 .d_tag = dyn.d_tag,
969 .d_val = dyn.d_val,
970 };
971}
972
973pub const EI = struct {
974 pub const CLASS = 4;
975 pub const DATA = 5;
976 pub const VERSION = 6;
977 pub const OSABI = 7;
978 pub const ABIVERSION = 8;
979 pub const PAD = 9;
980 pub const NIDENT = 16;
981};
982
983/// Deprecated, use `std.elf.EI.CLASS`
984pub const EI_CLASS = EI.CLASS;
985/// Deprecated, use `std.elf.EI.DATA`
986pub const EI_DATA = EI.DATA;
987/// Deprecated, use `std.elf.EI.VERSION`
988pub const EI_VERSION = EI.VERSION;
989/// Deprecated, use `std.elf.EI.OSABI`
990pub const EI_OSABI = EI.OSABI;
991/// Deprecated, use `std.elf.EI.ABIVERSION`
992pub const EI_ABIVERSION = EI.ABIVERSION;
993/// Deprecated, use `std.elf.EI.PAD`
994pub const EI_PAD = EI.PAD;
995/// Deprecated, use `std.elf.EI.NIDENT`
996pub const EI_NIDENT = EI.NIDENT;
997
998pub const Half = u16;
999pub const Word = u32;
1000pub const Sword = i32;
1001pub const Xword = u64;
1002pub const Sxword = i64;
1003pub const Section = u16;
1004pub const Elf32 = struct {
1005 pub const Addr = u32;
1006 pub const Off = u32;
1007 pub const Ehdr = extern struct {
1008 ident: Ident,
1009 type: ET,
1010 machine: EM,
1011 version: Word,
1012 entry: Elf32.Addr,
1013 phoff: Elf32.Off,
1014 shoff: Elf32.Off,
1015 flags: EhdrFlags,
1016 ehsize: Half,
1017 phentsize: Half,
1018 phnum: Half,
1019 shentsize: Half,
1020 shnum: Half,
1021 shstrndx: Half,
1022 };
1023 pub const Phdr = extern struct {
1024 type: PT,
1025 offset: Elf32.Off,
1026 vaddr: Elf32.Addr,
1027 paddr: Elf32.Addr,
1028 filesz: Word,
1029 memsz: Word,
1030 flags: PF,
1031 @"align": Word,
1032 };
1033 pub const Shdr = extern struct {
1034 name: Word,
1035 type: SHT,
1036 flags: packed struct(Word) { shf: SHF },
1037 addr: Elf32.Addr,
1038 offset: Elf32.Off,
1039 size: Word,
1040 link: Word,
1041 info: Word,
1042 addralign: Word,
1043 entsize: Word,
1044 };
1045 pub const Chdr = extern struct {
1046 type: COMPRESS,
1047 size: Word,
1048 addralign: Word,
1049 };
1050 pub const Sym = extern struct {
1051 name: Word,
1052 value: Elf32.Addr,
1053 size: Word,
1054 info: Info,
1055 other: Other,
1056 shndx: Section,
1057
1058 pub const Info = packed struct(u8) {
1059 type: STT,
1060 bind: STB,
1061 };
1062
1063 pub const Other = packed struct(u8) {
1064 visibility: STV,
1065 unused: u5 = 0,
1066 };
1067 };
1068 pub const Rel = extern struct {
1069 offset: Elf32.Addr,
1070 info: Info,
1071 addend: u0 = 0,
1072
1073 pub const Info = packed struct(u32) {
1074 type: u8,
1075 sym: u24,
1076 };
1077 };
1078 pub const Rela = extern struct {
1079 offset: Elf32.Addr,
1080 info: Info,
1081 addend: i32,
1082
1083 pub const Info = Elf32.Rel.Info;
1084 };
1085 comptime {
1086 assert(@sizeOf(Elf32.Ehdr) == 52);
1087 assert(@sizeOf(Elf32.Phdr) == 32);
1088 assert(@sizeOf(Elf32.Shdr) == 40);
1089 assert(@sizeOf(Elf32.Sym) == 16);
1090 assert(@sizeOf(Elf32.Rel) == 8);
1091 assert(@sizeOf(Elf32.Rela) == 12);
1092 }
1093};
1094pub const Elf64 = struct {
1095 pub const Addr = u64;
1096 pub const Off = u64;
1097 pub const Ehdr = extern struct {
1098 ident: Ident,
1099 type: ET,
1100 machine: EM,
1101 version: Word,
1102 entry: Elf64.Addr,
1103 phoff: Elf64.Off,
1104 shoff: Elf64.Off,
1105 flags: EhdrFlags,
1106 ehsize: Half,
1107 phentsize: Half,
1108 phnum: Half,
1109 shentsize: Half,
1110 shnum: Half,
1111 shstrndx: Half,
1112 };
1113 pub const Phdr = extern struct {
1114 type: PT,
1115 flags: PF,
1116 offset: Elf64.Off,
1117 vaddr: Elf64.Addr,
1118 paddr: Elf64.Addr,
1119 filesz: Xword,
1120 memsz: Xword,
1121 @"align": Xword,
1122 };
1123 pub const Shdr = extern struct {
1124 name: Word,
1125 type: SHT,
1126 flags: packed struct(Xword) { shf: SHF, unused: Word = 0 },
1127 addr: Elf64.Addr,
1128 offset: Elf64.Off,
1129 size: Xword,
1130 link: Word,
1131 info: Word,
1132 addralign: Xword,
1133 entsize: Xword,
1134 };
1135 pub const Chdr = extern struct {
1136 type: COMPRESS,
1137 reserved: Word = 0,
1138 size: Xword,
1139 addralign: Xword,
1140 };
1141 pub const Sym = extern struct {
1142 name: Word,
1143 info: Info,
1144 other: Other,
1145 shndx: Section,
1146 value: Elf64.Addr,
1147 size: Xword,
1148
1149 pub const Info = Elf32.Sym.Info;
1150 pub const Other = Elf32.Sym.Other;
1151 };
1152 pub const Rel = extern struct {
1153 offset: Elf64.Addr,
1154 info: Info,
1155 addend: u0 = 0,
1156
1157 pub const Info = packed struct(u64) {
1158 type: u32,
1159 sym: u32,
1160 };
1161 };
1162 pub const Rela = extern struct {
1163 offset: Elf64.Addr,
1164 info: Info,
1165 addend: i64,
1166
1167 pub const Info = Elf64.Rel.Info;
1168 };
1169 comptime {
1170 assert(@sizeOf(Elf64.Ehdr) == 64);
1171 assert(@sizeOf(Elf64.Phdr) == 56);
1172 assert(@sizeOf(Elf64.Shdr) == 64);
1173 assert(@sizeOf(Elf64.Sym) == 24);
1174 assert(@sizeOf(Elf64.Rel) == 16);
1175 assert(@sizeOf(Elf64.Rela) == 24);
1176 }
1177};
1178pub const ElfN = switch (@sizeOf(usize)) {
1179 4 => Elf32,
1180 8 => Elf64,
1181 else => @compileError("expected pointer size of 32 or 64"),
1182};
1183
1184/// Deprecated, use `std.elf.Xword`
1185pub const Elf32_Xword = Xword;
1186/// Deprecated, use `std.elf.Sxword`
1187pub const Elf32_Sxword = Sxword;
1188/// Deprecated, use `std.elf.Xword`
1189pub const Elf64_Xword = Xword;
1190/// Deprecated, use `std.elf.Sxword`
1191pub const Elf64_Sxword = i64;
1192/// Deprecated, use `std.elf.Elf32.Addr`
1193pub const Elf32_Addr = u32;
1194/// Deprecated, use `std.elf.Elf64.Addr`
1195pub const Elf64_Addr = u64;
1196/// Deprecated, use `std.elf.Elf32.Off`
1197pub const Elf32_Off = u32;
1198/// Deprecated, use `std.elf.Elf64.Off`
1199pub const Elf64_Off = u64;
1200/// Deprecated, use `std.elf.Section`
1201pub const Elf32_Section = u16;
1202/// Deprecated, use `std.elf.Section`
1203pub const Elf64_Section = u16;
1204/// Deprecated, use `std.elf.Elf32.Ehdr`
1205pub const Elf32_Ehdr = extern struct {
1206 e_ident: [EI_NIDENT]u8,
1207 e_type: ET,
1208 e_machine: EM,
1209 e_version: Word,
1210 e_entry: Elf32_Addr,
1211 e_phoff: Elf32_Off,
1212 e_shoff: Elf32_Off,
1213 e_flags: Word,
1214 e_ehsize: Half,
1215 e_phentsize: Half,
1216 e_phnum: Half,
1217 e_shentsize: Half,
1218 e_shnum: Half,
1219 e_shstrndx: Half,
1220};
1221/// Deprecated, use `std.elf.Elf64.Ehdr`
1222pub const Elf64_Ehdr = extern struct {
1223 e_ident: [EI.NIDENT]u8,
1224 e_type: ET,
1225 e_machine: EM,
1226 e_version: Word,
1227 e_entry: Elf64_Addr,
1228 e_phoff: Elf64_Off,
1229 e_shoff: Elf64_Off,
1230 e_flags: Word,
1231 e_ehsize: Half,
1232 e_phentsize: Half,
1233 e_phnum: Half,
1234 e_shentsize: Half,
1235 e_shnum: Half,
1236 e_shstrndx: Half,
1237};
1238/// Deprecated, use `std.elf.Elf32.Shdr`
1239pub const Elf32_Shdr = extern struct {
1240 sh_name: Word,
1241 sh_type: Word,
1242 sh_flags: Word,
1243 sh_addr: Elf32_Addr,
1244 sh_offset: Elf32_Off,
1245 sh_size: Word,
1246 sh_link: Word,
1247 sh_info: Word,
1248 sh_addralign: Word,
1249 sh_entsize: Word,
1250};
1251/// Deprecated, use `std.elf.Elf64.Shdr`
1252pub const Elf64_Shdr = extern struct {
1253 sh_name: Word,
1254 sh_type: Word,
1255 sh_flags: Elf64_Xword,
1256 sh_addr: Elf64_Addr,
1257 sh_offset: Elf64_Off,
1258 sh_size: Elf64_Xword,
1259 sh_link: Word,
1260 sh_info: Word,
1261 sh_addralign: Elf64_Xword,
1262 sh_entsize: Elf64_Xword,
1263};
1264/// Deprecated, use `std.elf.Elf32.Chdr`
1265pub const Elf32_Chdr = extern struct {
1266 ch_type: COMPRESS,
1267 ch_size: Word,
1268 ch_addralign: Word,
1269};
1270/// Deprecated, use `std.elf.Elf64.Chdr`
1271pub const Elf64_Chdr = extern struct {
1272 ch_type: COMPRESS,
1273 ch_reserved: Word = 0,
1274 ch_size: Elf64_Xword,
1275 ch_addralign: Elf64_Xword,
1276};
1277/// Deprecated, use `std.elf.Elf32.Sym`
1278pub const Elf32_Sym = extern struct {
1279 st_name: Word,
1280 st_value: Elf32_Addr,
1281 st_size: Word,
1282 st_info: u8,
1283 st_other: u8,
1284 st_shndx: Elf32_Section,
1285
1286 pub inline fn st_type(self: @This()) u4 {
1287 return @truncate(self.st_info);
1288 }
1289 pub inline fn st_bind(self: @This()) u4 {
1290 return @truncate(self.st_info >> 4);
1291 }
1292};
1293/// Deprecated, use `std.elf.Elf64.Sym`
1294pub const Elf64_Sym = extern struct {
1295 st_name: Word,
1296 st_info: u8,
1297 st_other: u8,
1298 st_shndx: Elf64_Section,
1299 st_value: Elf64_Addr,
1300 st_size: Elf64_Xword,
1301
1302 pub inline fn st_type(self: @This()) u4 {
1303 return @truncate(self.st_info);
1304 }
1305 pub inline fn st_bind(self: @This()) u4 {
1306 return @truncate(self.st_info >> 4);
1307 }
1308};
1309pub const Elf32_Syminfo = extern struct {
1310 si_boundto: Half,
1311 si_flags: Half,
1312};
1313pub const Elf64_Syminfo = extern struct {
1314 si_boundto: Half,
1315 si_flags: Half,
1316};
1317pub const Elf32_Rel = extern struct {
1318 r_offset: Elf32_Addr,
1319 r_info: Word,
1320
1321 pub inline fn r_sym(self: @This()) u24 {
1322 return @truncate(self.r_info >> 8);
1323 }
1324 pub inline fn r_type(self: @This()) u8 {
1325 return @truncate(self.r_info);
1326 }
1327};
1328pub const Elf64_Rel = extern struct {
1329 r_offset: Elf64_Addr,
1330 r_info: Elf64_Xword,
1331
1332 pub inline fn r_sym(self: @This()) u32 {
1333 return @truncate(self.r_info >> 32);
1334 }
1335 pub inline fn r_type(self: @This()) u32 {
1336 return @truncate(self.r_info);
1337 }
1338};
1339pub const Elf32_Rela = extern struct {
1340 r_offset: Elf32_Addr,
1341 r_info: Word,
1342 r_addend: Sword,
1343
1344 pub inline fn r_sym(self: @This()) u24 {
1345 return @truncate(self.r_info >> 8);
1346 }
1347 pub inline fn r_type(self: @This()) u8 {
1348 return @truncate(self.r_info);
1349 }
1350};
1351pub const Elf64_Rela = extern struct {
1352 r_offset: Elf64_Addr,
1353 r_info: Elf64_Xword,
1354 r_addend: Elf64_Sxword,
1355
1356 pub inline fn r_sym(self: @This()) u32 {
1357 return @truncate(self.r_info >> 32);
1358 }
1359 pub inline fn r_type(self: @This()) u32 {
1360 return @truncate(self.r_info);
1361 }
1362};
1363pub const Elf32_Relr = Word;
1364pub const Elf64_Relr = Elf64_Xword;
1365pub const Elf32_Dyn = extern struct {
1366 d_tag: Sword,
1367 d_val: Elf32_Addr,
1368};
1369pub const Elf64_Dyn = extern struct {
1370 d_tag: Elf64_Sxword,
1371 d_val: Elf64_Addr,
1372};
1373pub const Verdef = extern struct {
1374 version: Half,
1375 flags: Half,
1376 ndx: VER_NDX,
1377 cnt: Half,
1378 hash: Word,
1379 aux: Word,
1380 next: Word,
1381};
1382pub const Verdaux = extern struct {
1383 name: Word,
1384 next: Word,
1385};
1386pub const Elf32_Verneed = extern struct {
1387 vn_version: Half,
1388 vn_cnt: Half,
1389 vn_file: Word,
1390 vn_aux: Word,
1391 vn_next: Word,
1392};
1393pub const Elf64_Verneed = extern struct {
1394 vn_version: Half,
1395 vn_cnt: Half,
1396 vn_file: Word,
1397 vn_aux: Word,
1398 vn_next: Word,
1399};
1400pub const Vernaux = extern struct {
1401 hash: Word,
1402 flags: Half,
1403 other: Half,
1404 name: Word,
1405 next: Word,
1406};
1407pub const Elf32_auxv_t = extern struct {
1408 a_type: u32,
1409 a_un: extern union {
1410 a_val: u32,
1411 },
1412};
1413pub const Elf64_auxv_t = extern struct {
1414 a_type: u64,
1415 a_un: extern union {
1416 a_val: u64,
1417 },
1418};
1419pub const Elf32_Nhdr = extern struct {
1420 n_namesz: Word,
1421 n_descsz: Word,
1422 n_type: Word,
1423};
1424pub const Elf64_Nhdr = extern struct {
1425 n_namesz: Word,
1426 n_descsz: Word,
1427 n_type: Word,
1428};
1429pub const Elf32_Move = extern struct {
1430 m_value: Elf32_Xword,
1431 m_info: Word,
1432 m_poffset: Word,
1433 m_repeat: Half,
1434 m_stride: Half,
1435};
1436pub const Elf64_Move = extern struct {
1437 m_value: Elf64_Xword,
1438 m_info: Elf64_Xword,
1439 m_poffset: Elf64_Xword,
1440 m_repeat: Half,
1441 m_stride: Half,
1442};
1443pub const Elf32_gptab = extern union {
1444 gt_header: extern struct {
1445 gt_current_g_value: Word,
1446 gt_unused: Word,
1447 },
1448 gt_entry: extern struct {
1449 gt_g_value: Word,
1450 gt_bytes: Word,
1451 },
1452};
1453pub const Elf32_RegInfo = extern struct {
1454 ri_gprmask: Word,
1455 ri_cprmask: [4]Word,
1456 ri_gp_value: Sword,
1457};
1458pub const Elf_Options = extern struct {
1459 kind: u8,
1460 size: u8,
1461 section: Elf32_Section,
1462 info: Word,
1463};
1464pub const Elf_Options_Hw = extern struct {
1465 hwp_flags1: Word,
1466 hwp_flags2: Word,
1467};
1468pub const Elf32_Lib = extern struct {
1469 l_name: Word,
1470 l_time_stamp: Word,
1471 l_checksum: Word,
1472 l_version: Word,
1473 l_flags: Word,
1474};
1475pub const Elf64_Lib = extern struct {
1476 l_name: Word,
1477 l_time_stamp: Word,
1478 l_checksum: Word,
1479 l_version: Word,
1480 l_flags: Word,
1481};
1482pub const Elf32_Conflict = Elf32_Addr;
1483pub const Elf_MIPS_ABIFlags_v0 = extern struct {
1484 version: Half,
1485 isa_level: u8,
1486 isa_rev: u8,
1487 gpr_size: u8,
1488 cpr1_size: u8,
1489 cpr2_size: u8,
1490 fp_abi: u8,
1491 isa_ext: Word,
1492 ases: Word,
1493 flags1: Word,
1494 flags2: Word,
1495};
1496
1497pub const Auxv = switch (@sizeOf(usize)) {
1498 4 => Elf32_auxv_t,
1499 8 => Elf64_auxv_t,
1500 else => @compileError("expected pointer size of 32 or 64"),
1501};
1502/// Deprecated, use `std.elf.ElfN.Ehdr`
1503pub const Ehdr = switch (@sizeOf(usize)) {
1504 4 => Elf32_Ehdr,
1505 8 => Elf64_Ehdr,
1506 else => @compileError("expected pointer size of 32 or 64"),
1507};
1508pub const Dyn = switch (@sizeOf(usize)) {
1509 4 => Elf32_Dyn,
1510 8 => Elf64_Dyn,
1511 else => @compileError("expected pointer size of 32 or 64"),
1512};
1513pub const Rel = switch (@sizeOf(usize)) {
1514 4 => Elf32_Rel,
1515 8 => Elf64_Rel,
1516 else => @compileError("expected pointer size of 32 or 64"),
1517};
1518pub const Rela = switch (@sizeOf(usize)) {
1519 4 => Elf32_Rela,
1520 8 => Elf64_Rela,
1521 else => @compileError("expected pointer size of 32 or 64"),
1522};
1523pub const Relr = switch (@sizeOf(usize)) {
1524 4 => Elf32_Relr,
1525 8 => Elf64_Relr,
1526 else => @compileError("expected pointer size of 32 or 64"),
1527};
1528pub const Shdr = switch (@sizeOf(usize)) {
1529 4 => Elf32_Shdr,
1530 8 => Elf64_Shdr,
1531 else => @compileError("expected pointer size of 32 or 64"),
1532};
1533/// Deprecated, use `std.elf.ElfN.Chdr`
1534pub const Chdr = switch (@sizeOf(usize)) {
1535 4 => Elf32_Chdr,
1536 8 => Elf64_Chdr,
1537 else => @compileError("expected pointer size of 32 or 64"),
1538};
1539/// Deprecated, use `std.elf.ElfN.Sym`
1540pub const Sym = switch (@sizeOf(usize)) {
1541 4 => Elf32_Sym,
1542 8 => Elf64_Sym,
1543 else => @compileError("expected pointer size of 32 or 64"),
1544};
1545/// Deprecated, use `std.elf.ElfN.Addr`
1546pub const Addr = ElfN.Addr;
1547
1548pub const Ident = extern struct {
1549 magic: [MAGIC.len]u8 = MAGIC.*,
1550 class: CLASS,
1551 data: DATA,
1552 version: u8,
1553 osabi: OSABI,
1554 abiversion: u8,
1555 pad: [7]u8 = @splat(0),
1556
1557 comptime {
1558 assert(@sizeOf(Ident) == EI.NIDENT);
1559 }
1560};
1561
1562/// Deprecated, use `@intFromEnum(std.elf.CLASS.NONE)`
1563pub const ELFCLASSNONE = @backingInt(CLASS.NONE);
1564/// Deprecated, use `@intFromEnum(std.elf.CLASS.@"32")`
1565pub const ELFCLASS32 = @backingInt(CLASS.@"32");
1566/// Deprecated, use `@intFromEnum(std.elf.CLASS.@"64")`
1567pub const ELFCLASS64 = @backingInt(CLASS.@"64");
1568/// Deprecated, use `@intFromEnum(std.elf.CLASS.NUM)`
1569pub const ELFCLASSNUM = CLASS.NUM;
1570pub const CLASS = enum(u8) {
1571 NONE = 0,
1572 @"32" = 1,
1573 @"64" = 2,
1574 _,
1575
1576 pub const NUM = @typeInfo(CLASS).@"enum".field_names.len;
1577
1578 pub inline fn size(class: CLASS) u8 {
1579 return switch (class) {
1580 .NONE, _ => unreachable,
1581 .@"32" => 4,
1582 .@"64" => 8,
1583 };
1584 }
1585
1586 pub fn ElfN(comptime class: CLASS) type {
1587 return switch (class) {
1588 .NONE, _ => comptime unreachable,
1589 .@"32" => Elf32,
1590 .@"64" => Elf64,
1591 };
1592 }
1593};
1594
1595/// Deprecated, use `@intFromEnum(std.elf.DATA.NONE)`
1596pub const ELFDATANONE = @backingInt(DATA.NONE);
1597/// Deprecated, use `@intFromEnum(std.elf.DATA.@"2LSB")`
1598pub const ELFDATA2LSB = @backingInt(DATA.@"2LSB");
1599/// Deprecated, use `@intFromEnum(std.elf.DATA.@"2MSB")`
1600pub const ELFDATA2MSB = @backingInt(DATA.@"2MSB");
1601/// Deprecated, use `@intFromEnum(std.elf.DATA.NUM)`
1602pub const ELFDATANUM = DATA.NUM;
1603pub const DATA = enum(u8) {
1604 NONE = 0,
1605 @"2LSB" = 1,
1606 @"2MSB" = 2,
1607 _,
1608
1609 pub const NUM = @typeInfo(DATA).@"enum".field_names.len;
1610
1611 pub inline fn endian(data: DATA) std.lang.Endian {
1612 return switch (data) {
1613 .NONE, _ => unreachable,
1614 .@"2LSB" => .little,
1615 .@"2MSB" => .big,
1616 };
1617 }
1618};
1619
1620pub const OSABI = enum(u8) {
1621 /// UNIX System V ABI
1622 NONE = 0,
1623 /// HP-UX operating system
1624 HPUX = 1,
1625 /// NetBSD
1626 NETBSD = 2,
1627 /// GNU (Hurd/Linux)
1628 GNU = 3,
1629 /// Solaris
1630 SOLARIS = 6,
1631 /// AIX
1632 AIX = 7,
1633 /// IRIX
1634 IRIX = 8,
1635 /// FreeBSD
1636 FREEBSD = 9,
1637 /// TRU64 UNIX
1638 TRU64 = 10,
1639 /// Novell Modesto
1640 MODESTO = 11,
1641 /// OpenBSD
1642 OPENBSD = 12,
1643 /// OpenVMS
1644 OPENVMS = 13,
1645 /// Hewlett-Packard Non-Stop Kernel
1646 NSK = 14,
1647 /// AROS
1648 AROS = 15,
1649 /// FenixOS
1650 FENIXOS = 16,
1651 /// Nuxi CloudABI
1652 CLOUDABI = 17,
1653 /// Stratus Technologies OpenVOS
1654 OPENVOS = 18,
1655 /// NVIDIA CUDA architecture (not gABI assigned)
1656 CUDA = 51,
1657 /// AMD HSA Runtime (not gABI assigned)
1658 AMDGPU_HSA = 64,
1659 /// AMD PAL Runtime (not gABI assigned)
1660 AMDGPU_PAL = 65,
1661 /// AMD Mesa3D Runtime (not gABI assigned)
1662 AMDGPU_MESA3D = 66,
1663 /// ARM (not gABI assigned)
1664 ARM = 97,
1665 /// Standalone (embedded) application (not gABI assigned)
1666 STANDALONE = 255,
1667
1668 _,
1669};
1670
1671/// Machine architectures.
1672///
1673/// See current registered ELF machine architectures at:
1674/// http://www.sco.com/developers/gabi/latest/ch4.eheader.html
1675pub const EM = enum(u16) {
1676 /// No machine
1677 NONE = 0,
1678 /// AT&T WE 32100
1679 M32 = 1,
1680 /// SUN SPARC
1681 SPARC = 2,
1682 /// Intel 80386
1683 @"386" = 3,
1684 /// Motorola m68k family
1685 @"68K" = 4,
1686 /// Motorola m88k family
1687 @"88K" = 5,
1688 /// Intel MCU
1689 IAMCU = 6,
1690 /// Intel 80860
1691 @"860" = 7,
1692 /// MIPS R3000 (officially, big-endian only)
1693 MIPS = 8,
1694 /// IBM System/370
1695 S370 = 9,
1696 /// MIPS R3000 (and R4000) little-endian, Oct 4 1993 Draft (deprecated)
1697 MIPS_RS3_LE = 10,
1698 /// Old version of Sparc v9, from before the ABI (not gABI assigned)
1699 OLD_SPARCV9 = 11,
1700 /// HPPA
1701 PARISC = 15,
1702 /// Fujitsu VPP500 (also old version of PowerPC, which was not gABI assigned)
1703 VPP500 = 17,
1704 /// Sun's "v8plus"
1705 SPARC32PLUS = 18,
1706 /// Intel 80960
1707 @"960" = 19,
1708 /// PowerPC
1709 PPC = 20,
1710 /// 64-bit PowerPC
1711 PPC64 = 21,
1712 /// IBM S/390
1713 S390 = 22,
1714 /// Sony/Toshiba/IBM SPU
1715 SPU = 23,
1716 /// NEC V800 series
1717 V800 = 36,
1718 /// Fujitsu FR20
1719 FR20 = 37,
1720 /// TRW RH32
1721 RH32 = 38,
1722 /// Motorola M*Core, aka RCE (also old Fujitsu MMA, which was not gABI assigned)
1723 MCORE = 39,
1724 /// ARM
1725 ARM = 40,
1726 /// Digital Alpha
1727 OLD_ALPHA = 41,
1728 /// Renesas (formerly Hitachi) / SuperH SH
1729 SH = 42,
1730 /// SPARC v9 64-bit
1731 SPARCV9 = 43,
1732 /// Siemens Tricore embedded processor
1733 TRICORE = 44,
1734 /// ARC Cores
1735 ARC = 45,
1736 /// Renesas (formerly Hitachi) H8/300
1737 H8_300 = 46,
1738 /// Renesas (formerly Hitachi) H8/300H
1739 H8_300H = 47,
1740 /// Renesas (formerly Hitachi) H8S
1741 H8S = 48,
1742 /// Renesas (formerly Hitachi) H8/500
1743 H8_500 = 49,
1744 /// Intel IA-64 Processor
1745 IA_64 = 50,
1746 /// Stanford MIPS-X
1747 MIPS_X = 51,
1748 /// Motorola Coldfire
1749 COLDFIRE = 52,
1750 /// Motorola M68HC12
1751 @"68HC12" = 53,
1752 /// Fujitsu Multimedia Accelerator
1753 MMA = 54,
1754 /// Siemens PCP
1755 PCP = 55,
1756 /// Sony nCPU embedded RISC processor
1757 NCPU = 56,
1758 /// Denso NDR1 microprocessor
1759 NDR1 = 57,
1760 /// Motorola Star*Core processor
1761 STARCORE = 58,
1762 /// Toyota ME16 processor
1763 ME16 = 59,
1764 /// STMicroelectronics ST100 processor
1765 ST100 = 60,
1766 /// Advanced Logic Corp. TinyJ embedded processor
1767 TINYJ = 61,
1768 /// Advanced Micro Devices X86-64 processor
1769 X86_64 = 62,
1770 /// Sony DSP Processor
1771 PDSP = 63,
1772 /// Digital Equipment Corp. PDP-10
1773 PDP10 = 64,
1774 /// Digital Equipment Corp. PDP-11
1775 PDP11 = 65,
1776 /// Siemens FX66 microcontroller
1777 FX66 = 66,
1778 /// STMicroelectronics ST9+ 8/16 bit microcontroller
1779 ST9PLUS = 67,
1780 /// STMicroelectronics ST7 8-bit microcontroller
1781 ST7 = 68,
1782 /// Motorola MC68HC16 Microcontroller
1783 @"68HC16" = 69,
1784 /// Motorola MC68HC11 Microcontroller
1785 @"68HC11" = 70,
1786 /// Motorola MC68HC08 Microcontroller
1787 @"68HC08" = 71,
1788 /// Motorola MC68HC05 Microcontroller
1789 @"68HC05" = 72,
1790 /// Silicon Graphics SVx
1791 SVX = 73,
1792 /// STMicroelectronics ST19 8-bit cpu
1793 ST19 = 74,
1794 /// Digital VAX
1795 VAX = 75,
1796 /// Axis Communications 32-bit embedded processor
1797 CRIS = 76,
1798 /// Infineon Technologies 32-bit embedded cpu
1799 JAVELIN = 77,
1800 /// Element 14 64-bit DSP processor
1801 FIREPATH = 78,
1802 /// LSI Logic's 16-bit DSP processor
1803 ZSP = 79,
1804 /// Donald Knuth's educational 64-bit processor
1805 MMIX = 80,
1806 /// Harvard's machine-independent format
1807 HUANY = 81,
1808 /// SiTera Prism
1809 PRISM = 82,
1810 /// Atmel AVR 8-bit microcontroller
1811 AVR = 83,
1812 /// Fujitsu FR30
1813 FR30 = 84,
1814 /// Mitsubishi D10V
1815 D10V = 85,
1816 /// Mitsubishi D30V
1817 D30V = 86,
1818 /// Renesas V850 (formerly NEC V850)
1819 V850 = 87,
1820 /// Renesas M32R (formerly Mitsubishi M32R)
1821 M32R = 88,
1822 /// Matsushita MN10300
1823 MN10300 = 89,
1824 /// Matsushita MN10200
1825 MN10200 = 90,
1826 /// picoJava
1827 PJ = 91,
1828 /// OpenRISC 1000 32-bit embedded processor
1829 OR1K = 92,
1830 /// ARC International ARCompact processor
1831 ARC_COMPACT = 93,
1832 /// Tensilica Xtensa Architecture
1833 XTENSA = 94,
1834 /// Alphamosaic VideoCore processor (also old Sunplus S+core7 backend magic number, which was not gABI assigned)
1835 VIDEOCORE = 95,
1836 /// Thompson Multimedia General Purpose Processor
1837 TMM_GPP = 96,
1838 /// National Semiconductor 32000 series
1839 NS32K = 97,
1840 /// Tenor Network TPC processor
1841 TPC = 98,
1842 /// Trebia SNP 1000 processor (also old value for picoJava, which was not gABI assigned)
1843 SNP1K = 99,
1844 /// STMicroelectronics ST200 microcontroller
1845 ST200 = 100,
1846 /// Ubicom IP2022 micro controller
1847 IP2K = 101,
1848 /// MAX Processor
1849 MAX = 102,
1850 /// National Semiconductor CompactRISC
1851 CR = 103,
1852 /// Fujitsu F2MC16
1853 F2MC16 = 104,
1854 /// TI msp430 micro controller
1855 MSP430 = 105,
1856 /// ADI Blackfin
1857 BLACKFIN = 106,
1858 /// S1C33 Family of Seiko Epson processors
1859 SE_C33 = 107,
1860 /// Sharp embedded microprocessor
1861 SEP = 108,
1862 /// Arca RISC Microprocessor
1863 ARCA = 109,
1864 /// Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University
1865 UNICORE = 110,
1866 /// eXcess: 16/32/64-bit configurable embedded CPU
1867 EXCESS = 111,
1868 /// Icera Semiconductor Inc. Deep Execution Processor
1869 DXP = 112,
1870 /// Altera Nios II soft-core processor
1871 ALTERA_NIOS2 = 113,
1872 /// National Semiconductor CRX
1873 CRX = 114,
1874 /// Motorola XGATE embedded processor (also old value for National Semiconductor CompactRISC, which was not gABI assigned)
1875 XGATE = 115,
1876 /// Infineon C16x/XC16x processor
1877 C166 = 116,
1878 /// Renesas M16C series microprocessors
1879 M16C = 117,
1880 /// Microchip Technology dsPIC30F Digital Signal Controller
1881 DSPIC30F = 118,
1882 /// Freescale Communication Engine RISC core
1883 CE = 119,
1884 /// Renesas M32C series microprocessors
1885 M32C = 120,
1886 /// Altium TSK3000 core
1887 TSK3000 = 131,
1888 /// Freescale RS08 embedded processor
1889 RS08 = 132,
1890 /// Analog Devices SHARC family of 32-bit DSP processors
1891 SHARC = 133,
1892 /// Cyan Technology eCOG2 microprocessor
1893 ECOG2 = 134,
1894 /// Sunplus S+core (and S+core7) RISC processor
1895 SCORE = 135,
1896 /// New Japan Radio (NJR) 24-bit DSP Processor
1897 DSP24 = 136,
1898 /// Broadcom VideoCore III processor
1899 VIDEOCORE3 = 137,
1900 /// RISC processor for Lattice FPGA architecture
1901 LATTICEMICO32 = 138,
1902 /// Seiko Epson C17 family
1903 SE_C17 = 139,
1904 /// Texas Instruments TMS320C6000 DSP family
1905 TI_C6000 = 140,
1906 /// Texas Instruments TMS320C2000 DSP family
1907 TI_C2000 = 141,
1908 /// Texas Instruments TMS320C55x DSP family
1909 TI_C5500 = 142,
1910 /// Texas Instruments Application Specific RISC Processor, 32bit fetch
1911 TI_ARP32 = 143,
1912 /// Texas Instruments Programmable Realtime Unit
1913 TI_PRU = 144,
1914 /// STMicroelectronics 64bit VLIW Data Signal Processor
1915 MMDSP_PLUS = 160,
1916 /// Cypress M8C microprocessor
1917 CYPRESS_M8C = 161,
1918 /// Renesas R32C series microprocessors
1919 R32C = 162,
1920 /// NXP Semiconductors TriMedia architecture family
1921 TRIMEDIA = 163,
1922 /// QUALCOMM DSP6 Processor
1923 QDSP6 = 164,
1924 /// Intel 8051 and variants
1925 @"8051" = 165,
1926 /// STMicroelectronics STxP7x family
1927 STXP7X = 166,
1928 /// Andes Technology compact code size embedded RISC processor family
1929 NDS32 = 167,
1930 /// Cyan Technology eCOG1X family
1931 ECOG1X = 168,
1932 /// Dallas Semiconductor MAXQ30 Core Micro-controllers
1933 MAXQ30 = 169,
1934 /// New Japan Radio (NJR) 16-bit DSP Processor
1935 XIMO16 = 170,
1936 /// M2000 Reconfigurable RISC Microprocessor
1937 MANIK = 171,
1938 /// Cray Inc. NV2 vector architecture
1939 CRAYNV2 = 172,
1940 /// Renesas RX family
1941 RX = 173,
1942 /// Imagination Technologies Meta processor architecture
1943 METAG = 174,
1944 /// MCST Elbrus general purpose hardware architecture
1945 MCST_ELBRUS = 175,
1946 /// Cyan Technology eCOG16 family
1947 ECOG16 = 176,
1948 /// National Semiconductor CompactRISC 16-bit processor
1949 CR16 = 177,
1950 /// Freescale Extended Time Processing Unit
1951 ETPU = 178,
1952 /// Infineon Technologies SLE9X core
1953 SLE9X = 179,
1954 /// Intel L10M
1955 L10M = 180,
1956 /// Intel K10M
1957 K10M = 181,
1958 /// ARM 64-bit architecture
1959 AARCH64 = 183,
1960 /// Atmel Corporation 32-bit microprocessor family
1961 AVR32 = 185,
1962 /// STMicroeletronics STM8 8-bit microcontroller
1963 STM8 = 186,
1964 /// Tilera TILE64 multicore architecture family
1965 TILE64 = 187,
1966 /// Tilera TILEPro multicore architecture family
1967 TILEPRO = 188,
1968 /// Xilinx MicroBlaze 32-bit RISC soft processor core
1969 MICROBLAZE = 189,
1970 /// NVIDIA CUDA architecture
1971 CUDA = 190,
1972 /// Tilera TILE-Gx multicore architecture family
1973 TILEGX = 191,
1974 /// CloudShield architecture family
1975 CLOUDSHIELD = 192,
1976 /// KIPO-KAIST Core-A 1st generation processor family
1977 COREA_1ST = 193,
1978 /// KIPO-KAIST Core-A 2nd generation processor family
1979 COREA_2ND = 194,
1980 /// Synopsys ARCompact V2
1981 ARC_COMPACT2 = 195,
1982 /// Open8 8-bit RISC soft processor core
1983 OPEN8 = 196,
1984 /// Renesas RL78 family
1985 RL78 = 197,
1986 /// Broadcom VideoCore V processor
1987 VIDEOCORE5 = 198,
1988 /// Renesas 78K0R
1989 @"78K0R" = 199,
1990 /// Freescale 56800EX Digital Signal Controller (DSC)
1991 @"56800EX" = 200,
1992 /// Beyond BA1 CPU architecture
1993 BA1 = 201,
1994 /// Beyond BA2 CPU architecture
1995 BA2 = 202,
1996 /// XMOS xCORE processor family
1997 XCORE = 203,
1998 /// Microchip 8-bit PIC(r) family
1999 MCHP_PIC = 204,
2000 /// Intel Graphics Technology
2001 INTELGT = 205,
2002 /// KM211 KM32 32-bit processor
2003 KM32 = 210,
2004 /// KM211 KMX32 32-bit processor
2005 KMX32 = 211,
2006 /// KM211 KMX16 16-bit processor
2007 KMX16 = 212,
2008 /// KM211 KMX8 8-bit processor
2009 KMX8 = 213,
2010 /// KM211 KVARC processor
2011 KVARC = 214,
2012 /// Paneve CDP architecture family
2013 CDP = 215,
2014 /// Cognitive Smart Memory Processor
2015 COGE = 216,
2016 /// Bluechip Systems CoolEngine
2017 COOL = 217,
2018 /// Nanoradio Optimized RISC
2019 NORC = 218,
2020 /// CSR Kalimba architecture family
2021 CSR_KALIMBA = 219,
2022 /// Zilog Z80
2023 Z80 = 220,
2024 /// Controls and Data Services VISIUMcore processor
2025 VISIUM = 221,
2026 /// FTDI Chip FT32 high performance 32-bit RISC architecture
2027 FT32 = 222,
2028 /// Moxie processor family
2029 MOXIE = 223,
2030 /// AMD GPU architecture
2031 AMDGPU = 224,
2032 /// RISC-V
2033 RISCV = 243,
2034 /// Lanai 32-bit processor
2035 LANAI = 244,
2036 /// CEVA Processor Architecture Family
2037 CEVA = 245,
2038 /// CEVA X2 Processor Family
2039 CEVA_X2 = 246,
2040 /// Linux BPF - in-kernel virtual machine
2041 BPF = 247,
2042 /// Graphcore Intelligent Processing Unit
2043 GRAPHCORE_IPU = 248,
2044 /// Imagination Technologies
2045 IMG1 = 249,
2046 /// Netronome Flow Processor
2047 NFP = 250,
2048 /// NEC Vector Engine
2049 VE = 251,
2050 /// C-SKY processor family
2051 CSKY = 252,
2052 /// Synopsys ARCv2.3 64-bit
2053 ARC_COMPACT3_64 = 253,
2054 /// MOS Technology MCS 6502 processor
2055 MCS6502 = 254,
2056 /// Synopsys ARCv2.3 32-bit
2057 ARC_COMPACT3 = 255,
2058 /// Kalray VLIW core of the MPPA processor family
2059 KVX = 256,
2060 /// WDC 65816/65C816
2061 @"65816" = 257,
2062 /// LoongArch
2063 LOONGARCH = 258,
2064 /// ChipON KungFu32
2065 KF32 = 259,
2066 /// LAPIS nX-U16/U8
2067 U16_U8CORE = 260,
2068 /// Tachyum
2069 TACHYUM = 261,
2070 /// NXP 56800EF Digital Signal Controller (DSC)
2071 @"56800EF" = 262,
2072 /// Solana Bytecode Format
2073 SBF = 263,
2074 /// AMD/Xilinx AIEngine architecture
2075 AIENGINE = 264,
2076 /// SiMa MLA
2077 SIMA_MLA = 265,
2078 /// Cambricon BANG
2079 BANG = 266,
2080 /// Loongson LoongGPU
2081 LOONGGPU = 267,
2082 /// Wuxi Institute of Advanced Technology SW64
2083 SW64 = 268,
2084 /// AMD/Xilinx AIEngine ctrlcode
2085 AIECTRLCODE = 269,
2086 /// T-Head PPU
2087 PPU = 270,
2088 /// AVR
2089 AVR_OLD = 0x1057,
2090 /// MSP430
2091 MSP430_OLD = 0x1059,
2092 /// Morpho MT
2093 MT = 0x2530,
2094 /// FR30
2095 CYGNUS_FR30 = 0x3330,
2096 /// WebAssembly (as used by LLVM)
2097 WEBASSEMBLY = 0x4157,
2098 /// Infineon Technologies 16-bit microcontroller with C166-V2 core
2099 XC16X = 0x4688,
2100 /// Freescale S12Z
2101 S12Z = 0x4def,
2102 /// DLX
2103 DLX = 0x5aa5,
2104 /// FRV
2105 CYGNUS_FRV = 0x5441,
2106 /// D10V
2107 CYGNUS_D10V = 0x7650,
2108 /// D30V
2109 CYGNUS_D30V = 0x7676,
2110 /// Ubicom IP2xxx
2111 IP2K_OLD = 0x8217,
2112 /// Cygnus PowerPC ELF
2113 CYGNUS_POWERPC = 0x9025,
2114 /// Alpha
2115 ALPHA = 0x9026,
2116 /// Cygnus M32R ELF
2117 CYGNUS_M32R = 0x9041,
2118 /// V850
2119 CYGNUS_V850 = 0x9080,
2120 /// Old S/390
2121 S390_OLD = 0xa390,
2122 /// Old unofficial value for Xtensa
2123 XTENSA_OLD = 0xabc7,
2124 /// Xstormy16
2125 XSTORMY16 = 0xad45,
2126 /// MN10300
2127 CYGNUS_MN10300 = 0xbeef,
2128 /// MN10200
2129 CYGNUS_MN10200 = 0xdead,
2130 /// Renesas M32C and M16C
2131 M32C_OLD = 0xfeb0,
2132 /// Vitesse IQ2000
2133 IQ2000 = 0xfeba,
2134 /// NIOS
2135 NIOS32 = 0xfebb,
2136 /// Toshiba MeP
2137 CYGNUS_MEP = 0xf00d,
2138 /// Old unofficial value for Moxie
2139 MOXIE_OLD = 0xfeed,
2140 /// Old MicroBlaze
2141 MICROBLAZE_OLD = 0xbaab,
2142 /// Adapteva's Epiphany architecture
2143 ADAPTEVA_EPIPHANY = 0x1223,
2144
2145 /// Parallax Propeller (P1)
2146 /// This value is an unofficial ELF value used in: https://github.com/parallaxinc/propgcc
2147 PROPELLER = 0x5072,
2148
2149 /// Parallax Propeller 2 (P2)
2150 /// This value is an unofficial ELF value used in: https://github.com/ne75/llvm-project
2151 PROPELLER2 = 300,
2152
2153 _,
2154};
2155
2156pub const GRP_COMDAT = 1;
2157
2158/// Section data should be writable during execution.
2159pub const SHF_WRITE = 0x1;
2160
2161/// Section occupies memory during program execution.
2162pub const SHF_ALLOC = 0x2;
2163
2164/// Section contains executable machine instructions.
2165pub const SHF_EXECINSTR = 0x4;
2166
2167/// The data in this section may be merged.
2168pub const SHF_MERGE = 0x10;
2169
2170/// The data in this section is null-terminated strings.
2171pub const SHF_STRINGS = 0x20;
2172
2173/// A field in this section holds a section header table index.
2174pub const SHF_INFO_LINK = 0x40;
2175
2176/// Adds special ordering requirements for link editors.
2177pub const SHF_LINK_ORDER = 0x80;
2178
2179/// This section requires special OS-specific processing to avoid incorrect
2180/// behavior.
2181pub const SHF_OS_NONCONFORMING = 0x100;
2182
2183/// This section is a member of a section group.
2184pub const SHF_GROUP = 0x200;
2185
2186/// This section holds Thread-Local Storage.
2187pub const SHF_TLS = 0x400;
2188
2189/// Identifies a section containing compressed data.
2190pub const SHF_COMPRESSED = 0x800;
2191
2192/// Not to be GCed by the linker
2193pub const SHF_GNU_RETAIN = 0x200000;
2194
2195/// This section is excluded from the final executable or shared library.
2196pub const SHF_EXCLUDE = 0x80000000;
2197
2198/// Start of target-specific flags.
2199pub const SHF_MASKOS = 0x0ff00000;
2200
2201/// Bits indicating processor-specific flags.
2202pub const SHF_MASKPROC = 0xf0000000;
2203
2204/// All sections with the "d" flag are grouped together by the linker to form
2205/// the data section and the dp register is set to the start of the section by
2206/// the boot code.
2207pub const XCORE_SHF_DP_SECTION = 0x10000000;
2208
2209/// All sections with the "c" flag are grouped together by the linker to form
2210/// the constant pool and the cp register is set to the start of the constant
2211/// pool by the boot code.
2212pub const XCORE_SHF_CP_SECTION = 0x20000000;
2213
2214/// If an object file section does not have this flag set, then it may not hold
2215/// more than 2GB and can be freely referred to in objects using smaller code
2216/// models. Otherwise, only objects using larger code models can refer to them.
2217/// For example, a medium code model object can refer to data in a section that
2218/// sets this flag besides being able to refer to data in a section that does
2219/// not set it; likewise, a small code model object can refer only to code in a
2220/// section that does not set this flag.
2221pub const SHF_X86_64_LARGE = 0x10000000;
2222
2223/// All sections with the GPREL flag are grouped into a global data area
2224/// for faster accesses
2225pub const SHF_HEX_GPREL = 0x10000000;
2226
2227/// Section contains text/data which may be replicated in other sections.
2228/// Linker must retain only one copy.
2229pub const SHF_MIPS_NODUPES = 0x01000000;
2230
2231/// Linker must generate implicit hidden weak names.
2232pub const SHF_MIPS_NAMES = 0x02000000;
2233
2234/// Section data local to process.
2235pub const SHF_MIPS_LOCAL = 0x04000000;
2236
2237/// Do not strip this section.
2238pub const SHF_MIPS_NOSTRIP = 0x08000000;
2239
2240/// Section must be part of global data area.
2241pub const SHF_MIPS_GPREL = 0x10000000;
2242
2243/// This section should be merged.
2244pub const SHF_MIPS_MERGE = 0x20000000;
2245
2246/// Address size to be inferred from section entry size.
2247pub const SHF_MIPS_ADDR = 0x40000000;
2248
2249/// Section data is string data by default.
2250pub const SHF_MIPS_STRING = 0x80000000;
2251
2252/// Make code section unreadable when in execute-only mode
2253pub const SHF_ARM_PURECODE = 0x2000000;
2254
2255pub const SHF = packed struct(Word) {
2256 /// Section data should be writable during execution.
2257 WRITE: bool = false,
2258 /// Section occupies memory during program execution.
2259 ALLOC: bool = false,
2260 /// Section contains executable machine instructions.
2261 EXECINSTR: bool = false,
2262 unused3: u1 = 0,
2263 /// The data in this section may be merged.
2264 MERGE: bool = false,
2265 /// The data in this section is null-terminated strings.
2266 STRINGS: bool = false,
2267 /// A field in this section holds a section header table index.
2268 INFO_LINK: bool = false,
2269 /// Adds special ordering requirements for link editors.
2270 LINK_ORDER: bool = false,
2271 /// This section requires special OS-specific processing to avoid incorrect behavior.
2272 OS_NONCONFORMING: bool = false,
2273 /// This section is a member of a section group.
2274 GROUP: bool = false,
2275 /// This section holds Thread-Local Storage.
2276 TLS: bool = false,
2277 /// Identifies a section containing compressed data.
2278 COMPRESSED: bool = false,
2279 unused12: u8 = 0,
2280 OS: packed union {
2281 MASK: u8,
2282 GNU: packed struct(u8) {
2283 unused0: u1 = 0,
2284 /// Not to be GCed by the linker
2285 RETAIN: bool = false,
2286 unused2: u6 = 0,
2287 },
2288 MIPS: packed struct(u8) {
2289 unused0: u4 = 0,
2290 /// Section contains text/data which may be replicated in other sections.
2291 /// Linker must retain only one copy.
2292 NODUPES: bool = false,
2293 /// Linker must generate implicit hidden weak names.
2294 NAMES: bool = false,
2295 /// Section data local to process.
2296 LOCAL: bool = false,
2297 /// Do not strip this section.
2298 NOSTRIP: bool = false,
2299 },
2300 ARM: packed struct(u8) {
2301 unused0: u5 = 0,
2302 /// Make code section unreadable when in execute-only mode
2303 PURECODE: bool = false,
2304 unused6: u2 = 0,
2305 },
2306 } = .{ .MASK = 0 },
2307 PROC: packed union {
2308 MASK: u4,
2309 XCORE: packed struct(u4) {
2310 /// All sections with the "d" flag are grouped together by the linker to form
2311 /// the data section and the dp register is set to the start of the section by
2312 /// the boot code.
2313 DP_SECTION: bool = false,
2314 /// All sections with the "c" flag are grouped together by the linker to form
2315 /// the constant pool and the cp register is set to the start of the constant
2316 /// pool by the boot code.
2317 CP_SECTION: bool = false,
2318 unused2: u1 = 0,
2319 /// This section is excluded from the final executable or shared library.
2320 EXCLUDE: bool = false,
2321 },
2322 X86_64: packed struct(u4) {
2323 /// If an object file section does not have this flag set, then it may not hold
2324 /// more than 2GB and can be freely referred to in objects using smaller code
2325 /// models. Otherwise, only objects using larger code models can refer to them.
2326 /// For example, a medium code model object can refer to data in a section that
2327 /// sets this flag besides being able to refer to data in a section that does
2328 /// not set it; likewise, a small code model object can refer only to code in a
2329 /// section that does not set this flag.
2330 LARGE: bool = false,
2331 unused1: u2 = 0,
2332 /// This section is excluded from the final executable or shared library.
2333 EXCLUDE: bool = false,
2334 },
2335 HEX: packed struct(u4) {
2336 /// All sections with the GPREL flag are grouped into a global data area
2337 /// for faster accesses
2338 GPREL: bool = false,
2339 unused1: u2 = 0,
2340 /// This section is excluded from the final executable or shared library.
2341 EXCLUDE: bool = false,
2342 },
2343 MIPS: packed struct(u4) {
2344 /// All sections with the GPREL flag are grouped into a global data area
2345 /// for faster accesses
2346 GPREL: bool = false,
2347 /// This section should be merged.
2348 MERGE: bool = false,
2349 /// Address size to be inferred from section entry size.
2350 ADDR: bool = false,
2351 /// Section data is string data by default.
2352 STRING: bool = false,
2353 },
2354 } = .{ .MASK = 0 },
2355};
2356
2357/// Execute
2358pub const PF_X = 1;
2359
2360/// Write
2361pub const PF_W = 2;
2362
2363/// Read
2364pub const PF_R = 4;
2365
2366/// Bits for operating system-specific semantics.
2367pub const PF_MASKOS = 0x0ff00000;
2368
2369/// Bits for processor-specific semantics.
2370pub const PF_MASKPROC = 0xf0000000;
2371
2372pub const PF = packed struct(Word) {
2373 X: bool = false,
2374 W: bool = false,
2375 R: bool = false,
2376 unused3: u17 = 0,
2377 OS: packed union {
2378 MASK: u8,
2379 } = .{ .MASK = 0 },
2380 PROC: packed union {
2381 MASK: u4,
2382 } = .{ .MASK = 0 },
2383};
2384
2385/// Undefined section
2386pub const SHN_UNDEF = 0;
2387/// Start of reserved indices
2388pub const SHN_LORESERVE = 0xff00;
2389/// Start of processor-specific
2390pub const SHN_LOPROC = 0xff00;
2391/// End of processor-specific
2392pub const SHN_HIPROC = 0xff1f;
2393pub const SHN_LIVEPATCH = 0xff20;
2394/// Associated symbol is absolute
2395pub const SHN_ABS = 0xfff1;
2396/// Associated symbol is common
2397pub const SHN_COMMON = 0xfff2;
2398/// End of reserved indices
2399pub const SHN_HIRESERVE = 0xffff;
2400
2401// Legal values for ch_type (compression algorithm).
2402pub const COMPRESS = enum(u32) {
2403 ZLIB = 1,
2404 ZSTD = 2,
2405 LOOS = 0x60000000,
2406 HIOS = 0x6fffffff,
2407 LOPROC = 0x70000000,
2408 HIPROC = 0x7fffffff,
2409 _,
2410};
2411
2412/// AMD x86-64 relocations.
2413pub const R_X86_64 = enum(u32) {
2414 /// No reloc
2415 NONE = 0,
2416 /// Direct 64 bit
2417 @"64" = 1,
2418 /// PC relative 32 bit signed
2419 PC32 = 2,
2420 /// 32 bit GOT entry
2421 GOT32 = 3,
2422 /// 32 bit PLT address
2423 PLT32 = 4,
2424 /// Copy symbol at runtime
2425 COPY = 5,
2426 /// Create GOT entry
2427 GLOB_DAT = 6,
2428 /// Create PLT entry
2429 JUMP_SLOT = 7,
2430 /// Adjust by program base
2431 RELATIVE = 8,
2432 /// 32 bit signed PC relative offset to GOT
2433 GOTPCREL = 9,
2434 /// Direct 32 bit zero extended
2435 @"32" = 10,
2436 /// Direct 32 bit sign extended
2437 @"32S" = 11,
2438 /// Direct 16 bit zero extended
2439 @"16" = 12,
2440 /// 16 bit sign extended pc relative
2441 PC16 = 13,
2442 /// Direct 8 bit sign extended
2443 @"8" = 14,
2444 /// 8 bit sign extended pc relative
2445 PC8 = 15,
2446 /// ID of module containing symbol
2447 DTPMOD64 = 16,
2448 /// Offset in module's TLS block
2449 DTPOFF64 = 17,
2450 /// Offset in initial TLS block
2451 TPOFF64 = 18,
2452 /// 32 bit signed PC relative offset to two GOT entries for GD symbol
2453 TLSGD = 19,
2454 /// 32 bit signed PC relative offset to two GOT entries for LD symbol
2455 TLSLD = 20,
2456 /// Offset in TLS block
2457 DTPOFF32 = 21,
2458 /// 32 bit signed PC relative offset to GOT entry for IE symbol
2459 GOTTPOFF = 22,
2460 /// Offset in initial TLS block
2461 TPOFF32 = 23,
2462 /// PC relative 64 bit
2463 PC64 = 24,
2464 /// 64 bit offset to GOT
2465 GOTOFF64 = 25,
2466 /// 32 bit signed pc relative offset to GOT
2467 GOTPC32 = 26,
2468 /// 64 bit GOT entry offset
2469 GOT64 = 27,
2470 /// 64 bit PC relative offset to GOT entry
2471 GOTPCREL64 = 28,
2472 /// 64 bit PC relative offset to GOT
2473 GOTPC64 = 29,
2474 /// Like GOT64, says PLT entry needed
2475 GOTPLT64 = 30,
2476 /// 64-bit GOT relative offset to PLT entry
2477 PLTOFF64 = 31,
2478 /// Size of symbol plus 32-bit addend
2479 SIZE32 = 32,
2480 /// Size of symbol plus 64-bit addend
2481 SIZE64 = 33,
2482 /// GOT offset for TLS descriptor
2483 GOTPC32_TLSDESC = 34,
2484 /// Marker for call through TLS descriptor
2485 TLSDESC_CALL = 35,
2486 /// TLS descriptor
2487 TLSDESC = 36,
2488 /// Adjust indirectly by program base
2489 IRELATIVE = 37,
2490 /// 64-bit adjust by program base
2491 RELATIVE64 = 38,
2492 /// 39 Reserved was PC32_BND
2493 /// 40 Reserved was PLT32_BND
2494 /// Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable
2495 GOTPCRELX = 41,
2496 /// Load from 32 bit signed PC relative offset to GOT entry with REX prefix, relaxable
2497 REX_GOTPCRELX = 42,
2498 _,
2499};
2500
2501/// AArch64 relocations.
2502pub const R_AARCH64 = enum(u32) {
2503 /// No relocation.
2504 NONE = 0,
2505 /// ILP32 AArch64 relocs.
2506 /// Direct 32 bit.
2507 P32_ABS32 = 1,
2508 /// Copy symbol at runtime.
2509 P32_COPY = 180,
2510 /// Create GOT entry.
2511 P32_GLOB_DAT = 181,
2512 /// Create PLT entry.
2513 P32_JUMP_SLOT = 182,
2514 /// Adjust by program base.
2515 P32_RELATIVE = 183,
2516 /// Module number, 32 bit.
2517 P32_TLS_DTPMOD = 184,
2518 /// Module-relative offset, 32 bit.
2519 P32_TLS_DTPREL = 185,
2520 /// TP-relative offset, 32 bit.
2521 P32_TLS_TPREL = 186,
2522 /// TLS Descriptor.
2523 P32_TLSDESC = 187,
2524 /// STT_GNU_IFUNC relocation.
2525 P32_IRELATIVE = 188,
2526 /// LP64 AArch64 relocs.
2527 /// Direct 64 bit.
2528 ABS64 = 257,
2529 /// Direct 32 bit.
2530 ABS32 = 258,
2531 /// Direct 16-bit.
2532 ABS16 = 259,
2533 /// PC-relative 64-bit.
2534 PREL64 = 260,
2535 /// PC-relative 32-bit.
2536 PREL32 = 261,
2537 /// PC-relative 16-bit.
2538 PREL16 = 262,
2539 /// Dir. MOVZ imm. from bits 15:0.
2540 MOVW_UABS_G0 = 263,
2541 /// Likewise for MOVK; no check.
2542 MOVW_UABS_G0_NC = 264,
2543 /// Dir. MOVZ imm. from bits 31:16.
2544 MOVW_UABS_G1 = 265,
2545 /// Likewise for MOVK; no check.
2546 MOVW_UABS_G1_NC = 266,
2547 /// Dir. MOVZ imm. from bits 47:32.
2548 MOVW_UABS_G2 = 267,
2549 /// Likewise for MOVK; no check.
2550 MOVW_UABS_G2_NC = 268,
2551 /// Dir. MOV{K,Z} imm. from 63:48.
2552 MOVW_UABS_G3 = 269,
2553 /// Dir. MOV{N,Z} imm. from 15:0.
2554 MOVW_SABS_G0 = 270,
2555 /// Dir. MOV{N,Z} imm. from 31:16.
2556 MOVW_SABS_G1 = 271,
2557 /// Dir. MOV{N,Z} imm. from 47:32.
2558 MOVW_SABS_G2 = 272,
2559 /// PC-rel. LD imm. from bits 20:2.
2560 LD_PREL_LO19 = 273,
2561 /// PC-rel. ADR imm. from bits 20:0.
2562 ADR_PREL_LO21 = 274,
2563 /// Page-rel. ADRP imm. from 32:12.
2564 ADR_PREL_PG_HI21 = 275,
2565 /// Likewise; no overflow check.
2566 ADR_PREL_PG_HI21_NC = 276,
2567 /// Dir. ADD imm. from bits 11:0.
2568 ADD_ABS_LO12_NC = 277,
2569 /// Likewise for LD/ST; no check.
2570 LDST8_ABS_LO12_NC = 278,
2571 /// PC-rel. TBZ/TBNZ imm. from 15:2.
2572 TSTBR14 = 279,
2573 /// PC-rel. cond. br. imm. from 20:2.
2574 CONDBR19 = 280,
2575 /// PC-rel. B imm. from bits 27:2.
2576 JUMP26 = 282,
2577 /// Likewise for CALL.
2578 CALL26 = 283,
2579 /// Dir. ADD imm. from bits 11:1.
2580 LDST16_ABS_LO12_NC = 284,
2581 /// Likewise for bits 11:2.
2582 LDST32_ABS_LO12_NC = 285,
2583 /// Likewise for bits 11:3.
2584 LDST64_ABS_LO12_NC = 286,
2585 /// PC-rel. MOV{N,Z} imm. from 15:0.
2586 MOVW_PREL_G0 = 287,
2587 /// Likewise for MOVK; no check.
2588 MOVW_PREL_G0_NC = 288,
2589 /// PC-rel. MOV{N,Z} imm. from 31:16.
2590 MOVW_PREL_G1 = 289,
2591 /// Likewise for MOVK; no check.
2592 MOVW_PREL_G1_NC = 290,
2593 /// PC-rel. MOV{N,Z} imm. from 47:32.
2594 MOVW_PREL_G2 = 291,
2595 /// Likewise for MOVK; no check.
2596 MOVW_PREL_G2_NC = 292,
2597 /// PC-rel. MOV{N,Z} imm. from 63:48.
2598 MOVW_PREL_G3 = 293,
2599 /// Dir. ADD imm. from bits 11:4.
2600 LDST128_ABS_LO12_NC = 299,
2601 /// GOT-rel. off. MOV{N,Z} imm. 15:0.
2602 MOVW_GOTOFF_G0 = 300,
2603 /// Likewise for MOVK; no check.
2604 MOVW_GOTOFF_G0_NC = 301,
2605 /// GOT-rel. o. MOV{N,Z} imm. 31:16.
2606 MOVW_GOTOFF_G1 = 302,
2607 /// Likewise for MOVK; no check.
2608 MOVW_GOTOFF_G1_NC = 303,
2609 /// GOT-rel. o. MOV{N,Z} imm. 47:32.
2610 MOVW_GOTOFF_G2 = 304,
2611 /// Likewise for MOVK; no check.
2612 MOVW_GOTOFF_G2_NC = 305,
2613 /// GOT-rel. o. MOV{N,Z} imm. 63:48.
2614 MOVW_GOTOFF_G3 = 306,
2615 /// GOT-relative 64-bit.
2616 GOTREL64 = 307,
2617 /// GOT-relative 32-bit.
2618 GOTREL32 = 308,
2619 /// PC-rel. GOT off. load imm. 20:2.
2620 GOT_LD_PREL19 = 309,
2621 /// GOT-rel. off. LD/ST imm. 14:3.
2622 LD64_GOTOFF_LO15 = 310,
2623 /// P-page-rel. GOT off. ADRP 32:12.
2624 ADR_GOT_PAGE = 311,
2625 /// Dir. GOT off. LD/ST imm. 11:3.
2626 LD64_GOT_LO12_NC = 312,
2627 /// GOT-page-rel. GOT off. LD/ST 14:3
2628 LD64_GOTPAGE_LO15 = 313,
2629 /// PC-relative ADR imm. 20:0.
2630 TLSGD_ADR_PREL21 = 512,
2631 /// page-rel. ADRP imm. 32:12.
2632 TLSGD_ADR_PAGE21 = 513,
2633 /// direct ADD imm. from 11:0.
2634 TLSGD_ADD_LO12_NC = 514,
2635 /// GOT-rel. MOV{N,Z} 31:16.
2636 TLSGD_MOVW_G1 = 515,
2637 /// GOT-rel. MOVK imm. 15:0.
2638 TLSGD_MOVW_G0_NC = 516,
2639 /// Like 512; local dynamic model.
2640 TLSLD_ADR_PREL21 = 517,
2641 /// Like 513; local dynamic model.
2642 TLSLD_ADR_PAGE21 = 518,
2643 /// Like 514; local dynamic model.
2644 TLSLD_ADD_LO12_NC = 519,
2645 /// Like 515; local dynamic model.
2646 TLSLD_MOVW_G1 = 520,
2647 /// Like 516; local dynamic model.
2648 TLSLD_MOVW_G0_NC = 521,
2649 /// TLS PC-rel. load imm. 20:2.
2650 TLSLD_LD_PREL19 = 522,
2651 /// TLS DTP-rel. MOV{N,Z} 47:32.
2652 TLSLD_MOVW_DTPREL_G2 = 523,
2653 /// TLS DTP-rel. MOV{N,Z} 31:16.
2654 TLSLD_MOVW_DTPREL_G1 = 524,
2655 /// Likewise; MOVK; no check.
2656 TLSLD_MOVW_DTPREL_G1_NC = 525,
2657 /// TLS DTP-rel. MOV{N,Z} 15:0.
2658 TLSLD_MOVW_DTPREL_G0 = 526,
2659 /// Likewise; MOVK; no check.
2660 TLSLD_MOVW_DTPREL_G0_NC = 527,
2661 /// DTP-rel. ADD imm. from 23:12.
2662 TLSLD_ADD_DTPREL_HI12 = 528,
2663 /// DTP-rel. ADD imm. from 11:0.
2664 TLSLD_ADD_DTPREL_LO12 = 529,
2665 /// Likewise; no ovfl. check.
2666 TLSLD_ADD_DTPREL_LO12_NC = 530,
2667 /// DTP-rel. LD/ST imm. 11:0.
2668 TLSLD_LDST8_DTPREL_LO12 = 531,
2669 /// Likewise; no check.
2670 TLSLD_LDST8_DTPREL_LO12_NC = 532,
2671 /// DTP-rel. LD/ST imm. 11:1.
2672 TLSLD_LDST16_DTPREL_LO12 = 533,
2673 /// Likewise; no check.
2674 TLSLD_LDST16_DTPREL_LO12_NC = 534,
2675 /// DTP-rel. LD/ST imm. 11:2.
2676 TLSLD_LDST32_DTPREL_LO12 = 535,
2677 /// Likewise; no check.
2678 TLSLD_LDST32_DTPREL_LO12_NC = 536,
2679 /// DTP-rel. LD/ST imm. 11:3.
2680 TLSLD_LDST64_DTPREL_LO12 = 537,
2681 /// Likewise; no check.
2682 TLSLD_LDST64_DTPREL_LO12_NC = 538,
2683 /// GOT-rel. MOV{N,Z} 31:16.
2684 TLSIE_MOVW_GOTTPREL_G1 = 539,
2685 /// GOT-rel. MOVK 15:0.
2686 TLSIE_MOVW_GOTTPREL_G0_NC = 540,
2687 /// Page-rel. ADRP 32:12.
2688 TLSIE_ADR_GOTTPREL_PAGE21 = 541,
2689 /// Direct LD off. 11:3.
2690 TLSIE_LD64_GOTTPREL_LO12_NC = 542,
2691 /// PC-rel. load imm. 20:2.
2692 TLSIE_LD_GOTTPREL_PREL19 = 543,
2693 /// TLS TP-rel. MOV{N,Z} 47:32.
2694 TLSLE_MOVW_TPREL_G2 = 544,
2695 /// TLS TP-rel. MOV{N,Z} 31:16.
2696 TLSLE_MOVW_TPREL_G1 = 545,
2697 /// Likewise; MOVK; no check.
2698 TLSLE_MOVW_TPREL_G1_NC = 546,
2699 /// TLS TP-rel. MOV{N,Z} 15:0.
2700 TLSLE_MOVW_TPREL_G0 = 547,
2701 /// Likewise; MOVK; no check.
2702 TLSLE_MOVW_TPREL_G0_NC = 548,
2703 /// TP-rel. ADD imm. 23:12.
2704 TLSLE_ADD_TPREL_HI12 = 549,
2705 /// TP-rel. ADD imm. 11:0.
2706 TLSLE_ADD_TPREL_LO12 = 550,
2707 /// Likewise; no ovfl. check.
2708 TLSLE_ADD_TPREL_LO12_NC = 551,
2709 /// TP-rel. LD/ST off. 11:0.
2710 TLSLE_LDST8_TPREL_LO12 = 552,
2711 /// Likewise; no ovfl. check.
2712 TLSLE_LDST8_TPREL_LO12_NC = 553,
2713 /// TP-rel. LD/ST off. 11:1.
2714 TLSLE_LDST16_TPREL_LO12 = 554,
2715 /// Likewise; no check.
2716 TLSLE_LDST16_TPREL_LO12_NC = 555,
2717 /// TP-rel. LD/ST off. 11:2.
2718 TLSLE_LDST32_TPREL_LO12 = 556,
2719 /// Likewise; no check.
2720 TLSLE_LDST32_TPREL_LO12_NC = 557,
2721 /// TP-rel. LD/ST off. 11:3.
2722 TLSLE_LDST64_TPREL_LO12 = 558,
2723 /// Likewise; no check.
2724 TLSLE_LDST64_TPREL_LO12_NC = 559,
2725 /// PC-rel. load immediate 20:2.
2726 TLSDESC_LD_PREL19 = 560,
2727 /// PC-rel. ADR immediate 20:0.
2728 TLSDESC_ADR_PREL21 = 561,
2729 /// Page-rel. ADRP imm. 32:12.
2730 TLSDESC_ADR_PAGE21 = 562,
2731 /// Direct LD off. from 11:3.
2732 TLSDESC_LD64_LO12 = 563,
2733 /// Direct ADD imm. from 11:0.
2734 TLSDESC_ADD_LO12 = 564,
2735 /// GOT-rel. MOV{N,Z} imm. 31:16.
2736 TLSDESC_OFF_G1 = 565,
2737 /// GOT-rel. MOVK imm. 15:0; no ck.
2738 TLSDESC_OFF_G0_NC = 566,
2739 /// Relax LDR.
2740 TLSDESC_LDR = 567,
2741 /// Relax ADD.
2742 TLSDESC_ADD = 568,
2743 /// Relax BLR.
2744 TLSDESC_CALL = 569,
2745 /// TP-rel. LD/ST off. 11:4.
2746 TLSLE_LDST128_TPREL_LO12 = 570,
2747 /// Likewise; no check.
2748 TLSLE_LDST128_TPREL_LO12_NC = 571,
2749 /// DTP-rel. LD/ST imm. 11:4.
2750 TLSLD_LDST128_DTPREL_LO12 = 572,
2751 /// Likewise; no check.
2752 TLSLD_LDST128_DTPREL_LO12_NC = 573,
2753 /// Copy symbol at runtime.
2754 COPY = 1024,
2755 /// Create GOT entry.
2756 GLOB_DAT = 1025,
2757 /// Create PLT entry.
2758 JUMP_SLOT = 1026,
2759 /// Adjust by program base.
2760 RELATIVE = 1027,
2761 /// Module number, 64 bit.
2762 TLS_DTPMOD = 1028,
2763 /// Module-relative offset, 64 bit.
2764 TLS_DTPREL = 1029,
2765 /// TP-relative offset, 64 bit.
2766 TLS_TPREL = 1030,
2767 /// TLS Descriptor.
2768 TLSDESC = 1031,
2769 /// STT_GNU_IFUNC relocation.
2770 IRELATIVE = 1032,
2771 _,
2772};
2773
2774/// RISC-V relocations.
2775pub const R_RISCV = enum(u32) {
2776 NONE = 0,
2777 @"32" = 1,
2778 @"64" = 2,
2779 RELATIVE = 3,
2780 COPY = 4,
2781 JUMP_SLOT = 5,
2782 TLS_DTPMOD32 = 6,
2783 TLS_DTPMOD64 = 7,
2784 TLS_DTPREL32 = 8,
2785 TLS_DTPREL64 = 9,
2786 TLS_TPREL32 = 10,
2787 TLS_TPREL64 = 11,
2788 TLSDESC = 12,
2789 BRANCH = 16,
2790 JAL = 17,
2791 CALL = 18,
2792 CALL_PLT = 19,
2793 GOT_HI20 = 20,
2794 TLS_GOT_HI20 = 21,
2795 TLS_GD_HI20 = 22,
2796 PCREL_HI20 = 23,
2797 PCREL_LO12_I = 24,
2798 PCREL_LO12_S = 25,
2799 HI20 = 26,
2800 LO12_I = 27,
2801 LO12_S = 28,
2802 TPREL_HI20 = 29,
2803 TPREL_LO12_I = 30,
2804 TPREL_LO12_S = 31,
2805 TPREL_ADD = 32,
2806 ADD8 = 33,
2807 ADD16 = 34,
2808 ADD32 = 35,
2809 ADD64 = 36,
2810 SUB8 = 37,
2811 SUB16 = 38,
2812 SUB32 = 39,
2813 SUB64 = 40,
2814 GNU_VTINHERIT = 41,
2815 GNU_VTENTRY = 42,
2816 ALIGN = 43,
2817 RVC_BRANCH = 44,
2818 RVC_JUMP = 45,
2819 RVC_LUI = 46,
2820 GPREL_I = 47,
2821 GPREL_S = 48,
2822 TPREL_I = 49,
2823 TPREL_S = 50,
2824 RELAX = 51,
2825 SUB6 = 52,
2826 SET6 = 53,
2827 SET8 = 54,
2828 SET16 = 55,
2829 SET32 = 56,
2830 @"32_PCREL" = 57,
2831 IRELATIVE = 58,
2832 PLT32 = 59,
2833 SET_ULEB128 = 60,
2834 SUB_ULEB128 = 61,
2835 _,
2836};
2837
2838/// PowerPC64 relocations.
2839pub const R_PPC64 = enum(u32) {
2840 NONE = 0,
2841 ADDR32 = 1,
2842 ADDR24 = 2,
2843 ADDR16 = 3,
2844 ADDR16_LO = 4,
2845 ADDR16_HI = 5,
2846 ADDR16_HA = 6,
2847 ADDR14 = 7,
2848 ADDR14_BRTAKEN = 8,
2849 ADDR14_BRNTAKEN = 9,
2850 REL24 = 10,
2851 REL14 = 11,
2852 REL14_BRTAKEN = 12,
2853 REL14_BRNTAKEN = 13,
2854 GOT16 = 14,
2855 GOT16_LO = 15,
2856 GOT16_HI = 16,
2857 GOT16_HA = 17,
2858 COPY = 19,
2859 GLOB_DAT = 20,
2860 JMP_SLOT = 21,
2861 RELATIVE = 22,
2862 REL32 = 26,
2863 PLT16_LO = 29,
2864 PLT16_HI = 30,
2865 PLT16_HA = 31,
2866 ADDR64 = 38,
2867 ADDR16_HIGHER = 39,
2868 ADDR16_HIGHERA = 40,
2869 ADDR16_HIGHEST = 41,
2870 ADDR16_HIGHESTA = 42,
2871 REL64 = 44,
2872 TOC16 = 47,
2873 TOC16_LO = 48,
2874 TOC16_HI = 49,
2875 TOC16_HA = 50,
2876 TOC = 51,
2877 ADDR16_DS = 56,
2878 ADDR16_LO_DS = 57,
2879 GOT16_DS = 58,
2880 GOT16_LO_DS = 59,
2881 PLT16_LO_DS = 60,
2882 TOC16_DS = 63,
2883 TOC16_LO_DS = 64,
2884 TLS = 67,
2885 DTPMOD64 = 68,
2886 TPREL16 = 69,
2887 TPREL16_LO = 70,
2888 TPREL16_HI = 71,
2889 TPREL16_HA = 72,
2890 TPREL64 = 73,
2891 DTPREL16 = 74,
2892 DTPREL16_LO = 75,
2893 DTPREL16_HI = 76,
2894 DTPREL16_HA = 77,
2895 DTPREL64 = 78,
2896 GOT_TLSGD16 = 79,
2897 GOT_TLSGD16_LO = 80,
2898 GOT_TLSGD16_HI = 81,
2899 GOT_TLSGD16_HA = 82,
2900 GOT_TLSLD16 = 83,
2901 GOT_TLSLD16_LO = 84,
2902 GOT_TLSLD16_HI = 85,
2903 GOT_TLSLD16_HA = 86,
2904 GOT_TPREL16_DS = 87,
2905 GOT_TPREL16_LO_DS = 88,
2906 GOT_TPREL16_HI = 89,
2907 GOT_TPREL16_HA = 90,
2908 GOT_DTPREL16_DS = 91,
2909 GOT_DTPREL16_LO_DS = 92,
2910 GOT_DTPREL16_HI = 93,
2911 GOT_DTPREL16_HA = 94,
2912 TPREL16_DS = 95,
2913 TPREL16_LO_DS = 96,
2914 TPREL16_HIGHER = 97,
2915 TPREL16_HIGHERA = 98,
2916 TPREL16_HIGHEST = 99,
2917 TPREL16_HIGHESTA = 100,
2918 DTPREL16_DS = 101,
2919 DTPREL16_LO_DS = 102,
2920 DTPREL16_HIGHER = 103,
2921 DTPREL16_HIGHERA = 104,
2922 DTPREL16_HIGHEST = 105,
2923 DTPREL16_HIGHESTA = 106,
2924 TLSGD = 107,
2925 TLSLD = 108,
2926 ADDR16_HIGH = 110,
2927 ADDR16_HIGHA = 111,
2928 TPREL16_HIGH = 112,
2929 TPREL16_HIGHA = 113,
2930 DTPREL16_HIGH = 114,
2931 DTPREL16_HIGHA = 115,
2932 REL24_NOTOC = 116,
2933 PLTSEQ = 119,
2934 PLTCALL = 120,
2935 PLTSEQ_NOTOC = 121,
2936 PLTCALL_NOTOC = 122,
2937 PCREL_OPT = 123,
2938 PCREL34 = 132,
2939 GOT_PCREL34 = 133,
2940 PLT_PCREL34 = 134,
2941 PLT_PCREL34_NOTOC = 135,
2942 TPREL34 = 146,
2943 DTPREL34 = 147,
2944 GOT_TLSGD_PCREL34 = 148,
2945 GOT_TLSLD_PCREL34 = 149,
2946 GOT_TPREL_PCREL34 = 150,
2947 IRELATIVE = 248,
2948 REL16 = 249,
2949 REL16_LO = 250,
2950 REL16_HI = 251,
2951 REL16_HA = 252,
2952 _,
2953};
2954
2955/// LoongArch relocations, as of v2.50 of the ABI specs.
2956pub const R_LARCH = enum(u32) {
2957 NONE = 0,
2958 @"32" = 1,
2959 @"64" = 2,
2960 RELATIVE = 3,
2961 COPY = 4,
2962 JUMP_SLOT = 5,
2963 TLS_DTPMOD32 = 6,
2964 TLS_DTPMOD64 = 7,
2965 TLS_DTPREL32 = 8,
2966 TLS_DTPREL64 = 9,
2967 TLS_TPREL32 = 10,
2968 TLS_TPREL64 = 11,
2969 IRELATIVE = 12,
2970 TLS_DESC32 = 13,
2971 TLS_DESC64 = 14,
2972 MARK_LA = 20,
2973 MARK_PCREL = 21,
2974 SOP_PUSH_PCREL = 22,
2975 SOP_PUSH_ABSOLUTE = 23,
2976 SOP_PUSH_DUP = 24,
2977 SOP_PUSH_GPREL = 25,
2978 SOP_PUSH_TLS_TPREL = 26,
2979 SOP_PUSH_TLS_GOT = 27,
2980 SOP_PUSH_TLS_GD = 28,
2981 SOP_PUSH_PLT_PCREL = 29,
2982 SOP_ASSERT = 30,
2983 SOP_NOT = 31,
2984 SOP_SUB = 32,
2985 SOP_SL = 33,
2986 SOP_SR = 34,
2987 SOP_ADD = 35,
2988 SOP_AND = 36,
2989 SOP_IF_ELSE = 37,
2990 SOP_POP_32_S_10_5 = 38,
2991 SOP_POP_32_U_10_12 = 39,
2992 SOP_POP_32_S_10_12 = 40,
2993 SOP_POP_32_S_10_16 = 41,
2994 SOP_POP_32_S_10_16_S2 = 42,
2995 SOP_POP_32_S_5_20 = 43,
2996 SOP_POP_32_S_0_5_10_16_S2 = 44,
2997 SOP_POP_32_S_0_10_10_16_S2 = 45,
2998 SOP_POP_32_U = 46,
2999 ADD8 = 47,
3000 ADD16 = 48,
3001 ADD24 = 49,
3002 ADD32 = 50,
3003 ADD64 = 51,
3004 SUB8 = 52,
3005 SUB16 = 53,
3006 SUB24 = 54,
3007 SUB32 = 55,
3008 SUB64 = 56,
3009 GNU_VTINHERIT = 57,
3010 GNU_VTENTRY = 58,
3011 B16 = 64,
3012 B21 = 65,
3013 B26 = 66,
3014 ABS_HI20 = 67,
3015 ABS_LO12 = 68,
3016 ABS64_LO20 = 69,
3017 ABS64_HI12 = 70,
3018 PCALA_HI20 = 71,
3019 PCALA_LO12 = 72,
3020 PCALA64_LO20 = 73,
3021 PCALA64_HI12 = 74,
3022 GOT_PC_HI20 = 75,
3023 GOT_PC_LO12 = 76,
3024 GOT64_PC_LO20 = 77,
3025 GOT64_PC_HI12 = 78,
3026 GOT_HI20 = 79,
3027 GOT_LO12 = 80,
3028 GOT64_LO20 = 81,
3029 GOT64_HI12 = 82,
3030 TLS_LE_HI20 = 83,
3031 TLS_LE_LO12 = 84,
3032 TLS_LE64_LO20 = 85,
3033 TLS_LE64_HI12 = 86,
3034 TLS_IE_PC_HI20 = 87,
3035 TLS_IE_PC_LO12 = 88,
3036 TLS_IE64_PC_LO20 = 89,
3037 TLS_IE64_PC_HI12 = 90,
3038 TLS_IE_HI20 = 91,
3039 TLS_IE_LO12 = 92,
3040 TLS_IE64_LO20 = 93,
3041 TLS_IE64_HI12 = 94,
3042 TLS_LD_PC_HI20 = 95,
3043 TLS_LD_HI20 = 96,
3044 TLS_GD_PC_HI20 = 97,
3045 TLS_GD_HI20 = 98,
3046 @"32_PCREL" = 99,
3047 RELAX = 100,
3048 DELETE = 101,
3049 ALIGN = 102,
3050 PCREL20_S2 = 103,
3051 CFA = 104,
3052 ADD6 = 105,
3053 SUB6 = 106,
3054 ADD_ULEB128 = 107,
3055 SUB_ULEB128 = 108,
3056 @"64_PCREL" = 109,
3057 CALL36 = 110,
3058 TLS_DESC_PC_HI20 = 111,
3059 TLS_DESC_PC_LO12 = 112,
3060 TLS_DESC64_PC_LO20 = 113,
3061 TLS_DESC64_PC_HI12 = 114,
3062 TLS_DESC_HI20 = 115,
3063 TLS_DESC_LO12 = 116,
3064 TLS_DESC64_LO20 = 117,
3065 TLS_DESC64_HI12 = 118,
3066 TLS_DESC_LD = 119,
3067 TLS_DESC_CALL = 120,
3068 TLS_LE_HI20_R = 121,
3069 TLS_LE_ADD_R = 122,
3070 TLS_LE_LO12_R = 123,
3071 TLS_LD_PCREL20_S2 = 124,
3072 TLS_GD_PCREL20_S2 = 125,
3073 TLS_DESC_PCREL20_S2 = 126,
3074 CALL30 = 127,
3075 PCADD_HI20 = 128,
3076 PCADD_LO12 = 129,
3077 GOT_PCADD_HI20 = 130,
3078 GOT_PCADD_LO12 = 131,
3079 TLS_IE_PCADD_HI20 = 132,
3080 TLS_IE_PCADD_LO12 = 133,
3081 TLS_LD_PCADD_HI20 = 134,
3082 TLS_LD_PCADD_LO12 = 135,
3083 TLS_GD_PCADD_HI20 = 136,
3084 TLS_GD_PCADD_LO12 = 137,
3085 TLS_DESC_PCADD_HI20 = 138,
3086 TLS_DESC_PCADD_LO12 = 139,
3087 _,
3088};
3089
3090pub const R_SPARC = enum(u32) {
3091 NONE = 0,
3092 @"8" = 1,
3093 @"16" = 2,
3094 @"32" = 3,
3095 DISP8 = 4,
3096 DISP16 = 5,
3097 DISP32 = 6,
3098 WDISP30 = 7,
3099 WDISP22 = 8,
3100 HI22 = 9,
3101 @"22" = 10,
3102 @"13" = 11,
3103 LO10 = 12,
3104 GOT10 = 13,
3105 GOT13 = 14,
3106 GOT22 = 15,
3107 PC10 = 16,
3108 PC22 = 17,
3109 WPLT30 = 18,
3110 COPY = 19,
3111 GLOB_DAT = 20,
3112 JMP_SLOT = 21,
3113 RELATIVE = 22,
3114 UA32 = 23,
3115 PLT32 = 24,
3116 HIPLT22 = 25,
3117 LOPLT10 = 26,
3118 PCPLT32 = 27,
3119 PCPLT22 = 28,
3120 PCPLT10 = 29,
3121 @"10" = 30,
3122 @"11" = 31,
3123 @"64" = 32,
3124 OLO10 = 33,
3125 HH22 = 34,
3126 HM10 = 35,
3127 LM22 = 36,
3128 PC_HH22 = 37,
3129 PC_HM10 = 38,
3130 PC_LM22 = 39,
3131 WDISP16 = 40,
3132 WDISP19 = 41,
3133 @"7" = 43,
3134 @"5" = 44,
3135 @"6" = 45,
3136 DISP64 = 46,
3137 PLT64 = 47,
3138 HIX22 = 48,
3139 LOX10 = 49,
3140 H44 = 50,
3141 M44 = 51,
3142 L44 = 52,
3143 REGISTER = 53,
3144 UA64 = 54,
3145 UA16 = 55,
3146 TLS_GD_HI22 = 56,
3147 TLS_GD_LO10 = 57,
3148 TLS_GD_ADD = 58,
3149 TLS_GD_CALL = 59,
3150 TLS_LDM_HI22 = 60,
3151 TLS_LDM_LO10 = 61,
3152 TLS_LDM_ADD = 62,
3153 TLS_LDM_CALL = 63,
3154 TLS_LDO_HIX22 = 64,
3155 TLS_LDO_LOX10 = 65,
3156 TLS_LDO_ADD = 66,
3157 TLS_IE_HI22 = 67,
3158 TLS_IE_LO10 = 68,
3159 TLS_IE_LD = 69,
3160 TLS_IE_LDX = 70,
3161 TLS_IE_ADD = 71,
3162 TLS_LE_HIX22 = 72,
3163 TLS_LE_LOX10 = 73,
3164 TLS_DTPMOD32 = 74,
3165 TLS_DTPMOD64 = 75,
3166 TLS_DTPOFF32 = 76,
3167 TLS_DTPOFF64 = 77,
3168 TLS_TPOFF32 = 78,
3169 TLS_TPOFF64 = 79,
3170 GOTDATA_HIX22 = 80,
3171 GOTDATA_LOX10 = 81,
3172 GOTDATA_OP_HIX22 = 82,
3173 GOTDATA_OP_LOX10 = 83,
3174 GOTDATA_OP = 84,
3175 H34 = 85,
3176 SIZE32 = 86,
3177 SIZE64 = 87,
3178 WDISP10 = 88,
3179 IRELATIVE = 249,
3180 _,
3181};
3182
3183pub const ar_hdr = extern struct {
3184 /// Member file name, sometimes / terminated.
3185 ar_name: [16]u8,
3186
3187 /// File date, decimal seconds since Epoch.
3188 ar_date: [12]u8,
3189
3190 /// User ID, in ASCII format.
3191 ar_uid: [6]u8,
3192
3193 /// Group ID, in ASCII format.
3194 ar_gid: [6]u8,
3195
3196 /// File mode, in ASCII octal.
3197 ar_mode: [8]u8,
3198
3199 /// File size, in ASCII decimal.
3200 ar_size: [10]u8,
3201
3202 /// Always contains ARFMAG.
3203 ar_fmag: [2]u8,
3204
3205 pub fn date(self: ar_hdr) std.fmt.ParseIntError!u64 {
3206 const value = mem.trimEnd(u8, &self.ar_date, " ");
3207 return std.fmt.parseInt(u64, value, 10);
3208 }
3209
3210 pub fn size(self: ar_hdr) std.fmt.ParseIntError!u32 {
3211 const value = mem.trimEnd(u8, &self.ar_size, " ");
3212 return std.fmt.parseInt(u32, value, 10);
3213 }
3214
3215 pub fn isStrtab(self: ar_hdr) bool {
3216 return mem.eql(u8, &self.ar_name, STRNAME);
3217 }
3218
3219 pub fn isSymtab(self: ar_hdr) bool {
3220 return mem.eql(u8, &self.ar_name, SYMNAME);
3221 }
3222
3223 pub fn isSymtab64(self: ar_hdr) bool {
3224 return mem.eql(u8, &self.ar_name, SYM64NAME);
3225 }
3226
3227 pub fn isSymdef(self: ar_hdr) bool {
3228 return mem.eql(u8, &self.ar_name, SYMDEFNAME);
3229 }
3230
3231 pub fn isSymdefSorted(self: ar_hdr) bool {
3232 return mem.eql(u8, &self.ar_name, SYMDEFSORTEDNAME);
3233 }
3234
3235 pub fn name(self: *const ar_hdr) ?[]const u8 {
3236 const value = &self.ar_name;
3237 if (value[0] == '/') return null;
3238 const sentinel = mem.findScalar(u8, value, '/') orelse value.len;
3239 return value[0..sentinel];
3240 }
3241
3242 pub fn nameOffset(self: ar_hdr) std.fmt.ParseIntError!?u32 {
3243 const value = &self.ar_name;
3244 if (value[0] != '/') return null;
3245 const trimmed = mem.trimEnd(u8, value, " ");
3246 return try std.fmt.parseInt(u32, trimmed[1..], 10);
3247 }
3248};
3249
3250fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 {
3251 assert(name.len <= 16);
3252 const padding = 16 - name.len;
3253 return name ++ @as([padding]u8, @splat(' '));
3254}
3255
3256// Archive files start with the ARMAG identifying string. Then follows a
3257// `struct ar_hdr', and as many bytes of member file data as its `ar_size'
3258// member indicates, for each member file.
3259/// String that begins an archive file.
3260pub const ARMAG = "!<arch>\n";
3261/// String that begins a thin archive file.
3262pub const ARMAG_THIN = "!<thin>\n";
3263/// String in ar_fmag at the end of each header.
3264pub const ARFMAG = "`\n";
3265/// 32-bit symtab identifier
3266pub const SYMNAME = genSpecialMemberName("/");
3267/// Strtab identifier
3268pub const STRNAME = genSpecialMemberName("//");
3269/// 64-bit symtab identifier
3270pub const SYM64NAME = genSpecialMemberName("/SYM64/");
3271pub const SYMDEFNAME = genSpecialMemberName("__.SYMDEF");
3272pub const SYMDEFSORTEDNAME = genSpecialMemberName("__.SYMDEF SORTED");
3273
3274pub const gnu_hash = struct {
3275
3276 // See https://flapenguin.me/elf-dt-gnu-hash
3277
3278 pub const Header = extern struct {
3279 nbuckets: u32,
3280 symoffset: u32,
3281 bloom_size: u32,
3282 bloom_shift: u32,
3283 };
3284
3285 pub const ChainEntry = packed struct(u32) {
3286 end_of_chain: bool,
3287 /// Contains the top bits of the hash value.
3288 hash: u31,
3289 };
3290
3291 /// Calculate the hash value for a name
3292 pub fn calculate(name: []const u8) u32 {
3293 var h: u32 = 5381;
3294 for (name) |char| {
3295 h = (h << 5) +% h +% char;
3296 }
3297 return h;
3298 }
3299
3300 test calculate {
3301 try std.testing.expectEqual(0x00001505, calculate(""));
3302 try std.testing.expectEqual(0x156b2bb8, calculate("printf"));
3303 try std.testing.expectEqual(0x7c967e3f, calculate("exit"));
3304 try std.testing.expectEqual(0xbac212a0, calculate("syscall"));
3305 try std.testing.expectEqual(0x8ae9f18e, calculate("flapenguin.me"));
3306 }
3307};
3308
3309/// Things for the `SHT.HASH` section type.
3310///
3311/// Resources:
3312/// * https://refspecs.linuxfoundation.org/elf/gabi4+/ch5.dynamic.html#hash
3313/// * https://flapenguin.me/elf-dt-hash
3314/// * https://github.com/IBM/s390x-abi
3315pub const hash = struct {
3316 pub fn calculate(name: []const u8) u32 {
3317 var h: u32 = 0;
3318 for (name) |c| {
3319 h = (h << 4) +% c;
3320 const g = h & 0xF000_0000;
3321 h = (h ^ (g >> 24)) & ~g;
3322 }
3323 return h;
3324 }
3325
3326 /// The header of a `SHT.HASH` section on most architectures. Immediately followed by:
3327 /// * `buckets: [nbucket]u32`
3328 /// * `chains: [nchain]u32`
3329 ///
3330 /// The bucket for a symbol named `name` is `std.elf.hash.calculate(name) % nbuckets`.
3331 ///
3332 /// `buckets[b]` is the index of the first symbol in bucket `b`. If bucket `b` is empty then the
3333 /// value is 0 (`STN_UNDEF`).
3334 ///
3335 /// `chain[sym_index]` is the index of the next symbol in the same bucket as `sym_index`. If
3336 /// `sym_index` is the last symbol in its bucket then the value is 0 (`STN_UNDEF`).
3337 ///
3338 /// See also `Header64`.
3339 pub const Header32 = extern struct {
3340 nbucket: u32,
3341 nchain: u32,
3342 };
3343
3344 /// The header of a `SHT.HASH` section on alpha and s390x. Immediately followed by:
3345 /// * `buckets: [nbucket]u64`
3346 /// * `chains: [nchain]u64`
3347 ///
3348 /// See also `Header32`.
3349 pub const Header64 = extern struct {
3350 nbucket: u64,
3351 nchain: u64,
3352 };
3353};
3354
3355pub const EhdrFlags = packed union(Word) {
3356 int: u32,
3357 loongarch: Loongarch,
3358 sparc: Sparc,
3359
3360 pub const Loongarch = packed struct(u32) {
3361 base_abi_modifier: BaseAbiModifier,
3362 abi_extension: AbiExtension,
3363 abi_version: u2,
3364 reserved: u24 = 0,
3365
3366 pub const BaseAbiModifier = enum(u3) {
3367 s = 1,
3368 f = 2,
3369 d = 3,
3370 _,
3371 };
3372 pub const AbiExtension = enum(u3) { base = 0, _ };
3373 };
3374
3375 pub const Sparc = packed struct(u32) {
3376 mm: MemoryModel,
3377 _reserved1: u6 = 0,
3378 ext: Extensions,
3379 _reserved2: u8 = 0,
3380
3381 pub const MemoryModel = enum(u2) {
3382 /// Total Store Ordering
3383 tso = 0,
3384 /// Partial Store Ordering
3385 pso = 1,
3386 /// Relaxed Memory Ordering
3387 rmo = 2,
3388 };
3389
3390 pub const Extensions = packed struct(u16) {
3391 /// Uses SPARC v8 ABI (w/ 32-bit pointers) on SPARC v9. Also known as v8+.
3392 @"32plus": bool,
3393 /// Uses Sun UltraSPARC extensions.
3394 sun_us1: bool,
3395 /// Uses HaL R1 extensions.
3396 hal_r1: bool,
3397 /// Uses Sun UltraSPARC III extensions.
3398 sun_us3: bool,
3399 _reserved: u11 = 0,
3400 /// Uses little endian data (SPARC v9+).
3401 le_data: bool,
3402 };
3403 };
3404};