Debian Codegraph @

format/elf/types.ha

raw
1 // SPDX-License-Identifier: MPL-2.0
2 // (c) Hare authors <https://harelang.org>
3
4 // TODO:
5 // - Flesh out ELF32 structures
6
7 export def MAGIC: str = "\x7FELF";
8 export def EI_MAG0: uint = 0;
9 export def EI_MAG1: uint = 1;
10 export def EI_MAG2: uint = 2;
11 export def EI_MAG3: uint = 3;
12 export def EI_CLASS: uint = 4;
13 export def EI_DATA: uint = 5;
14 export def EI_VERSION: uint = 6;
15 export def EI_OSABI: uint = 7;
16 export def EI_ABIVERSION: uint = 8;
17 export def EI_PAD: uint = 9;
18 export def EI_NIDENT: uint = 16;
19 export def EV_CURRENT: u32 = 1;
20
21 // ELF header for ELF64
22 export type header64 = struct {
23 // ELF identification
24 e_ident: [EI_NIDENT]u8,
25 // Object file type
26 e_type: elf_type,
27 // Machine type
28 e_machine: elf_machine,
29 // Object file version ([EV_CURRENT])
30 e_version: u32,
31 // Entry point address
32 e_entry: u64,
33 // Program header offset
34 e_phoff: u64,
35 // Section header offset
36 e_shoff: u64,
37 // Processor-specific flags
38 e_flags: u32,
39 // ELF header size
40 e_ehsize: u16,
41 // Size of program header entry
42 e_phentsize: u16,
43 // Number of program header entries
44 e_phnum: u16,
45 // Size of section header entry
46 e_shentsize: u16,
47 // Number of section header entries
48 e_shnum: u16,
49 // Section name string table index, or [shn::UNDEF]
50 e_shstrndx: u16,
51 };
52
53 // Section header for ELF64
54 export type section64 = struct {
55 // Section name
56 sh_name: u32,
57 // Section type
58 sh_type: u32,
59 // Section attributes
60 sh_flags: u64,
61 // Virtual address in memory
62 sh_addr: u64,
63 // Offset in file
64 sh_offset: u64,
65 // Size of section
66 sh_size: u64,
67 // Link to other section
68 sh_link: u32,
69 // Miscellaenous information
70 sh_info: u32,
71 // Address alignment boundary
72 sh_addralign: u64,
73 // Size of entries, if section has table
74 sh_entsize: u64,
75 };
76
77 // ELF file class
78 export type ident_class = enum u8 {
79 // 32-bit objects
80 ELF32 = 1,
81 // 64-bit objects
82 ELF64 = 2,
83 };
84
85 // Byte ordering
86 export type ident_data = enum u8 {
87 // Object file data structures are little-endian
88 LSB = 1,
89 // Object file data structures are big-endian
90 MSB = 2,
91 };
92
93 // Machine architecture
94 export type elf_machine = enum u16 {
95 // Unknown machine
96 NONE = 0,
97 // AT&T WE32100
98 M32 = 1,
99 // Sun SPARC
100 SPARC = 2,
101 // Intel i386
102 I386 = 3,
103 // Motorola 68000
104 M68K = 4,
105 // Motorola 88000
106 M88K = 5,
107 // Intel i860
108 M860 = 7,
109 // MIPS R3000 Big-Endian only
110 MIPS = 8,
111 // IBM System/370
112 S370 = 9,
113 // MIPS R3000 Little-Endian
114 MIPS_RS3_LE = 10,
115 // HP PA-RISC
116 PARISC = 15,
117 // Fujitsu VPP500
118 VPP500 = 17,
119 // SPARC v8plus
120 SPARC32PLUS = 18,
121 // Intel 80960
122 I960 = 19,
123 // PowerPC 32-bit
124 PPC = 20,
125 // PowerPC 64-bit
126 PPC64 = 21,
127 // IBM System/390
128 S390 = 22,
129 // NEC V800
130 V800 = 36,
131 // Fujitsu FR20
132 FR20 = 37,
133 // TRW RH-32
134 RH32 = 38,
135 // Motorola RCE
136 RCE = 39,
137 // ARM
138 ARM = 40,
139 // Hitachi SH
140 SH = 42,
141 // SPARC v9 64-bit
142 SPARCV9 = 43,
143 // Siemens TriCore embedded processor
144 TRICORE = 44,
145 // Argonaut RISC Core
146 ARC = 45,
147 // Hitachi H8/300
148 H8_300 = 46,
149 // Hitachi H8/300H
150 H8_300H = 47,
151 // Hitachi H8S
152 H8S = 48,
153 // Hitachi H8/500
154 H8_500 = 49,
155 // Intel IA-64 Processor
156 IA_64 = 50,
157 // Stanford MIPS-X
158 MIPS_X = 51,
159 // Motorola ColdFire
160 COLDFIRE = 52,
161 // Motorola M68HC12
162 M68HC12 = 53,
163 // Fujitsu MMA
164 MMA = 54,
165 // Siemens PCP
166 PCP = 55,
167 // Sony nCPU
168 NCPU = 56,
169 // Denso NDR1 microprocessor
170 NDR1 = 57,
171 // Motorola Star*Core processor
172 STARCORE = 58,
173 // Toyota ME16 processor
174 ME16 = 59,
175 // STMicroelectronics ST100 processor
176 ST100 = 60,
177 // Advanced Logic Corp. TinyJ processor
178 TINYJ = 61,
179 // Advanced Micro Devices x86-64
180 X86_64 = 62,
181 // Sony DSP Processor
182 PDSP = 63,
183 // Digital Equipment Corp. PDP-10
184 PDP10 = 64,
185 // Digital Equipment Corp. PDP-11
186 PDP11 = 65,
187 // Siemens FX66 microcontroller
188 FX66 = 66,
189 // STMicroelectronics ST9+ 8/16 bit microcontroller
190 ST9PLUS = 67,
191 // STMicroelectronics ST7 8-bit microcontroller
192 ST7 = 68,
193 // Motorola MC68HC16 Microcontroller
194 M68HC16 = 69,
195 // Motorola MC68HC11 Microcontroller
196 M68HC11 = 70,
197 // Motorola MC68HC08 Microcontroller
198 M68HC08 = 71,
199 // Motorola MC68HC05 Microcontroller
200 M68HC05 = 72,
201 // Silicon Graphics SVx
202 SVX = 73,
203 // STMicroelectronics ST19 8-bit microcontroller
204 ST19 = 74,
205 // Digital VAX
206 VAX = 75,
207 // Axis Communications 32-bit embedded processor
208 CRIS = 76,
209 // Infineon Technologies 32-bit embedded processor
210 JAVELIN = 77,
211 // Element 14 64-bit DSP Processor
212 FIREPATH = 78,
213 // LSI Logic 16-bit DSP Processor
214 ZSP = 79,
215 // Donald Knuth's educational 64-bit processor
216 MMIX = 80,
217 // Harvard University machine-independent object files
218 HUANY = 81,
219 // SiTera Prism
220 PRISM = 82,
221 // Atmel AVR 8-bit microcontroller
222 AVR = 83,
223 // Fujitsu FR30
224 FR30 = 84,
225 // Mitsubishi D10V
226 D10V = 85,
227 // Mitsubishi D30V
228 D30V = 86,
229 // NEC v850
230 V850 = 87,
231 // Mitsubishi M32R
232 M32R = 88,
233 // Matsushita MN10300
234 MN10300 = 89,
235 // Matsushita MN10200
236 MN10200 = 90,
237 // picoJava
238 PJ = 91,
239 // OpenRISC 32-bit embedded processor
240 OPENRISC = 92,
241 // ARC International ARCompact processor
242 ARC_COMPACT = 93,
243 // Tensilica Xtensa Architecture
244 XTENSA = 94,
245 // Alphamosaic VideoCore processor
246 VIDEOCORE = 95,
247 // Thompson Multimedia General Purpose Processor
248 TMM_GPP = 96,
249 // National Semiconductor 32000 series
250 NS32K = 97,
251 // Tenor Network TPC processor
252 TPC = 98,
253 // Trebia SNP 1000 processor
254 SNP1K = 99,
255 // STMicroelectronics (www.st.com) ST200 microcontroller
256 ST200 = 100,
257 // Ubicom IP2xxx microcontroller family
258 IP2K = 101,
259 // MAX Processor
260 MAX = 102,
261 // National Semiconductor CompactRISC microprocessor
262 CR = 103,
263 // Fujitsu F2MC16
264 F2MC16 = 104,
265 // Texas Instruments embedded microcontroller msp430
266 MSP430 = 105,
267 // Analog Devices Blackfin (DSP) processor
268 BLACKFIN = 106,
269 // S1C33 Family of Seiko Epson processors
270 SE_C33 = 107,
271 // Sharp embedded microprocessor
272 SEP = 108,
273 // Arca RISC Microprocessor
274 ARCA = 109,
275 // Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University
276 UNICORE = 110,
277 // eXcess: 16/32/64-bit configurable embedded CPU
278 EXCESS = 111,
279 // Icera Semiconductor Inc. Deep Execution Processor
280 DXP = 112,
281 // Altera Nios II soft-core processor
282 ALTERA_NIOS2 = 113,
283 // National Semiconductor CompactRISC CRX microprocessor
284 CRX = 114,
285 // Motorola XGATE embedded processor
286 XGATE = 115,
287 // Infineon C16x/XC16x processor
288 C166 = 116,
289 // Renesas M16C series microprocessors
290 M16C = 117,
291 // Microchip Technology dsPIC30F Digital Signal Controller
292 DSPIC30F = 118,
293 // Freescale Communication Engine RISC core
294 CE = 119,
295 // Renesas M32C series microprocessors
296 M32C = 120,
297 // Altium TSK3000 core
298 TSK3000 = 131,
299 // Freescale RS08 embedded processor
300 RS08 = 132,
301 // Analog Devices SHARC family of 32-bit DSP processors
302 SHARC = 133,
303 // Cyan Technology eCOG2 microprocessor
304 ECOG2 = 134,
305 // Sunplus S+core7 RISC processor
306 SCORE7 = 135,
307 // New Japan Radio (NJR) 24-bit DSP Processor
308 DSP24 = 136,
309 // Broadcom VideoCore III processor
310 VIDEOCORE3 = 137,
311 // RISC processor for Lattice FPGA architecture
312 LATTICEMICO32 = 138,
313 // Seiko Epson C17 family
314 SE_C17 = 139,
315 // The Texas Instruments TMS320C6000 DSP family
316 TI_C6000 = 140,
317 // The Texas Instruments TMS320C2000 DSP family
318 TI_C2000 = 141,
319 // The Texas Instruments TMS320C55x DSP family
320 TI_C5500 = 142,
321 // Texas Instruments Application Specific RISC Processor, 32bit fetch
322 TI_ARP32 = 143,
323 // Texas Instruments Programmable Realtime Unit
324 TI_PRU = 144,
325 // STMicroelectronics 64bit VLIW Data Signal Processor
326 MMDSP_PLUS = 160,
327 // Cypress M8C microprocessor
328 CYPRESS_M8C = 161,
329 // Renesas R32C series microprocessors
330 R32C = 162,
331 // NXP Semiconductors TriMedia architecture family
332 TRIMEDIA = 163,
333 // QUALCOMM DSP6 Processor
334 QDSP6 = 164,
335 // Intel 8051 and variants
336 I8051 = 165,
337 // STMicroelectronics STxP7x family of configurable and extensible RISC processors
338 STXP7X = 166,
339 // Andes Technology compact code size embedded RISC processor family
340 NDS32 = 167,
341 // Cyan Technology eCOG1X family
342 ECOG1 = 168,
343 // Cyan Technology eCOG1X family
344 ECOG1X = 168,
345 // Dallas Semiconductor MAXQ30 Core Micro-controllers
346 MAXQ30 = 169,
347 // New Japan Radio (NJR) 16-bit DSP Processor
348 XIMO16 = 170,
349 // M2000 Reconfigurable RISC Microprocessor
350 MANIK = 171,
351 // Cray Inc. NV2 vector architecture
352 CRAYNV2 = 172,
353 // Renesas RX family
354 RX = 173,
355 // Imagination Technologies META processor architecture
356 METAG = 174,
357 // MCST Elbrus general purpose hardware architecture
358 MCST_ELBRUS = 175,
359 // Cyan Technology eCOG16 family
360 ECOG16 = 176,
361 // National Semiconductor CompactRISC CR16 16-bit microprocessor
362 CR16 = 177,
363 // Freescale Extended Time Processing Unit
364 ETPU = 178,
365 // Infineon Technologies SLE9X core
366 SLE9X = 179,
367 // Intel L10M
368 L10M = 180,
369 // Intel K10M
370 K10M = 181,
371 // ARM 64-bit Architecture (AArch64)
372 AARCH64 = 183,
373 // Atmel Corporation 32-bit microprocessor family
374 AVR32 = 185,
375 // STMicroeletronics STM8 8-bit microcontroller
376 STM8 = 186,
377 // Tilera TILE64 multicore architecture family
378 TILE64 = 187,
379 // Tilera TILEPro multicore architecture family
380 TILEPRO = 188,
381 // Xilinx MicroBlaze 32-bit RISC soft processor core
382 MICROBLAZE = 189,
383 // NVIDIA CUDA architecture
384 CUDA = 190,
385 // Tilera TILE-Gx multicore architecture family
386 TILEGX = 191,
387 // CloudShield architecture family
388 CLOUDSHIELD = 192,
389 // KIPO-KAIST Core-A 1st generation processor family
390 COREA_1ST = 193,
391 // KIPO-KAIST Core-A 2nd generation processor family
392 COREA_2ND = 194,
393 // Synopsys ARCompact V2
394 ARC_COMPACT2 = 195,
395 // Open8 8-bit RISC soft processor core
396 OPEN8 = 196,
397 // Renesas RL78 family
398 RL78 = 197,
399 // Broadcom VideoCore V processor
400 VIDEOCORE5 = 198,
401 // Renesas 78KOR family
402 R78KOR = 199,
403 // Freescale 56800EX Digital Signal Controller (DSC)
404 F56800EX = 200,
405 // Beyond BA1 CPU architecture
406 BA1 = 201,
407 // Beyond BA2 CPU architecture
408 BA2 = 202,
409 // XMOS xCORE processor family
410 XCORE = 203,
411 // Microchip 8-bit PIC(r) family
412 MCHP_PIC = 204,
413 // Reserved by Intel
414 INTEL205 = 205,
415 // Reserved by Intel
416 INTEL206 = 206,
417 // Reserved by Intel
418 INTEL207 = 207,
419 // Reserved by Intel
420 INTEL208 = 208,
421 // Reserved by Intel
422 INTEL209 = 209,
423 // KM211 KM32 32-bit processor
424 KM32 = 210,
425 // KM211 KMX32 32-bit processor
426 KMX32 = 211,
427 // KM211 KMX16 16-bit processor
428 KMX16 = 212,
429 // KM211 KMX8 8-bit processor
430 KMX8 = 213,
431 // KM211 KVARC processor
432 KVARC = 214,
433 // Paneve CDP architecture family
434 CDP = 215,
435 // Cognitive Smart Memory Processor
436 COGE = 216,
437 // Bluechip Systems CoolEngine
438 COOL = 217,
439 // Nanoradio Optimized RISC
440 NORC = 218,
441 // CSR Kalimba architecture family
442 CSR_KALIMBA = 219,
443 // Zilog Z80
444 Z80 = 220,
445 // Controls and Data Services VISIUMcore processor
446 VISIUM = 221,
447 // FTDI Chip FT32 high performance 32-bit RISC architecture
448 FT32 = 222,
449 // Moxie processor family
450 MOXIE = 223,
451 // AMD GPU architecture
452 AMDGPU = 224,
453 // RISC-V
454 RISCV = 243,
455 // Lanai 32-bit processor
456 LANAI = 244,
457 // Linux BPF – in-kernel virtual machine
458 BPF = 247,
459
460 // Intel i486 (deprecated)
461 I486 = 6,
462 // MIPS R4000 Big-Endian (deprecated)
463 MIPS_RS4_BE = 10,
464 // Digital Alpha (deprecated)
465 ALPHA_STD = 41,
466 // Alpha (deprecated)
467 ALPHA = 0x9026,
468 };
469
470 // ELF file type
471 export type elf_type = enum u16 {
472 // No file type
473 NONE = 0,
474 // Relocatable object file
475 REL = 1,
476 // Executable file
477 EXEC = 2,
478 // Shared object file
479 DYN = 3,
480 // Core file
481 CORE = 4,
482 // Environment-specific use
483 LOOS = 0xFE00,
484 // Environment-specific use
485 HIOS = 0xFEFF,
486 // Processor-specific use
487 LOPROC = 0xFF00,
488 // Processor-specific use
489 HIPROC = 0xFFFF,
490 };
491
492 // Application binary interface
493 export type ident_abi = enum u8 {
494 // System-V ABI
495 SYSV = 0,
496 // HP-UX operating system
497 HPUX = 1,
498 // Standalone (embedded) application
499 STANDALONE = 255,
500 };
501
502 // Special section indicies
503 export type shn = enum u16 {
504 // Used to mark an undefined or meaningless section reference
505 UNDEF = 0,
506 // Processor-specific use
507 LOPROC = 0xFF00,
508 // Processor-specific use
509 HIPROC = 0xFF1F,
510 // Environment-specific-use
511 LOOS = 0xFF20,
512 // Environment-specific-use
513 HIOS = 0xFF3F,
514 // Indicates that the corresponding reference is an absolute value
515 ABS = 0xFFF1,
516 // Indicates a symbol that has been declared as a common block
517 COMMON = 0xFFF2,
518 };
519
520 // Section type
521 export type sht = enum u32 {
522 // Marks an unused section header
523 NULL = 0,
524 // Contains information defined by the program
525 PROGBITS = 1,
526 // Contains a linker symbol table
527 SYMTAB = 2,
528 // Contains a string table
529 STRTAB = 3,
530 // Contains "Rela" type relocation entries
531 RELA = 4,
532 // Contains a symbol hash table
533 HASH = 5,
534 // Contains dynamic linking tables
535 DYNAMIC = 6,
536 // Contains note information
537 NOTE = 7,
538 // Contains uninitialized space; does not occupy any space in the file
539 NOBITS = 8,
540 // Contains "Rel" type relocation entries
541 REL = 9,
542 // Reserved
543 SHLIB = 10,
544 // Contains a dynamic loader symbol table
545 DYNSYM = 11,
546 // Environment-specific use
547 LOOS = 0x60000000,
548 // Environment-specific use
549 HIOS = 0x6FFFFFFF,
550 // Processor-specific use
551 LOPROC = 0x70000000,
552 // Processor-specific use
553 HIPROC = 0x7FFFFFFF,
554 };
555
556 // Section flags
557 export type shf = enum u32 {
558 // Section contains no data
559 NONE = 0,
560 // Section contains writable data
561 WRITE = 0x1,
562 // Section is allocated in memory image of program
563 ALLOC = 0x2,
564 // Section contains executable instructions
565 EXECINSTR = 0x4,
566 // Environment-specific use
567 MASKOS = 0x0F000000,
568 // Processor-specific use
569 MASKPROC = 0xF0000000,
570 };
571
572 // Symbol table entry
573 export type sym64 = struct {
574 // Symbol name offset
575 st_name: u32,
576 // Type and binding attributes
577 st_info: u8,
578 // Reserved
579 st_other: u8,
580 // Section table index
581 st_shndx: u16,
582 // Symbol value
583 st_value: u64,
584 // Size of object
585 st_size: u64,
586 };
587
588 // Symbol bindings
589 export type stb = enum u8 {
590 // Not visible outside the object file
591 LOCAL = 0,
592 // Global symbol, visible to all object files
593 GLOBAL = 1,
594 // Global scope, but with lower precedence than global symbols
595 WEAK = 2,
596 // Environment-specific use
597 LOOS = 10,
598 // Environment-specific use
599 HIOS = 12,
600 // Processor-specific use
601 LOPROC = 13,
602 // Processor-specific use
603 HIPROC = 15,
604 };
605
606 // Obtains the binding part of [sym64.st_info].
607 //
608 // Equivalent to the ELF64_ST_BIND macro.
609 export fn st_bind(i: u8) stb = (i >> 4): stb;
610
611 // Symbol types
612 export type stt = enum u8 {
613 // No type specified (e.g. an absolute symbol)
614 NOTYPE = 0,
615 // Data object
616 OBJECT = 1,
617 // Function entry point
618 FUNC = 2,
619 // Symbol is associated with a section
620 SECTION = 3,
621 // Source file associated with the object
622 FILE = 4,
623 // Symbol is a common data object
624 COMMON = 5,
625 // Environment-specific use
626 LOOS = 10,
627 // Environment-specific use
628 HIOS = 12,
629 // Processor-specific use
630 LOPROC = 13,
631 // Processor-specific use
632 HIPROC = 15,
633 };
634
635 // Obtains the type part of [sym64.st_info].
636 //
637 // Equivalent to the ELF64_ST_TYPE macro.
638 export fn st_type(i: u8) stt = (i & 0xF): stt;
639
640 // Converts symbol bindings and type into [sym64.st_info].
641 //
642 // Equivalent to the ELF64_ST_INFO macro.
643 export fn st_info(b: stb, t: stt) u8 = b: u8 << 4 + t: u8 & 0xF;
644
645 // Relocation entry
646 export type rel64 = struct {
647 // Address of reference
648 r_offset: u64,
649 // Symbol table index and type of relocation
650 r_info: u64,
651 };
652
653 // Relocation entry with explicit addend
654 export type rela64 = struct {
655 // Address of reference
656 r_offset: u64,
657 // Symbol table index and type of relocation
658 r_info: u64,
659 // Constant part of expression
660 r_addend: i64,
661 };
662
663 // Obtains the symbol table index part of [rel64.r_info].
664 //
665 // Equivalent to the ELF64_R_SYM macro.
666 export fn r64_sym(info: u64) u64 = info >> 32;
667
668 // Obtains the relocation type part of [rel64.r_info].
669 //
670 // Equivalent to the ELF64_R_TYPE macro.
671 export fn r64_type(info: u64) u64 = info & 0xFFFFFFFF;
672
673 // Converts symbol table index and a relocation type into [rel64.r_info].
674 //
675 // Equivalent to the ELF64_R_INFO macro.
676 export fn r64_info(sym: u64, stype: u64) u64 = sym << 32 | stype & 0xFFFFFFFF;
677
678 // Program header table entry (segment)
679 export type phdr64 = struct {
680 // Type of segment
681 p_type: pt,
682 // Segment attributes
683 p_flags: u32,
684 // Offset in file
685 p_offset: u64,
686 // Virtual address in memory
687 p_vaddr: u64,
688 // Reserved
689 p_paddr: u64,
690 // Size of segment in file
691 p_filesz: u64,
692 // Size of segment in memory
693 p_memsz: u64,
694 // Alignment of segment
695 p_align: u64,
696 };
697
698 // Segment types
699 export type pt = enum u32 {
700 // Unused entry
701 NULL = 0,
702 // Loadable segment
703 LOAD = 1,
704 // Dynamic linking tables
705 DYNAMIC = 2,
706 // Program interpreter path name
707 INTERP = 3,
708 // Note sections
709 NOTE = 4,
710 // Reserved
711 SHLIB = 5,
712 // Program header table
713 PHDR = 6,
714 // Environment-specific use
715 LOOS = 0x60000000,
716 // Environment-specific use
717 HIOS = 0x6FFFFFFF,
718 // Processor-specific use
719 LOPROC = 0x70000000,
720 // Processor-specific use
721 HIPROC = 0x7FFFFFFF,
722 };
723
724 // Segment attributes
725 export type pf = enum u32 {
726 // No permission
727 NONE = 0,
728 // Execute permission
729 X = 0x1,
730 // Write permission
731 W = 0x2,
732 // Read permission
733 R = 0x4,
734 // Reserved for environment-specific use
735 MASKOS = 0x00FF0000,
736 // Reserved for processor-specific use
737 MASKPROC = 0xFF000000,
738 };
739
740 // Dynamic table entry
741 export type dyn64 = struct {
742 // The type of this entry
743 d_tag: dt,
744 // Additional data associated with this entry. The value which is valid
745 // is selected based on the entry type.
746 union {
747 d_val: u64,
748 d_ptr: u64,
749 },
750 };
751
752 // Dynamic table entry type
753 export type dt = enum i64 {
754 // Marks the end of the dynamic array.
755 NULL = 0,
756 // The string table offset of the name of a needed library.
757 NEEDED = 1,
758 // Total size, in bytes, of the relocation entries associated with the
759 // procedure linkage table.
760 PLTRELSZ = 2,
761 // Contains an address associated with the linkage table. The specific
762 // meaning of this field is processor-dependent.
763 PLTGOT = 3,
764 // Address of the symbol hash table.
765 HASH = 4,
766 // Address of the dynamic string table.
767 STRTAB = 5,
768 // Address of the dynamic symbol table.
769 SYMTAB = 6,
770 // Address of a relocation table with rela64 entries.
771 RELA = 7,
772 // Total size, in bytes, of the RELA relocation table.
773 RELASZ = 8,
774 // Size, in bytes, of each RELA relocation entry.
775 RELAENT = 9,
776 // Total size, in bytes, of the string table.
777 STRSZ = 10,
778 // Size, in bytes, of each symbol table entry.
779 SYMENT = 11,
780 // Address of the initialization function.
781 INIT = 12,
782 // Address of the termination function.
783 FINI = 13,
784 // The string table offset of the name of this shared object.
785 SONAME = 14,
786 // The string table offset of a shared library search path string.
787 RPATH = 15,
788 // The presence of this dynamic table entry modifies the symbol
789 // resolution algorithm for references within the library. Symbols
790 // defined within the library are used to resolve references before the
791 // dynamic linker searches the usual search path.
792 SYMBOLIC = 16,
793 // Address of a relocation table with rel64 entries.
794 REL = 17,
795 // Total size, in bytes, of the REL relocation table.
796 RELSZ = 18,
797 // Size, in bytes, of each REL relocation entry.
798 RELENT = 19,
799 // Type of relocation entry used for the procedure linkage table. The
800 // d_val member contains either [dt::REL] or [dt::RELA].
801 PLTREL = 20,
802 // Reserved for debugger use.
803 DEBUG = 21,
804 // The presence of this dynamic table entry signals that the relocation
805 // table contains relocations for a non-writable segment.
806 TEXTREL = 22,
807 // Address of the relocations associated with the procedure linkage
808 // table.
809 JMPREL = 23,
810 // The presence of this dynamic table entry signals that the dynamic
811 // loader should process all relocations for this object before
812 // transferring control to the program.
813 BIND_NOW = 24,
814 // Pointer to an array of initialiation functions.
815 INIT_ARRAY = 25,
816 // Pointer to an array of termination functions.
817 FINI_ARRAY = 26,
818 // Size, in bytes, of the array of initialization functions.
819 INIT_ARRAYSZ = 27,
820 // Size, in bytes, of the array of termination functions.
821 FINI_ARRAYSZ = 28,
822 // Reserved for environment-specific use.
823 LOOS = 0x60000000,
824
825 // Symbol versioning entry types, GNU extension
826 // Version table records
827 // .gnu.version section address
828 VERSYM = 0x6FFFFFF0,
829 // .gnu.version_d section address
830 VERDEF = 0x6FFFFFFC,
831 // Number of version definitions
832 VERDEFNUM = 0x6FFFFFFD,
833 // .gnu.version_r section address
834 VERNEED = 0x6FFFFFFE,
835 // Number of needed versions
836 VERNEEDNUM = 0x6FFFFFFF,
837
838 // Reserved for environment-specific use.
839 HIOS = 0x6FFFFFFF,
840 // Reserved for processor-specific use.
841 LOPROC = 0x70000000,
842 // Reserved for processor-specific use.
843 HIPROC = 0x7FFFFFFF,
844 };
845
846 // Auxiliary vector
847 export type auxv64 = struct {
848 // Entry type
849 a_type: at,
850 union {
851 // Integer value
852 a_val: u64,
853 a_ptr: *opaque,
854 a_fnc: *fn() void,
855 }
856 };
857
858 // Legal auxiliary vector entry types
859 export type at = enum u64 {
860 // End of vector
861 NULL = 0,
862 // Entry should be ignored
863 IGNORE = 1,
864 // File descriptor of program
865 EXECFD = 2,
866 // Program headers for program
867 PHDR = 3,
868 // Size of program header entry
869 PHENT = 4,
870 // Number of program headers
871 PHNUM = 5,
872 // System page size
873 PAGESZ = 6,
874 // Base address of interpreter
875 BASE = 7,
876 // Flags
877 FLAGS = 8,
878 // Entry point of program
879 ENTRY = 9,
880 // Program is not ELF
881 NOTELF = 10,
882 // Real uid
883 UID = 11,
884 // Effective uid
885 EUID = 12,
886 // Real gid
887 GID = 13,
888 // Effective gid
889 EGID = 14,
890 // Frequency of times()
891 CLKTCK = 17,
892
893 // String identifying platform.
894 PLATFORM = 15,
895 // Machine-dependent hints about processor capabilities.
896 HWCAP = 16,
897
898 // Used FPU control word.
899 FPUCW = 18,
900
901 // Data cache block size.
902 DCACHEBSIZE = 19,
903 // Instruction cache block size.
904 ICACHEBSIZE = 20,
905 // Unified cache block size.
906 UCACHEBSIZE = 21,
907
908 // A special ignored value for PPC, used by the kernel to control the
909 // interpretation of the AUXV. Must be > 16.
910 // Entry should be ignored.
911 IGNOREPPC = 22,
912 // Boolean, was exec setuid-like?
913 SECURE = 23,
914 // String identifying real platforms.
915 BASE_PLATFORM = 24,
916 // Address of 16 random bytes.
917 RANDOM = 25,
918 // More machine-dependent hints about processor capabilities.
919 HWCAP2 = 26,
920 // Filename of executable.
921 EXECFN = 31,
922
923 // Pointer to the global system page used for system calls and other
924 // nice things.
925 SYSINFO = 32,
926 SYSINFO_EHDR = 33,
927
928 // Shapes of the caches. Bits 0-3 contains associativity, bits 4-7 contains
929 // log2 of line size, mask those to get cache size.
930 L1I_CACHESHAPE = 34,
931 L1D_CACHESHAPE = 35,
932 L2_CACHESHAPE = 36,
933 L3_CACHESHAPE = 37,
934
935 // Shapes of the caches, with more room to describe them.
936 // *GEOMETRY are comprised of cache line size in bytes in the bottom 16 bits
937 // and the cache associativity in the next 16 bits.
938 L1I_CACHESIZE = 40,
939 L1I_CACHEGEOMETRY = 41,
940 L1D_CACHESIZE = 42,
941 L1D_CACHEGEOMETRY = 43,
942 L2_CACHESIZE = 44,
943 L2_CACHEGEOMETRY = 45,
944 L3_CACHESIZE = 46,
945 L3_CACHEGEOMETRY = 47,
946
947 // Stack needed for signal delivery (AArch64).
948 MINSIGSTKSZ = 51,
949 };
950
951 // Version definition section
952 export type verdef64 = struct {
953 // Version revision
954 vd_version: u16,
955 // Version information
956 vd_flags: u16,
957 // Version Index
958 vd_ndx: u16,
959 // Number of associated aux entries
960 vd_cnt: u16,
961 // Version name hash value
962 vd_hash: u32,
963 // Offset in bytes to verdaux array
964 vd_aux: u32,
965 // Offset in bytes to next verdef entry
966 vd_next: u32,
967 };
968
969 // Auxiliary version information
970 export type verdaux64 = struct {
971 vda_name: u32,
972 vda_next: u32,
973 };
974
975 // Version revision values
976 export type ver_def = enum u16 {
977 NONE = 0,
978 CURRENT = 1,
979 NUM = 2,
980 };
981
982 // Version information flags
983 export type ver_flg = enum u16 {
984 BASE = 0x1,
985 WEAK = 0x2,
986 };
987
988 // Versym index values
989 export type ver_ndx = enum u16 {
990 LOCAL = 0,
991 GLOBAL = 1,
992 LORESERVE = 0xff00,
993 ELIMINATE = 0xff01,
994 };
995
996 // DT_HASH section header
997 export type hashhdr = struct {
998 nbucket: u32,
999 nchain: u32,
1000 };