1 /* $OpenBSD: exec_elf.h,v 1.41 2006/01/06 18:53:05 millert Exp $ */ 2 /* 3 * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * This is the ELF ABI header file 30 * formerly known as "elf_abi.h". 31 */ 32 33 #ifndef _SYS_EXEC_ELF_H_ 34 #define _SYS_EXEC_ELF_H_ 35 36 #include <machine/_types.h> 37 #include <machine/exec.h> 38 39 typedef __uint8_t Elf_Byte; 40 41 typedef __uint32_t Elf32_Addr; /* Unsigned program address */ 42 typedef __uint32_t Elf32_Off; /* Unsigned file offset */ 43 typedef __int32_t Elf32_Sword; /* Signed large integer */ 44 typedef __uint32_t Elf32_Word; /* Unsigned large integer */ 45 typedef __uint16_t Elf32_Half; /* Unsigned medium integer */ 46 47 typedef __uint64_t Elf64_Addr; 48 typedef __uint64_t Elf64_Off; 49 typedef __int32_t Elf64_Shalf; 50 51 #ifdef __alpha__ 52 typedef __int64_t Elf64_Sword; 53 typedef __uint64_t Elf64_Word; 54 #else 55 typedef __int32_t Elf64_Sword; 56 typedef __uint32_t Elf64_Word; 57 #endif 58 59 typedef __int64_t Elf64_Sxword; 60 typedef __uint64_t Elf64_Xword; 61 62 typedef __uint32_t Elf64_Half; 63 typedef __uint16_t Elf64_Quarter; 64 65 /* 66 * e_ident[] identification indexes 67 * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html 68 */ 69 #define EI_MAG0 0 /* file ID */ 70 #define EI_MAG1 1 /* file ID */ 71 #define EI_MAG2 2 /* file ID */ 72 #define EI_MAG3 3 /* file ID */ 73 #define EI_CLASS 4 /* file class */ 74 #define EI_DATA 5 /* data encoding */ 75 #define EI_VERSION 6 /* ELF header version */ 76 #define EI_OSABI 7 /* OS/ABI ID */ 77 #define EI_ABIVERSION 8 /* ABI version */ 78 #define EI_PAD 9 /* start of pad bytes */ 79 #define EI_NIDENT 16 /* Size of e_ident[] */ 80 81 /* e_ident[] magic number */ 82 #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ 83 #define ELFMAG1 'E' /* e_ident[EI_MAG1] */ 84 #define ELFMAG2 'L' /* e_ident[EI_MAG2] */ 85 #define ELFMAG3 'F' /* e_ident[EI_MAG3] */ 86 #define ELFMAG "\177ELF" /* magic */ 87 #define SELFMAG 4 /* size of magic */ 88 89 /* e_ident[] file class */ 90 #define ELFCLASSNONE 0 /* invalid */ 91 #define ELFCLASS32 1 /* 32-bit objs */ 92 #define ELFCLASS64 2 /* 64-bit objs */ 93 #define ELFCLASSNUM 3 /* number of classes */ 94 95 /* e_ident[] data encoding */ 96 #define ELFDATANONE 0 /* invalid */ 97 #define ELFDATA2LSB 1 /* Little-Endian */ 98 #define ELFDATA2MSB 2 /* Big-Endian */ 99 #define ELFDATANUM 3 /* number of data encode defines */ 100 101 /* e_ident[] Operating System/ABI */ 102 #define ELFOSABI_SYSV 0 /* UNIX System V ABI */ 103 #define ELFOSABI_HPUX 1 /* HP-UX operating system */ 104 #define ELFOSABI_NETBSD 2 /* NetBSD */ 105 #define ELFOSABI_LINUX 3 /* GNU/Linux */ 106 #define ELFOSABI_HURD 4 /* GNU/Hurd */ 107 #define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ 108 #define ELFOSABI_SOLARIS 6 /* Solaris */ 109 #define ELFOSABI_MONTEREY 7 /* Monterey */ 110 #define ELFOSABI_IRIX 8 /* IRIX */ 111 #define ELFOSABI_FREEBSD 9 /* FreeBSD */ 112 #define ELFOSABI_TRU64 10 /* TRU64 UNIX */ 113 #define ELFOSABI_MODESTO 11 /* Novell Modesto */ 114 #define ELFOSABI_OPENBSD 12 /* OpenBSD */ 115 #define ELFOSABI_ARM 97 /* ARM */ 116 #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 117 118 /* e_ident */ 119 #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 120 (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 121 (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 122 (ehdr).e_ident[EI_MAG3] == ELFMAG3) 123 124 /* ELF Header */ 125 typedef struct elfhdr { 126 unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ 127 Elf32_Half e_type; /* object file type */ 128 Elf32_Half e_machine; /* machine */ 129 Elf32_Word e_version; /* object file version */ 130 Elf32_Addr e_entry; /* virtual entry point */ 131 Elf32_Off e_phoff; /* program header table offset */ 132 Elf32_Off e_shoff; /* section header table offset */ 133 Elf32_Word e_flags; /* processor-specific flags */ 134 Elf32_Half e_ehsize; /* ELF header size */ 135 Elf32_Half e_phentsize; /* program header entry size */ 136 Elf32_Half e_phnum; /* number of program header entries */ 137 Elf32_Half e_shentsize; /* section header entry size */ 138 Elf32_Half e_shnum; /* number of section header entries */ 139 Elf32_Half e_shstrndx; /* section header table's "section 140 header string table" entry offset */ 141 } Elf32_Ehdr; 142 143 typedef struct { 144 unsigned char e_ident[EI_NIDENT]; /* Id bytes */ 145 Elf64_Quarter e_type; /* file type */ 146 Elf64_Quarter e_machine; /* machine type */ 147 Elf64_Half e_version; /* version number */ 148 Elf64_Addr e_entry; /* entry point */ 149 Elf64_Off e_phoff; /* Program hdr offset */ 150 Elf64_Off e_shoff; /* Section hdr offset */ 151 Elf64_Half e_flags; /* Processor flags */ 152 Elf64_Quarter e_ehsize; /* sizeof ehdr */ 153 Elf64_Quarter e_phentsize; /* Program header entry size */ 154 Elf64_Quarter e_phnum; /* Number of program headers */ 155 Elf64_Quarter e_shentsize; /* Section header entry size */ 156 Elf64_Quarter e_shnum; /* Number of section headers */ 157 Elf64_Quarter e_shstrndx; /* String table index */ 158 } Elf64_Ehdr; 159 160 /* e_type */ 161 #define ET_NONE 0 /* No file type */ 162 #define ET_REL 1 /* relocatable file */ 163 #define ET_EXEC 2 /* executable file */ 164 #define ET_DYN 3 /* shared object file */ 165 #define ET_CORE 4 /* core file */ 166 #define ET_NUM 5 /* number of types */ 167 #define ET_LOPROC 0xff00 /* reserved range for processor */ 168 #define ET_HIPROC 0xffff /* specific e_type */ 169 170 /* e_machine */ 171 #define EM_NONE 0 /* No Machine */ 172 #define EM_M32 1 /* AT&T WE 32100 */ 173 #define EM_SPARC 2 /* SPARC */ 174 #define EM_386 3 /* Intel 80386 */ 175 #define EM_68K 4 /* Motorola 68000 */ 176 #define EM_88K 5 /* Motorola 88000 */ 177 #define EM_486 6 /* Intel 80486 - unused? */ 178 #define EM_860 7 /* Intel 80860 */ 179 #define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ 180 /* 181 * Don't know if EM_MIPS_RS4_BE, 182 * EM_SPARC64, EM_PARISC, 183 * or EM_PPC are ABI compliant 184 */ 185 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ 186 #define EM_SPARC64 11 /* SPARC v9 64-bit unoffical */ 187 #define EM_PARISC 15 /* HPPA */ 188 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ 189 #define EM_PPC 20 /* PowerPC */ 190 #define EM_ARM 40 /* Advanced RISC Machines ARM */ 191 #define EM_ALPHA 41 /* DEC ALPHA */ 192 #define EM_SPARCV9 43 /* SPARC version 9 */ 193 #define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ 194 #define EM_AMD64 62 /* AMD64 architecture */ 195 #define EM_VAX 75 /* DEC VAX */ 196 #define EM_NUM 15 /* number of machine types */ 197 198 /* Version */ 199 #define EV_NONE 0 /* Invalid */ 200 #define EV_CURRENT 1 /* Current */ 201 #define EV_NUM 2 /* number of versions */ 202 203 /* Section Header */ 204 typedef struct { 205 Elf32_Word sh_name; /* name - index into section header 206 string table section */ 207 Elf32_Word sh_type; /* type */ 208 Elf32_Word sh_flags; /* flags */ 209 Elf32_Addr sh_addr; /* address */ 210 Elf32_Off sh_offset; /* file offset */ 211 Elf32_Word sh_size; /* section size */ 212 Elf32_Word sh_link; /* section header table index link */ 213 Elf32_Word sh_info; /* extra information */ 214 Elf32_Word sh_addralign; /* address alignment */ 215 Elf32_Word sh_entsize; /* section entry size */ 216 } Elf32_Shdr; 217 218 typedef struct { 219 Elf64_Half sh_name; /* section name */ 220 Elf64_Half sh_type; /* section type */ 221 Elf64_Xword sh_flags; /* section flags */ 222 Elf64_Addr sh_addr; /* virtual address */ 223 Elf64_Off sh_offset; /* file offset */ 224 Elf64_Xword sh_size; /* section size */ 225 Elf64_Half sh_link; /* link to another */ 226 Elf64_Half sh_info; /* misc info */ 227 Elf64_Xword sh_addralign; /* memory alignment */ 228 Elf64_Xword sh_entsize; /* table entry size */ 229 } Elf64_Shdr; 230 231 /* Special Section Indexes */ 232 #define SHN_UNDEF 0 /* undefined */ 233 #define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ 234 #define SHN_LOPROC 0xff00 /* reserved range for processor */ 235 #define SHN_HIPROC 0xff1f /* specific section indexes */ 236 #define SHN_ABS 0xfff1 /* absolute value */ 237 #define SHN_COMMON 0xfff2 /* common symbol */ 238 #define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ 239 240 /* sh_type */ 241 #define SHT_NULL 0 /* inactive */ 242 #define SHT_PROGBITS 1 /* program defined information */ 243 #define SHT_SYMTAB 2 /* symbol table section */ 244 #define SHT_STRTAB 3 /* string table section */ 245 #define SHT_RELA 4 /* relocation section with addends*/ 246 #define SHT_HASH 5 /* symbol hash table section */ 247 #define SHT_DYNAMIC 6 /* dynamic section */ 248 #define SHT_NOTE 7 /* note section */ 249 #define SHT_NOBITS 8 /* no space section */ 250 #define SHT_REL 9 /* relation section without addends */ 251 #define SHT_SHLIB 10 /* reserved - purpose unknown */ 252 #define SHT_DYNSYM 11 /* dynamic symbol table section */ 253 #define SHT_NUM 12 /* number of section types */ 254 #define SHT_LOPROC 0x70000000 /* reserved range for processor */ 255 #define SHT_HIPROC 0x7fffffff /* specific section header types */ 256 #define SHT_LOUSER 0x80000000 /* reserved range for application */ 257 #define SHT_HIUSER 0xffffffff /* specific indexes */ 258 259 /* Section names */ 260 #define ELF_BSS ".bss" /* uninitialized data */ 261 #define ELF_DATA ".data" /* initialized data */ 262 #define ELF_DEBUG ".debug" /* debug */ 263 #define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ 264 #define ELF_DYNSTR ".dynstr" /* dynamic string table */ 265 #define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ 266 #define ELF_FINI ".fini" /* termination code */ 267 #define ELF_GOT ".got" /* global offset table */ 268 #define ELF_HASH ".hash" /* symbol hash table */ 269 #define ELF_INIT ".init" /* initialization code */ 270 #define ELF_REL_DATA ".rel.data" /* relocation data */ 271 #define ELF_REL_FINI ".rel.fini" /* relocation termination code */ 272 #define ELF_REL_INIT ".rel.init" /* relocation initialization code */ 273 #define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ 274 #define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ 275 #define ELF_REL_TEXT ".rel.text" /* relocation code */ 276 #define ELF_RODATA ".rodata" /* read-only data */ 277 #define ELF_SHSTRTAB ".shstrtab" /* section header string table */ 278 #define ELF_STRTAB ".strtab" /* string table */ 279 #define ELF_SYMTAB ".symtab" /* symbol table */ 280 #define ELF_TEXT ".text" /* code */ 281 282 283 /* Section Attribute Flags - sh_flags */ 284 #define SHF_WRITE 0x1 /* Writable */ 285 #define SHF_ALLOC 0x2 /* occupies memory */ 286 #define SHF_EXECINSTR 0x4 /* executable */ 287 #define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ 288 /* specific section attributes */ 289 290 /* Symbol Table Entry */ 291 typedef struct elf32_sym { 292 Elf32_Word st_name; /* name - index into string table */ 293 Elf32_Addr st_value; /* symbol value */ 294 Elf32_Word st_size; /* symbol size */ 295 unsigned char st_info; /* type and binding */ 296 unsigned char st_other; /* 0 - no defined meaning */ 297 Elf32_Half st_shndx; /* section header index */ 298 } Elf32_Sym; 299 300 typedef struct { 301 Elf64_Half st_name; /* Symbol name index in str table */ 302 Elf_Byte st_info; /* type / binding attrs */ 303 Elf_Byte st_other; /* unused */ 304 Elf64_Quarter st_shndx; /* section index of symbol */ 305 Elf64_Xword st_value; /* value of symbol */ 306 Elf64_Xword st_size; /* size of symbol */ 307 } Elf64_Sym; 308 309 /* Symbol table index */ 310 #define STN_UNDEF 0 /* undefined */ 311 312 /* Extract symbol info - st_info */ 313 #define ELF32_ST_BIND(x) ((x) >> 4) 314 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) 315 #define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 316 317 #define ELF64_ST_BIND(x) ((x) >> 4) 318 #define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf) 319 #define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 320 321 /* Symbol Binding - ELF32_ST_BIND - st_info */ 322 #define STB_LOCAL 0 /* Local symbol */ 323 #define STB_GLOBAL 1 /* Global symbol */ 324 #define STB_WEAK 2 /* like global - lower precedence */ 325 #define STB_NUM 3 /* number of symbol bindings */ 326 #define STB_LOPROC 13 /* reserved range for processor */ 327 #define STB_HIPROC 15 /* specific symbol bindings */ 328 329 /* Symbol type - ELF32_ST_TYPE - st_info */ 330 #define STT_NOTYPE 0 /* not specified */ 331 #define STT_OBJECT 1 /* data object */ 332 #define STT_FUNC 2 /* function */ 333 #define STT_SECTION 3 /* section */ 334 #define STT_FILE 4 /* file */ 335 #define STT_NUM 5 /* number of symbol types */ 336 #define STT_LOPROC 13 /* reserved range for processor */ 337 #define STT_HIPROC 15 /* specific symbol types */ 338 339 /* Relocation entry with implicit addend */ 340 typedef struct { 341 Elf32_Addr r_offset; /* offset of relocation */ 342 Elf32_Word r_info; /* symbol table index and type */ 343 } Elf32_Rel; 344 345 /* Relocation entry with explicit addend */ 346 typedef struct { 347 Elf32_Addr r_offset; /* offset of relocation */ 348 Elf32_Word r_info; /* symbol table index and type */ 349 Elf32_Sword r_addend; 350 } Elf32_Rela; 351 352 /* Extract relocation info - r_info */ 353 #define ELF32_R_SYM(i) ((i) >> 8) 354 #define ELF32_R_TYPE(i) ((unsigned char) (i)) 355 #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) 356 357 typedef struct { 358 Elf64_Xword r_offset; /* where to do it */ 359 Elf64_Xword r_info; /* index & type of relocation */ 360 } Elf64_Rel; 361 362 typedef struct { 363 Elf64_Xword r_offset; /* where to do it */ 364 Elf64_Xword r_info; /* index & type of relocation */ 365 Elf64_Sxword r_addend; /* adjustment value */ 366 } Elf64_Rela; 367 368 #define ELF64_R_SYM(info) ((info) >> 32) 369 #define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF) 370 #define ELF64_R_INFO(s,t) (((s) << 32) + (__uint32_t)(t)) 371 372 /* Program Header */ 373 typedef struct { 374 Elf32_Word p_type; /* segment type */ 375 Elf32_Off p_offset; /* segment offset */ 376 Elf32_Addr p_vaddr; /* virtual address of segment */ 377 Elf32_Addr p_paddr; /* physical address - ignored? */ 378 Elf32_Word p_filesz; /* number of bytes in file for seg. */ 379 Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ 380 Elf32_Word p_flags; /* flags */ 381 Elf32_Word p_align; /* memory alignment */ 382 } Elf32_Phdr; 383 384 typedef struct { 385 Elf64_Half p_type; /* entry type */ 386 Elf64_Half p_flags; /* flags */ 387 Elf64_Off p_offset; /* offset */ 388 Elf64_Addr p_vaddr; /* virtual address */ 389 Elf64_Addr p_paddr; /* physical address */ 390 Elf64_Xword p_filesz; /* file size */ 391 Elf64_Xword p_memsz; /* memory size */ 392 Elf64_Xword p_align; /* memory & file alignment */ 393 } Elf64_Phdr; 394 395 /* Segment types - p_type */ 396 #define PT_NULL 0 /* unused */ 397 #define PT_LOAD 1 /* loadable segment */ 398 #define PT_DYNAMIC 2 /* dynamic linking section */ 399 #define PT_INTERP 3 /* the RTLD */ 400 #define PT_NOTE 4 /* auxiliary information */ 401 #define PT_SHLIB 5 /* reserved - purpose undefined */ 402 #define PT_PHDR 6 /* program header */ 403 #define PT_NUM 7 /* Number of segment types */ 404 #define PT_LOOS 0x60000000 /* reserved range for OS */ 405 #define PT_HIOS 0x6fffffff /* specific segment types */ 406 #define PT_LOPROC 0x70000000 /* reserved range for processor */ 407 #define PT_HIPROC 0x7fffffff /* specific segment types */ 408 409 /* Segment flags - p_flags */ 410 #define PF_X 0x1 /* Executable */ 411 #define PF_W 0x2 /* Writable */ 412 #define PF_R 0x4 /* Readable */ 413 #define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ 414 /* specific segment flags */ 415 416 /* Dynamic structure */ 417 typedef struct { 418 Elf32_Sword d_tag; /* controls meaning of d_val */ 419 union { 420 Elf32_Word d_val; /* Multiple meanings - see d_tag */ 421 Elf32_Addr d_ptr; /* program virtual address */ 422 } d_un; 423 } Elf32_Dyn; 424 425 typedef struct { 426 Elf64_Xword d_tag; /* controls meaning of d_val */ 427 union { 428 Elf64_Addr d_ptr; 429 Elf64_Xword d_val; 430 } d_un; 431 } Elf64_Dyn; 432 433 /* Dynamic Array Tags - d_tag */ 434 #define DT_NULL 0 /* marks end of _DYNAMIC array */ 435 #define DT_NEEDED 1 /* string table offset of needed lib */ 436 #define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ 437 #define DT_PLTGOT 3 /* address PLT/GOT */ 438 #define DT_HASH 4 /* address of symbol hash table */ 439 #define DT_STRTAB 5 /* address of string table */ 440 #define DT_SYMTAB 6 /* address of symbol table */ 441 #define DT_RELA 7 /* address of relocation table */ 442 #define DT_RELASZ 8 /* size of relocation table */ 443 #define DT_RELAENT 9 /* size of relocation entry */ 444 #define DT_STRSZ 10 /* size of string table */ 445 #define DT_SYMENT 11 /* size of symbol table entry */ 446 #define DT_INIT 12 /* address of initialization func. */ 447 #define DT_FINI 13 /* address of termination function */ 448 #define DT_SONAME 14 /* string table offset of shared obj */ 449 #define DT_RPATH 15 /* string table offset of library 450 search path */ 451 #define DT_SYMBOLIC 16 /* start sym search in shared obj. */ 452 #define DT_REL 17 /* address of rel. tbl. w addends */ 453 #define DT_RELSZ 18 /* size of DT_REL relocation table */ 454 #define DT_RELENT 19 /* size of DT_REL relocation entry */ 455 #define DT_PLTREL 20 /* PLT referenced relocation entry */ 456 #define DT_DEBUG 21 /* bugger */ 457 #define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ 458 #define DT_JMPREL 23 /* add. of PLT's relocation entries */ 459 #define DT_BIND_NOW 24 /* Bind now regardless of env setting */ 460 #define DT_NUM 25 /* Number used. */ 461 #define DT_LOPROC 0x70000000 /* reserved range for processor */ 462 #define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ 463 464 /* Standard ELF hashing function */ 465 unsigned int elf_hash(const unsigned char *name); 466 467 /* 468 * Note Definitions 469 */ 470 typedef struct { 471 Elf32_Word namesz; 472 Elf32_Word descsz; 473 Elf32_Word type; 474 } Elf32_Note; 475 476 typedef struct { 477 Elf64_Half namesz; 478 Elf64_Half descsz; 479 Elf64_Half type; 480 } Elf64_Note; 481 482 /* 483 * XXX - these _KERNEL items aren't part of the ABI! 484 */ 485 #if defined(_KERNEL) || defined(_DYN_LOADER) 486 487 #define ELF32_NO_ADDR ((u_long) ~0) /* Indicates addr. not yet filled in */ 488 #define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */ 489 490 typedef struct { 491 Elf32_Sword au_id; /* 32-bit id */ 492 Elf32_Word au_v; /* 32-bit value */ 493 } Aux32Info; 494 495 #define ELF64_NO_ADDR ((__uint64_t) ~0)/* Indicates addr. not yet filled in */ 496 #define ELF64_AUX_ENTRIES 8 /* Size of aux array passed to loader */ 497 498 typedef struct { 499 Elf64_Shalf au_id; /* 32-bit id */ 500 Elf64_Xword au_v; /* 64-bit id */ 501 } Aux64Info; 502 503 enum AuxID { 504 AUX_null = 0, 505 AUX_ignore = 1, 506 AUX_execfd = 2, 507 AUX_phdr = 3, /* &phdr[0] */ 508 AUX_phent = 4, /* sizeof(phdr[0]) */ 509 AUX_phnum = 5, /* # phdr entries */ 510 AUX_pagesz = 6, /* PAGESIZE */ 511 AUX_base = 7, /* ld.so base addr */ 512 AUX_flags = 8, /* processor flags */ 513 AUX_entry = 9, /* a.out entry */ 514 AUX_sun_uid = 2000, /* euid */ 515 AUX_sun_ruid = 2001, /* ruid */ 516 AUX_sun_gid = 2002, /* egid */ 517 AUX_sun_rgid = 2003 /* rgid */ 518 }; 519 520 struct elf_args { 521 u_long arg_entry; /* program entry point */ 522 u_long arg_interp; /* Interpreter load address */ 523 u_long arg_phaddr; /* program header address */ 524 u_long arg_phentsize; /* Size of program header */ 525 u_long arg_phnum; /* Number of program headers */ 526 u_long arg_os; /* OS tag */ 527 }; 528 529 #endif 530 531 #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) 532 #define ELFSIZE ARCH_ELFSIZE 533 #endif 534 535 #if defined(ELFSIZE) 536 #define CONCAT(x,y) __CONCAT(x,y) 537 #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) 538 #define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) 539 #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) 540 #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) 541 #endif 542 543 #if defined(ELFSIZE) && (ELFSIZE == 32) 544 #define Elf_Ehdr Elf32_Ehdr 545 #define Elf_Phdr Elf32_Phdr 546 #define Elf_Shdr Elf32_Shdr 547 #define Elf_Sym Elf32_Sym 548 #define Elf_Rel Elf32_Rel 549 #define Elf_RelA Elf32_Rela 550 #define Elf_Dyn Elf32_Dyn 551 #define Elf_Half Elf32_Half 552 #define Elf_Word Elf32_Word 553 #define Elf_Sword Elf32_Sword 554 #define Elf_Addr Elf32_Addr 555 #define Elf_Off Elf32_Off 556 #define Elf_Nhdr Elf32_Nhdr 557 #define Elf_Note Elf32_Note 558 559 #define ELF_R_SYM ELF32_R_SYM 560 #define ELF_R_TYPE ELF32_R_TYPE 561 #define ELF_R_INFO ELF32_R_INFO 562 #define ELFCLASS ELFCLASS32 563 564 #define ELF_ST_BIND ELF32_ST_BIND 565 #define ELF_ST_TYPE ELF32_ST_TYPE 566 #define ELF_ST_INFO ELF32_ST_INFO 567 568 #define AuxInfo Aux32Info 569 #elif defined(ELFSIZE) && (ELFSIZE == 64) 570 #define Elf_Ehdr Elf64_Ehdr 571 #define Elf_Phdr Elf64_Phdr 572 #define Elf_Shdr Elf64_Shdr 573 #define Elf_Sym Elf64_Sym 574 #define Elf_Rel Elf64_Rel 575 #define Elf_RelA Elf64_Rela 576 #define Elf_Dyn Elf64_Dyn 577 #define Elf_Half Elf64_Half 578 #define Elf_Word Elf64_Word 579 #define Elf_Sword Elf64_Sword 580 #define Elf_Addr Elf64_Addr 581 #define Elf_Off Elf64_Off 582 #define Elf_Nhdr Elf64_Nhdr 583 #define Elf_Note Elf64_Note 584 585 #define ELF_R_SYM ELF64_R_SYM 586 #define ELF_R_TYPE ELF64_R_TYPE 587 #define ELF_R_INFO ELF64_R_INFO 588 #define ELFCLASS ELFCLASS64 589 590 #define ELF_ST_BIND ELF64_ST_BIND 591 #define ELF_ST_TYPE ELF64_ST_TYPE 592 #define ELF_ST_INFO ELF64_ST_INFO 593 594 #define AuxInfo Aux64Info 595 #endif 596 597 #ifndef _KERNEL 598 extern Elf_Dyn _DYNAMIC[]; 599 #endif 600 601 #ifdef _KERNEL 602 #ifdef _KERN_DO_ELF64 603 int exec_elf64_makecmds(struct proc *, struct exec_package *); 604 void *elf64_copyargs(struct exec_package *, struct ps_strings *, 605 void *, void *); 606 int exec_elf64_fixup(struct proc *, struct exec_package *); 607 char *elf64_check_brand(Elf64_Ehdr *); 608 int elf64_os_pt_note(struct proc *, struct exec_package *, Elf64_Ehdr *, 609 char *, size_t, size_t); 610 #endif 611 #ifdef _KERN_DO_ELF 612 int exec_elf32_makecmds(struct proc *, struct exec_package *); 613 void *elf32_copyargs(struct exec_package *, struct ps_strings *, 614 void *, void *); 615 int exec_elf32_fixup(struct proc *, struct exec_package *); 616 char *elf32_check_brand(Elf32_Ehdr *); 617 int elf32_os_pt_note(struct proc *, struct exec_package *, Elf32_Ehdr *, 618 char *, size_t, size_t); 619 #endif 620 621 #endif /* _KERNEL */ 622 623 #define ELF_TARG_VER 1 /* The ver for which this code is intended */ 624 625 #endif /* _SYS_EXEC_ELF_H_ */ 626