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