1 /* 2 * Copyright 2002-2016 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _ELF_H 6 #define _ELF_H 7 8 9 #include <SupportDefs.h> 10 #include <ByteOrder.h> 11 12 13 typedef uint32 Elf32_Addr; 14 typedef uint16 Elf32_Half; 15 typedef uint32 Elf32_Off; 16 typedef int32 Elf32_Sword; 17 typedef uint32 Elf32_Word; 18 19 typedef Elf32_Half Elf32_Versym; 20 21 typedef uint64 Elf64_Addr; 22 typedef uint64 Elf64_Off; 23 typedef uint16 Elf64_Half; 24 typedef uint32 Elf64_Word; 25 typedef int32 Elf64_Sword; 26 typedef uint64 Elf64_Xword; 27 typedef int64 Elf64_Sxword; 28 29 typedef Elf64_Half Elf64_Versym; 30 31 32 /*** ELF header ***/ 33 34 #define EI_NIDENT 16 35 36 typedef struct { 37 uint8 e_ident[EI_NIDENT]; 38 Elf32_Half e_type; 39 Elf32_Half e_machine; 40 Elf32_Word e_version; 41 Elf32_Addr e_entry; 42 Elf32_Off e_phoff; 43 Elf32_Off e_shoff; 44 Elf32_Word e_flags; 45 Elf32_Half e_ehsize; 46 Elf32_Half e_phentsize; 47 Elf32_Half e_phnum; 48 Elf32_Half e_shentsize; 49 Elf32_Half e_shnum; 50 Elf32_Half e_shstrndx; 51 52 #ifdef __cplusplus 53 bool IsHostEndian() const; 54 #endif 55 } Elf32_Ehdr; 56 57 typedef struct { 58 uint8 e_ident[EI_NIDENT]; 59 Elf64_Half e_type; 60 Elf64_Half e_machine; 61 Elf64_Word e_version; 62 Elf64_Addr e_entry; 63 Elf64_Off e_phoff; 64 Elf64_Off e_shoff; 65 Elf64_Word e_flags; 66 Elf64_Half e_ehsize; 67 Elf64_Half e_phentsize; 68 Elf64_Half e_phnum; 69 Elf64_Half e_shentsize; 70 Elf64_Half e_shnum; 71 Elf64_Half e_shstrndx; 72 73 #ifdef __cplusplus 74 bool IsHostEndian() const; 75 #endif 76 } Elf64_Ehdr; 77 78 /* e_ident[] indices */ 79 #define EI_MAG0 0 80 #define EI_MAG1 1 81 #define EI_MAG2 2 82 #define EI_MAG3 3 83 #define EI_CLASS 4 84 #define EI_DATA 5 85 #define EI_VERSION 6 86 #define EI_PAD 7 87 88 /* Values for the magic number bytes. */ 89 #define ELFMAG0 0x7f 90 #define ELFMAG1 'E' 91 #define ELFMAG2 'L' 92 #define ELFMAG3 'F' 93 #define ELFMAG "\x7f""ELF" 94 #define SELFMAG 4 95 96 /* e_type (Object file type) */ 97 #define ET_NONE 0 /* No file type */ 98 #define ET_REL 1 /* Relocatable file */ 99 #define ET_EXEC 2 /* Executable file */ 100 #define ET_DYN 3 /* Shared-object file */ 101 #define ET_CORE 4 /* Core file */ 102 #define ET_LOOS 0xfe00 /* OS-specific range start */ 103 #define ET_HIOS 0xfeff /* OS-specific range end */ 104 #define ET_LOPROC 0xff00 /* Processor-specific range start */ 105 #define ET_HIPROC 0xffff /* Processor-specific range end */ 106 107 /* e_machine (Architecture) */ 108 #define EM_NONE 0 /* No machine */ 109 #define EM_M32 1 /* AT&T WE 32100 */ 110 #define EM_SPARC 2 /* Sparc */ 111 #define EM_386 3 /* Intel 80386 */ 112 #define EM_68K 4 /* Motorola m68k family */ 113 #define EM_88K 5 /* Motorola m88k family */ 114 #define EM_486 6 /* Intel 80486, Reserved for future use */ 115 #define EM_860 7 /* Intel 80860 */ 116 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */ 117 #define EM_S370 9 /* IBM System/370 */ 118 #define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian, Deprecated */ 119 #define EM_PARISC 15 /* HPPA */ 120 #define EM_VPP550 17 /* Fujitsu VPP500 */ 121 #define EM_SPARC32PLUS 18 /* Sun "v8plus" */ 122 #define EM_960 19 /* Intel 80960 */ 123 #define EM_PPC 20 /* PowerPC */ 124 #define EM_PPC64 21 /* 64-bit PowerPC */ 125 #define EM_S390 22 /* IBM S/390 */ 126 #define EM_V800 36 /* NEC V800 series */ 127 #define EM_FR20 37 /* Fujitsu FR20 */ 128 #define EM_RH32 38 /* TRW RH32 */ 129 #define EM_MCORE 39 /* Motorola M*Core */ 130 #define EM_RCE 39 /* Old name for MCore */ 131 #define EM_ARM 40 /* ARM */ 132 #define EM_OLD_ALPHA 41 /* Digital Alpha */ 133 #define EM_SH 42 /* Renesas / SuperH SH */ 134 #define EM_SPARCV9 43 /* SPARC v9 64-bit */ 135 #define EM_TRICORE 44 /* Siemens Tricore embedded processor */ 136 #define EM_ARC 45 /* ARC Cores */ 137 #define EM_H8_300 46 /* Renesas H8/300 */ 138 #define EM_H8_300H 47 /* Renesas H8/300H */ 139 #define EM_H8S 48 /* Renesas H8S */ 140 #define EM_H8_500 49 /* Renesas H8/500 */ 141 #define EM_IA_64 50 /* Intel IA-64 Processor */ 142 #define EM_MIPS_X 51 /* Stanford MIPS-X */ 143 #define EM_COLDFIRE 52 /* Motorola Coldfire */ 144 #define EM_68HC12 53 /* Motorola M68HC12 */ 145 #define EM_MMA 54 /* Fujitsu Multimedia Accelerator */ 146 #define EM_PCP 55 /* Siemens PCP */ 147 #define EM_NCPU 56 /* Sony nCPU embedded RISC processor */ 148 #define EM_NDR1 57 /* Denso NDR1 microprocesspr */ 149 #define EM_STARCORE 58 /* Motorola Star*Core processor */ 150 #define EM_ME16 59 /* Toyota ME16 processor */ 151 #define EM_ST100 60 /* STMicroelectronics ST100 processor */ 152 #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor */ 153 #define EM_X86_64 62 /* Advanced Micro Devices X86-64 processor */ 154 #define EM_PDSP 63 /* Sony DSP Processor */ 155 156 #define EM_FX66 66 /* Siemens FX66 microcontroller */ 157 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ 158 #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */ 159 #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ 160 #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ 161 #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ 162 #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ 163 #define EM_SVX 73 /* Silicon Graphics SVx */ 164 #define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ 165 #define EM_VAX 75 /* Digital VAX */ 166 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ 167 #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ 168 #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ 169 #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ 170 #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ 171 #define EM_HUANY 81 /* Harvard University machine-independent object files */ 172 #define EM_PRISM 82 /* SiTera Prism */ 173 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ 174 #define EM_FR30 84 /* Fujitsu FR30 */ 175 #define EM_D10V 85 /* Mitsubishi D10V */ 176 #define EM_D30V 86 /* Mitsubishi D30V */ 177 #define EM_V850 87 /* NEC v850 */ 178 #define EM_M32R 88 /* Mitsubishi M32R */ 179 #define EM_MN10300 89 /* Matsushita MN10300 */ 180 #define EM_MN10200 90 /* Matsushita MN10200 */ 181 #define EM_PJ 91 /* picoJava */ 182 #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ 183 #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ 184 #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ 185 #define EM_NUM 95 186 187 /* architecture class (EI_CLASS) */ 188 #define ELFCLASSNONE 0 189 #define ELFCLASS32 1 190 #define ELFCLASS64 2 191 192 /* endian (EI_DATA) */ 193 #define ELFDATANONE 0 /* invalid */ 194 #define ELFDATA2LSB 1 /* little endian */ 195 #define ELFDATA2MSB 2 /* big endian */ 196 197 /* ELF version (EI_VERSION) */ 198 #define EV_NONE 0 /* invalid */ 199 #define EV_CURRENT 1 /* current version */ 200 201 /*** section header ***/ 202 203 typedef struct { 204 Elf32_Word sh_name; 205 Elf32_Word sh_type; 206 Elf32_Word sh_flags; 207 Elf32_Addr sh_addr; 208 Elf32_Off sh_offset; 209 Elf32_Word sh_size; 210 Elf32_Word sh_link; 211 Elf32_Word sh_info; 212 Elf32_Word sh_addralign; 213 Elf32_Word sh_entsize; 214 } Elf32_Shdr; 215 216 typedef struct { 217 Elf64_Word sh_name; 218 Elf64_Word sh_type; 219 Elf64_Xword sh_flags; 220 Elf64_Addr sh_addr; 221 Elf64_Off sh_offset; 222 Elf64_Xword sh_size; 223 Elf64_Word sh_link; 224 Elf64_Word sh_info; 225 Elf64_Xword sh_addralign; 226 Elf64_Xword sh_entsize; 227 } Elf64_Shdr; 228 229 /* special section indices */ 230 #define SHN_UNDEF 0 231 #define SHN_LORESERVE 0xff00 232 #define SHN_LOPROC 0xff00 233 #define SHN_HIPROC 0xff1f 234 #define SHN_ABS 0xfff1 235 #define SHN_COMMON 0xfff2 236 #define SHN_HIRESERVE 0xffff 237 238 /* section header type */ 239 #define SHT_NULL 0 240 #define SHT_PROGBITS 1 241 #define SHT_SYMTAB 2 242 #define SHT_STRTAB 3 243 #define SHT_RELA 4 244 #define SHT_HASH 5 245 #define SHT_DYNAMIC 6 246 #define SHT_NOTE 7 247 #define SHT_NOBITS 8 248 #define SHT_REL 9 249 #define SHT_SHLIB 10 250 #define SHT_DYNSYM 11 251 252 #define SHT_GNU_verdef 0x6ffffffd /* version definition section */ 253 #define SHT_GNU_verneed 0x6ffffffe /* version needs section */ 254 #define SHT_GNU_versym 0x6fffffff /* version symbol table */ 255 256 #define SHT_LOPROC 0x70000000 257 #define SHT_HIPROC 0x7fffffff 258 #define SHT_LOUSER 0x80000000 259 #define SHT_HIUSER 0xffffffff 260 261 /* section header flags */ 262 #define SHF_WRITE 1 263 #define SHF_ALLOC 2 264 #define SHF_EXECINSTR 4 265 266 #define SHF_MASKPROC 0xf0000000 267 268 269 /*** program header ***/ 270 271 typedef struct { 272 Elf32_Word p_type; 273 Elf32_Off p_offset; /* offset from the beginning of the file of the segment */ 274 Elf32_Addr p_vaddr; /* virtual address for the segment in memory */ 275 Elf32_Addr p_paddr; 276 Elf32_Word p_filesz; /* the size of the segment in the file */ 277 Elf32_Word p_memsz; /* the size of the segment in memory */ 278 Elf32_Word p_flags; 279 Elf32_Word p_align; 280 281 #ifdef __cplusplus 282 bool IsReadWrite() const; 283 bool IsExecutable() const; 284 #endif 285 } Elf32_Phdr; 286 287 typedef struct { 288 Elf64_Word p_type; 289 Elf64_Word p_flags; 290 Elf64_Off p_offset; /* offset from the beginning of the file of the segment */ 291 Elf64_Addr p_vaddr; /* virtual address for the segment in memory */ 292 Elf64_Addr p_paddr; 293 Elf64_Xword p_filesz; /* the size of the segment in the file */ 294 Elf64_Xword p_memsz; /* the size of the segment in memory */ 295 Elf64_Xword p_align; 296 297 #ifdef __cplusplus 298 bool IsReadWrite() const; 299 bool IsExecutable() const; 300 #endif 301 } Elf64_Phdr; 302 303 /* program header segment types */ 304 #define PT_NULL 0 305 #define PT_LOAD 1 306 #define PT_DYNAMIC 2 307 #define PT_INTERP 3 308 #define PT_NOTE 4 309 #define PT_SHLIB 5 310 #define PT_PHDR 6 311 #define PT_TLS 7 312 #define PT_STACK 0x6474e551 313 #define PT_RELRO 0x6474e552 314 315 #define PT_LOPROC 0x70000000 316 #define PT_ARM_UNWIND 0x70000001 317 #define PT_HIPROC 0x7fffffff 318 319 /* program header segment flags */ 320 #define PF_EXECUTE 0x1 321 #define PF_WRITE 0x2 322 #define PF_READ 0x4 323 #define PF_PROTECTION_MASK (PF_EXECUTE | PF_WRITE | PF_READ) 324 325 #define PF_MASKPROC 0xf0000000 326 327 328 /* symbol table entry */ 329 330 typedef struct { 331 Elf32_Word st_name; 332 Elf32_Addr st_value; 333 Elf32_Word st_size; 334 uint8 st_info; 335 uint8 st_other; 336 Elf32_Half st_shndx; 337 338 #ifdef __cplusplus 339 uint8 Bind() const; 340 uint8 Type() const; 341 void SetInfo(uint8 bind, uint8 type); 342 #endif 343 } Elf32_Sym; 344 345 typedef struct { 346 Elf64_Word st_name; 347 uint8 st_info; 348 uint8 st_other; 349 Elf64_Half st_shndx; 350 Elf64_Addr st_value; 351 Elf64_Xword st_size; 352 353 #ifdef __cplusplus 354 uint8 Bind() const; 355 uint8 Type() const; 356 void SetInfo(uint8 bind, uint8 type); 357 #endif 358 } Elf64_Sym; 359 360 #define ELF32_ST_BIND(i) ((i) >> 4) 361 #define ELF32_ST_TYPE(i) ((i) & 0xf) 362 #define ELF32_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf)) 363 364 #define ELF64_ST_BIND(i) ((i) >> 4) 365 #define ELF64_ST_TYPE(i) ((i) & 0xf) 366 #define ELF64_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf)) 367 368 /* symbol types */ 369 #define STT_NOTYPE 0 370 #define STT_OBJECT 1 371 #define STT_FUNC 2 372 #define STT_SECTION 3 373 #define STT_FILE 4 374 #define STT_TLS 6 375 #define STT_LOPROC 13 376 #define STT_HIPROC 15 377 378 /* symbol binding */ 379 #define STB_LOCAL 0 380 #define STB_GLOBAL 1 381 #define STB_WEAK 2 382 #define STB_LOPROC 13 383 #define STB_HIPROC 15 384 385 /* special symbol indices */ 386 #define STN_UNDEF 0 387 388 389 /* relocation table entry */ 390 391 typedef struct { 392 Elf32_Addr r_offset; 393 Elf32_Word r_info; 394 395 #ifdef __cplusplus 396 uint8 SymbolIndex() const; 397 uint8 Type() const; 398 #endif 399 } Elf32_Rel; 400 401 typedef struct { 402 Elf64_Addr r_offset; 403 Elf64_Xword r_info; 404 405 #ifdef __cplusplus 406 uint8 SymbolIndex() const; 407 uint8 Type() const; 408 #endif 409 } Elf64_Rel; 410 411 #ifdef __cplusplus 412 typedef struct Elf32_Rela : public Elf32_Rel { 413 #else 414 typedef struct { 415 Elf32_Addr r_offset; 416 Elf32_Word r_info; 417 #endif 418 Elf32_Sword r_addend; 419 } Elf32_Rela; 420 421 #ifdef __cplusplus 422 typedef struct Elf64_Rela : public Elf64_Rel { 423 #else 424 typedef struct { 425 Elf64_Addr r_offset; 426 Elf64_Xword r_info; 427 #endif 428 Elf64_Sxword r_addend; 429 } Elf64_Rela; 430 431 #define ELF32_R_SYM(i) ((i) >> 8) 432 #define ELF32_R_TYPE(i) ((unsigned char)(i)) 433 #define ELF32_R_INFO(s, t) (((s) << 8) + (unsigned char)(t)) 434 435 #define ELF64_R_SYM(i) ((i) >> 32) 436 #define ELF64_R_TYPE(i) ((i) & 0xffffffffL) 437 #define ELF64_R_INFO(s, t) ((((Elf64_Xword)(s)) << 32) + ((t) & 0xffffffffL)) 438 439 440 /* dynamic section entry */ 441 442 typedef struct { 443 Elf32_Sword d_tag; 444 union { 445 Elf32_Word d_val; 446 Elf32_Addr d_ptr; 447 } d_un; 448 } Elf32_Dyn; 449 450 typedef struct { 451 Elf64_Sxword d_tag; 452 union { 453 Elf64_Xword d_val; 454 Elf64_Addr d_ptr; 455 } d_un; 456 } Elf64_Dyn; 457 458 /* dynamic entry type */ 459 #define DT_NULL 0 460 #define DT_NEEDED 1 461 #define DT_PLTRELSZ 2 462 #define DT_PLTGOT 3 463 #define DT_HASH 4 464 #define DT_STRTAB 5 465 #define DT_SYMTAB 6 466 #define DT_RELA 7 467 #define DT_RELASZ 8 468 #define DT_RELAENT 9 469 #define DT_STRSZ 10 470 #define DT_SYMENT 11 471 #define DT_INIT 12 472 #define DT_FINI 13 473 #define DT_SONAME 14 474 #define DT_RPATH 15 475 #define DT_SYMBOLIC 16 476 #define DT_REL 17 477 #define DT_RELSZ 18 478 #define DT_RELENT 19 479 #define DT_PLTREL 20 480 #define DT_DEBUG 21 481 #define DT_TEXTREL 22 482 #define DT_JMPREL 23 483 #define DT_BIND_NOW 24 /* no lazy binding */ 484 #define DT_INIT_ARRAY 25 /* init function array */ 485 #define DT_FINI_ARRAY 26 /* termination function array */ 486 #define DT_INIT_ARRAYSZ 27 /* init function array size */ 487 #define DT_FINI_ARRAYSZ 28 /* termination function array size */ 488 #define DT_RUNPATH 29 /* library search path (supersedes DT_RPATH) */ 489 #define DT_FLAGS 30 /* flags (see below) */ 490 #define DT_ENCODING 32 491 #define DT_PREINIT_ARRAY 32 /* preinitialization array */ 492 #define DT_PREINIT_ARRAYSZ 33 /* preinitialization array size */ 493 494 #define DT_VERSYM 0x6ffffff0 /* symbol version table */ 495 #define DT_VERDEF 0x6ffffffc /* version definition table */ 496 #define DT_VERDEFNUM 0x6ffffffd /* number of version definitions */ 497 #define DT_VERNEED 0x6ffffffe /* table with needed versions */ 498 #define DT_VERNEEDNUM 0x6fffffff /* number of needed versions */ 499 500 #define DT_LOPROC 0x70000000 501 #define DT_HIPROC 0x7fffffff 502 503 /* DT_FLAGS values */ 504 #define DF_ORIGIN 0x01 505 #define DF_SYMBOLIC 0x02 506 #define DF_TEXTREL 0x04 507 #define DF_BIND_NOW 0x08 508 #define DF_STATIC_TLS 0x10 509 510 511 /* version definition section */ 512 513 typedef struct { 514 Elf32_Half vd_version; /* version revision */ 515 Elf32_Half vd_flags; /* version information flags */ 516 Elf32_Half vd_ndx; /* version index as specified in the 517 symbol version table */ 518 Elf32_Half vd_cnt; /* number of associated verdaux entries */ 519 Elf32_Word vd_hash; /* version name hash value */ 520 Elf32_Word vd_aux; /* byte offset to verdaux array */ 521 Elf32_Word vd_next; /* byte offset to next verdef entry */ 522 } Elf32_Verdef; 523 524 typedef struct { 525 Elf64_Half vd_version; /* version revision */ 526 Elf64_Half vd_flags; /* version information flags */ 527 Elf64_Half vd_ndx; /* version index as specified in the 528 symbol version table */ 529 Elf64_Half vd_cnt; /* number of associated verdaux entries */ 530 Elf64_Word vd_hash; /* version name hash value */ 531 Elf64_Word vd_aux; /* byte offset to verdaux array */ 532 Elf64_Word vd_next; /* byte offset to next verdef entry */ 533 } Elf64_Verdef; 534 535 /* values for vd_version (version revision) */ 536 #define VER_DEF_NONE 0 /* no version */ 537 #define VER_DEF_CURRENT 1 /* current version */ 538 #define VER_DEF_NUM 2 /* given version number */ 539 540 /* values for vd_flags (version information flags) */ 541 #define VER_FLG_BASE 0x1 /* version definition of file itself */ 542 #define VER_FLG_WEAK 0x2 /* weak version identifier */ 543 544 /* values for versym symbol index */ 545 #define VER_NDX_LOCAL 0 /* symbol is local */ 546 #define VER_NDX_GLOBAL 1 /* symbol is global/unversioned */ 547 #define VER_NDX_INITIAL 2 /* initial version -- that's the one given 548 to symbols when a library becomes 549 versioned; handled by the linker (and 550 runtime loader) similar to 551 VER_NDX_GLOBAL */ 552 #define VER_NDX_LORESERVE 0xff00 /* beginning of reserved entries */ 553 #define VER_NDX_ELIMINATE 0xff01 /* symbol is to be eliminated */ 554 555 #define VER_NDX_FLAG_HIDDEN 0x8000 /* flag: version is hidden */ 556 #define VER_NDX_MASK 0x7fff /* mask to get the actual version index */ 557 #define VER_NDX(x) ((x) & VER_NDX_MASK) 558 559 560 /* auxiliary version information */ 561 562 typedef struct { 563 Elf32_Word vda_name; /* string table offset to version or dependency 564 name */ 565 Elf32_Word vda_next; /* byte offset to next verdaux entry */ 566 } Elf32_Verdaux; 567 568 typedef struct { 569 Elf64_Word vda_name; /* string table offset to version or dependency 570 name */ 571 Elf64_Word vda_next; /* byte offset to next verdaux entry */ 572 } Elf64_Verdaux; 573 574 575 /* version dependency section */ 576 577 typedef struct { 578 Elf32_Half vn_version; /* version of structure */ 579 Elf32_Half vn_cnt; /* number of associated vernaux entries */ 580 Elf32_Word vn_file; /* byte offset to file name for this 581 dependency */ 582 Elf32_Word vn_aux; /* byte offset to vernaux array */ 583 Elf32_Word vn_next; /* byte offset to next verneed entry */ 584 } Elf32_Verneed; 585 586 typedef struct { 587 Elf64_Half vn_version; /* version of structure */ 588 Elf64_Half vn_cnt; /* number of associated vernaux entries */ 589 Elf64_Word vn_file; /* byte offset to file name for this 590 dependency */ 591 Elf64_Word vn_aux; /* byte offset to vernaux array */ 592 Elf64_Word vn_next; /* byte offset to next verneed entry */ 593 } Elf64_Verneed; 594 595 /* values for vn_version (version revision) */ 596 #define VER_NEED_NONE 0 /* no version */ 597 #define VER_NEED_CURRENT 1 /* current version */ 598 #define VER_NEED_NUM 2 /* given version number */ 599 600 601 /* auxiliary needed version information */ 602 603 typedef struct { 604 Elf32_Word vna_hash; /* dependency name hash value */ 605 Elf32_Half vna_flags; /* dependency specific information flags */ 606 Elf32_Half vna_other; /* version index as specified in the symbol 607 version table */ 608 Elf32_Word vna_name; /* string table offset to dependency name */ 609 Elf32_Word vna_next; /* byte offset to next vernaux entry */ 610 } Elf32_Vernaux; 611 612 typedef struct { 613 Elf64_Word vna_hash; /* dependency name hash value */ 614 Elf64_Half vna_flags; /* dependency specific information flags */ 615 Elf64_Half vna_other; /* version index as specified in the symbol 616 version table */ 617 Elf64_Word vna_name; /* string table offset to dependency name */ 618 Elf64_Word vna_next; /* byte offset to next vernaux entry */ 619 } Elf64_Vernaux; 620 621 /* values for vna_flags */ 622 #define VER_FLG_WEAK 0x2 /* weak version identifier */ 623 624 625 /*** core files ***/ 626 627 /* note section header */ 628 629 typedef struct { 630 Elf32_Word n_namesz; /* length of the note's name */ 631 Elf32_Word n_descsz; /* length of the note's descriptor */ 632 Elf32_Word n_type; /* note type */ 633 } Elf32_Nhdr; 634 635 typedef struct { 636 Elf64_Word n_namesz; /* length of the note's name */ 637 Elf64_Word n_descsz; /* length of the note's descriptor */ 638 Elf64_Word n_type; /* note type */ 639 } Elf64_Nhdr; 640 641 /* values for note name */ 642 #define ELF_NOTE_CORE "CORE" 643 #define ELF_NOTE_HAIKU "Haiku" 644 645 /* values for note type (n_type) */ 646 /* ELF_NOTE_CORE/... */ 647 #define NT_FILE 0x46494c45 /* mapped files */ 648 649 /* ELF_NOTE_HAIKU/... */ 650 #define NT_TEAM 0x7465616d /* team */ 651 #define NT_AREAS 0x61726561 /* areas */ 652 #define NT_IMAGES 0x696d6167 /* images */ 653 #define NT_THREADS 0x74687264 /* threads */ 654 #define NT_SYMBOLS 0x73796d73 /* symbols */ 655 656 /* NT_TEAM: uint32 entrySize; Elf32_Note_Team; char[] args */ 657 typedef struct { 658 int32 nt_id; /* team ID */ 659 int32 nt_uid; /* team owner ID */ 660 int32 nt_gid; /* team group ID */ 661 } Elf32_Note_Team; 662 663 typedef Elf32_Note_Team Elf64_Note_Team; 664 665 /* NT_AREAS: 666 * uint32 count; 667 * uint32 entrySize; 668 * Elf32_Note_Area_Entry[count]; 669 * char[] names 670 */ 671 typedef struct { 672 int32 na_id; /* area ID */ 673 uint32 na_lock; /* lock type (B_NO_LOCK, ...) */ 674 uint32 na_protection; /* protection (B_READ_AREA | ...) */ 675 uint32 na_base; /* area base address */ 676 uint32 na_size; /* area size */ 677 uint32 na_ram_size; /* physical memory used */ 678 } Elf32_Note_Area_Entry; 679 680 /* NT_AREAS: 681 * uint32 count; 682 * uint32 entrySize; 683 * Elf64_Note_Area_Entry[count]; 684 * char[] names 685 */ 686 typedef struct { 687 int32 na_id; /* area ID */ 688 uint32 na_lock; /* lock type (B_NO_LOCK, ...) */ 689 uint32 na_protection; /* protection (B_READ_AREA | ...) */ 690 uint32 na_pad1; 691 uint64 na_base; /* area base address */ 692 uint64 na_size; /* area size */ 693 uint64 na_ram_size; /* physical memory used */ 694 } Elf64_Note_Area_Entry; 695 696 /* NT_IMAGES: 697 * uint32 count; 698 * uint32 entrySize; 699 * Elf32_Note_Image_Entry[count]; 700 * char[] names 701 */ 702 typedef struct { 703 int32 ni_id; /* image ID */ 704 int32 ni_type; /* image type (B_APP_IMAGE, ...) */ 705 uint32 ni_init_routine; /* address of init function */ 706 uint32 ni_term_routine; /* address of termination function */ 707 int32 ni_device; /* device ID of mapped file */ 708 int64 ni_node; /* node ID of mapped file */ 709 uint32 ni_text_base; /* base address of text segment */ 710 uint32 ni_text_size; /* size of text segment */ 711 int32 ni_text_delta; /* delta of the text segment relative to 712 load address specified in the ELF file */ 713 uint32 ni_data_base; /* base address of data segment */ 714 uint32 ni_data_size; /* size of data segment */ 715 uint32 ni_symbol_table; /* address of dynamic symbol table */ 716 uint32 ni_symbol_hash; /* address of dynamic symbol hash */ 717 uint32 ni_string_table; /* address of dynamic string table */ 718 } Elf32_Note_Image_Entry; 719 720 /* NT_IMAGES: 721 * uint32 count; 722 * uint32 entrySize; 723 * Elf64_Note_Image_Entry[count]; 724 * char[] names 725 */ 726 typedef struct { 727 int32 ni_id; /* image ID */ 728 int32 ni_type; /* image type (B_APP_IMAGE, ...) */ 729 uint64 ni_init_routine; /* address of init function */ 730 uint64 ni_term_routine; /* address of termination function */ 731 uint32 ni_pad1; 732 int32 ni_device; /* device ID of mapped file */ 733 int64 ni_node; /* node ID of mapped file */ 734 uint64 ni_text_base; /* base address of text segment */ 735 uint64 ni_text_size; /* size of text segment */ 736 int64 ni_text_delta; /* delta of the text segment relative to 737 load address specified in the ELF file */ 738 uint64 ni_data_base; /* base address of data segment */ 739 uint64 ni_data_size; /* size of data segment */ 740 uint64 ni_symbol_table; /* address of dynamic symbol table */ 741 uint64 ni_symbol_hash; /* address of dynamic symbol hash */ 742 uint64 ni_string_table; /* address of dynamic string table */ 743 } Elf64_Note_Image_Entry; 744 745 /* NT_THREADS: 746 * uint32 count; 747 * uint32 entrySize; 748 * uint32 cpuStateSize; 749 * {Elf32_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count]; 750 * char[] names 751 */ 752 typedef struct { 753 int32 nth_id; /* thread ID */ 754 int32 nth_state; /* thread state (B_THREAD_RUNNING, ...) */ 755 int32 nth_priority; /* thread priority */ 756 uint32 nth_stack_base; /* thread stack base address */ 757 uint32 nth_stack_end; /* thread stack end address */ 758 } Elf32_Note_Thread_Entry; 759 760 /* NT_THREADS: 761 * uint32 count; 762 * uint32 entrySize; 763 * uint32 cpuStateSize; 764 * {Elf64_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count]; 765 * char[] names 766 */ 767 typedef struct { 768 int32 nth_id; /* thread ID */ 769 int32 nth_state; /* thread state (B_THREAD_RUNNING, ...) */ 770 int32 nth_priority; /* thread priority */ 771 uint32 nth_pad1; 772 uint64 nth_stack_base; /* thread stack base address */ 773 uint64 nth_stack_end; /* thread stack end address */ 774 } Elf64_Note_Thread_Entry; 775 776 /* NT_SYMBOLS: 777 * int32 imageId; 778 * uint32 symbolCount; 779 * uint32 entrySize; 780 * Elf{32,64}_Sym[count]; 781 * char[] strings 782 */ 783 784 785 /*** inline functions ***/ 786 787 #ifdef __cplusplus 788 789 inline bool 790 Elf32_Ehdr::IsHostEndian() const 791 { 792 #if B_HOST_IS_LENDIAN 793 return e_ident[EI_DATA] == ELFDATA2LSB; 794 #elif B_HOST_IS_BENDIAN 795 return e_ident[EI_DATA] == ELFDATA2MSB; 796 #endif 797 } 798 799 800 inline bool 801 Elf64_Ehdr::IsHostEndian() const 802 { 803 #if B_HOST_IS_LENDIAN 804 return e_ident[EI_DATA] == ELFDATA2LSB; 805 #elif B_HOST_IS_BENDIAN 806 return e_ident[EI_DATA] == ELFDATA2MSB; 807 #endif 808 } 809 810 811 inline bool 812 Elf32_Phdr::IsReadWrite() const 813 { 814 return !(~p_flags & (PF_READ | PF_WRITE)); 815 } 816 817 818 inline bool 819 Elf32_Phdr::IsExecutable() const 820 { 821 return (p_flags & PF_EXECUTE) != 0; 822 } 823 824 825 inline bool 826 Elf64_Phdr::IsReadWrite() const 827 { 828 return !(~p_flags & (PF_READ | PF_WRITE)); 829 } 830 831 832 inline bool 833 Elf64_Phdr::IsExecutable() const 834 { 835 return (p_flags & PF_EXECUTE) != 0; 836 } 837 838 839 inline uint8 840 Elf32_Sym::Bind() const 841 { 842 return ELF32_ST_BIND(st_info); 843 } 844 845 846 inline uint8 847 Elf32_Sym::Type() const 848 { 849 return ELF32_ST_TYPE(st_info); 850 } 851 852 853 inline void 854 Elf32_Sym::SetInfo(uint8 bind, uint8 type) 855 { 856 st_info = ELF32_ST_INFO(bind, type); 857 } 858 859 860 inline uint8 861 Elf64_Sym::Bind() const 862 { 863 return ELF64_ST_BIND(st_info); 864 } 865 866 867 inline uint8 868 Elf64_Sym::Type() const 869 { 870 return ELF64_ST_TYPE(st_info); 871 } 872 873 874 inline void 875 Elf64_Sym::SetInfo(uint8 bind, uint8 type) 876 { 877 st_info = ELF64_ST_INFO(bind, type); 878 } 879 880 881 inline uint8 882 Elf32_Rel::SymbolIndex() const 883 { 884 return ELF32_R_SYM(r_info); 885 } 886 887 888 inline uint8 889 Elf32_Rel::Type() const 890 { 891 return ELF32_R_TYPE(r_info); 892 } 893 894 895 inline uint8 896 Elf64_Rel::SymbolIndex() const 897 { 898 return ELF64_R_SYM(r_info); 899 } 900 901 902 inline uint8 903 Elf64_Rel::Type() const 904 { 905 return ELF64_R_TYPE(r_info); 906 } 907 908 #endif /* __cplusplus */ 909 910 911 #endif /* _ELF_H */ 912