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