PatchworkOS  c9fea19
A non-POSIX operating system.
Loading...
Searching...
No Matches
elf.h
Go to the documentation of this file.
1#ifndef _SYS_ELF_H
2#define _SYS_ELF_H 1
3
4#include <stdbool.h>
5#include <stdint.h>
6
7/**
8 * @brief Executable and linkable format definitions.
9 * @defgroup libstd_sys_elf ELF file
10 * @ingroup libstd
11 *
12 * The ELF (Executable and Linkable Format) is a commonly utilized file format for generic binary files, including
13 * executables, object code, shared libraries, etc. and we utilize it in various parts of the operating system.
14 *
15 * Only 64-bit ELF is implemented/handled in PatchworkOS.
16 *
17 * For the sake of alignment with the ELF specification we use the same naming conventions, even if they are different
18 * from the usual conventions used in PatchworkOS.
19 *
20 * @see [ELF Specification](https://gabi.xinuos.com/index.html) for more information.
21 * @see [https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf] for the x86_64 ABI specification.
22 *
23 * @{
24 */
25
26/**
27 * @brief ELF64 Unsigned program address
28 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
29 */
31
32/**
33 * @brief ELF64 Unsigned file offset
34 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
35 */
37
38/**
39 * @brief ELF64 Unsigned medium integer
40 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
41 */
43
44/**
45 * @brief ELF64 Unsigned integer
46 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
47 */
49
50/**
51 * @brief ELF64 Signed integer
52 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
53 */
55
56/**
57 * @brief ELF64 Unsigned long integer
58 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
59 */
61
62/**
63 * @brief ELF64 Signed long integer
64 * @see https://gabi.xinuos.com/elf/01-intro.html#file-format
65 */
67
68/**
69 * @brief Indices for `e_ident[]`.
70 * @see https://gabi.xinuos.com/elf/02-eheader.html
71 */
72typedef enum
73{
74 EI_MAG0 = 0, ///< Index of magic number byte 0
75 EI_MAG1 = 1, ///< Index of magic number byte 1
76 EI_MAG2 = 2, ///< Index of magic number byte 2
77 EI_MAG3 = 3, ///< Index of magic number byte 3
78 EI_CLASS = 4, ///< Index of the file class byte
79 EI_DATA = 5, ///< Index of the data encoding byte
80 EI_VERSION = 6, ///< Index of the file version byte
81 EI_OSABI = 7, ///< Index of the OS/ABI identification byte
82 EI_ABIVERSION = 8, ///< Index of the ABI version byte
83 EI_PAD = 9, ///< Index of the start of padding bytes
84 EI_NIDENT = 16 ///< Total size of e_ident
86
87/**
88 * @brief ELF64 Header
89 *
90 * Stored in the beginning of an ELF file.
91 *
92 * @see https://gabi.xinuos.com/elf/02-eheader.html
93 */
94typedef struct
95{
96 unsigned char e_ident[EI_NIDENT]; ///< Identification bytes
97 Elf64_Half e_type; ///< Object file type
98 Elf64_Half e_machine; ///< The required architecture
99 Elf64_Word e_version; ///< Object file version
100 Elf64_Addr e_entry; ///< Entry point virtual address
101 Elf64_Off e_phoff; ///< Program header tables's file offset in bytes, or 0 if there are no program headers
102 Elf64_Off e_shoff; ///< Section header table's file offset in bytes, or 0 if there are no section headers
103 Elf64_Word e_flags; ///< Processor-specific flags
104 Elf64_Half e_ehsize; ///< Size of this header in bytes, should be `sizeof(Elf64_Ehdr)`
105 Elf64_Half e_phentsize; ///< Size in bytes of one entry in the files program header table.
106 Elf64_Half e_phnum; ///< Number of entries in the program header table.
107 Elf64_Half e_shentsize; ///< Size in bytes of one entry in the files section header table.
108 /**
109 * Number of entries in the section header table, or `0` if there are no section headers.
110 *
111 * If the number of sections is greater than or equal to `SHN_LORESERVE` (0xff00), this field contains `0` and the
112 * actual number of section header table entires is contained in the `sh_size` field of section header index `0`.
113 */
115 /**
116 * Section header table index of the entry associated with the section name string table, or `SHN_UNDEF` if there
117 * are no section names.
118 *
119 * If the section name string table section index is greater than or equal to `SHN_LORESERVE` (0xff00), this field
120 * contains `SHN_XINDEX(0xffff)` and the actual section index is contained in the `sh_link` field of section header
121 * index `0`.
122 */
124} Elf64_Ehdr;
125
126/**
127 * @brief Expected magic values in `e_ident[EI_MAG0]` to `e_ident[EI_MAG3]`.
128 * @see https://gabi.xinuos.com/elf/02-eheader.html
129 */
130typedef enum
131{
132 ELFMAG0 = 0x7f, ///< Expected value for `e_ident[EI_MAG0]`
133 ELFMAG1 = 'E', ///< Expected value for `e_ident[EI_MAG1]`
134 ELFMAG2 = 'L', ///< Expected value for `e_ident[EI_MAG2]`
135 ELFMAG3 = 'F' ///< Expected value for `e_ident[EI_MAG3]`
137
138/**
139 * @brief File class values for `e_ident[EI_CLASS]`.
140 *
141 * Identifies whether the file is 32-bit or 64-bit.
142 *
143 * @see https://gabi.xinuos.com/elf/02-eheader.html
144 */
145typedef enum
146{
147 ELFCLASSNONE = 0, ///< Invalid class
148 ELFCLASS32 = 1, ///< 32-bit objects
149 ELFCLASS64 = 2 ///< 64-bit objects, we always expect this value
151
152/**
153 * @brief Data encoding values for `e_ident[EI_DATA]`.
154 *
155 * Identifies the endianness of the file.
156 *
157 * @see https://gabi.xinuos.com/elf/02-eheader.html
158 */
159typedef enum
160{
161 ELFDATANONE = 0, ///< Invalid data encoding
162 ELFDATALSB = 1, ///< Little-endian encoding, we always expect this value
163 ELFDATAMSB = 2 ///< Big-endian encoding
165
166/**
167 * @brief Version values for `e_ident[EI_VERSION]` and `e_version`.
168 * @see https://gabi.xinuos.com/elf/02-eheader.html
169 */
170typedef enum
171{
172 EV_NONE = 0, ///< Invalid version
173 EV_CURRENT = 1 ///< Current version, we always expect this value
175
176/**
177 * @brief OS/ABI identification values for `e_ident[EI_OSABI]`.
178 *
179 * Defines the expected operating system or ABI for the file.
180 *
181 * Even if we are in fact not Linux or GNU, we still expect this value or `0` since we for the most part follow the same
182 * conventions.
183 *
184 * We ignore the "ABI Version" field `e_ident[EI_ABIVERSION]` entirely.
185 *
186 * @see https://gabi.xinuos.com/elf/b-osabi.html
187 */
188typedef enum
189{
190 ELFOSABI_NONE = 0, ///< No extensions or unspecified
191 ELFOSABI_HPUX = 1, ///< Hewlett-Packard HP-UX
192 ELFOSABI_NETBSD = 2, ///< NetBSD
193 ELFOSABI_GNU = 3, ///< GNU, we always expect this value
194 ELFOSABI_LINUX = 3, ///< Linux, alias for ELFOSABI_GNU
195 ELFOSABI_SOLARIS = 6, ///< Sun Solaris
196 ELFOSABI_AIX = 7, ///< IBM AIX
197 ELFOSABI_IRIX = 8, ///< SGI Irix
198 ELFOSABI_FREEBSD = 9, ///< FreeBSD
199 ELFOSABI_TRU64 = 10, ///< Compaq TRU64 UNIX
200 ELFOSABI_MODESTO = 11, ///< Novell Modesto
201 ELFOSABI_OPENBSD = 12, ///< Open BSD
202 ELFOSABI_OPENVMS = 13, ///< Open VMS
203 ELFOSABI_NSK = 14, ///< Hewlett-Packard Non-Stop Kernel
204 ELFOSABI_AROS = 15, ///< Amiga Research OS
205 ELFOSABI_FENIXOS = 16, ///< Fenix OS
206 ELFOSABI_CLOUDABI = 17, ///< Nuxi CloudABI
207 ELFOSABI_OPENVOS = 18 ///< Stratus Technologies OpenVOS
209
210/**
211 * @brief Object file type values for `e_type`.
212 * @see https://gabi.xinuos.com/elf/02-eheader.html
213 */
214typedef enum
215{
216 ET_NONE = 0, ///< No file type
217 ET_REL = 1, ///< Relocatable file
218 ET_EXEC = 2, ///< Executable file
219 ET_DYN = 3, ///< Shared object file
220 ET_CORE = 4 ///< Core file
222
223/**
224 * @brief Machine architecture values for `e_machine`.
225 * @see https://gabi.xinuos.com/elf/a-emachine.html
226 */
227typedef enum
228{
229 EM_NONE = 0, ///< No machine
230 EM_M32 = 1, ///< AT&T WE 32100
231 EM_SPARC = 2, ///< SPARC
232 EM_386 = 3, ///< Intel 80386
233 EM_68K = 4, ///< Motorola 68000
234 EM_88K = 5, ///< Motorola 88000
235 EM_IAMCU = 6, ///< Intel MCU
236 EM_860 = 7, ///< Intel 80860
237 EM_MIPS = 8, ///< MIPS I Architecture
238 EM_S370 = 9, ///< IBM System/370 Processor
239 EM_MIPS_RS3_LE = 10, ///< MIPS RS3000 Little-endian
240 EM_PARISC = 15, ///< Hewlett-Packard PA-RISC
241 EM_VPP500 = 17, ///< Fujitsu VPP500
242 EM_SPARC32PLUS = 18, ///< Enhanced instruction set SPARC
243 EM_960 = 19, ///< Intel 80960
244 EM_PPC = 20, ///< PowerPC
245 EM_PPC64 = 21, ///< 64-bit PowerPC
246 EM_S390 = 22, ///< IBM System/390 Processor
247 EM_SPU = 23, ///< IBM SPU/SPC
248 EM_V800 = 36, ///< NEC V800
249 EM_FR20 = 37, ///< Fujitsu FR20
250 EM_RH32 = 38, ///< TRW RH-32
251 EM_RCE = 39, ///< Motorola RCE
252 EM_ARM = 40, ///< ARM 32-bit architecture (AARCH32)
253 EM_ALPHA = 41, ///< Digital Alpha
254 EM_SH = 42, ///< Hitachi SH
255 EM_SPARCV9 = 43, ///< SPARC Version 9
256 EM_TRICORE = 44, ///< Siemens TriCore embedded processor
257 EM_ARC = 45, ///< Argonaut RISC Core, Argonaut Technologies Inc.
258 EM_H8_300 = 46, ///< Hitachi H8/300
259 EM_H8_300H = 47, ///< Hitachi H8/300H
260 EM_H8S = 48, ///< Hitachi H8S
261 EM_H8_500 = 49, ///< Hitachi H8/500
262 EM_IA_64 = 50, ///< Intel IA-64 processor architecture
263 EM_MIPS_X = 51, ///< Stanford MIPS-X
264 EM_COLDFIRE = 52, ///< Motorola ColdFire
265 EM_68HC12 = 53, ///< Motorola M68HC12
266 EM_MMA = 54, ///< Fujitsu MMA Multimedia Accelerator
267 EM_PCP = 55, ///< Siemens PCP
268 EM_NCPU = 56, ///< Sony nCPU embedded RISC processor
269 EM_NDR1 = 57, ///< Denso NDR1 microprocessor
270 EM_STARCORE = 58, ///< Motorola Star*Core processor
271 EM_ME16 = 59, ///< Toyota ME16 processor
272 EM_ST100 = 60, ///< STMicroelectronics ST100 processor
273 EM_TINYJ = 61, ///< Advanced Logic Corp. TinyJ embedded processor family
274 EM_X86_64 = 62, ///< AMD x86-64 architecture, we always expect this value
275 EM_PDSP = 63, ///< Sony DSP Processor
276 EM_PDP10 = 64, ///< Digital Equipment Corp. PDP-10
277 EM_PDP11 = 65, ///< Digital Equipment Corp. PDP-11
278 EM_FX66 = 66, ///< Siemens FX66 microcontroller
279 EM_ST9PLUS = 67, ///< STMicroelectronics ST9+ 8/16 bit microcontroller
280 EM_ST7 = 68, ///< STMicroelectronics ST7 8-bit microcontroller
281 EM_68HC16 = 69, ///< Motorola MC68HC16 Microcontroller
282 EM_68HC11 = 70, ///< Motorola MC68HC11 Microcontroller
283 EM_68HC08 = 71, ///< Motorola MC68HC08 Microcontroller
284 EM_68HC05 = 72, ///< Motorola MC68HC05 Microcontroller
285 EM_SVX = 73, ///< Silicon Graphics SVx
286 EM_ST19 = 74, ///< STMicroelectronics ST19 8-bit microcontroller
287 EM_VAX = 75, ///< Digital VAX
288 EM_CRIS = 76, ///< Axis Communications 32-bit embedded processor
289 EM_JAVELIN = 77, ///< Infineon Technologies 32-bit embedded processor
290 EM_FIREPATH = 78, ///< Element 14 64-bit DSP Processor
291 EM_ZSP = 79, ///< LSI Logic 16-bit DSP Processor
292 EM_MMIX = 80, ///< Donald Knuth’s educational 64-bit processor
293 EM_HUANY = 81, ///< Harvard University machine-independent object files
294 EM_PRISM = 82, ///< SiTera Prism
295 EM_AVR = 83, ///< Atmel AVR 8-bit microcontroller
296 EM_FR30 = 84, ///< Fujitsu FR30
297 EM_D10V = 85, ///< Mitsubishi D10V
298 EM_D30V = 86, ///< Mitsubishi D30V
299 EM_V850 = 87, ///< NEC v850
300 EM_M32R = 88, ///< Mitsubishi M32R
301 EM_MN10300 = 89, ///< Matsushita MN10300
302 EM_MN10200 = 90, ///< Matsushita MN10200
303 EM_PJ = 91, ///< picoJava
304 EM_OPENRISC = 92, ///< OpenRISC 32-bit embedded processor
305 EM_ARC_COMPACT = 93, ///< ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5)
306 EM_XTENSA = 94, ///< Tensilica Xtensa Architecture
307 EM_VIDEOCORE = 95, ///< Alphamosaic VideoCore processor
308 EM_TMM_GPP = 96, ///< Thompson Multimedia General Purpose Processor
309 EM_NS32K = 97, ///< National Semiconductor 32000 series
310 EM_TPC = 98, ///< Tenor Network TPC processor
311 EM_SNP1K = 99, ///< Trebia SNP 1000 processor
312 EM_ST200 = 100, ///< STMicroelectronics (www.st.com) ST200 microcontroller
313 EM_IP2K = 101, ///< Ubicom IP2xxx microcontroller family
314 EM_MAX = 102, ///< MAX Processor
315 EM_CR = 103, ///< National Semiconductor CompactRISC microprocessor
316 EM_F2MC16 = 104, ///< Fujitsu F2MC16
317 EM_MSP430 = 105, ///< Texas Instruments embedded microcontroller msp430
318 EM_BLACKFIN = 106, ///< Analog Devices Blackfin (DSP) processor
319 EM_SE_C33 = 107, ///< S1C33 Family of Seiko Epson processors
320 EM_SEP = 108, ///< Sharp embedded microprocessor
321 EM_ARCA = 109, ///< Arca RISC Microprocessor
322 EM_UNICORE = 110, ///< Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University
323 EM_EXCESS = 111, ///< eXcess: 16/32/64-bit configurable embedded CPU
324 EM_DXP = 112, ///< Icera Semiconductor Inc. Deep Execution Processor
325 EM_ALTERA_NIOS2 = 113, ///< Altera Nios II soft-core processor
326 EM_CRX = 114, ///< National Semiconductor CompactRISC CRX microprocessor
327 EM_XGATE = 115, ///< Motorola XGATE embedded processor
328 EM_C166 = 116, ///< Infineon C16x/XC16x processor
329 EM_M16C = 117, ///< Renesas M16C series microprocessors
330 EM_DSPIC30F = 118, ///< Microchip Technology dsPIC30F Digital Signal Controller
331 EM_CE = 119, ///< Freescale Communication Engine RISC core
332 EM_M32C = 120, ///< Renesas M32C series microprocessors
333 EM_TSK3000 = 131, ///< Altium TSK3000 core
334 EM_RS08 = 132, ///< Freescale RS08 embedded processor
335 EM_SHARC = 133, ///< Analog Devices SHARC family of 32-bit DSP processors
336 EM_ECOG2 = 134, ///< Cyan Technology eCOG2 microprocessor
337 EM_SCORE7 = 135, ///< Sunplus S+core7 RISC processor
338 EM_DSP24 = 136, ///< New Japan Radio (NJR) 24-bit DSP Processor
339 EM_VIDEOCORE3 = 137, ///< Broadcom VideoCore III processor
340 EM_LATTICEMICO32 = 138, ///< RISC processor for Lattice FPGA architecture
341 EM_SE_C17 = 139, ///< Seiko Epson C17 family
342 EM_TI_C6000 = 140, ///< The Texas Instruments TMS320C6000 DSP family
343 EM_TI_C2000 = 141, ///< The Texas Instruments TMS320C2000 DSP family
344 EM_TI_C5500 = 142, ///< The Texas Instruments TMS320C55x DSP family
345 EM_TI_ARP32 = 143, ///< Texas Instruments Application Specific RISC Processor, 32bit fetch
346 EM_TI_PRU = 144, ///< Texas Instruments Programmable Realtime Unit
347 EM_MMDSP_PLUS = 160, ///< STMicroelectronics 64bit VLIW Data Signal Processor
348 EM_CYPRESS_M8C = 161, ///< Cypress M8C microprocessor
349 EM_R32C = 162, ///< Renesas R32C series microprocessors
350 EM_TRIMEDIA = 163, ///< NXP Semiconductors TriMedia architecture family
351 EM_QDSP6 = 164, ///< QUALCOMM DSP6 Processor
352 EM_8051 = 165, ///< Intel 8051 and variants
353 EM_STXP7X = 166, ///< STMicroelectronics STxP7x family of configurable and extensible RISC processors
354 EM_NDS32 = 167, ///< Andes Technology compact code size embedded RISC processor family
355 EM_ECOG1 = 168, ///< Cyan Technology eCOG1X family
356 EM_ECOG1X = 168, ///< Cyan Technology eCOG1X family
357 EM_MAXQ30 = 169, ///< Dallas Semiconductor MAXQ30 Core Micro-controllers
358 EM_XIMO16 = 170, ///< New Japan Radio (NJR) 16-bit DSP Processor
359 EM_MANIK = 171, ///< M2000 Reconfigurable RISC Microprocessor
360 EM_CRAYNV2 = 172, ///< Cray Inc. NV2 vector architecture
361 EM_RX = 173, ///< Renesas RX family
362 EM_METAG = 174, ///< Imagination Technologies META processor architecture
363 EM_MCST_ELBRUS = 175, ///< MCST Elbrus general purpose hardware architecture
364 EM_ECOG16 = 176, ///< Cyan Technology eCOG16 family
365 EM_CR16 = 177, ///< National Semiconductor CompactRISC CR16 16-bit microprocessor
366 EM_ETPU = 178, ///< Freescale Extended Time Processing Unit
367 EM_SLE9X = 179, ///< Infineon Technologies SLE9X core
368 EM_L10M = 180, ///< Intel L10M
369 EM_K10M = 181, ///< Intel K10M
370 EM_AARCH64 = 183, ///< ARM 64-bit architecture (AARCH64)
371 EM_AVR32 = 185, ///< Atmel Corporation 32-bit microprocessor family
372 EM_STM8 = 186, ///< STMicroeletronics STM8 8-bit microcontroller
373 EM_TILE64 = 187, ///< Tilera TILE64 multicore architecture family
374 EM_TILEPRO = 188, ///< Tilera TILEPro multicore architecture family
375 EM_MICROBLAZE = 189, ///< Xilinx MicroBlaze 32-bit RISC soft processor core
376 EM_CUDA = 190, ///< NVIDIA CUDA architecture
377 EM_TILEGX = 191, ///< Tilera TILE-Gx multicore architecture family
378 EM_CLOUDSHIELD = 192, ///< CloudShield architecture family
379 EM_COREA_1ST = 193, ///< KIPO-KAIST Core-A 1st generation processor family
380 EM_COREA_2ND = 194, ///< KIPO-KAIST Core-A 2nd generation processor family
381 EM_ARC_COMPACT2 = 195, ///< Synopsys ARCompact V2
382 EM_OPEN8 = 196, ///< Open8 8-bit RISC soft processor core
383 EM_RL78 = 197, ///< Renesas RL78 family
384 EM_VIDEOCORE5 = 198, ///< Broadcom VideoCore V processor
385 EM_78KOR = 199, ///< Renesas 78KOR family
386 EM_56800EX = 200, ///< Freescale 56800EX Digital Signal Controller (DSC)
387 EM_BA1 = 201, ///< Beyond BA1 CPU architecture
388 EM_BA2 = 202, ///< Beyond BA2 CPU architecture
389 EM_XCORE = 203, ///< XMOS xCORE processor family
390 EM_MCHP_PIC = 204, ///< Microchip 8-bit PIC(r) family
391 EM_INTEL205 = 205, ///< Reserved by Intel
392 EM_INTEL206 = 206, ///< Reserved by Intel
393 EM_INTEL207 = 207, ///< Reserved by Intel
394 EM_INTEL208 = 208, ///< Reserved by Intel
395 EM_INTEL209 = 209, ///< Reserved by Intel
396 EM_KM32 = 210, ///< KM211 KM32 32-bit processor
397 EM_KMX32 = 211, ///< KM211 KMX32 32-bit processor
398 EM_KMX16 = 212, ///< KM211 KMX16 16-bit processor
399 EM_KMX8 = 213, ///< KM211 KMX8 8-bit processor
400 EM_KVARC = 214, ///< KM211 KVARC processor
401 EM_CDP = 215, ///< Paneve CDP architecture family
402 EM_COGE = 216, ///< Cognitive Smart Memory Processor
403 EM_COOL = 217, ///< Bluechip Systems CoolEngine
404 EM_NORC = 218, ///< Nanoradio Optimized RISC
405 EM_CSR_KALIMBA = 219, ///< CSR Kalimba architecture family
406 EM_Z80 = 220, ///< Zilog Z80
407 EM_VISIUM = 221, ///< Controls and Data Services VISIUMcore processor
408 EM_FT32 = 222, ///< FTDI Chip FT32 high performance 32-bit RISC architecture
409 EM_MOXIE = 223, ///< Moxie processor family
410 EM_AMDGPU = 224, ///< AMD GPU architecture
411 EM_RISCV = 243, ///< RISC-V
412 EM_LANAI = 244, ///< Lanai processor
413 EM_CEVA = 245, ///< CEVA Processor Architecture Family
414 EM_CEVA_X2 = 246, ///< CEVA X2 Processor Family
415 EM_BPF = 247, ///< Linux BPF – in-kernel virtual machine
416 EM_GRAPHCORE_IPU = 248, ///< Graphcore Intelligent Processing Unit
417 EM_IMG1 = 249, ///< Imagination Technologies
418 EM_NFP = 250, ///< Netronome Flow Processor (NFP)
419 EM_VE = 251, ///< NEC Vector Engine
420 EM_CSKY = 252, ///< C-SKY processor family
421 EM_ARC_COMPACT3_64 = 253, ///< Synopsys ARCv2.3 64-bit
422 EM_MCS6502 = 254, ///< MOS Technology MCS 6502 processor
423 EM_ARC_COMPACT3 = 255, ///< Synopsys ARCv2.3 32-bit
424 EM_KVX = 256, ///< Kalray VLIW core of the MPPA processor family
425 EM_65816 = 257, ///< WDC 65816/65C816
426 EM_LOONGARCH = 258, ///< Loongson Loongarch
427 EM_KF32 = 259, ///< ChipON KungFu32
428 EM_U16_U8CORE = 260, ///< LAPIS nX-U16/U8
429 EM_TACHYUM = 261, ///< Reserved for Tachyum processor
430 EM_56800EF = 262, ///< NXP 56800EF Digital Signal Controller (DSC)
431 EM_SBF = 263, ///< Solana Bytecode Format
432 EM_AIENGINE = 264, ///< AMD/Xilinx AIEngine architecture
433 EM_SIMA_MLA = 265, ///< SiMa MLA
434 EM_BANG = 266, ///< Cambricon BANG
435 EM_LOONGGPU = 267, ///< Loongson LoongGPU
436 EM_SW64 = 268, ///< Wuxi Institute of Advanced Technology SW64
437 EM_AIECTRLCODE = 269, ///< AMD/Xilinx AIEngine ctrlcode
439
440/**
441 * @brief Special section indexes.
442 * @see https://gabi.xinuos.com/elf/03-sheader.html
443 */
444typedef enum
445{
446 SHN_UNDEF = 0, ///< Undefined section
447 SHN_LORESERVE = 0xff00, ///< Start of reserved indexes
448 SHN_LOPROC = 0xff00, ///< Start of processor-specific indexes
449 SHN_HIPROC = 0xff1f, ///< End of processor-specific indexes
450 SHN_LOOS = 0xff20, ///< Start of OS-specific indexes
451 SHN_HIOS = 0xff3f, ///< End of OS-specific indexes
452 SHN_ABS = 0xfff1, ///< Specifies absolute values for the corresponding reference
453 SHN_COMMON = 0xfff2, ///< Symbols defined relative to this section are common symbols
454 SHN_XINDEX = 0xffff, ///< Indicates that the actual index is too large to fit and is stored elsewhere
455 SHN_HIRESERVE = 0xffff ///< End of reserved indexes
457
458/**
459 * @brief ELF64 Section Header
460 * @see https://gabi.xinuos.com/elf/03-sheader.html
461 *
462 * Stored in the section header table, which is located at the file offset `e_shoff` and contains `e_shnum` entries
463 * where each entry is `e_shentsize` bytes long.
464 *
465 * Each section header describes a section in the ELF file, for example the `.text` or `.data` sections.
466 */
467typedef struct
468{
469 Elf64_Word sh_name; ///< Index of the section name in the string table
470 Elf64_Word sh_type; ///< Section type
471 Elf64_Xword sh_flags; ///< Section flags
472 Elf64_Addr sh_addr; ///< If the section will appear in memory, this will be its virtual address, otherwise `0`
473 Elf64_Off sh_offset; ///< Section's file offset in bytes
474 Elf64_Xword sh_size; ///< Section size in bytes
475 Elf64_Word sh_link; ///< Depends on section type, for symbol tables this is the section header index of the
476 ///< associated string table
477 Elf64_Word sh_info; ///< Depends on section type
478 Elf64_Xword sh_addralign; ///< Section byte alignment requirement
479 Elf64_Xword sh_entsize; ///< If the section holds a table of fixed-size entries, this is the size of each entry,
480 /// otherwise `0`
481} Elf64_Shdr;
482
483/**
484 * @brief Section type values for `sh_type`.
485 * @see https://gabi.xinuos.com/elf/03-sheader.html
486 */
487typedef enum
488{
489 SHT_NULL = 0, ///< Does not have an associated section
490 SHT_PROGBITS = 1, ///< Contains information defined by the program
491 SHT_SYMTAB = 2, ///< Contains a symbol table, only 1 per file
492 SHT_STRTAB = 3, ///< Contains a string table
493 SHT_RELA = 4, ///< Contains relocation entries with explicit addends
494 SHT_HASH = 5, ///< Contains a symbol hash table, only 1 per file
495 SHT_DYNAMIC = 6, ///< Contains dynamic linking information, only 1 per file
496 SHT_NOTE = 7, ///< Contains unspecified auxiliary information
497 SHT_NOBITS = 8, ///< Acts like `SHT_PROGBITS` but does not occupy any space in the file
498 SHT_REL = 9, ///< Contains relocation entries without explicit addends
499 SHT_SHLIB = 10, ///< Reserved, has unspecified semantics
500 SHT_DYNSYM = 11, ///< Acts like `SHT_SYMTAB` but holds a minimal set of dynamic linking symbols, only 1 per file
501 SHT_INIT_ARRAY = 14, ///< Contains an array of pointers to initialization functions
502 SHT_FINI_ARRAY = 15, ///< Contains an array of pointers to termination functions
503 SHT_PREINIT_ARRAY = 16, ///< Contains an array of pointers to pre-initialization functions
504 SHT_GROUP = 17, ///< Contains a section group, can only appear in relocatable files
505 SHT_SYMTAB_SHNDX = 18, ///< Contains extended section indexes for a symbol table, used with `SHN_XINDEX`
506 SHT_RELR = 19, ///< Contains relocation entries for relative relocations without explicit addends
507 SHT_LOOS = 0x60000000, ///< Start of OS-specific section types
508 SHT_HIOS = 0x6fffffff, ///< End of OS-specific section types
509 SHT_LOPROC = 0x70000000, ///< Start of processor-specific section types
510 SHT_HIPROC = 0x7fffffff, ///< End of processor-specific section types
511 SHT_LOUSER = 0x80000000, ///< Start of application-specific section types
512 SHT_HIUSER = 0xffffffff, ///< End of application-specific section types
514
515/**
516 * @brief Section flag values for `sh_flags`.
517 * @see https://gabi.xinuos.com/elf/03-sheader.html
518 */
519typedef enum
520{
521 SHF_WRITE = 0x1, ///< Section should be writable when loaded to memory
522 SHF_ALLOC = 0x2, ///< Section should be loaded to memory
523 SHF_EXECINSTR = 0x4, ///< Section should be executable when loaded to memory
524 SHF_MERGE = 0x10, ///< Section may be merged to eliminate duplication
525 SHF_STRINGS = 0x20, ///< Section contains null-terminated strings, `sh_entsize` contains the char size
526 SHF_INFO_LINK = 0x40, ///< `sh_info` contains a section header table index
527 SHF_LINK_ORDER = 0x80, ///< Preserve section ordering when linking
528 SHF_OS_NONCONFORMING = 0x100, ///< Section requires special OS-specific processing
529 SHF_GROUP = 0x200, ///< Is part of a section group
530 SHF_TLS = 0x400, ///< Section holds thread-local storage
531 SHF_COMPRESSED = 0x800, ///< Section holds compressed data
532 SHF_MASKOS = 0x0ff00000, ///< All bits in this mask are reserved for OS-specific semantics
533 SHF_MASKPROC = 0xf0000000, ///< All bits in this mask are reserved for processor-specific semantics
535
536/**
537 * @brief ELF64 Symbol Table Entry
538 * @see https://gabi.xinuos.com/elf/05-symtab.html
539 *
540 * Stored in sections of type `SHT_SYMTAB` or `SHT_DYNSYM`.
541 */
551
552/**
553 * @brief Extract the binding from `st_info`.
554 *
555 * @param i The `st_info` value
556 * @return The binding value
557 */
558#define ELF64_ST_BIND(i) ((i) >> 4)
559
560/**
561 * @brief Symbol binding values stored in `st_info`.
562 * @see https://gabi.xinuos.com/elf/05-symtab.html
563 */
564typedef enum
565{
566 STB_LOCAL = 0, ///< Local symbol, not visible outside the object file
567 STB_GLOBAL = 1, ///< Global symbol, visible to all object files being combined
568 STB_WEAK = 2, ///< Weak symbol, like global but with lower precedence
569 STB_LOOS = 10, ///< Start of OS-specific symbol bindings
570 STB_HIOS = 12, ///< End of OS-specific symbol bindings
571 STB_LOPROC = 13, ///< Start of processor-specific symbol bindings
572 STB_HIPROC = 15 ///< End of processor-specific symbol bindings
574
575/**
576 * @brief Extract the type from `st_info`.
577 *
578 * @param i The `st_info` value
579 * @return The type value
580 */
581#define ELF64_ST_TYPE(i) ((i) & 0xf)
582
583/**
584 * @brief Symbol type values stored in `st_info`.
585 * @see https://gabi.xinuos.com/elf/05-symtab.html
586 */
587typedef enum
588{
589 STT_NOTYPE = 0, ///< Symbol type is unspecified
590 STT_OBJECT = 1, ///< Symbol is a data object
591 STT_FUNC = 2, ///< Symbol is a code object
592 STT_SECTION = 3, ///< Symbol associated with a section
593 STT_FILE = 4, ///< Symbol's name is the name of a source file
594 STT_LOOS = 10, ///< Start of OS-specific symbol types
595 STT_HIOS = 12, ///< End of OS-specific symbol types
596 STT_LOPROC = 13, ///< Start of processor-specific symbol types
597 STT_HIPROC = 15 ///< End of processor-specific symbol types
599
600/**
601 * @brief Create an `st_info` value from binding and type.
602 *
603 * @see https://gabi.xinuos.com/elf/05-symtab.html
604 *
605 * @param b The binding value
606 * @param t The type value
607 * @return The combined `st_info` value
608 */
609#define ELF64_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf))
610
611/**
612 * @brief ELF64 Rel Entry without addend
613 * @see https://gabi.xinuos.com/elf/06-reloc.html
614 */
620
621/**
622 * @brief ELF64 Rela Entry with addend
623 * @see https://gabi.xinuos.com/elf/06-reloc.html
624 */
631
632/**
633 * @brief Extract the symbol index from `r_info`.
634 *
635 * @see https://gabi.xinuos.com/elf/06-reloc.html
636 *
637 * @param i The `r_info` value
638 * @return The symbol index
639 */
640#define ELF64_R_SYM(i) ((i) >> 32)
641
642/**
643 * @brief Extract the type from `r_info`.
644 *
645 * @see https://gabi.xinuos.com/elf/06-reloc.html
646 *
647 * @param i The `r_info` value
648 * @return The type value
649 */
650#define ELF64_R_TYPE(i) ((i) & 0xffffffffL)
651
652/**
653 * @brief Relocation type values for `r_info`.
654 *
655 * The associated comments describe the calculation performed for each relocation type where:
656 * - A = The addend used to compute the value of the relocatable field.
657 * - B = The base address at which the object is loaded into memory
658 * - G = The offset into the Global Offset Table
659 * - GOT = The address of the Global Offset Table
660 * - L = The address of the procedure linkage table entry for the symbol
661 * - P = The place (section offset or address) of the storage unit being relocated
662 * - S = value of the symbol in the relocation entry
663 * - Z = The size of the symbol
664 *
665 * Additionally the size of the relocated field is indicated (word8, word16, word32, word64).
666 *
667 * Most of these are not used.
668 *
669 * @see https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf table 4.10
670 */
671typedef enum
672{
673 R_X86_64_NONE = 0, ///< none none
674 R_X86_64_64 = 1, ///< word64 S + A
675 R_X86_64_PC32 = 2, ///< word32 S + A - P
676 R_X86_64_GOT32 = 3, ///< word32 G + A
677 R_X86_64_PLT32 = 4, ///< word32 L + A - P
678 R_X86_64_COPY = 5, ///< none none
679 R_X86_64_GLOB_DAT = 6, ///< word64 S
680 R_X86_64_JUMP_SLOT = 7, ///< word64 S
681 R_X86_64_RELATIVE = 8, ///< word64 B + A
682 R_X86_64_GOTPCREL = 9, ///< word32 G + GOT + A - P
683 R_X86_64_32 = 10, ///< word32 S + A
684 R_X86_64_32S = 11, ///< word32 S + A
685 R_X86_64_16 = 12, ///< word16 S + A
686 R_X86_64_PC16 = 13, ///< word16 S + A - P
687 R_X86_64_8 = 14, ///< word8 S + A
688 R_X86_64_PC8 = 15, ///< word8 S + A - P
689 R_X86_64_DTPMOD64 = 16, ///< word64
690 R_X86_64_DTPOFF64 = 17, ///< word64
691 R_X86_64_TPOFF64 = 18, ///< word64
692 R_X86_64_TLSGD = 19, ///< word32
693 R_X86_64_TLSLD = 20, ///< word32
694 R_X86_64_DTPOFF32 = 21, ///< word32
695 R_X86_64_GOTTPOFF = 22, ///< word32
696 R_X86_64_TPOFF32 = 23, ///< word32
697 R_X86_64_PC64 = 24, ///< word64 S + A - P
698 R_X86_64_GOTOFF64 = 25, ///< word64 S + A - GOT
699 R_X86_64_GOTPC32 = 26, ///< word32 GOT + A - P
700 R_X86_64_SIZE32 = 32, ///< word32 Z + A
701 R_X86_64_SIZE64 = 33, ///< word64 Z + A
702 R_X86_64_GOTPC32_TLSDESC = 34, ///< word32
703 R_X86_64_TLSDESC_CALL = 35, ///< none
704 R_X86_64_TLSDESC = 36, ///< word64×2
705 R_X86_64_IRELATIVE = 37, ///< word64 indirect (B + A)
707
708/**
709 * @brief Create an `r_info` value from symbol index and type.
710 *
711 * @see https://gabi.xinuos.com/elf/06-reloc.html
712 *
713 * @param s The symbol index
714 * @param t The type value
715 * @return The combined `r_info` value
716 */
717#define ELF64_R_INFO(s, t) (((s) << 32) + ((t) & 0xffffffffL))
718
719/**
720 * @brief ELF64 Program Header
721 *
722 * Stored in the program header table, which is located at the file offset `e_phoff` and contains `e_phnum` entries
723 * where each entry is `e_phentsize` bytes long.
724 *
725 * Each program header describes a segment in the ELF file, which is used during program loading.
726 *
727 * @see https://gabi.xinuos.com/elf/07-pheader.html
728 */
729typedef struct
730{
731 Elf64_Word p_type; ///< Segment type
732 Elf64_Word p_flags; ///< Segment flags
733 Elf64_Off p_offset; ///< Segment file offset in bytes
734 Elf64_Addr p_vaddr; ///< Target virtual address in memory
735 Elf64_Addr p_paddr; ///< Target physical address, ignored on systems without physical addressing
736 Elf64_Xword p_filesz; ///< Size of segment in file in bytes
737 Elf64_Xword p_memsz; ///< Size of segment in memory in bytes
738 Elf64_Xword p_align; ///< Segment alignment requirement
739} Elf64_Phdr;
740
741/**
742 * @brief Segment type values for `p_type`.
743 * @see https://gabi.xinuos.com/elf/07-pheader.html
744 */
745typedef enum
746{
747 PT_NULL = 0, ///< Unused segment
748 PT_LOAD = 1, ///< Loadable segment
749 PT_DYNAMIC = 2, ///< Dynamic linking information
750 PT_INTERP = 3, ///< Program interpreter path name
751 PT_NOTE = 4, ///< Auxiliary information
752 PT_SHLIB = 5, ///< Reserved, has unspecified semantics
753 PT_PHDR = 6, ///< Location and size of program header table
754 PT_TLS = 7, ///< Thread-local storage template
755 PT_LOOS = 0x60000000, ///< Start of OS-specific segment types
756 PT_HIOS = 0x6fffffff, ///< End of OS-specific segment types
757 PT_LOPROC = 0x70000000, ///< Start of processor-specific segment types
758 PT_HIPROC = 0x7fffffff ///< End of processor-specific segment types
760
761/**
762 * @brief Segment flag values for `p_flags`.
763 * @see https://gabi.xinuos.com/elf/07-pheader.html
764 *
765 * A segment is allowed to be readable even if the `PF_R` flag is not set.
766 */
767typedef enum
768{
769 PF_X = 0x1, ///< Executable segment
770 PF_W = 0x2, ///< Writable segment
771 PF_R = 0x4, ///< Readable segment
772 PF_MASKOS = 0x0ff00000, ///< All bits in this mask are reserved for OS-specific semantics
773 PF_MASKPROC = 0xf0000000 ///< All bits in this mask are reserved for processor-specific semantics
775
776/**
777 * @brief ELF File Helper structure
778 * @struct Elf64_File
779 */
780typedef struct
781{
782 Elf64_Ehdr* header; ///< The data in the file, pointed to the start of the ELF header
783 uint64_t size; ///< The size of the file in bytes
784 Elf64_Shdr* symtab; ///< The symbol table section, or `NULL` if not found
785 Elf64_Shdr* dynsym; ///< The dynamic symbol table section, or `NULL` if not found
786} Elf64_File;
787
788/**
789 * @brief Get the program header at the given index from an ELF file
790 *
791 * @param elf The ELF file
792 * @param index The program header index
793 * @return Pointer to the program header
794 */
795#define ELF64_GET_PHDR(elf, index) \
796 ((Elf64_Phdr*)((uint8_t*)(elf)->header + (elf)->header->e_phoff + ((index) * (elf)->header->e_phentsize)))
797
798/**
799 * @brief Get the section header at the given index from an ELF file
800 *
801 * @param elf The ELF file
802 * @param index The section header index
803 * @return Pointer to the section header
804 */
805#define ELF64_GET_SHDR(elf, index) \
806 ((Elf64_Shdr*)((uint8_t*)(elf)->header + (elf)->header->e_shoff + ((index) * (elf)->header->e_shentsize)))
807/**
808 * @brief Get a pointer to a location in the ELF file at the given offset
809 *
810 * @param elf The ELF file
811 * @param offset The offset in bytes
812 * @return Pointer to the location in the ELF file
813 */
814#define ELF64_AT_OFFSET(elf, offset) ((void*)((uint8_t*)(elf)->header + (offset)))
815
816/**
817 * @brief Validate a files content and initalize a `ELF64_File` structure using it
818 *
819 * The idea behind this function is to verify every aspect of a ELF file such that other functions acting on the ELF64
820 * file do not need to perform any validation.
821 *
822 * The reason this does not read from a file is such that it will be generic and usable in user space, in the kernel and
823 * the bootloader.
824 *
825 * Having to load the entire file might seem wasteful, but its actually very important in order to avoid a situation
826 * where we validate the file, another process modifies it, and then we read actual data later on causing a TOCTOU
827 * vulnerability.
828 *
829 * @param elf Pointer to the structure to initialize
830 * @param data Pointer to the ELF file data in memory, caller retains ownership
831 * @param size Size of the ELF file data in bytes
832 * @return On success, `0`. On failure, a non-zero error code. Check the implementation. Does not use `ERR` or `errno`.
833 */
835
836/**
837 * @brief Get the loadable virtual memory bounds of an ELF file
838 *
839 * @param elf The ELF file
840 * @param minAddr Output pointer to store the minimum loadable virtual address
841 * @param maxAddr Output pointer to store the maximum loadable virtual address
842 */
843void elf64_get_loadable_bounds(const Elf64_File* elf, Elf64_Addr* minAddr, Elf64_Addr* maxAddr);
844
845/**
846 * @brief Load all loadable segments of an ELF file into memory
847 *
848 * Each segment has virtual addresses specified in `p_vaddr` which is where the segment is intended to be loaded in
849 * memory. But we may not want to load it directly to that address, we might have a buffer where we wish to place the
850 * segments instead. Either way, we must still place the segments at the correct offsets relative to each other. Leading
851 * to the slightly unintuitive parameters of this function.
852 *
853 * The final address where a segment is loaded is calculated as `base + (p_vaddr - offset)`, meaning that if you wish to
854 * load a file directly to its intended virtual addresses, you would do:
855 * ```c
856 * elf64_load_segments(elf, (void*)0x0, 0x0);
857 * ```
858 * If you wanted to load the contents to a buffer located at `buffer` which could later be mapped to the intended
859 * virtual addresses or if you wanted to load relocatable code, you would do:
860 * ```c
861 * Elf64_Addr minAddr, maxAddr;
862 * elf64_get_loadable_bounds(elf, &minAddr, &maxAddr);
863 * elf64_load_segments(elf, buffer, minAddr);
864 * ```
865 *
866 * @note This function does not allocate memory, it assumes that the caller has already allocated enough memory at `base
867 * + (p_vaddr - offset)` for each segment.
868 *
869 * @param elf The ELF file
870 * @param base The base address to load the segments into
871 * @param offset The offset in bytes to subtract from each segment's virtual address when loading
872 */
873void elf64_load_segments(const Elf64_File* elf, Elf64_Addr base, Elf64_Off offset);
874
875/**
876 * @brief Perform relocations on an ELF file loaded into memory
877 *
878 * This function will process all relocation sections in the ELF file and apply the relocations to the loaded segments
879 * in memory, including resolving symbol addresses using the provided callback as necessary.
880 *
881 * Relocations are necessary when a ELF file contains references to symbols whose addresses are not known at compile
882 * time, for example the ELF file might be a shared library or kernel module.
883 *
884 * Check `elf64_load_segments()` for an explanation of the `base` and `offset` parameters.
885 *
886 * The `resolve_symbol` callback is used to resolve symbol names to addresses, this will be utilized for relocations of
887 * undefined symbols. Should return `NULL` if the symbol could not be resolved.
888 *
889 * TOOD: Implement more relocation types as needed.
890 *
891 * @param elf The ELF file
892 * @param base The base address where the segments are loaded in memory
893 * @param offset The offset in bytes that was subtracted from each segment's virtual address when loading
894 * @param resolve_symbol Callback function to resolve symbol names to addresses
895 * @param private Private data pointer passed to the `resolve_symbol` callback
896 * @return On success, `0`. On failure, `ERR`.
897 */
898uint64_t elf64_relocate(const Elf64_File* elf, Elf64_Addr base, Elf64_Off offset,
899 void* (*resolve_symbol)(const char* name, void* private), void* private);
900
901/**
902 * @brief Get a string from the string table section at the given offset
903 *
904 * @param elf The ELF file
905 * @param strTabIndex The index of the string table section to use
906 * @param offset The offset in bytes into the string table
907 * @return Pointer to the string in the ELF file or `NULL` if not found
908 */
909const char* elf64_get_string(const Elf64_File* elf, Elf64_Xword strTabIndex, Elf64_Off offset);
910
911/**
912 * @brief Get a section by its name
913 *
914 * @param elf The ELF file
915 * @param name The name of the section to find
916 * @return Pointer to the section header or `NULL` if not found
917 */
918Elf64_Shdr* elf64_get_section_by_name(const Elf64_File* elf, const char* name);
919
920/**
921 * @brief Get the name of a section
922 *
923 * @param elf The ELF file
924 * @param section The section to get the name of
925 * @return Pointer to the section name string or `NULL` if not found
926 */
927const char* elf64_get_section_name(const Elf64_File* elf, const Elf64_Shdr* section);
928
929/**
930 * @brief Get a symbol by its index from the symbol table
931 *
932 * @param elf The ELF file
933 * @param symbolIndex The index of the symbol to get
934 * @return Pointer to the symbol or `NULL` if not found
935 */
937
938/**
939 * @brief Get a symbol by its name from the symbol table
940 *
941 * @param elf The ELF file
942 * @param name The name of the symbol to find
943 * @return Pointer to the symbol or `NULL` if not found
944 */
945Elf64_Sym* elf64_get_symbol_by_name(const Elf64_File* elf, const char* name);
946
947/**
948 * @brief Get the name of a symbol
949 *
950 * @param elf The ELF file
951 * @param symbol The symbol to get the name of
952 * @return Pointer to the symbol name string or `NULL` if not found
953 */
954const char* elf64_get_symbol_name(const Elf64_File* elf, const Elf64_Sym* symbol);
955
956/**
957 * @brief Get a dynamic symbol by its index from the dynamic symbol table
958 *
959 * Dynamic symbols are, for example, found in `.rela.*` sections used for dynamic linking.
960 *
961 * @param elf The ELF file
962 * @param symbolIndex The index of the dynamic symbol to get
963 * @return Pointer to the dynamic symbol or `NULL` if not found
964 */
966
967/**
968 * @brief Get the name of a dynamic symbol
969 *
970 * @param elf The ELF file
971 * @param symbol The dynamic symbol to get the name of
972 * @return Pointer to the dynamic symbol name string or `NULL` if not found
973 */
974const char* elf64_get_dynamic_symbol_name(const Elf64_File* elf, const Elf64_Sym* symbol);
975
976/** @} */
977
978#endif
static fd_t data
Definition dwm.c:21
const char * elf64_get_string(const Elf64_File *elf, Elf64_Xword strTabIndex, Elf64_Off offset)
Get a string from the string table section at the given offset.
Elf64_Magic
Expected magic values in e_ident[EI_MAG0] to e_ident[EI_MAG3].
Definition elf.h:131
Elf64_Shn_Indexes
Special section indexes.
Definition elf.h:445
uint64_t Elf64_Sxword
ELF64 Signed long integer.
Definition elf.h:66
Elf64_Sym * elf64_get_dynamic_symbol_by_index(const Elf64_File *elf, Elf64_Xword symbolIndex)
Get a dynamic symbol by its index from the dynamic symbol table.
Elf64_Class
File class values for e_ident[EI_CLASS].
Definition elf.h:146
Elf64_Data
Data encoding values for e_ident[EI_DATA].
Definition elf.h:160
Elf64_Version
Version values for e_ident[EI_VERSION] and e_version.
Definition elf.h:171
int32_t Elf64_Sword
ELF64 Signed integer.
Definition elf.h:54
Elf64_Section_Flags
Section flag values for sh_flags.
Definition elf.h:520
Elf64_Sym * elf64_get_symbol_by_name(const Elf64_File *elf, const char *name)
Get a symbol by its name from the symbol table.
uint64_t Elf64_Xword
ELF64 Unsigned long integer.
Definition elf.h:60
const char * elf64_get_section_name(const Elf64_File *elf, const Elf64_Shdr *section)
Get the name of a section.
Elf64_Symbol_Binding
Symbol binding values stored in st_info.
Definition elf.h:565
uint64_t elf64_relocate(const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset, void *(*resolve_symbol)(const char *name, void *private), void *private)
Perform relocations on an ELF file loaded into memory.
void elf64_load_segments(const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset)
Load all loadable segments of an ELF file into memory.
uint64_t elf64_validate(Elf64_File *elf, void *data, uint64_t size)
Validate a files content and initalize a ELF64_File structure using it.
uint64_t Elf64_Off
ELF64 Unsigned file offset.
Definition elf.h:36
Elf64_Ident_Indexes
Indices for e_ident[].
Definition elf.h:73
const char * elf64_get_dynamic_symbol_name(const Elf64_File *elf, const Elf64_Sym *symbol)
Get the name of a dynamic symbol.
Elf64_Program_Types
Segment type values for p_type.
Definition elf.h:746
Elf64_Machine
Machine architecture values for e_machine.
Definition elf.h:228
Elf64_Sym * elf64_get_symbol_by_index(const Elf64_File *elf, Elf64_Xword symbolIndex)
Get a symbol by its index from the symbol table.
Elf64_Relocation_Types_x86_64
Relocation type values for r_info.
Definition elf.h:672
uint32_t Elf64_Word
ELF64 Unsigned integer.
Definition elf.h:48
const char * elf64_get_symbol_name(const Elf64_File *elf, const Elf64_Sym *symbol)
Get the name of a symbol.
Elf64_OsAbi
OS/ABI identification values for e_ident[EI_OSABI].
Definition elf.h:189
void elf64_get_loadable_bounds(const Elf64_File *elf, Elf64_Addr *minAddr, Elf64_Addr *maxAddr)
Get the loadable virtual memory bounds of an ELF file.
Elf64_Section_Types
Section type values for sh_type.
Definition elf.h:488
uint16_t Elf64_Half
ELF64 Unsigned medium integer.
Definition elf.h:42
Elf64_Program_Flags
Segment flag values for p_flags.
Definition elf.h:768
uint64_t Elf64_Addr
ELF64 Unsigned program address.
Definition elf.h:30
Elf64_Type
Object file type values for e_type.
Definition elf.h:215
Elf64_Shdr * elf64_get_section_by_name(const Elf64_File *elf, const char *name)
Get a section by its name.
Elf64_Symbol_Type
Symbol type values stored in st_info.
Definition elf.h:588
@ ELFMAG1
Expected value for e_ident[EI_MAG1]
Definition elf.h:133
@ ELFMAG0
Expected value for e_ident[EI_MAG0]
Definition elf.h:132
@ ELFMAG3
Expected value for e_ident[EI_MAG3]
Definition elf.h:135
@ ELFMAG2
Expected value for e_ident[EI_MAG2]
Definition elf.h:134
@ SHN_XINDEX
Indicates that the actual index is too large to fit and is stored elsewhere.
Definition elf.h:454
@ SHN_LOOS
Start of OS-specific indexes.
Definition elf.h:450
@ SHN_COMMON
Symbols defined relative to this section are common symbols.
Definition elf.h:453
@ SHN_UNDEF
Undefined section.
Definition elf.h:446
@ SHN_HIPROC
End of processor-specific indexes.
Definition elf.h:449
@ SHN_LOPROC
Start of processor-specific indexes.
Definition elf.h:448
@ SHN_HIOS
End of OS-specific indexes.
Definition elf.h:451
@ SHN_ABS
Specifies absolute values for the corresponding reference.
Definition elf.h:452
@ SHN_LORESERVE
Start of reserved indexes.
Definition elf.h:447
@ SHN_HIRESERVE
End of reserved indexes.
Definition elf.h:455
@ ELFCLASS64
64-bit objects, we always expect this value
Definition elf.h:149
@ ELFCLASS32
32-bit objects
Definition elf.h:148
@ ELFCLASSNONE
Invalid class.
Definition elf.h:147
@ ELFDATAMSB
Big-endian encoding.
Definition elf.h:163
@ ELFDATALSB
Little-endian encoding, we always expect this value.
Definition elf.h:162
@ ELFDATANONE
Invalid data encoding.
Definition elf.h:161
@ EV_CURRENT
Current version, we always expect this value.
Definition elf.h:173
@ EV_NONE
Invalid version.
Definition elf.h:172
@ SHF_MERGE
Section may be merged to eliminate duplication.
Definition elf.h:524
@ SHF_INFO_LINK
sh_info contains a section header table index
Definition elf.h:526
@ SHF_STRINGS
Section contains null-terminated strings, sh_entsize contains the char size.
Definition elf.h:525
@ SHF_ALLOC
Section should be loaded to memory.
Definition elf.h:522
@ SHF_MASKPROC
All bits in this mask are reserved for processor-specific semantics.
Definition elf.h:533
@ SHF_COMPRESSED
Section holds compressed data.
Definition elf.h:531
@ SHF_GROUP
Is part of a section group.
Definition elf.h:529
@ SHF_EXECINSTR
Section should be executable when loaded to memory.
Definition elf.h:523
@ SHF_OS_NONCONFORMING
Section requires special OS-specific processing.
Definition elf.h:528
@ SHF_LINK_ORDER
Preserve section ordering when linking.
Definition elf.h:527
@ SHF_TLS
Section holds thread-local storage.
Definition elf.h:530
@ SHF_WRITE
Section should be writable when loaded to memory.
Definition elf.h:521
@ SHF_MASKOS
All bits in this mask are reserved for OS-specific semantics.
Definition elf.h:532
@ STB_LOOS
Start of OS-specific symbol bindings.
Definition elf.h:569
@ STB_GLOBAL
Global symbol, visible to all object files being combined.
Definition elf.h:567
@ STB_LOPROC
Start of processor-specific symbol bindings.
Definition elf.h:571
@ STB_LOCAL
Local symbol, not visible outside the object file.
Definition elf.h:566
@ STB_WEAK
Weak symbol, like global but with lower precedence.
Definition elf.h:568
@ STB_HIPROC
End of processor-specific symbol bindings.
Definition elf.h:572
@ STB_HIOS
End of OS-specific symbol bindings.
Definition elf.h:570
@ EI_ABIVERSION
Index of the ABI version byte.
Definition elf.h:82
@ EI_MAG1
Index of magic number byte 1.
Definition elf.h:75
@ EI_DATA
Index of the data encoding byte.
Definition elf.h:79
@ EI_MAG0
Index of magic number byte 0.
Definition elf.h:74
@ EI_PAD
Index of the start of padding bytes.
Definition elf.h:83
@ EI_MAG3
Index of magic number byte 3.
Definition elf.h:77
@ EI_CLASS
Index of the file class byte.
Definition elf.h:78
@ EI_OSABI
Index of the OS/ABI identification byte.
Definition elf.h:81
@ EI_NIDENT
Total size of e_ident.
Definition elf.h:84
@ EI_VERSION
Index of the file version byte.
Definition elf.h:80
@ EI_MAG2
Index of magic number byte 2.
Definition elf.h:76
@ PT_LOPROC
Start of processor-specific segment types.
Definition elf.h:757
@ PT_HIOS
End of OS-specific segment types.
Definition elf.h:756
@ PT_SHLIB
Reserved, has unspecified semantics.
Definition elf.h:752
@ PT_PHDR
Location and size of program header table.
Definition elf.h:753
@ PT_TLS
Thread-local storage template.
Definition elf.h:754
@ PT_HIPROC
End of processor-specific segment types.
Definition elf.h:758
@ PT_NULL
Unused segment.
Definition elf.h:747
@ PT_LOOS
Start of OS-specific segment types.
Definition elf.h:755
@ PT_DYNAMIC
Dynamic linking information.
Definition elf.h:749
@ PT_NOTE
Auxiliary information.
Definition elf.h:751
@ PT_INTERP
Program interpreter path name.
Definition elf.h:750
@ PT_LOAD
Loadable segment.
Definition elf.h:748
@ EM_88K
Motorola 88000.
Definition elf.h:234
@ EM_TI_C2000
The Texas Instruments TMS320C2000 DSP family.
Definition elf.h:343
@ EM_H8_300
Hitachi H8/300.
Definition elf.h:258
@ EM_TRICORE
Siemens TriCore embedded processor.
Definition elf.h:256
@ EM_VIDEOCORE
Alphamosaic VideoCore processor.
Definition elf.h:307
@ EM_SCORE7
Sunplus S+core7 RISC processor.
Definition elf.h:337
@ EM_C166
Infineon C16x/XC16x processor.
Definition elf.h:328
@ EM_MCHP_PIC
Microchip 8-bit PIC(r) family.
Definition elf.h:390
@ EM_CSKY
C-SKY processor family.
Definition elf.h:420
@ EM_STARCORE
Motorola Star*Core processor.
Definition elf.h:270
@ EM_56800EF
NXP 56800EF Digital Signal Controller (DSC)
Definition elf.h:430
@ EM_CE
Freescale Communication Engine RISC core.
Definition elf.h:331
@ EM_BANG
Cambricon BANG.
Definition elf.h:434
@ EM_RL78
Renesas RL78 family.
Definition elf.h:383
@ EM_SVX
Silicon Graphics SVx.
Definition elf.h:285
@ EM_IA_64
Intel IA-64 processor architecture.
Definition elf.h:262
@ EM_PJ
picoJava
Definition elf.h:303
@ EM_Z80
Zilog Z80.
Definition elf.h:406
@ EM_OPEN8
Open8 8-bit RISC soft processor core.
Definition elf.h:382
@ EM_TPC
Tenor Network TPC processor.
Definition elf.h:310
@ EM_NS32K
National Semiconductor 32000 series.
Definition elf.h:309
@ EM_S370
IBM System/370 Processor.
Definition elf.h:238
@ EM_SLE9X
Infineon Technologies SLE9X core.
Definition elf.h:367
@ EM_FR20
Fujitsu FR20.
Definition elf.h:249
@ EM_S390
IBM System/390 Processor.
Definition elf.h:246
@ EM_TSK3000
Altium TSK3000 core.
Definition elf.h:333
@ EM_TILEPRO
Tilera TILEPro multicore architecture family.
Definition elf.h:374
@ EM_COREA_2ND
KIPO-KAIST Core-A 2nd generation processor family.
Definition elf.h:380
@ EM_MMIX
Donald Knuth’s educational 64-bit processor.
Definition elf.h:292
@ EM_ARC_COMPACT3
Synopsys ARCv2.3 32-bit.
Definition elf.h:423
@ EM_M32
AT&T WE 32100.
Definition elf.h:230
@ EM_PDSP
Sony DSP Processor.
Definition elf.h:275
@ EM_SPARC
SPARC.
Definition elf.h:231
@ EM_CEVA
CEVA Processor Architecture Family.
Definition elf.h:413
@ EM_TI_C5500
The Texas Instruments TMS320C55x DSP family.
Definition elf.h:344
@ EM_AIECTRLCODE
AMD/Xilinx AIEngine ctrlcode.
Definition elf.h:437
@ EM_KMX32
KM211 KMX32 32-bit processor.
Definition elf.h:397
@ EM_LANAI
Lanai processor.
Definition elf.h:412
@ EM_X86_64
AMD x86-64 architecture, we always expect this value.
Definition elf.h:274
@ EM_XGATE
Motorola XGATE embedded processor.
Definition elf.h:327
@ EM_ECOG16
Cyan Technology eCOG16 family.
Definition elf.h:364
@ EM_TILEGX
Tilera TILE-Gx multicore architecture family.
Definition elf.h:377
@ EM_IP2K
Ubicom IP2xxx microcontroller family.
Definition elf.h:313
@ EM_OPENRISC
OpenRISC 32-bit embedded processor.
Definition elf.h:304
@ EM_68HC11
Motorola MC68HC11 Microcontroller.
Definition elf.h:282
@ EM_K10M
Intel K10M.
Definition elf.h:369
@ EM_INTEL207
Reserved by Intel.
Definition elf.h:393
@ EM_U16_U8CORE
LAPIS nX-U16/U8.
Definition elf.h:428
@ EM_BPF
Linux BPF – in-kernel virtual machine.
Definition elf.h:415
@ EM_M32R
Mitsubishi M32R.
Definition elf.h:300
@ EM_ARM
ARM 32-bit architecture (AARCH32)
Definition elf.h:252
@ EM_TI_C6000
The Texas Instruments TMS320C6000 DSP family.
Definition elf.h:342
@ EM_TI_ARP32
Texas Instruments Application Specific RISC Processor, 32bit fetch.
Definition elf.h:345
@ EM_LOONGGPU
Loongson LoongGPU.
Definition elf.h:435
@ EM_ALPHA
Digital Alpha.
Definition elf.h:253
@ EM_H8_300H
Hitachi H8/300H.
Definition elf.h:259
@ EM_MMDSP_PLUS
STMicroelectronics 64bit VLIW Data Signal Processor.
Definition elf.h:347
@ EM_CLOUDSHIELD
CloudShield architecture family.
Definition elf.h:378
@ EM_QDSP6
QUALCOMM DSP6 Processor.
Definition elf.h:351
@ EM_MIPS_RS3_LE
MIPS RS3000 Little-endian.
Definition elf.h:239
@ EM_ECOG1X
Cyan Technology eCOG1X family.
Definition elf.h:356
@ EM_H8S
Hitachi H8S.
Definition elf.h:260
@ EM_CSR_KALIMBA
CSR Kalimba architecture family.
Definition elf.h:405
@ EM_68K
Motorola 68000.
Definition elf.h:233
@ EM_COREA_1ST
KIPO-KAIST Core-A 1st generation processor family.
Definition elf.h:379
@ EM_PRISM
SiTera Prism.
Definition elf.h:294
@ EM_F2MC16
Fujitsu F2MC16.
Definition elf.h:316
@ EM_ST19
STMicroelectronics ST19 8-bit microcontroller.
Definition elf.h:286
@ EM_MMA
Fujitsu MMA Multimedia Accelerator.
Definition elf.h:266
@ EM_KVX
Kalray VLIW core of the MPPA processor family.
Definition elf.h:424
@ EM_INTEL208
Reserved by Intel.
Definition elf.h:394
@ EM_SHARC
Analog Devices SHARC family of 32-bit DSP processors.
Definition elf.h:335
@ EM_ARC_COMPACT3_64
Synopsys ARCv2.3 64-bit.
Definition elf.h:421
@ EM_PPC64
64-bit PowerPC
Definition elf.h:245
@ EM_CRAYNV2
Cray Inc. NV2 vector architecture.
Definition elf.h:360
@ EM_JAVELIN
Infineon Technologies 32-bit embedded processor.
Definition elf.h:289
@ EM_FR30
Fujitsu FR30.
Definition elf.h:296
@ EM_KF32
ChipON KungFu32.
Definition elf.h:427
@ EM_ETPU
Freescale Extended Time Processing Unit.
Definition elf.h:366
@ EM_ST9PLUS
STMicroelectronics ST9+ 8/16 bit microcontroller.
Definition elf.h:279
@ EM_VIDEOCORE3
Broadcom VideoCore III processor.
Definition elf.h:339
@ EM_RX
Renesas RX family.
Definition elf.h:361
@ EM_AVR32
Atmel Corporation 32-bit microprocessor family.
Definition elf.h:371
@ EM_LOONGARCH
Loongson Loongarch.
Definition elf.h:426
@ EM_MAX
MAX Processor.
Definition elf.h:314
@ EM_MCST_ELBRUS
MCST Elbrus general purpose hardware architecture.
Definition elf.h:363
@ EM_MANIK
M2000 Reconfigurable RISC Microprocessor.
Definition elf.h:359
@ EM_68HC08
Motorola MC68HC08 Microcontroller.
Definition elf.h:283
@ EM_XCORE
XMOS xCORE processor family.
Definition elf.h:389
@ EM_TMM_GPP
Thompson Multimedia General Purpose Processor.
Definition elf.h:308
@ EM_ME16
Toyota ME16 processor.
Definition elf.h:271
@ EM_VE
NEC Vector Engine.
Definition elf.h:419
@ EM_ALTERA_NIOS2
Altera Nios II soft-core processor.
Definition elf.h:325
@ EM_56800EX
Freescale 56800EX Digital Signal Controller (DSC)
Definition elf.h:386
@ EM_MIPS
MIPS I Architecture.
Definition elf.h:237
@ EM_TI_PRU
Texas Instruments Programmable Realtime Unit.
Definition elf.h:346
@ EM_BLACKFIN
Analog Devices Blackfin (DSP) processor.
Definition elf.h:318
@ EM_65816
WDC 65816/65C816.
Definition elf.h:425
@ EM_MOXIE
Moxie processor family.
Definition elf.h:409
@ EM_FT32
FTDI Chip FT32 high performance 32-bit RISC architecture.
Definition elf.h:408
@ EM_78KOR
Renesas 78KOR family.
Definition elf.h:385
@ EM_KMX16
KM211 KMX16 16-bit processor.
Definition elf.h:398
@ EM_SE_C17
Seiko Epson C17 family.
Definition elf.h:341
@ EM_SBF
Solana Bytecode Format.
Definition elf.h:431
@ EM_L10M
Intel L10M.
Definition elf.h:368
@ EM_SE_C33
S1C33 Family of Seiko Epson processors.
Definition elf.h:319
@ EM_STXP7X
STMicroelectronics STxP7x family of configurable and extensible RISC processors.
Definition elf.h:353
@ EM_M32C
Renesas M32C series microprocessors.
Definition elf.h:332
@ EM_VISIUM
Controls and Data Services VISIUMcore processor.
Definition elf.h:407
@ EM_KMX8
KM211 KMX8 8-bit processor.
Definition elf.h:399
@ EM_AARCH64
ARM 64-bit architecture (AARCH64)
Definition elf.h:370
@ EM_TILE64
Tilera TILE64 multicore architecture family.
Definition elf.h:373
@ EM_M16C
Renesas M16C series microprocessors.
Definition elf.h:329
@ EM_CRIS
Axis Communications 32-bit embedded processor.
Definition elf.h:288
@ EM_ECOG2
Cyan Technology eCOG2 microprocessor.
Definition elf.h:336
@ EM_HUANY
Harvard University machine-independent object files.
Definition elf.h:293
@ EM_NDS32
Andes Technology compact code size embedded RISC processor family.
Definition elf.h:354
@ EM_68HC16
Motorola MC68HC16 Microcontroller.
Definition elf.h:281
@ EM_PDP10
Digital Equipment Corp. PDP-10.
Definition elf.h:276
@ EM_CR
National Semiconductor CompactRISC microprocessor.
Definition elf.h:315
@ EM_68HC05
Motorola MC68HC05 Microcontroller.
Definition elf.h:284
@ EM_H8_500
Hitachi H8/500.
Definition elf.h:261
@ EM_VPP500
Fujitsu VPP500.
Definition elf.h:241
@ EM_PARISC
Hewlett-Packard PA-RISC.
Definition elf.h:240
@ EM_SNP1K
Trebia SNP 1000 processor.
Definition elf.h:311
@ EM_DXP
Icera Semiconductor Inc. Deep Execution Processor.
Definition elf.h:324
@ EM_TINYJ
Advanced Logic Corp. TinyJ embedded processor family.
Definition elf.h:273
@ EM_ST200
STMicroelectronics (www.st.com) ST200 microcontroller.
Definition elf.h:312
@ EM_960
Intel 80960.
Definition elf.h:243
@ EM_KM32
KM211 KM32 32-bit processor.
Definition elf.h:396
@ EM_METAG
Imagination Technologies META processor architecture.
Definition elf.h:362
@ EM_860
Intel 80860.
Definition elf.h:236
@ EM_INTEL209
Reserved by Intel.
Definition elf.h:395
@ EM_MCS6502
MOS Technology MCS 6502 processor.
Definition elf.h:422
@ EM_SIMA_MLA
SiMa MLA.
Definition elf.h:433
@ EM_DSPIC30F
Microchip Technology dsPIC30F Digital Signal Controller.
Definition elf.h:330
@ EM_FX66
Siemens FX66 microcontroller.
Definition elf.h:278
@ EM_ARC_COMPACT
ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5)
Definition elf.h:305
@ EM_KVARC
KM211 KVARC processor.
Definition elf.h:400
@ EM_XTENSA
Tensilica Xtensa Architecture.
Definition elf.h:306
@ EM_68HC12
Motorola M68HC12.
Definition elf.h:265
@ EM_DSP24
New Japan Radio (NJR) 24-bit DSP Processor.
Definition elf.h:338
@ EM_MN10200
Matsushita MN10200.
Definition elf.h:302
@ EM_RS08
Freescale RS08 embedded processor.
Definition elf.h:334
@ EM_CRX
National Semiconductor CompactRISC CRX microprocessor.
Definition elf.h:326
@ EM_VAX
Digital VAX.
Definition elf.h:287
@ EM_CR16
National Semiconductor CompactRISC CR16 16-bit microprocessor.
Definition elf.h:365
@ EM_TACHYUM
Reserved for Tachyum processor.
Definition elf.h:429
@ EM_BA1
Beyond BA1 CPU architecture.
Definition elf.h:387
@ EM_COLDFIRE
Motorola ColdFire.
Definition elf.h:264
@ EM_IMG1
Imagination Technologies.
Definition elf.h:417
@ EM_CDP
Paneve CDP architecture family.
Definition elf.h:401
@ EM_SPARC32PLUS
Enhanced instruction set SPARC.
Definition elf.h:242
@ EM_AIENGINE
AMD/Xilinx AIEngine architecture.
Definition elf.h:432
@ EM_ARCA
Arca RISC Microprocessor.
Definition elf.h:321
@ EM_XIMO16
New Japan Radio (NJR) 16-bit DSP Processor.
Definition elf.h:358
@ EM_RCE
Motorola RCE.
Definition elf.h:251
@ EM_PDP11
Digital Equipment Corp. PDP-11.
Definition elf.h:277
@ EM_SPU
IBM SPU/SPC.
Definition elf.h:247
@ EM_NORC
Nanoradio Optimized RISC.
Definition elf.h:404
@ EM_V800
NEC V800.
Definition elf.h:248
@ EM_ECOG1
Cyan Technology eCOG1X family.
Definition elf.h:355
@ EM_RH32
TRW RH-32.
Definition elf.h:250
@ EM_NONE
No machine.
Definition elf.h:229
@ EM_R32C
Renesas R32C series microprocessors.
Definition elf.h:349
@ EM_ARC
Argonaut RISC Core, Argonaut Technologies Inc.
Definition elf.h:257
@ EM_ZSP
LSI Logic 16-bit DSP Processor.
Definition elf.h:291
@ EM_NDR1
Denso NDR1 microprocessor.
Definition elf.h:269
@ EM_EXCESS
eXcess: 16/32/64-bit configurable embedded CPU
Definition elf.h:323
@ EM_PPC
PowerPC.
Definition elf.h:244
@ EM_SW64
Wuxi Institute of Advanced Technology SW64.
Definition elf.h:436
@ EM_SH
Hitachi SH.
Definition elf.h:254
@ EM_ST100
STMicroelectronics ST100 processor.
Definition elf.h:272
@ EM_CEVA_X2
CEVA X2 Processor Family.
Definition elf.h:414
@ EM_MSP430
Texas Instruments embedded microcontroller msp430.
Definition elf.h:317
@ EM_COOL
Bluechip Systems CoolEngine.
Definition elf.h:403
@ EM_CYPRESS_M8C
Cypress M8C microprocessor.
Definition elf.h:348
@ EM_8051
Intel 8051 and variants.
Definition elf.h:352
@ EM_INTEL205
Reserved by Intel.
Definition elf.h:391
@ EM_GRAPHCORE_IPU
Graphcore Intelligent Processing Unit.
Definition elf.h:416
@ EM_NFP
Netronome Flow Processor (NFP)
Definition elf.h:418
@ EM_AVR
Atmel AVR 8-bit microcontroller.
Definition elf.h:295
@ EM_VIDEOCORE5
Broadcom VideoCore V processor.
Definition elf.h:384
@ EM_NCPU
Sony nCPU embedded RISC processor.
Definition elf.h:268
@ EM_MIPS_X
Stanford MIPS-X.
Definition elf.h:263
@ EM_MAXQ30
Dallas Semiconductor MAXQ30 Core Micro-controllers.
Definition elf.h:357
@ EM_CUDA
NVIDIA CUDA architecture.
Definition elf.h:376
@ EM_D30V
Mitsubishi D30V.
Definition elf.h:298
@ EM_IAMCU
Intel MCU.
Definition elf.h:235
@ EM_UNICORE
Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University.
Definition elf.h:322
@ EM_SEP
Sharp embedded microprocessor.
Definition elf.h:320
@ EM_BA2
Beyond BA2 CPU architecture.
Definition elf.h:388
@ EM_MN10300
Matsushita MN10300.
Definition elf.h:301
@ EM_D10V
Mitsubishi D10V.
Definition elf.h:297
@ EM_RISCV
RISC-V.
Definition elf.h:411
@ EM_SPARCV9
SPARC Version 9.
Definition elf.h:255
@ EM_INTEL206
Reserved by Intel.
Definition elf.h:392
@ EM_LATTICEMICO32
RISC processor for Lattice FPGA architecture.
Definition elf.h:340
@ EM_MICROBLAZE
Xilinx MicroBlaze 32-bit RISC soft processor core.
Definition elf.h:375
@ EM_AMDGPU
AMD GPU architecture.
Definition elf.h:410
@ EM_386
Intel 80386.
Definition elf.h:232
@ EM_FIREPATH
Element 14 64-bit DSP Processor.
Definition elf.h:290
@ EM_ARC_COMPACT2
Synopsys ARCompact V2.
Definition elf.h:381
@ EM_TRIMEDIA
NXP Semiconductors TriMedia architecture family.
Definition elf.h:350
@ EM_PCP
Siemens PCP.
Definition elf.h:267
@ EM_STM8
STMicroeletronics STM8 8-bit microcontroller.
Definition elf.h:372
@ EM_COGE
Cognitive Smart Memory Processor.
Definition elf.h:402
@ EM_ST7
STMicroelectronics ST7 8-bit microcontroller.
Definition elf.h:280
@ EM_V850
NEC v850.
Definition elf.h:299
@ R_X86_64_SIZE32
word32 Z + A
Definition elf.h:700
@ R_X86_64_RELATIVE
word64 B + A
Definition elf.h:681
@ R_X86_64_GLOB_DAT
word64 S
Definition elf.h:679
@ R_X86_64_COPY
none none
Definition elf.h:678
@ R_X86_64_GOTTPOFF
word32
Definition elf.h:695
@ R_X86_64_32
word32 S + A
Definition elf.h:683
@ R_X86_64_TPOFF32
word32
Definition elf.h:696
@ R_X86_64_GOTOFF64
word64 S + A - GOT
Definition elf.h:698
@ R_X86_64_IRELATIVE
word64 indirect (B + A)
Definition elf.h:705
@ R_X86_64_GOTPCREL
word32 G + GOT + A - P
Definition elf.h:682
@ R_X86_64_TLSGD
word32
Definition elf.h:692
@ R_X86_64_64
word64 S + A
Definition elf.h:674
@ R_X86_64_TLSDESC_CALL
none
Definition elf.h:703
@ R_X86_64_GOTPC32
word32 GOT + A - P
Definition elf.h:699
@ R_X86_64_GOTPC32_TLSDESC
word32
Definition elf.h:702
@ R_X86_64_DTPOFF64
word64
Definition elf.h:690
@ R_X86_64_32S
word32 S + A
Definition elf.h:684
@ R_X86_64_TPOFF64
word64
Definition elf.h:691
@ R_X86_64_PC64
word64 S + A - P
Definition elf.h:697
@ R_X86_64_GOT32
word32 G + A
Definition elf.h:676
@ R_X86_64_PC16
word16 S + A - P
Definition elf.h:686
@ R_X86_64_NONE
none none
Definition elf.h:673
@ R_X86_64_SIZE64
word64 Z + A
Definition elf.h:701
@ R_X86_64_TLSLD
word32
Definition elf.h:693
@ R_X86_64_PC8
word8 S + A - P
Definition elf.h:688
@ R_X86_64_JUMP_SLOT
word64 S
Definition elf.h:680
@ R_X86_64_PC32
word32 S + A - P
Definition elf.h:675
@ R_X86_64_8
word8 S + A
Definition elf.h:687
@ R_X86_64_DTPOFF32
word32
Definition elf.h:694
@ R_X86_64_DTPMOD64
word64
Definition elf.h:689
@ R_X86_64_PLT32
word32 L + A - P
Definition elf.h:677
@ R_X86_64_16
word16 S + A
Definition elf.h:685
@ R_X86_64_TLSDESC
word64×2
Definition elf.h:704
@ ELFOSABI_LINUX
Linux, alias for ELFOSABI_GNU.
Definition elf.h:194
@ ELFOSABI_TRU64
Compaq TRU64 UNIX.
Definition elf.h:199
@ ELFOSABI_HPUX
Hewlett-Packard HP-UX.
Definition elf.h:191
@ ELFOSABI_NETBSD
NetBSD.
Definition elf.h:192
@ ELFOSABI_NSK
Hewlett-Packard Non-Stop Kernel.
Definition elf.h:203
@ ELFOSABI_AROS
Amiga Research OS.
Definition elf.h:204
@ ELFOSABI_OPENVMS
Open VMS.
Definition elf.h:202
@ ELFOSABI_IRIX
SGI Irix.
Definition elf.h:197
@ ELFOSABI_OPENBSD
Open BSD.
Definition elf.h:201
@ ELFOSABI_NONE
No extensions or unspecified.
Definition elf.h:190
@ ELFOSABI_AIX
IBM AIX.
Definition elf.h:196
@ ELFOSABI_SOLARIS
Sun Solaris.
Definition elf.h:195
@ ELFOSABI_OPENVOS
Stratus Technologies OpenVOS.
Definition elf.h:207
@ ELFOSABI_FENIXOS
Fenix OS.
Definition elf.h:205
@ ELFOSABI_GNU
GNU, we always expect this value.
Definition elf.h:193
@ ELFOSABI_FREEBSD
FreeBSD.
Definition elf.h:198
@ ELFOSABI_CLOUDABI
Nuxi CloudABI.
Definition elf.h:206
@ ELFOSABI_MODESTO
Novell Modesto.
Definition elf.h:200
@ SHT_HASH
Contains a symbol hash table, only 1 per file.
Definition elf.h:494
@ SHT_RELA
Contains relocation entries with explicit addends.
Definition elf.h:493
@ SHT_PROGBITS
Contains information defined by the program.
Definition elf.h:490
@ SHT_STRTAB
Contains a string table.
Definition elf.h:492
@ SHT_SYMTAB_SHNDX
Contains extended section indexes for a symbol table, used with SHN_XINDEX
Definition elf.h:505
@ SHT_REL
Contains relocation entries without explicit addends.
Definition elf.h:498
@ SHT_HIOS
End of OS-specific section types.
Definition elf.h:508
@ SHT_FINI_ARRAY
Contains an array of pointers to termination functions.
Definition elf.h:502
@ SHT_HIPROC
End of processor-specific section types.
Definition elf.h:510
@ SHT_GROUP
Contains a section group, can only appear in relocatable files.
Definition elf.h:504
@ SHT_INIT_ARRAY
Contains an array of pointers to initialization functions.
Definition elf.h:501
@ SHT_NOTE
Contains unspecified auxiliary information.
Definition elf.h:496
@ SHT_SYMTAB
Contains a symbol table, only 1 per file.
Definition elf.h:491
@ SHT_NOBITS
Acts like SHT_PROGBITS but does not occupy any space in the file.
Definition elf.h:497
@ SHT_LOUSER
Start of application-specific section types.
Definition elf.h:511
@ SHT_NULL
Does not have an associated section.
Definition elf.h:489
@ SHT_HIUSER
End of application-specific section types.
Definition elf.h:512
@ SHT_LOOS
Start of OS-specific section types.
Definition elf.h:507
@ SHT_DYNSYM
Acts like SHT_SYMTAB but holds a minimal set of dynamic linking symbols, only 1 per file.
Definition elf.h:500
@ SHT_RELR
Contains relocation entries for relative relocations without explicit addends.
Definition elf.h:506
@ SHT_PREINIT_ARRAY
Contains an array of pointers to pre-initialization functions.
Definition elf.h:503
@ SHT_SHLIB
Reserved, has unspecified semantics.
Definition elf.h:499
@ SHT_LOPROC
Start of processor-specific section types.
Definition elf.h:509
@ SHT_DYNAMIC
Contains dynamic linking information, only 1 per file.
Definition elf.h:495
@ PF_R
Readable segment.
Definition elf.h:771
@ PF_MASKPROC
All bits in this mask are reserved for processor-specific semantics.
Definition elf.h:773
@ PF_X
Executable segment.
Definition elf.h:769
@ PF_MASKOS
All bits in this mask are reserved for OS-specific semantics.
Definition elf.h:772
@ PF_W
Writable segment.
Definition elf.h:770
@ ET_NONE
No file type.
Definition elf.h:216
@ ET_REL
Relocatable file.
Definition elf.h:217
@ ET_DYN
Shared object file.
Definition elf.h:219
@ ET_CORE
Core file.
Definition elf.h:220
@ ET_EXEC
Executable file.
Definition elf.h:218
@ STT_LOPROC
Start of processor-specific symbol types.
Definition elf.h:596
@ STT_FUNC
Symbol is a code object.
Definition elf.h:591
@ STT_LOOS
Start of OS-specific symbol types.
Definition elf.h:594
@ STT_NOTYPE
Symbol type is unspecified.
Definition elf.h:589
@ STT_OBJECT
Symbol is a data object.
Definition elf.h:590
@ STT_HIOS
End of OS-specific symbol types.
Definition elf.h:595
@ STT_FILE
Symbol's name is the name of a source file.
Definition elf.h:593
@ STT_SECTION
Symbol associated with a section.
Definition elf.h:592
@ STT_HIPROC
End of processor-specific symbol types.
Definition elf.h:597
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__INT32_TYPE__ int32_t
Definition stdint.h:14
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
ELF64 Header.
Definition elf.h:95
Elf64_Half e_type
Object file type.
Definition elf.h:97
Elf64_Half e_shentsize
Size in bytes of one entry in the files section header table.
Definition elf.h:107
Elf64_Half e_shnum
Definition elf.h:114
Elf64_Word e_version
Object file version.
Definition elf.h:99
Elf64_Half e_ehsize
Size of this header in bytes, should be sizeof(Elf64_Ehdr)
Definition elf.h:104
Elf64_Off e_shoff
Section header table's file offset in bytes, or 0 if there are no section headers.
Definition elf.h:102
Elf64_Addr e_entry
Entry point virtual address.
Definition elf.h:100
Elf64_Half e_phentsize
Size in bytes of one entry in the files program header table.
Definition elf.h:105
Elf64_Off e_phoff
Program header tables's file offset in bytes, or 0 if there are no program headers.
Definition elf.h:101
Elf64_Half e_machine
The required architecture.
Definition elf.h:98
Elf64_Word e_flags
Processor-specific flags.
Definition elf.h:103
Elf64_Half e_shstrndx
Definition elf.h:123
Elf64_Half e_phnum
Number of entries in the program header table.
Definition elf.h:106
ELF File Helper structure.
Definition elf.h:781
uint64_t size
The size of the file in bytes.
Definition elf.h:783
Elf64_Shdr * dynsym
The dynamic symbol table section, or NULL if not found.
Definition elf.h:785
Elf64_Ehdr * header
The data in the file, pointed to the start of the ELF header.
Definition elf.h:782
Elf64_Shdr * symtab
The symbol table section, or NULL if not found.
Definition elf.h:784
ELF64 Program Header.
Definition elf.h:730
Elf64_Xword p_memsz
Size of segment in memory in bytes.
Definition elf.h:737
Elf64_Addr p_vaddr
Target virtual address in memory.
Definition elf.h:734
Elf64_Addr p_paddr
Target physical address, ignored on systems without physical addressing.
Definition elf.h:735
Elf64_Off p_offset
Segment file offset in bytes.
Definition elf.h:733
Elf64_Xword p_align
Segment alignment requirement.
Definition elf.h:738
Elf64_Word p_flags
Segment flags.
Definition elf.h:732
Elf64_Word p_type
Segment type.
Definition elf.h:731
Elf64_Xword p_filesz
Size of segment in file in bytes.
Definition elf.h:736
ELF64 Rel Entry without addend.
Definition elf.h:616
Elf64_Xword r_info
Definition elf.h:618
Elf64_Addr r_offset
Definition elf.h:617
ELF64 Rela Entry with addend.
Definition elf.h:626
Elf64_Sxword r_addend
Definition elf.h:629
Elf64_Addr r_offset
Definition elf.h:627
Elf64_Xword r_info
Definition elf.h:628
ELF64 Section Header.
Definition elf.h:468
Elf64_Word sh_name
Index of the section name in the string table.
Definition elf.h:469
Elf64_Xword sh_flags
Section flags.
Definition elf.h:471
Elf64_Word sh_link
Definition elf.h:475
Elf64_Word sh_type
Section type.
Definition elf.h:470
Elf64_Word sh_info
Depends on section type.
Definition elf.h:477
Elf64_Xword sh_entsize
Definition elf.h:479
Elf64_Xword sh_size
Section size in bytes.
Definition elf.h:474
Elf64_Xword sh_addralign
Section byte alignment requirement.
Definition elf.h:478
Elf64_Addr sh_addr
If the section will appear in memory, this will be its virtual address, otherwise 0
Definition elf.h:472
Elf64_Off sh_offset
Section's file offset in bytes.
Definition elf.h:473
ELF64 Symbol Table Entry.
Definition elf.h:543
Elf64_Half st_shndx
Definition elf.h:547
Elf64_Word st_name
Definition elf.h:544
Elf64_Addr st_value
Definition elf.h:548
unsigned char st_info
Definition elf.h:545
unsigned char st_other
Definition elf.h:546
Elf64_Xword st_size
Definition elf.h:549