1 /* $NetBSD: exec_elf.h,v 1.186 2025/12/10 14:30:33 jkoshy Exp $ */ 2 3 /*- 4 * Copyright (c) 1994 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _SYS_EXEC_ELF_H_ 33 #define _SYS_EXEC_ELF_H_ 2 34 /* 35 * File version 2: changed Elfnn_Versym (and so Elf_Versym) 36 * from being a struct with a vs_vers field containing the 37 * version info, to being an Elf_Half (ie: uint16_t) which 38 * contains the version directly. 39 */ 40 41 /* 42 * The current ELF ABI specification is available at: 43 * http://www.sco.com/developers/gabi/ 44 * 45 * The definition of the ELF object file format is available at: 46 * https://gabi.xinuos.com/ 47 */ 48 49 #if defined(_KERNEL) || defined(_STANDALONE) 50 #include <sys/types.h> 51 #else 52 #include <inttypes.h> 53 #include <stddef.h> 54 #endif /* _KERNEL || _STANDALONE */ 55 56 #if HAVE_NBTOOL_CONFIG_H 57 #include <nbinclude/machine/elf_machdep.h> 58 #else 59 #include <machine/elf_machdep.h> 60 #endif 61 62 /* 63 * Skip the generic ELF-related definitions provide by this file 64 * if <sys/elfdefinitions.h> has already been seen. 65 * 66 * This is a work-around to allow code to use either or both of 67 * <sys/elfdefinitions.h> and <sys/exec_elf.h> without breaking 68 * the build. 69 */ 70 #if !defined(_SYS_ELFDEFINITIONS_H_) 71 /* 72 * Definitions that make up the ELF(3) API. 73 */ 74 75 typedef uint8_t Elf_Byte; 76 77 typedef uint32_t Elf32_Addr; 78 typedef uint32_t Elf32_Off; 79 typedef int32_t Elf32_SOff; 80 typedef int32_t Elf32_Sword; 81 typedef uint32_t Elf32_Word; 82 typedef uint16_t Elf32_Half; 83 typedef uint64_t Elf32_Lword; 84 85 typedef uint64_t Elf64_Addr; 86 typedef uint64_t Elf64_Off; 87 typedef int64_t Elf64_SOff; 88 89 typedef int32_t Elf64_Sword; 90 typedef uint32_t Elf64_Word; 91 92 typedef int64_t Elf64_Sxword; 93 typedef uint64_t Elf64_Xword; 94 typedef uint64_t Elf64_Lword; 95 typedef uint16_t Elf64_Half; 96 97 /* 98 * ELF Header 99 */ 100 #define EI_NIDENT 16 101 102 typedef struct { 103 unsigned char e_ident[EI_NIDENT]; /* Id bytes */ 104 Elf32_Half e_type; /* file type */ 105 Elf32_Half e_machine; /* machine type */ 106 Elf32_Word e_version; /* version number */ 107 Elf32_Addr e_entry; /* entry point */ 108 Elf32_Off e_phoff; /* Program hdr offset */ 109 Elf32_Off e_shoff; /* Section hdr offset */ 110 Elf32_Word e_flags; /* Processor flags */ 111 Elf32_Half e_ehsize; /* sizeof ehdr */ 112 Elf32_Half e_phentsize; /* Program header entry size */ 113 Elf32_Half e_phnum; /* Number of program headers */ 114 Elf32_Half e_shentsize; /* Section header entry size */ 115 Elf32_Half e_shnum; /* Number of section headers */ 116 Elf32_Half e_shstrndx; /* String table index */ 117 } Elf32_Ehdr; 118 119 typedef struct { 120 unsigned char e_ident[EI_NIDENT]; /* Id bytes */ 121 Elf64_Half e_type; /* file type */ 122 Elf64_Half e_machine; /* machine type */ 123 Elf64_Word e_version; /* version number */ 124 Elf64_Addr e_entry; /* entry point */ 125 Elf64_Off e_phoff; /* Program hdr offset */ 126 Elf64_Off e_shoff; /* Section hdr offset */ 127 Elf64_Word e_flags; /* Processor flags */ 128 Elf64_Half e_ehsize; /* sizeof ehdr */ 129 Elf64_Half e_phentsize; /* Program header entry size */ 130 Elf64_Half e_phnum; /* Number of program headers */ 131 Elf64_Half e_shentsize; /* Section header entry size */ 132 Elf64_Half e_shnum; /* Number of section headers */ 133 Elf64_Half e_shstrndx; /* String table index */ 134 } Elf64_Ehdr; 135 136 /* e_ident offsets */ 137 #define EI_MAG0 0 /* '\177' */ 138 #define EI_MAG1 1 /* 'E' */ 139 #define EI_MAG2 2 /* 'L' */ 140 #define EI_MAG3 3 /* 'F' */ 141 #define EI_CLASS 4 /* File class */ 142 #define EI_DATA 5 /* Data encoding */ 143 #define EI_VERSION 6 /* File version */ 144 #define EI_OSABI 7 /* Operating system/ABI identification */ 145 #define EI_ABIVERSION 8 /* ABI version */ 146 #define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/ 147 148 /* e_ident[EI_MAG0,EI_MAG3] */ 149 #define ELFMAG0 0x7f 150 #define ELFMAG1 'E' 151 #define ELFMAG2 'L' 152 #define ELFMAG3 'F' 153 #define ELFMAG "\177ELF" 154 #define SELFMAG 4 155 156 /* e_ident[EI_CLASS] */ 157 #define ELFCLASSNONE 0 /* Invalid class */ 158 #define ELFCLASS32 1 /* 32-bit objects */ 159 #define ELFCLASS64 2 /* 64-bit objects */ 160 161 /* e_ident[EI_DATA] */ 162 #define ELFDATANONE 0 /* Invalid data encoding */ 163 #define ELFDATA2LSB 1 /* 2's complement values, LSB first */ 164 #define ELFDATA2MSB 2 /* 2's complement values, MSB first */ 165 166 /* e_ident[EI_VERSION] */ 167 #define EV_NONE 0 /* Invalid version */ 168 #define EV_CURRENT 1 /* Current version */ 169 170 /* e_ident[EI_OSABI] */ 171 #define ELFOSABI_SYSV 0 /* UNIX System V ABI */ 172 #define ELFOSABI_HPUX 1 /* HP-UX operating system */ 173 #define ELFOSABI_NETBSD 2 /* NetBSD */ 174 #define ELFOSABI_GNU 3 /* GNU/Linux */ 175 #define ELFOSABI_HURD 4 /* GNU/Hurd - historical */ 176 #define ELFOSABI_86OPEN 5 /* 86Open - historical */ 177 #define ELFOSABI_SOLARIS 6 /* Solaris */ 178 #define ELFOSABI_AIX 7 /* AIX */ 179 #define ELFOSABI_IRIX 8 /* IRIX */ 180 #define ELFOSABI_FREEBSD 9 /* FreeBSD */ 181 #define ELFOSABI_TRU64 10 /* TRU64 UNIX */ 182 #define ELFOSABI_MODESTO 11 /* Novell Modesto */ 183 #define ELFOSABI_OPENBSD 12 /* OpenBSD */ 184 #define ELFOSABI_OPENVMS 13 /* OpenVMS */ 185 #define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */ 186 #define ELFOSABI_AROS 15 /* Amiga Research OS */ 187 #define ELFOSABI_FENIXOS 16 /* The FenixOS highly scalable multi-core OS */ 188 #define ELFOSABI_CLOUDABI 17 /* Nuxi CloudABI */ 189 #define ELFOSABI_OPENVOS 18 /* Stratus Technologies OpenVOS */ 190 /* Unofficial OSABIs follow */ 191 #define ELFOSABI_ARM 97 /* ARM */ 192 #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 193 194 #define ELFOSABI_NONE ELFOSABI_SYSV 195 196 /* Historical aliases. */ 197 #define ELFOSABI_LINUX ELFOSABI_GNU 198 #define ELFOSABI_MONTEREY ELFOSABI_AIX 199 200 /* e_type */ 201 #define ET_NONE 0 /* No file type */ 202 #define ET_REL 1 /* Relocatable file */ 203 #define ET_EXEC 2 /* Executable file */ 204 #define ET_DYN 3 /* Shared object file */ 205 #define ET_CORE 4 /* Core file */ 206 207 #define ET_LOOS 0xfe00 /* Operating system specific range */ 208 #define ET_HIOS 0xfeff 209 #define ET_LOPROC 0xff00 /* Processor-specific range */ 210 #define ET_HIPROC 0xffff 211 212 /* e_machine */ 213 #define EM_NONE 0 /* No machine */ 214 #define EM_M32 1 /* AT&T WE 32100 */ 215 #define EM_SPARC 2 /* SPARC */ 216 #define EM_386 3 /* Intel 80386 */ 217 #define EM_68K 4 /* Motorola 68000 */ 218 #define EM_88K 5 /* Motorola 88000 */ 219 #define EM_486 6 /* Intel 80486 [old] */ 220 #define EM_IAMCU EM_486 /* Intel MCU. */ 221 #define EM_860 7 /* Intel 80860 */ 222 #define EM_MIPS 8 /* MIPS I Architecture */ 223 #define EM_S370 9 /* Amdahl UTS on System/370 */ 224 #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ 225 /* 11-14 - Reserved */ 226 #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ 227 /* 16 - Reserved */ 228 #define EM_VPP500 17 /* Fujitsu VPP500 */ 229 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ 230 #define EM_960 19 /* Intel 80960 */ 231 #define EM_PPC 20 /* PowerPC */ 232 #define EM_PPC64 21 /* 64-bit PowerPC */ 233 #define EM_S390 22 /* IBM System/390 Processor */ 234 #define EM_SPU 23 /* IBM SPU/SPC */ 235 /* 24-35 - Reserved */ 236 #define EM_V800 36 /* NEC V800 */ 237 #define EM_FR20 37 /* Fujitsu FR20 */ 238 #define EM_RH32 38 /* TRW RH-32 */ 239 #define EM_RCE 39 /* Motorola RCE */ 240 #define EM_ARM 40 /* Advanced RISC Machines ARM */ 241 #define EM_OLD_ALPHA 41 /* DIGITAL Alpha (obsolete) */ 242 #define EM_SH 42 /* Hitachi Super-H */ 243 #define EM_SPARCV9 43 /* SPARC Version 9 */ 244 #define EM_TRICORE 44 /* Siemens Tricore */ 245 #define EM_ARC 45 /* Argonaut RISC Core */ 246 #define EM_H8_300 46 /* Hitachi H8/300 */ 247 #define EM_H8_300H 47 /* Hitachi H8/300H */ 248 #define EM_H8S 48 /* Hitachi H8S */ 249 #define EM_H8_500 49 /* Hitachi H8/500 */ 250 #define EM_IA_64 50 /* Intel Merced Processor */ 251 #define EM_MIPS_X 51 /* Stanford MIPS-X */ 252 #define EM_COLDFIRE 52 /* Motorola Coldfire */ 253 #define EM_68HC12 53 /* Motorola MC68HC12 */ 254 #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */ 255 #define EM_PCP 55 /* Siemens PCP */ 256 #define EM_NCPU 56 /* Sony nCPU embedded RISC processor */ 257 #define EM_NDR1 57 /* Denso NDR1 microprocessor */ 258 #define EM_STARCORE 58 /* Motorola Star*Core processor */ 259 #define EM_ME16 59 /* Toyota ME16 processor */ 260 #define EM_ST100 60 /* STMicroelectronics ST100 processor */ 261 #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded family processor */ 262 #define EM_X86_64 62 /* AMD x86-64 architecture */ 263 #define EM_PDSP 63 /* Sony DSP Processor */ 264 #define EM_PDP10 64 /* Digital Equipment Corp. PDP-10 */ 265 #define EM_PDP11 65 /* Digital Equipment Corp. PDP-11 */ 266 #define EM_FX66 66 /* Siemens FX66 microcontroller */ 267 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */ 268 #define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */ 269 #define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */ 270 #define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */ 271 #define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */ 272 #define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */ 273 #define EM_SVX 73 /* Silicon Graphics SVx */ 274 #define EM_ST19 74 /* STMicroelectronics ST19 8-bit CPU */ 275 #define EM_VAX 75 /* Digital VAX */ 276 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ 277 #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded CPU */ 278 #define EM_FIREPATH 78 /* Element 14 64-bit DSP processor */ 279 #define EM_ZSP 79 /* LSI Logic's 16-bit DSP processor */ 280 #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ 281 #define EM_HUANY 81 /* Harvard's machine-independent format */ 282 #define EM_PRISM 82 /* SiTera Prism */ 283 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ 284 #define EM_FR30 84 /* Fujitsu FR30 */ 285 #define EM_D10V 85 /* Mitsubishi D10V */ 286 #define EM_D30V 86 /* Mitsubishi D30V */ 287 #define EM_V850 87 /* NEC v850 */ 288 #define EM_M32R 88 /* Mitsubishi M32R */ 289 #define EM_MN10300 89 /* Matsushita MN10300 */ 290 #define EM_MN10200 90 /* Matsushita MN10200 */ 291 #define EM_PJ 91 /* picoJava */ 292 #define EM_OR1K 92 /* OpenRISC 32-bit embedded processor */ 293 #define EM_OPENRISC EM_OR1K 294 #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ 295 #define EM_ARC_COMPACT EM_ARC_A5 /* ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5) */ 296 #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ 297 #define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */ 298 #define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */ 299 #define EM_NS32K 97 /* National Semiconductor 32000 series */ 300 #define EM_TPC 98 /* Tenor Network TPC processor */ 301 #define EM_SNP1K 99 /* Trebia SNP 1000 processor */ 302 #define EM_ST200 100 /* STMicroelectronics ST200 microcontroller */ 303 #define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */ 304 #define EM_MAX 102 /* MAX processor */ 305 #define EM_CR 103 /* National Semiconductor CompactRISC microprocessor */ 306 #define EM_F2MC16 104 /* Fujitsu F2MC16 */ 307 #define EM_MSP430 105 /* Texas Instruments MSP430 */ 308 #define EM_BLACKFIN 106 /* Analog Devices Blackfin DSP */ 309 #define EM_SE_C33 107 /* Seiko Epson S1C33 family */ 310 #define EM_SEP 108 /* Sharp embedded microprocessor */ 311 #define EM_ARCA 109 /* Arca RISC microprocessor */ 312 #define EM_UNICORE 110 /* UNICORE from PKU-Unity Ltd. and MPRC Peking University */ 313 #define EM_EXCESS 111 /* eXcess: 16/32/64-bit configurable embedded CPU */ 314 #define EM_DXP 112 /* Icera Semiconductor Inc. Deep Execution Processor */ 315 #define EM_ALTERA_NIOS2 113 /* Altera Nios II soft-core processor */ 316 #define EM_CRX 114 /* National Semiconductor CompactRISC CRX microprocessor */ 317 #define EM_XGATE 115 /* Motorola XGATE embedded processor */ 318 #define EM_C166 116 /* Infineon C16x/XC16x processor */ 319 #define EM_M16C 117 /* Renesas M16C series microprocessors */ 320 #define EM_DSPIC30F 118 /* Microchip Technology dsPIC30F Digital Signal Controller */ 321 #define EM_CE 119 /* Freescale Communication Engine RISC core */ 322 #define EM_M32C 120 /* Renesas M32C series microprocessors */ 323 /* 121-130 - Reserved */ 324 #define EM_TSK3000 131 /* Altium TSK3000 core */ 325 #define EM_RS08 132 /* Freescale RS08 embedded processor */ 326 #define EM_SHARC 133 /* Analog Devices SHARC family of 32-bit DSP processors */ 327 #define EM_ECOG2 134 /* Cyan Technology eCOG2 microprocessor */ 328 #define EM_SCORE7 135 /* Sunplus S+core7 RISC processor */ 329 #define EM_DSP24 136 /* New Japan Radio (NJR) 24-bit DSP Processor */ 330 #define EM_VIDEOCORE3 137 /* Broadcom VideoCore III processor */ 331 #define EM_LATTICEMICO32 138 /* RISC processor for Lattice FPGA architecture */ 332 #define EM_SE_C17 139 /* Seiko Epson C17 family */ 333 #define EM_TI_C6000 140 /* The Texas Instruments TMS320C6000 DSP family */ 334 #define EM_TI_C2000 141 /* The Texas Instruments TMS320C2000 DSP family */ 335 #define EM_TI_C5500 142 /* The Texas Instruments TMS320C55x DSP family */ 336 #define EM_TI_ARP32 143 /* Texas Instruments Application Specific RISC Processor, 32bit fetch */ 337 #define EM_TI_PRU 144 /* Texas Instruments Programmable Realtime Unit */ 338 /* 145-159 - Reserved */ 339 #define EM_MMDSP_PLUS 160 /* STMicroelectronics 64bit VLIW Data Signal Processor */ 340 #define EM_CYPRESS_M8C 161 /* Cypress M8C microprocessor */ 341 #define EM_R32C 162 /* Renesas R32C series microprocessors */ 342 #define EM_TRIMEDIA 163 /* NXP Semiconductors TriMedia architecture family */ 343 #define EM_QDSP6 164 /* QUALCOMM DSP6 Processor */ 344 #define EM_8051 165 /* Intel 8051 and variants */ 345 #define EM_STXP7X 166 /* STMicroelectronics STxP7x family of configurable and extensible RISC processors */ 346 #define EM_NDS32 167 /* Andes Technology compact code size embedded RISC processor family */ 347 #define EM_ECOG1 168 /* Cyan Technology eCOG1X family */ 348 #define EM_ECOG1X 168 /* Cyan Technology eCOG1X family */ 349 #define EM_MAXQ30 169 /* Dallas Semiconductor MAXQ30 Core Micro-controllers */ 350 #define EM_XIMO16 170 /* New Japan Radio (NJR) 16-bit DSP Processor */ 351 #define EM_MANIK 171 /* M2000 Reconfigurable RISC Microprocessor */ 352 #define EM_CRAYNV2 172 /* Cray Inc. NV2 vector architecture */ 353 #define EM_RX 173 /* Renesas RX family */ 354 #define EM_METAG 174 /* Imagination Technologies META processor architecture */ 355 #define EM_MCST_ELBRUS 175 /* MCST Elbrus general purpose hardware architecture */ 356 #define EM_ECOG16 176 /* Cyan Technology eCOG16 family */ 357 #define EM_CR16 177 /* National Semiconductor CompactRISC CR16 16-bit microprocessor */ 358 #define EM_ETPU 178 /* Freescale Extended Time Processing Unit */ 359 #define EM_SLE9X 179 /* Infineon Technologies SLE9X core */ 360 #define EM_L10M 180 /* Intel L10M */ 361 #define EM_K10M 181 /* Intel K10M */ 362 /* 182 - Reserved */ 363 #define EM_AARCH64 183 /* AArch64 64-bit ARM microprocessor */ 364 /* 184 - Reserved */ 365 #define EM_AVR32 185 /* Atmel Corporation 32-bit microprocessor family*/ 366 #define EM_STM8 186 /* STMicroelectronics STM8 8-bit microcontroller */ 367 #define EM_TILE64 187 /* Tilera TILE64 multicore architecture family */ 368 #define EM_TILEPRO 188 /* Tilera TILEPro multicore architecture family */ 369 #define EM_MICROBLAZE 189 /* Xilinx MicroBlaze 32-bit RISC soft processor core */ 370 #define EM_CUDA 190 /* NVIDIA CUDA architecture */ 371 #define EM_TILEGX 191 /* Tilera TILE-GX multicore architecture family */ 372 #define EM_CLOUDSHIELD 192 /* CloudShield architecture family */ 373 #define EM_COREA_1ST 193 /* KIPO-KAIST Core-A 1st generation processor family */ 374 #define EM_COREA_2ND 194 /* KIPO-KAIST Core-A 2nd generation processor family */ 375 #define EM_ARC_COMPACT2 195 /* Synopsys ARCompact V2 */ 376 #define EM_OPEN8 196 /* Open8 8-bit RISC soft processor core */ 377 #define EM_RL78 197 /* Renesas RL78 family */ 378 #define EM_VIDEOCORE5 198 /* Broadcom VideoCore V processor */ 379 #define EM_78KOR 199 /* Renesas 78KOR family */ 380 #define EM_56800EX 200 /* Freescale 56800EX Digital Signal Controller (DSC) */ 381 #define EM_BA1 201 /* Beyond BA1 CPU architecture */ 382 #define EM_BA2 202 /* Beyond BA2 CPU architecture */ 383 #define EM_XCORE 203 /* XMOS xCORE processor family */ 384 #define EM_MCHP_PIC 204 /* Microchip 8-bit PIC(r) family */ 385 #define EM_INTEL205 205 /* Reserved by Intel */ 386 #define EM_INTEL206 206 /* Reserved by Intel */ 387 #define EM_INTEL207 207 /* Reserved by Intel */ 388 #define EM_INTEL208 208 /* Reserved by Intel */ 389 #define EM_INTEL209 209 /* Reserved by Intel */ 390 #define EM_KM32 210 /* KM211 KM32 32-bit processor */ 391 #define EM_KMX32 211 /* KM211 KMX32 32-bit processor */ 392 #define EM_KMX16 212 /* KM211 KMX16 16-bit processor */ 393 #define EM_KMX8 213 /* KM211 KMX8 8-bit processor */ 394 #define EM_KVARC 214 /* KM211 KVARC processor */ 395 #define EM_CDP 215 /* Paneve CDP architecture family */ 396 #define EM_COGE 216 /* Cognitive Smart Memory Processor */ 397 #define EM_COOL 217 /* Bluechip Systems CoolEngine */ 398 #define EM_NORC 218 /* Nanoradio Optimized RISC */ 399 #define EM_CSR_KALIMBA 219 /* CSR Kalimba architecture family */ 400 #define EM_Z80 220 /* Zilog Z80 */ 401 #define EM_VISIUM 221 /* Controls and Data Services VISIUMcore processor */ 402 #define EM_FT32 222 /* FTDI Chip FT32 high performance 32-bit RISC architecture */ 403 #define EM_MOXIE 223 /* Moxie processor family */ 404 #define EM_AMDGPU 224 /* AMD GPU architecture */ 405 /* 225-242 - Reserved */ 406 #define EM_RISCV 243 /* RISC-V */ 407 408 /* Unofficial machine types follow */ 409 #define EM_ALPHA 36902 /* DIGITAL Alpha */ 410 411 /* 412 * Program Header 413 */ 414 typedef struct { 415 Elf32_Word p_type; /* entry type */ 416 Elf32_Off p_offset; /* offset */ 417 Elf32_Addr p_vaddr; /* virtual address */ 418 Elf32_Addr p_paddr; /* physical address */ 419 Elf32_Word p_filesz; /* file size */ 420 Elf32_Word p_memsz; /* memory size */ 421 Elf32_Word p_flags; /* flags */ 422 Elf32_Word p_align; /* memory & file alignment */ 423 } Elf32_Phdr; 424 425 typedef struct { 426 Elf64_Word p_type; /* entry type */ 427 Elf64_Word p_flags; /* flags */ 428 Elf64_Off p_offset; /* offset */ 429 Elf64_Addr p_vaddr; /* virtual address */ 430 Elf64_Addr p_paddr; /* physical address */ 431 Elf64_Xword p_filesz; /* file size */ 432 Elf64_Xword p_memsz; /* memory size */ 433 Elf64_Xword p_align; /* memory & file alignment */ 434 } Elf64_Phdr; 435 436 /* p_type */ 437 #define PT_NULL 0 /* Program header table entry unused */ 438 #define PT_LOAD 1 /* Loadable program segment */ 439 #define PT_DYNAMIC 2 /* Dynamic linking information */ 440 #define PT_INTERP 3 /* Program interpreter */ 441 #define PT_NOTE 4 /* Auxiliary information */ 442 #define PT_SHLIB 5 /* Reserved, unspecified semantics */ 443 #define PT_PHDR 6 /* Entry for header table itself */ 444 #define PT_TLS 7 /* TLS initialisation image */ 445 #define PT_NUM 8 446 447 #define PT_LOOS 0x60000000 /* OS-specific range */ 448 449 /* GNU-specific */ 450 #define PT_GNU_EH_FRAME 0x6474e550 /* EH frame segment */ 451 #define PT_GNU_STACK 0x6474e551 /* Indicate executable stack */ 452 #define PT_GNU_RELRO 0x6474e552 /* Make read-only after relocation */ 453 454 #define PT_HIOS 0x6fffffff 455 #define PT_LOPROC 0x70000000 /* Processor-specific range */ 456 #define PT_HIPROC 0x7fffffff 457 458 #define PT_MIPS_REGINFO 0x70000000 459 #define PT_MIPS_ABIFLAGS 0x70000003 460 461 /* p_flags */ 462 #define PF_R 0x4 /* Segment is readable */ 463 #define PF_W 0x2 /* Segment is writable */ 464 #define PF_X 0x1 /* Segment is executable */ 465 466 #define PF_MASKOS 0x0ff00000 /* Operating system specific values */ 467 #define PF_MASKPROC 0xf0000000 /* Processor-specific values */ 468 469 /* Extended program header index. */ 470 #define PN_XNUM 0xffff 471 472 /* 473 * Section Headers 474 */ 475 typedef struct { 476 Elf32_Word sh_name; /* section name (.shstrtab index) */ 477 Elf32_Word sh_type; /* section type */ 478 Elf32_Word sh_flags; /* section flags */ 479 Elf32_Addr sh_addr; /* virtual address */ 480 Elf32_Off sh_offset; /* file offset */ 481 Elf32_Word sh_size; /* section size */ 482 Elf32_Word sh_link; /* link to another */ 483 Elf32_Word sh_info; /* misc info */ 484 Elf32_Word sh_addralign; /* memory alignment */ 485 Elf32_Word sh_entsize; /* table entry size */ 486 } Elf32_Shdr; 487 488 typedef struct { 489 Elf64_Word sh_name; /* section name (.shstrtab index) */ 490 Elf64_Word sh_type; /* section type */ 491 Elf64_Xword sh_flags; /* section flags */ 492 Elf64_Addr sh_addr; /* virtual address */ 493 Elf64_Off sh_offset; /* file offset */ 494 Elf64_Xword sh_size; /* section size */ 495 Elf64_Word sh_link; /* link to another */ 496 Elf64_Word sh_info; /* misc info */ 497 Elf64_Xword sh_addralign; /* memory alignment */ 498 Elf64_Xword sh_entsize; /* table entry size */ 499 } Elf64_Shdr; 500 501 /* sh_type */ 502 #define SHT_NULL 0 /* Section header table entry unused */ 503 #define SHT_PROGBITS 1 /* Program information */ 504 #define SHT_SYMTAB 2 /* Symbol table */ 505 #define SHT_STRTAB 3 /* String table */ 506 #define SHT_RELA 4 /* Relocation information w/ addend */ 507 #define SHT_HASH 5 /* Symbol hash table */ 508 #define SHT_DYNAMIC 6 /* Dynamic linking information */ 509 #define SHT_NOTE 7 /* Auxiliary information */ 510 #define SHT_NOBITS 8 /* No space allocated in file image */ 511 #define SHT_REL 9 /* Relocation information w/o addend */ 512 #define SHT_SHLIB 10 /* Reserved, unspecified semantics */ 513 #define SHT_DYNSYM 11 /* Symbol table for dynamic linker */ 514 #define SHT_INIT_ARRAY 14 /* Initialization function pointers */ 515 #define SHT_FINI_ARRAY 15 /* Termination function pointers */ 516 #define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs */ 517 #define SHT_GROUP 17 /* Section group */ 518 #define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX) */ 519 #define SHT_RELR 19 /* Relative relocation information */ 520 521 #define SHT_LOOS 0x60000000 /* Operating system specific range */ 522 #define SHT_GNU_INCREMENTAL_INPUTS 0x6fff4700 /* GNU incremental build data */ 523 #define SHT_SUNW_dof 0x6ffffff4 524 #define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* GNU object attributes */ 525 #define SHT_SUNW_cap 0x6ffffff5 526 #define SHT_SUNW_SIGNATURE 0x6ffffff6 527 #define SHT_GNU_HASH 0x6ffffff6 /* GNU style symbol hash table */ 528 #define SHT_GNU_LIBLIST 0x6ffffff7 /* GNU list of prelink dependencies */ 529 #define SHT_SUNW_move 0x6ffffffa 530 #define SHT_SUNW_COMDAT 0x6ffffffb 531 #define SHT_SUNW_syminfo 0x6ffffffc 532 #define SHT_SUNW_verdef 0x6ffffffd /* Versions defined by file */ 533 #define SHT_GNU_verdef SHT_SUNW_verdef 534 #define SHT_SUNW_verneed 0x6ffffffe /* Versions needed by file */ 535 #define SHT_GNU_verneed SHT_SUNW_verneed 536 #define SHT_SUNW_versym 0x6fffffff /* Symbol versions */ 537 #define SHT_GNU_versym SHT_SUNW_versym 538 #define SHT_HIOS 0x6fffffff 539 #define SHT_LOPROC 0x70000000 /* Processor-specific range */ 540 #define SHT_AMD64_UNWIND 0x70000001 /* unwind information */ 541 #define SHT_ARM_EXIDX 0x70000001 /* exception index table */ 542 #define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking 543 * pre-emption map */ 544 #define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility 545 * attributes */ 546 #define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */ 547 #define SHT_ARM_OVERLAYSECTION 0x70000005 548 #define SHT_MIPS_REGINFO 0x70000006 549 #define SHT_MIPS_OPTIONS 0x7000000d 550 #define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */ 551 #define SHT_MIPS_XHASH 0x7000002b /* MIPS version of GNU_HASH */ 552 #define SHT_HIPROC 0x7fffffff 553 #define SHT_LOUSER 0x80000000 /* Application-specific range */ 554 #define SHT_HIUSER 0xffffffff 555 556 /* sh_flags */ 557 #define SHF_WRITE 0x00000001 /* Contains writable data */ 558 #define SHF_ALLOC 0x00000002 /* Occupies memory */ 559 #define SHF_EXECINSTR 0x00000004 /* Contains executable insns */ 560 #define SHF_MERGE 0x00000010 /* Might be merged */ 561 #define SHF_STRINGS 0x00000020 /* Contains nul terminated strings */ 562 #define SHF_INFO_LINK 0x00000040 /* "sh_info" contains SHT index */ 563 #define SHF_LINK_ORDER 0x00000080 /* Preserve order after combining */ 564 #define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */ 565 #define SHF_GROUP 0x00000200 /* Is member of a group */ 566 #define SHF_TLS 0x00000400 /* Holds thread-local data */ 567 #define SHF_MASKOS 0x0ff00000 /* Operating system specific values */ 568 #define SHF_MASKPROC 0xf0000000 /* Processor-specific values */ 569 #define SHF_ORDERED 0x40000000 /* Ordering requirement (Solaris) */ 570 #define SHF_EXCLUDE 0x80000000 /* Excluded unless unles ref/alloc 571 (Solaris).*/ 572 /* 573 * Symbol Table 574 */ 575 typedef struct { 576 Elf32_Word st_name; /* Symbol name (.strtab index) */ 577 Elf32_Addr st_value; /* value of symbol */ 578 Elf32_Word st_size; /* size of symbol */ 579 Elf_Byte st_info; /* type / binding attrs */ 580 Elf_Byte st_other; /* unused */ 581 Elf32_Half st_shndx; /* section index of symbol */ 582 } Elf32_Sym; 583 584 typedef struct { 585 Elf64_Word st_name; /* Symbol name (.strtab index) */ 586 Elf_Byte st_info; /* type / binding attrs */ 587 Elf_Byte st_other; /* unused */ 588 Elf64_Half st_shndx; /* section index of symbol */ 589 Elf64_Addr st_value; /* value of symbol */ 590 Elf64_Xword st_size; /* size of symbol */ 591 } Elf64_Sym; 592 593 #define STN_UNDEF 0 /* undefined index */ 594 595 /* st_info: Symbol Bindings */ 596 #define STB_LOCAL 0 /* local symbol */ 597 #define STB_GLOBAL 1 /* global symbol */ 598 #define STB_WEAK 2 /* weakly defined global symbol */ 599 600 #define STB_LOOS 10 /* Operating system specific range */ 601 #define STB_HIOS 12 602 #define STB_LOPROC 13 /* Processor-specific range */ 603 #define STB_HIPROC 15 604 605 /* st_info: Symbol Types */ 606 #define STT_NOTYPE 0 /* Type not specified */ 607 #define STT_OBJECT 1 /* Associated with a data object */ 608 #define STT_FUNC 2 /* Associated with a function */ 609 #define STT_SECTION 3 /* Associated with a section */ 610 #define STT_FILE 4 /* Associated with a file name */ 611 #define STT_COMMON 5 /* Uninitialised common block */ 612 #define STT_TLS 6 /* Thread local data object */ 613 #define STT_NUM 7 614 615 #define STT_LOOS 10 /* Operating system specific range */ 616 #define STT_GNU_IFUNC 10 /* GNU extension: indirect function */ 617 #define STT_HIOS 12 618 #define STT_LOPROC 13 /* Processor-specific range */ 619 #define STT_HIPROC 15 620 621 /* st_other: Visibility Types */ 622 #define STV_DEFAULT 0 /* use binding type */ 623 #define STV_INTERNAL 1 /* not referenced from outside */ 624 #define STV_HIDDEN 2 /* not visible, may be used via ptr */ 625 #define STV_PROTECTED 3 /* visible, not preemptible */ 626 #define STV_EXPORTED 4 627 #define STV_SINGLETON 5 628 #define STV_ELIMINATE 6 629 630 /* 631 * Special section indexes 632 */ 633 #define SHN_UNDEF 0 /* Undefined section */ 634 635 #define SHN_LORESERVE 0xff00 /* Reserved range */ 636 #define SHN_ABS 0xfff1 /* Absolute symbols */ 637 #define SHN_COMMON 0xfff2 /* Common symbols */ 638 #define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere */ 639 #define SHN_HIRESERVE 0xffff 640 641 #define SHN_LOPROC 0xff00 /* Processor-specific range */ 642 #define SHN_HIPROC 0xff1f 643 #define SHN_LOOS 0xff20 /* Operating system specific range */ 644 #define SHN_HIOS 0xff3f 645 646 #define SHN_MIPS_ACOMMON 0xff00 647 #define SHN_MIPS_TEXT 0xff01 648 #define SHN_MIPS_DATA 0xff02 649 #define SHN_MIPS_SCOMMON 0xff03 650 651 /* 652 * Relocation Entries 653 */ 654 typedef struct { 655 Elf32_Word r_offset; /* where to do it */ 656 Elf32_Word r_info; /* index & type of relocation */ 657 } Elf32_Rel; 658 659 typedef struct { 660 Elf32_Word r_offset; /* where to do it */ 661 Elf32_Word r_info; /* index & type of relocation */ 662 Elf32_Sword r_addend; /* adjustment value */ 663 } Elf32_Rela; 664 665 /* r_info utility macros */ 666 #define ELF32_R_SYM(info) ((info) >> 8) 667 #define ELF32_R_TYPE(info) ((info) & 0xff) 668 #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) 669 670 /* Relative relocations (DT_RELR, SHT_RELR, .relr.dyn) */ 671 typedef Elf32_Word Elf32_Relr; 672 673 typedef struct { 674 Elf64_Addr r_offset; /* where to do it */ 675 Elf64_Xword r_info; /* index & type of relocation */ 676 } Elf64_Rel; 677 678 typedef struct { 679 Elf64_Addr r_offset; /* where to do it */ 680 Elf64_Xword r_info; /* index & type of relocation */ 681 Elf64_Sxword r_addend; /* adjustment value */ 682 } Elf64_Rela; 683 684 /* r_info utility macros */ 685 #define ELF64_R_SYM(info) ((info) >> 32) 686 #define ELF64_R_TYPE(info) ((info) & 0xffffffff) 687 #define ELF64_R_INFO(sym,type) (((sym) << 32) + (type)) 688 689 /* Relative relocations (DT_RELR, SHT_RELR, .relr.dyn) */ 690 typedef Elf64_Xword Elf64_Relr; 691 692 /* 693 * Move entries 694 */ 695 typedef struct { 696 Elf32_Lword m_value; /* symbol value */ 697 Elf32_Word m_info; /* size + index */ 698 Elf32_Word m_poffset; /* symbol offset */ 699 Elf32_Half m_repeat; /* repeat count */ 700 Elf32_Half m_stride; /* stride info */ 701 } Elf32_Move; 702 703 #define ELF32_M_SYM(info) ((info) >> 8) 704 #define ELF32_M_SIZE(info) ((info) & 0xff) 705 #define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size)) 706 707 typedef struct { 708 Elf64_Lword m_value; /* symbol value */ 709 Elf64_Xword m_info; /* size + index */ 710 Elf64_Xword m_poffset; /* symbol offset */ 711 Elf64_Word m_repeat; /* repeat count */ 712 Elf64_Word m_stride; /* stride info */ 713 } Elf64_Move; 714 715 #define ELF64_M_SYM(info) ((info) >> 8) 716 #define ELF64_M_SIZE(info) ((info) & 0xff) 717 #define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size)) 718 719 /* 720 * Hardware/software capabilities entry 721 */ 722 typedef struct { 723 Elf32_Word c_tag; /* entry tag value */ 724 union { 725 Elf32_Addr c_ptr; 726 Elf32_Word c_val; 727 } c_un; 728 } Elf32_Cap; 729 730 typedef struct { 731 Elf64_Xword c_tag; /* entry tag value */ 732 union { 733 Elf64_Addr c_ptr; 734 Elf64_Xword c_val; 735 } c_un; 736 } Elf64_Cap; 737 738 /* 739 * Dynamic Section structure array 740 */ 741 typedef struct { 742 Elf32_Word d_tag; /* entry tag value */ 743 union { 744 Elf32_Addr d_ptr; 745 Elf32_Word d_val; 746 } d_un; 747 } Elf32_Dyn; 748 749 typedef struct { 750 Elf64_Xword d_tag; /* entry tag value */ 751 union { 752 Elf64_Addr d_ptr; 753 Elf64_Xword d_val; 754 } d_un; 755 } Elf64_Dyn; 756 757 /* d_tag */ 758 #define DT_NULL 0 /* Marks end of dynamic array */ 759 #define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */ 760 #define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */ 761 #define DT_PLTGOT 3 /* Address of PLT and/or GOT */ 762 #define DT_HASH 4 /* Address of symbol hash table */ 763 #define DT_STRTAB 5 /* Address of string table */ 764 #define DT_SYMTAB 6 /* Address of symbol table */ 765 #define DT_RELA 7 /* Address of Rela relocation table */ 766 #define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */ 767 #define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */ 768 #define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */ 769 #define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */ 770 #define DT_INIT 12 /* Address of initialization function */ 771 #define DT_FINI 13 /* Address of termination function */ 772 #define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */ 773 #define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */ 774 #define DT_SYMBOLIC 16 /* Start symbol search within local object */ 775 #define DT_REL 17 /* Address of Rel relocation table */ 776 #define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */ 777 #define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */ 778 #define DT_PLTREL 20 /* Type of PLT relocation entries */ 779 #define DT_DEBUG 21 /* Used for debugging; unspecified */ 780 #define DT_TEXTREL 22 /* Relocations might modify non-writable seg */ 781 #define DT_JMPREL 23 /* Address of relocations associated with PLT */ 782 #define DT_BIND_NOW 24 /* Process all relocations at load-time */ 783 #define DT_INIT_ARRAY 25 /* Address of initialization function array */ 784 #define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */ 785 #define DT_INIT_ARRAYSZ 27 /* Address of termination function array */ 786 #define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/ 787 #define DT_RUNPATH 29 /* overrides DT_RPATH */ 788 #define DT_FLAGS 30 /* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */ 789 #define DT_ENCODING 32 /* In [32, DT_LOOS), only evens use d_ptr */ 790 #define DT_PREINIT_ARRAY 32 /* Address of pre-init function array */ 791 #define DT_PREINIT_ARRAYSZ 33 /* Size, in bytes, of DT_PREINIT_ARRAY array */ 792 #define DT_SYMTAB_SHNDX 34 /* Addr. of SHT_SYMTAB_SHNDX of DT_SYMTAB */ 793 #define DT_RELRSZ 35 /* Size, in bytes, of DT_RELR table */ 794 #define DT_RELR 36 /* Address of Relr relocation table */ 795 #define DT_RELRENT 37 /* Size, in bytes, of one DT_RELR entry */ 796 797 #define DT_LOOS 0x60000000 /* Operating system specific range */ 798 #define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table */ 799 #define DT_VERSYM 0x6ffffff0 /* Symbol versions */ 800 #define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */ 801 #define DT_VERDEF 0x6ffffffc /* Versions defined by file */ 802 #define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */ 803 #define DT_VERNEED 0x6ffffffe /* Versions needed by file */ 804 #define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */ 805 #define DT_HIOS 0x6fffffff 806 #define DT_LOPROC 0x70000000 /* Processor-specific range */ 807 #define DT_MIPS_XHASH 0x70000036 /* MIPS version of GNU_HASH */ 808 #define DT_HIPROC 0x7fffffff 809 810 /* Flag values for DT_FLAGS */ 811 #define DF_ORIGIN 0x00000001 /* uses $ORIGIN */ 812 #define DF_SYMBOLIC 0x00000002 /* */ 813 #define DF_TEXTREL 0x00000004 /* */ 814 #define DF_BIND_NOW 0x00000008 /* */ 815 #define DF_STATIC_TLS 0x00000010 /* */ 816 817 /* Flag values for DT_FLAGS_1 */ 818 #define DF_1_NOW 0x00000001 /* Same as DF_BIND_NOW */ 819 #define DF_1_GLOBAL 0x00000002 /* Unused */ 820 #define DF_1_GROUP 0x00000004 /* Is member of group */ 821 #define DF_1_NODELETE 0x00000008 /* Cannot be deleted from process */ 822 #define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filters */ 823 #define DF_1_INITFIRST 0x00000020 /* init/fini takes priority */ 824 #define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */ 825 #define DF_1_ORIGIN 0x00000080 /* Require $ORIGIN processing */ 826 #define DF_1_DIRECT 0x00000100 /* Enable direct bindings */ 827 #define DF_1_INTERPOSE 0x00000400 /* Is an interposer */ 828 #define DF_1_NODEFLIB 0x00000800 /* Ignore default library search path */ 829 #define DF_1_NODUMP 0x00001000 /* Cannot be dumped with dldump(3C) */ 830 #define DF_1_CONFALT 0x00002000 /* Configuration alternative */ 831 #define DF_1_ENDFILTEE 0x00004000 /* Filtee ends filter's search */ 832 #define DF_1_DISPRELDNE 0x00008000 /* Did displacement relocation */ 833 #define DF_1_DISPRELPND 0x00010000 /* Pending displacement relocation */ 834 #define DF_1_NODIRECT 0x00020000 /* Has non-direct bindings */ 835 #define DF_1_IGNMULDEF 0x00040000 /* Used internally */ 836 #define DF_1_NOKSYMS 0x00080000 /* Used internally */ 837 #define DF_1_NOHDR 0x00100000 /* Used internally */ 838 #define DF_1_EDITED 0x00200000 /* Has been modified since build */ 839 #define DF_1_NORELOC 0x00400000 /* Used internally */ 840 #define DF_1_SYMINTPOSE 0x00800000 /* Has individual symbol interposers */ 841 #define DF_1_GLOBAUDIT 0x01000000 /* Require global auditing */ 842 #define DF_1_SINGLETON 0x02000000 /* Has singleton symbols */ 843 #define DF_1_STUB 0x04000000 /* Stub */ 844 #define DF_1_PIE 0x08000000 /* Position Independent Executable */ 845 846 /* 847 * The header for GNU-style hash sections. 848 */ 849 typedef struct { 850 uint32_t gh_nbuckets; /* Number of hash buckets. */ 851 uint32_t gh_symndx; /* First visible symbol in .dynsym. */ 852 uint32_t gh_maskwords; /* #maskwords used in bloom filter. */ 853 uint32_t gh_shift2; /* Bloom filter shift count. */ 854 } Elf_GNU_Hash_Header; 855 856 /* 857 * Note Headers 858 */ 859 typedef struct { 860 Elf32_Word n_namesz; 861 Elf32_Word n_descsz; 862 Elf32_Word n_type; 863 } Elf32_Nhdr; 864 865 typedef struct { 866 Elf64_Word n_namesz; 867 Elf64_Word n_descsz; 868 Elf64_Word n_type; 869 } Elf64_Nhdr; 870 871 /* st_info/st_other utility macros */ 872 #define ELF_ST_BIND(info) ((uint32_t)(info) >> 4) 873 #define ELF_ST_TYPE(info) ((uint32_t)(info) & 0xf) 874 #define ELF_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | \ 875 ((type) & 0xf))) 876 #define ELF_ST_VISIBILITY(other) ((uint32_t)(other) & 3) 877 878 #define ELF32_ST_BIND(info) ELF_ST_BIND(info) 879 #define ELF32_ST_TYPE(info) ELF_ST_TYPE(info) 880 #define ELF32_ST_INFO(bind,type) ELF_ST_INFO(bind,type) 881 #define ELF32_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other) 882 883 #define ELF64_ST_BIND(info) ELF_ST_BIND(info) 884 #define ELF64_ST_TYPE(info) ELF_ST_TYPE(info) 885 #define ELF64_ST_INFO(bind,type) ELF_ST_INFO(bind,type) 886 #define ELF64_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other) 887 888 typedef struct { 889 Elf32_Half si_boundto; /* direct bindings - symbol bound to */ 890 Elf32_Half si_flags; /* per symbol flags */ 891 } Elf32_Syminfo; 892 893 typedef struct { 894 Elf64_Word si_boundto; /* direct bindings- symbol bound to */ 895 Elf64_Word si_flags; /* per symbol flags */ 896 } Elf64_Syminfo; 897 898 #define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association 899 to object containing definition */ 900 #define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */ 901 #define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */ 902 #define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be 903 lazily-loaded */ 904 #define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to 905 object containing definition */ 906 #define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference 907 directly bind to this symbol */ 908 #define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */ 909 #define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */ 910 911 #define SYMINFO_BT_SELF 0xffff /* symbol bound to self */ 912 #define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */ 913 #define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */ 914 #define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */ 915 #define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */ 916 917 #define SYMINFO_NONE 0 /* Syminfo version */ 918 #define SYMINFO_CURRENT 1 919 #define SYMINFO_NUM 2 920 921 /* 922 * These constants are used for Elf32_Verdef struct's version number. 923 */ 924 #define VER_DEF_NONE 0 925 #define VER_DEF_CURRENT 1 926 927 /* 928 * These constants are used for Elf32_Verdef struct's vd_ndx. 929 */ 930 #define VER_DEF_IDX(x) VER_NDX(x) 931 932 /* 933 * These constants are used for Elf32_Verdef struct's vd_flags. 934 */ 935 #define VER_FLG_BASE 0x1 936 #define VER_FLG_WEAK 0x2 937 938 /* 939 * These are used in an Elf32_Versym field. 940 */ 941 #define VER_NDX_LOCAL 0 942 #define VER_NDX_GLOBAL 1 943 #define VER_NDX_GIVEN 2 944 945 /* 946 * These constants are used for Elf32_Verneed struct's version number. 947 */ 948 #define VER_NEED_NONE 0 949 #define VER_NEED_CURRENT 1 950 951 /* 952 * These constants are used for Elf32_Vernaux struct's vna_other. 953 */ 954 #define VER_NEED_HIDDEN VER_NDX_HIDDEN 955 #define VER_NEED_IDX(x) VER_NDX(x) 956 957 /* index */ 958 #define VER_NDX_HIDDEN 0x8000 959 #define VER_NDX(x) ((x) & ~VER_NDX_HIDDEN) 960 961 /* 962 * GNU Extension hiding symbol 963 */ 964 #define VERSYM_HIDDEN 0x8000 965 #define VERSYM_VERSION 0x7fff 966 967 #define ELF_VER_CHR '@' 968 969 /* 970 * These are current size independent. 971 */ 972 973 typedef struct { 974 Elf32_Half vd_version; /* version number of structure */ 975 Elf32_Half vd_flags; /* flags (VER_FLG_*) */ 976 Elf32_Half vd_ndx; /* version index */ 977 Elf32_Half vd_cnt; /* number of verdaux entries */ 978 Elf32_Word vd_hash; /* hash of name */ 979 Elf32_Word vd_aux; /* offset to verdaux entries */ 980 Elf32_Word vd_next; /* offset to next verdef */ 981 } Elf32_Verdef; 982 typedef Elf32_Verdef Elf64_Verdef; 983 984 typedef struct { 985 Elf32_Word vda_name; /* string table offset of name */ 986 Elf32_Word vda_next; /* offset to verdaux */ 987 } Elf32_Verdaux; 988 typedef Elf32_Verdaux Elf64_Verdaux; 989 990 typedef struct { 991 Elf32_Half vn_version; /* version number of structure */ 992 Elf32_Half vn_cnt; /* number of vernaux entries */ 993 Elf32_Word vn_file; /* string table offset of library name*/ 994 Elf32_Word vn_aux; /* offset to vernaux entries */ 995 Elf32_Word vn_next; /* offset to next verneed */ 996 } Elf32_Verneed; 997 typedef Elf32_Verneed Elf64_Verneed; 998 999 typedef struct { 1000 Elf32_Word vna_hash; /* Hash of dependency name */ 1001 Elf32_Half vna_flags; /* flags (VER_FLG_*) */ 1002 Elf32_Half vna_other; /* unused */ 1003 Elf32_Word vna_name; /* string table offset to version name*/ 1004 Elf32_Word vna_next; /* offset to next vernaux */ 1005 } Elf32_Vernaux; 1006 typedef Elf32_Vernaux Elf64_Vernaux; 1007 1008 typedef Elf32_Half Elf32_Versym; 1009 typedef Elf64_Half Elf64_Versym; 1010 1011 #else /* !defined(_SYS_ELFDEFINITIONS_H_) */ 1012 /* 1013 * Local overrides needed when using <sys/elfdefinitions.h>. 1014 */ 1015 1016 /* NetBSD uses the pre-standardisation value for EM_ALPHA. */ 1017 #undef EM_ALPHA 1018 #define EM_ALPHA 36902 /* DIGITAL Alpha */ 1019 1020 #endif /* !defined(_SYS_ELFDEFINITIONS_H_) */ 1021 1022 /* 1023 * NetBSD-specific symbols and identifier spellings. 1024 */ 1025 #define ELF_NIDENT EI_INDENT /* Prior spelling. */ 1026 1027 #define ELFCLASSNUM 3 /* Number of ELFCLASS* types. */ 1028 #define EV_NUM 2 /* Number of ELF file format versions. */ 1029 #define ET_NUM 5 /* Number of ABI-defined object types. */ 1030 1031 #define EM_RS6000 11 /* IBM RS/6000 XXX reserved */ 1032 #define EM_NCUBE 16 /* NCube XXX reserved */ 1033 #define EM_NUM 36903 /* EM_ALPHA(NetBSD) + 1 */ 1034 1035 #define SHT_LOSUNW 0x6ffffff4 /* Also: SHT_SUNW_dof */ 1036 #define SHT_HISUNW 0x6fffffff /* Also: SHT_HIOS */ 1037 1038 #define SHT_NUM 20 /* Number of generic section types. */ 1039 #define STB_NUM 3 /* Number of generic symbol bindings. */ 1040 #define DT_NUM 38 /* Number of generic dynamic array tags. */ 1041 1042 /* File sizes of basic ELF types. */ 1043 #define ELF32_FSZ_ADDR 4 1044 #define ELF32_FSZ_HALF 2 1045 #define ELF32_FSZ_LWORD 8 1046 #define ELF32_FSZ_OFF 4 1047 #define ELF32_FSZ_SWORD 4 1048 #define ELF32_FSZ_WORD 4 1049 1050 #define ELF64_FSZ_ADDR 8 1051 #define ELF64_FSZ_HALF 2 1052 #define ELF64_FSZ_LWORD 8 1053 #define ELF64_FSZ_OFF 8 1054 #define ELF64_FSZ_SWORD 4 1055 #define ELF64_FSZ_SXWORD 8 1056 #define ELF64_FSZ_WORD 4 1057 #define ELF64_FSZ_XWORD 8 1058 1059 /* Symbol Table index of the undefined symbol */ 1060 #define ELF_SYM_UNDEFINED 0 1061 1062 /* 1063 * Auxiliary Vectors 1064 */ 1065 typedef struct { 1066 Elf32_Word a_type; /* 32-bit id */ 1067 Elf32_Word a_v; /* 32-bit id */ 1068 } Aux32Info; 1069 1070 typedef struct { 1071 Elf64_Word a_type; /* 32-bit id */ 1072 Elf64_Xword a_v; /* 64-bit id */ 1073 } Aux64Info; 1074 1075 /* a_type */ 1076 #define AT_NULL 0 /* Marks end of array */ 1077 #define AT_IGNORE 1 /* No meaning, a_un is undefined */ 1078 #define AT_EXECFD 2 /* Open file descriptor of object file */ 1079 #define AT_PHDR 3 /* &phdr[0] */ 1080 #define AT_PHENT 4 /* sizeof(phdr[0]) */ 1081 #define AT_PHNUM 5 /* # phdr entries */ 1082 #define AT_PAGESZ 6 /* PAGESIZE */ 1083 #define AT_BASE 7 /* Interpreter base addr */ 1084 #define AT_FLAGS 8 /* Processor flags */ 1085 #define AT_ENTRY 9 /* Entry address of executable */ 1086 #define AT_DCACHEBSIZE 10 /* Data cache block size */ 1087 #define AT_ICACHEBSIZE 11 /* Instruction cache block size */ 1088 #define AT_UCACHEBSIZE 12 /* Unified cache block size */ 1089 #define AT_STACKBASE 13 /* Base address of the main thread */ 1090 1091 /* Vendor specific */ 1092 #define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */ 1093 1094 #define AT_EUID 2000 /* euid (solaris compatible numbers) */ 1095 #define AT_RUID 2001 /* ruid (solaris compatible numbers) */ 1096 #define AT_EGID 2002 /* egid (solaris compatible numbers) */ 1097 #define AT_RGID 2003 /* rgid (solaris compatible numbers) */ 1098 1099 /* Solaris kernel specific */ 1100 #define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */ 1101 #define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */ 1102 #define AT_SUN_LDNAME 2006 /* dynamic linker's name */ 1103 #define AT_SUN_LPGSIZE 2007 /* large pagesize */ 1104 1105 /* Other information */ 1106 #define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */ 1107 #define AT_SUN_HWCAP 2009 /* process hardware capabilities */ 1108 #define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */ 1109 #define AT_SUN_CPU 2011 /* CPU name */ 1110 /* ibcs2 emulation band aid */ 1111 #define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */ 1112 #define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */ 1113 /* Executable's fully resolved name */ 1114 #define AT_SUN_EXECNAME 2014 1115 1116 #define ELF_NOTE_GNU_NAMESZ 4 1117 #define ELF_NOTE_GNU_NAME "GNU\0" 1118 1119 /* 1120 * GNU-specific note type: ABI tag 1121 * name: GNU\0 1122 * namesz: 4 1123 * desc: 1124 * word[0]: OS tag 1125 * word[1]: major version 1126 * word[2]: minor version 1127 * word[3]: teeny version 1128 * descsz: 16 1129 */ 1130 /* GNU-specific note name and description sizes */ 1131 #define ELF_NOTE_TYPE_ABI_TAG 1 1132 #define ELF_NOTE_ABI_NAME ELF_NOTE_GNU_NAME 1133 #define ELF_NOTE_ABI_NAMESZ ELF_NOTE_GNU_NAMESZ 1134 #define ELF_NOTE_ABI_DESCSZ 16 1135 /* GNU-specific OS/version value stuff */ 1136 #define ELF_NOTE_ABI_OS_LINUX 0 1137 #define ELF_NOTE_ABI_OS_HURD 1 1138 #define ELF_NOTE_ABI_OS_SOLARIS 2 1139 #define ELF_NOTE_ABI_OS_KFREEBSD 3 1140 #define ELF_NOTE_ABI_OS_KNETBSD 4 1141 1142 /* Old gcc style, under the ABI tag */ 1143 #define ELF_NOTE_OGCC_NAMESZ 8 1144 #define ELF_NOTE_OGCC_NAME "01.01\0\0\0\0" 1145 #define ELF_NOTE_OGCC_DESCSZ 0 1146 1147 /* 1148 * GNU-specific note type: Hardware capabilities 1149 * name: GNU\0 1150 * namesz: 4 1151 * desc: 1152 * word[0]: Number of entries 1153 * word[1]: Bitmask of enabled entries 1154 * Followed by a byte id, and a NUL terminated string per entry 1155 * descsz: variable 1156 */ 1157 #define ELF_NOTE_TYPE_GNU_HWCAP 2 1158 1159 /* 1160 * GNU-specific note type: Build ID generated by ld 1161 * name: GNU\0 1162 * desc: 1163 * word[0..4] SHA1 [default] 1164 * or 1165 * word[0..3] md5 or uuid 1166 * descsz: 16 or 20 1167 */ 1168 #define ELF_NOTE_TYPE_GNU_BUILD_ID 3 1169 1170 /* SuSE-specific note type: ABI 1171 * name: SuSE\0 1172 * namesz: 5 1173 * desc: 1174 * half[0] = MMmm 1175 * 1176 * M = product major version 1177 * m = product minor version 1178 * descsz: 2 1179 */ 1180 #define ELF_NOTE_TYPE_SUSE_TAG 1 1181 /* SuSE-specific note name and description sizes */ 1182 #define ELF_NOTE_SUSE_NAMESZ 5 1183 #define ELF_NOTE_SUSE_DESCSZ 2 1184 /* SuSE-specific note name */ 1185 #define ELF_NOTE_SUSE_NAME "SuSE\0" 1186 1187 /* SuSE-specific note type: version 1188 * name: SuSE\0\0\0\0 1189 * namesz: 8 1190 * desc: 1191 * word[0] = VVTTMMmm 1192 * 1193 * V = version of following data 1194 * T = product type: [box, sles, nld, whatever] 1195 * M = product major version 1196 * m = product minor version 1197 * descsz: 8 1198 */ 1199 #define ELF_NOTE_TYPE_SUSE_VERSION_TAG 0x45537553 /* SuSE in LE */ 1200 /* SuSE-specific note name and description sizes */ 1201 #define ELF_NOTE_SUSE_VERSION_NAMESZ 8 1202 #define ELF_NOTE_SUSE_VERSION_DESCSZ 8 1203 /* SuSE-specific note name */ 1204 #define ELF_NOTE_SUSE_VERSION_NAME "SuSE\0\0\0\0" 1205 1206 /* Go-specific note type: buildid 1207 * name: Go\0\0 1208 * namesz: 4 1209 * desc: 1210 * words[10] 1211 * descsz: 40 1212 */ 1213 #define ELF_NOTE_TYPE_GO_BUILDID_TAG 4 1214 #define ELF_NOTE_GO_BUILDID_NAMESZ 4 1215 #define ELF_NOTE_GO_BUILDID_DESCSZ 40 1216 #define ELF_NOTE_GO_BUILDID_NAME "Go\0\0" 1217 1218 /* 1219 * FDO-specific note type: packaging metadata 1220 * name: FDO\0 1221 * namesz: 4 1222 * desc: 1223 * a single JSON object encoded as a zero-terminated UTF-8 string 1224 * (see https://systemd.io/COREDUMP_PACKAGE_METADATA/) 1225 * descsz: variable 1226 */ 1227 #define ELF_NOTE_TYPE_FDO_PACKAGING_METADATA 0xcafe1a7e 1228 #define ELF_NOTE_FDO_PACKAGING_METADATA_NAMESZ 4 1229 #define ELF_NOTE_FDO_PACKAGING_METADATA_NAME "FDO\0" 1230 1231 /* NetBSD-specific note type: NetBSD ABI version. 1232 * name: NetBSD\0\0 1233 * namesz: 8 1234 * desc: 1235 * word[0]: MMmmrrpp00 1236 * 1237 * M = major version 1238 * m = minor version 1239 * r = release ["",A-Z,Z[A-Z] but numeric] 1240 * p = patchlevel 1241 * descsz: 4 1242 */ 1243 #define ELF_NOTE_TYPE_NETBSD_TAG 1 1244 /* NetBSD-specific note name and description sizes */ 1245 #define ELF_NOTE_NETBSD_NAMESZ 7 1246 #define ELF_NOTE_NETBSD_DESCSZ 4 1247 /* NetBSD-specific note name */ 1248 #define ELF_NOTE_NETBSD_NAME "NetBSD\0\0" 1249 1250 /* NetBSD-specific note type: Emulation (obsolete; last used early 2000) 1251 * name: NetBSD\0\0 1252 * namesz: 8 1253 * desc: 1254 * "netbsd\0" 1255 * 1256 * descsz: 8 1257 */ 1258 #define ELF_NOTE_TYPE_NETBSD_EMUL_TAG 2 1259 #define ELF_NOTE_NETBSD_EMUL_NAMESZ 7 1260 #define ELF_NOTE_NETBSD_EMUL_DESCSZ 7 1261 /* NetBSD-specific note name */ 1262 #define ELF_NOTE_NETBSD_EMUL_NAME "NetBSD\0\0" 1263 1264 /* 1265 * NetBSD-specific note type: PaX. 1266 * There should be 1 NOTE per executable. 1267 * name: PaX\0 1268 * namesz: 4 1269 * desc: 1270 * word[0]: capability bitmask 1271 * descsz: 4 1272 */ 1273 #define ELF_NOTE_TYPE_PAX_TAG 3 1274 #define ELF_NOTE_PAX_MPROTECT 0x01 /* Force enable Mprotect */ 1275 #define ELF_NOTE_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */ 1276 #define ELF_NOTE_PAX_GUARD 0x04 /* Force enable Segvguard */ 1277 #define ELF_NOTE_PAX_NOGUARD 0x08 /* Force disable Segvguard */ 1278 #define ELF_NOTE_PAX_ASLR 0x10 /* Force enable ASLR */ 1279 #define ELF_NOTE_PAX_NOASLR 0x20 /* Force disable ASLR */ 1280 #define ELF_NOTE_PAX_NAMESZ 4 1281 #define ELF_NOTE_PAX_NAME "PaX\0" 1282 #define ELF_NOTE_PAX_DESCSZ 4 1283 1284 /* 1285 * NetBSD-specific core file information. 1286 * 1287 * NetBSD ELF core files use notes to provide information about 1288 * the process's state. The note name is "NetBSD-CORE" for 1289 * information that is global to the process, and "NetBSD-CORE@nn", 1290 * where "nn" is the lwpid of the LWP that the information belongs 1291 * to (such as register state). 1292 * 1293 * We use the following note identifiers: 1294 * 1295 * ELF_NOTE_NETBSD_CORE_PROCINFO 1296 * Note is a "netbsd_elfcore_procinfo" structure. 1297 * ELF_NOTE_NETBSD_CORE_AUXV 1298 * Note is an array of AuxInfo structures. 1299 * 1300 * We also use ptrace(2) request numbers (the ones that exist in 1301 * machine-dependent space) to identify register info notes. The 1302 * info in such notes is in the same format that ptrace(2) would 1303 * export that information. 1304 * 1305 * Please try to keep the members of this structure nicely aligned, 1306 * and if you add elements, add them to the end and bump the version. 1307 */ 1308 1309 #define ELF_NOTE_NETBSD_CORE_NAME "NetBSD-CORE" 1310 1311 #define ELF_NOTE_NETBSD_CORE_PROCINFO 1 1312 #define ELF_NOTE_NETBSD_CORE_AUXV 2 1313 1314 #define NETBSD_ELFCORE_PROCINFO_VERSION 1 1315 1316 struct netbsd_elfcore_procinfo { 1317 /* Version 1 fields start here. */ 1318 uint32_t cpi_version; /* our version */ 1319 uint32_t cpi_cpisize; /* sizeof(this struct) */ 1320 uint32_t cpi_signo; /* killing signal */ 1321 uint32_t cpi_sigcode; /* signal code */ 1322 uint32_t cpi_sigpend[4]; /* pending signals */ 1323 uint32_t cpi_sigmask[4]; /* blocked signals */ 1324 uint32_t cpi_sigignore[4]; /* ignored signals */ 1325 uint32_t cpi_sigcatch[4]; /* caught signals */ 1326 int32_t cpi_pid; /* process ID */ 1327 int32_t cpi_ppid; /* parent process ID */ 1328 int32_t cpi_pgrp; /* process group ID */ 1329 int32_t cpi_sid; /* session ID */ 1330 uint32_t cpi_ruid; /* real user ID */ 1331 uint32_t cpi_euid; /* effective user ID */ 1332 uint32_t cpi_svuid; /* saved user ID */ 1333 uint32_t cpi_rgid; /* real group ID */ 1334 uint32_t cpi_egid; /* effective group ID */ 1335 uint32_t cpi_svgid; /* saved group ID */ 1336 uint32_t cpi_nlwps; /* number of LWPs */ 1337 int8_t cpi_name[32]; /* copy of p->p_comm */ 1338 /* Add version 2 fields below here. */ 1339 int32_t cpi_siglwp; /* LWP target of killing signal */ 1340 }; 1341 1342 /* 1343 * NetBSD-specific note type: MACHINE_ARCH. 1344 * There should be 1 NOTE per executable. 1345 * name: NetBSD\0 1346 * namesz: 7 1347 * desc: string 1348 * descsz: variable 1349 */ 1350 #define ELF_NOTE_TYPE_MARCH_TAG 5 1351 /* NetBSD-specific note name and description sizes */ 1352 #define ELF_NOTE_MARCH_NAMESZ ELF_NOTE_NETBSD_NAMESZ 1353 /* NetBSD-specific note name */ 1354 #define ELF_NOTE_MARCH_NAME ELF_NOTE_NETBSD_NAME 1355 1356 /* 1357 * NetBSD-specific note type: MCMODEL 1358 * There should be 1 NOTE per executable. 1359 * name: NetBSD\0 1360 * namesz: 7 1361 * code model: string 1362 */ 1363 1364 #define ELF_NOTE_TYPE_MCMODEL_TAG 6 1365 /* NetBSD-specific note name and description sizes */ 1366 #define ELF_NOTE_MCMODEL_NAMESZ ELF_NOTE_NETBSD_NAMESZ 1367 /* NetBSD-specific note name */ 1368 #define ELF_NOTE_MCMODEL_NAME ELF_NOTE_NETBSD_NAME 1369 1370 #if !defined(ELFSIZE) 1371 # if defined(_RUMPKERNEL) || !defined(_KERNEL) 1372 # define ELFSIZE ARCH_ELFSIZE 1373 # else 1374 # define ELFSIZE KERN_ELFSIZE 1375 # endif 1376 #endif 1377 1378 #if defined(ELFSIZE) 1379 #define CONCAT(x,y) __CONCAT(x,y) 1380 #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) 1381 #define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) 1382 #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) 1383 #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) 1384 #define ElfW(x) CONCAT(Elf,CONCAT(ELFSIZE,CONCAT(_,x))) 1385 #endif 1386 1387 #if defined(ELFSIZE) && (ELFSIZE == 32) 1388 #define Elf_Ehdr Elf32_Ehdr 1389 #define Elf_Phdr Elf32_Phdr 1390 #define Elf_Shdr Elf32_Shdr 1391 #define Elf_Sym Elf32_Sym 1392 #define Elf_Rel Elf32_Rel 1393 #define Elf_Rela Elf32_Rela 1394 #define Elf_Relr Elf32_Relr 1395 #define Elf_Dyn Elf32_Dyn 1396 #define Elf_Word Elf32_Word 1397 #define Elf_Sword Elf32_Sword 1398 #define Elf_Half Elf32_Half 1399 #define Elf_Addr Elf32_Addr 1400 #define Elf_Off Elf32_Off 1401 #define Elf_SOff Elf32_SOff 1402 #define Elf_Nhdr Elf32_Nhdr 1403 #define Elf_Verdef Elf32_Verdef 1404 #define Elf_Verdaux Elf32_Verdaux 1405 #define Elf_Verneed Elf32_Verneed 1406 #define Elf_Vernaux Elf32_Vernaux 1407 #define Elf_Versym Elf32_Versym 1408 1409 #define ELF_R_SYM ELF32_R_SYM 1410 #define ELF_R_TYPE ELF32_R_TYPE 1411 #define ELFCLASS ELFCLASS32 1412 1413 #define AuxInfo Aux32Info 1414 #elif defined(ELFSIZE) && (ELFSIZE == 64) 1415 #define Elf_Ehdr Elf64_Ehdr 1416 #define Elf_Phdr Elf64_Phdr 1417 #define Elf_Shdr Elf64_Shdr 1418 #define Elf_Sym Elf64_Sym 1419 #define Elf_Rel Elf64_Rel 1420 #define Elf_Rela Elf64_Rela 1421 #define Elf_Relr Elf64_Relr 1422 #define Elf_Dyn Elf64_Dyn 1423 #define Elf_Word Elf64_Word 1424 #define Elf_Sword Elf64_Sword 1425 #define Elf_Half Elf64_Half 1426 #define Elf_Addr Elf64_Addr 1427 #define Elf_Off Elf64_Off 1428 #define Elf_SOff Elf64_SOff 1429 #define Elf_Nhdr Elf64_Nhdr 1430 #define Elf_Verdef Elf64_Verdef 1431 #define Elf_Verdaux Elf64_Verdaux 1432 #define Elf_Verneed Elf64_Verneed 1433 #define Elf_Vernaux Elf64_Vernaux 1434 #define Elf_Versym Elf64_Versym 1435 1436 #define ELF_R_SYM ELF64_R_SYM 1437 #define ELF_R_TYPE ELF64_R_TYPE 1438 #define ELFCLASS ELFCLASS64 1439 1440 #define AuxInfo Aux64Info 1441 #endif 1442 1443 #ifndef Elf_Symindx 1444 #define Elf_Symindx uint32_t 1445 #endif 1446 1447 1448 #ifdef _KERNEL 1449 1450 /* 1451 * Arbitrary limits to avoid DoS for excessive memory allocation. 1452 */ 1453 #define ELF_MAXPHNUM 128 1454 #define ELF_MAXSHNUM 32768 1455 #define ELF_MAXNOTESIZE 1024 1456 1457 #define ELF_AUX_ENTRIES 15 /* Max size of aux array passed to loader */ 1458 #define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */ 1459 #define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */ 1460 #define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */ 1461 #define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */ 1462 1463 #if defined(ELFSIZE) && (ELFSIZE == 64) 1464 #define ELF_NO_ADDR ELF64_NO_ADDR 1465 #define ELF_LINK_ADDR ELF64_LINK_ADDR 1466 #elif defined(ELFSIZE) && (ELFSIZE == 32) 1467 #define ELF_NO_ADDR ELF32_NO_ADDR 1468 #define ELF_LINK_ADDR ELF32_LINK_ADDR 1469 #endif 1470 1471 #ifndef ELF32_EHDR_FLAGS_OK 1472 #define ELF32_EHDR_FLAGS_OK(eh) 1 1473 #endif 1474 1475 #ifndef ELF64_EHDR_FLAGS_OK 1476 #define ELF64_EHDR_FLAGS_OK(eh) 1 1477 #endif 1478 1479 #if defined(ELFSIZE) && (ELFSIZE == 64) 1480 #define ELF_EHDR_FLAGS_OK(eh) ELF64_EHDR_FLAGS_OK(eh) 1481 #else 1482 #define ELF_EHDR_FLAGS_OK(eh) ELF32_EHDR_FLAGS_OK(eh) 1483 #endif 1484 1485 #if defined(ELFSIZE) 1486 struct elf_args { 1487 Elf_Addr arg_entry; /* program entry point */ 1488 Elf_Addr arg_interp; /* Interpreter load address */ 1489 Elf_Addr arg_phaddr; /* program header address */ 1490 Elf_Addr arg_phentsize; /* Size of program header */ 1491 Elf_Addr arg_phnum; /* Number of program headers */ 1492 }; 1493 #endif 1494 1495 #ifdef _KERNEL_OPT 1496 #include "opt_execfmt.h" 1497 #endif 1498 1499 struct ps_strings; 1500 struct coredump_iostate; 1501 struct note_state; 1502 struct exec_package; 1503 1504 #ifdef EXEC_ELF32 1505 int exec_elf32_makecmds(struct lwp *, struct exec_package *); 1506 int elf32_populate_auxv(struct lwp *, struct exec_package *, char **); 1507 int elf32_copyargs(struct lwp *, struct exec_package *, 1508 struct ps_strings *, char **, void *); 1509 1510 int elf32_check_header(Elf32_Ehdr *); 1511 #endif 1512 1513 int real_coredump_elf32(struct lwp *, struct coredump_iostate *); 1514 int coredump_elf32(struct lwp *, struct coredump_iostate *); 1515 void coredump_savenote_elf32(struct note_state *, unsigned int, 1516 const char *, void *, size_t); 1517 1518 #ifdef EXEC_ELF64 1519 int exec_elf64_makecmds(struct lwp *, struct exec_package *); 1520 int elf64_populate_auxv(struct lwp *, struct exec_package *, char **); 1521 int elf64_copyargs(struct lwp *, struct exec_package *, 1522 struct ps_strings *, char **, void *); 1523 1524 int elf64_check_header(Elf64_Ehdr *); 1525 #endif 1526 1527 int real_coredump_elf64(struct lwp *, struct coredump_iostate *); 1528 int coredump_elf64(struct lwp *, struct coredump_iostate *); 1529 void coredump_savenote_elf64(struct note_state *, unsigned int, 1530 const char *, void *, size_t); 1531 1532 #endif /* _KERNEL */ 1533 1534 #endif /* !_SYS_EXEC_ELF_H_ */ 1535