
1: /* This file defines standard ELF types, structures, and macros. 2: Copyright (C) 1995-2003,2004,2005,2006,2007 Free Software Foundation, Inc. 3: This file is part of the GNU C Library. 4: 5: The GNU C Library is free software; you can redistribute it and/or 6: modify it under the terms of the GNU Lesser General Public 7: License as published by the Free Software Foundation; either 8: version 2.1 of the License, or (at your option) any later version. 9: 10: The GNU C Library is distributed in the hope that it will be useful, 11: but WITHOUT ANY WARRANTY; without even the implied warranty of 12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13: Lesser General Public License for more details. 14: 15: You should have received a copy of the GNU Lesser General Public 16: License along with the GNU C Library; if not, write to the Free 17: Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18: 02111-1307 USA. */ 19: 20: #ifndef _ELF_H 21: #define _ELF_H 1 22: 23: #include <features.h> 24: 25: __BEGIN_DECLS 26: 27: /* Standard ELF types. */ 28: 29: #include <stdint.h> 30: 31: /* Type for a 16-bit quantity. */ 32: typedef uint16_t Elf32_Half; 33: typedef uint16_t Elf64_Half; 34: 35: /* Types for signed and unsigned 32-bit quantities. */ 36: typedef uint32_t Elf32_Word; 37: typedef int32_t Elf32_Sword; 38: typedef uint32_t Elf64_Word; 39: typedef int32_t Elf64_Sword; 40: 41: /* Types for signed and unsigned 64-bit quantities. */ 42: typedef uint64_t Elf32_Xword; 43: typedef int64_t Elf32_Sxword; 44: typedef uint64_t Elf64_Xword; 45: typedef int64_t Elf64_Sxword; 46: 47: /* Type of addresses. */ 48: typedef uint32_t Elf32_Addr; 49: typedef uint64_t Elf64_Addr; 50: 51: /* Type of file offsets. */ 52: typedef uint32_t Elf32_Off; 53: typedef uint64_t Elf64_Off; 54: 55: /* Type for section indices, which are 16-bit quantities. */ 56: typedef uint16_t Elf32_Section; 57: typedef uint16_t Elf64_Section; 58: 59: /* Type for version symbol information. */ 60: typedef Elf32_Half Elf32_Versym; 61: typedef Elf64_Half Elf64_Versym; 62: 63: 64: /* The ELF file header. This appears at the start of every ELF file. */ 65: 66: #define EI_NIDENT (16) 67: 68: typedef struct 69: { 70: unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ 71: Elf32_Half e_type; /* Object file type */ 72: Elf32_Half e_machine; /* Architecture */ 73: Elf32_Word e_version; /* Object file version */ 74: Elf32_Addr e_entry; /* Entry point virtual address */ 75: Elf32_Off e_phoff; /* Program header table file offset */ 76: Elf32_Off e_shoff; /* Section header table file offset */ 77: Elf32_Word e_flags; /* Processor-specific flags */ 78: Elf32_Half e_ehsize; /* ELF header size in bytes */ 79: Elf32_Half e_phentsize; /* Program header table entry size */ 80: Elf32_Half e_phnum; /* Program header table entry count */ 81: Elf32_Half e_shentsize; /* Section header table entry size */ 82: Elf32_Half e_shnum; /* Section header table entry count */ 83: Elf32_Half e_shstrndx; /* Section header string table index */ 84: } Elf32_Ehdr; 85: 86: typedef struct 87: { 88: unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ 89: Elf64_Half e_type; /* Object file type */ 90: Elf64_Half e_machine; /* Architecture */ 91: Elf64_Word e_version; /* Object file version */ 92: Elf64_Addr e_entry; /* Entry point virtual address */ 93: Elf64_Off e_phoff; /* Program header table file offset */ 94: Elf64_Off e_shoff; /* Section header table file offset */ 95: Elf64_Word e_flags; /* Processor-specific flags */ 96: Elf64_Half e_ehsize; /* ELF header size in bytes */ 97: Elf64_Half e_phentsize; /* Program header table entry size */ 98: Elf64_Half e_phnum; /* Program header table entry count */ 99: Elf64_Half e_shentsize; /* Section header table entry size */ 100: Elf64_Half e_shnum; /* Section header table entry count */ 101: Elf64_Half e_shstrndx; /* Section header string table index */ 102: } Elf64_Ehdr; 103: 104: /* Fields in the e_ident array. The EI_* macros are indices into the 105: array. The macros under each EI_* macro are the values the byte 106: may have. */ 107: 108: #define EI_MAG0 0 /* File identification byte 0 index */ 109: #define ELFMAG0 0x7f /* Magic number byte 0 */ 110: 111: #define EI_MAG1 1 /* File identification byte 1 index */ 112: #define ELFMAG1 'E' /* Magic number byte 1 */ 113: 114: #define EI_MAG2 2 /* File identification byte 2 index */ 115: #define ELFMAG2 'L' /* Magic number byte 2 */ 116: 117: #define EI_MAG3 3 /* File identification byte 3 index */ 118: #define ELFMAG3 'F' /* Magic number byte 3 */ 119: 120: /* Conglomeration of the identification bytes, for easy testing as a word. */ 121: #define ELFMAG "\177ELF" 122: #define SELFMAG 4 123: 124: #define EI_CLASS 4 /* File class byte index */ 125: #define ELFCLASSNONE 0 /* Invalid class */ 126: #define ELFCLASS32 1 /* 32-bit objects */ 127: #define ELFCLASS64 2 /* 64-bit objects */ 128: #define ELFCLASSNUM 3 129: 130: #define EI_DATA 5 /* Data encoding byte index */ 131: #define ELFDATANONE 0 /* Invalid data encoding */ 132: #define ELFDATA2LSB 1 /* 2's complement, little endian */ 133: #define ELFDATA2MSB 2 /* 2's complement, big endian */ 134: #define ELFDATANUM 3 135: 136: #define EI_VERSION 6 /* File version byte index */ 137: /* Value must be EV_CURRENT */ 138: 139: #define EI_OSABI 7 /* OS ABI identification */ 140: #define ELFOSABI_NONE 0 /* UNIX System V ABI */ 141: #define ELFOSABI_SYSV 0 /* Alias. */ 142: #define ELFOSABI_HPUX 1 /* HP-UX */ 143: #define ELFOSABI_NETBSD 2 /* NetBSD. */ 144: #define ELFOSABI_LINUX 3 /* Linux. */ 145: #define ELFOSABI_SOLARIS 6 /* Sun Solaris. */ 146: #define ELFOSABI_AIX 7 /* IBM AIX. */ 147: #define ELFOSABI_IRIX 8 /* SGI Irix. */ 148: #define ELFOSABI_FREEBSD 9 /* FreeBSD. */ 149: #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */ 150: #define ELFOSABI_MODESTO 11 /* Novell Modesto. */ 151: #define ELFOSABI_OPENBSD 12 /* OpenBSD. */ 152: #define ELFOSABI_ARM 97 /* ARM */ 153: #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 154: 155: #define EI_ABIVERSION 8 /* ABI version */ 156: 157: #define EI_PAD 9 /* Byte index of padding bytes */ 158: 159: /* Legal values for e_type (object file type). */ 160: 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 defined types */ 167: #define ET_LOOS 0xfe00 /* OS-specific range start */ 168: #define ET_HIOS 0xfeff /* OS-specific range end */ 169: #define ET_LOPROC 0xff00 /* Processor-specific range start */ 170: #define ET_HIPROC 0xffff /* Processor-specific range end */ 171: 172: /* Legal values for e_machine (architecture). */ 173: 174: #define EM_NONE 0 /* No machine */ 175: #define EM_M32 1 /* AT&T WE 32100 */ 176: #define EM_SPARC 2 /* SUN SPARC */ 177: #define EM_386 3 /* Intel 80386 */ 178: #define EM_68K 4 /* Motorola m68k family */ 179: #define EM_88K 5 /* Motorola m88k family */ 180: #define EM_860 7 /* Intel 80860 */ 181: #define EM_MIPS 8 /* MIPS R3000 big-endian */ 182: #define EM_S370 9 /* IBM System/370 */ 183: #define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ 184: 185: #define EM_PARISC 15 /* HPPA */ 186: #define EM_VPP500 17 /* Fujitsu VPP500 */ 187: #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ 188: #define EM_960 19 /* Intel 80960 */ 189: #define EM_PPC 20 /* PowerPC */ 190: #define EM_PPC64 21 /* PowerPC 64-bit */ 191: #define EM_S390 22 /* IBM S390 */ 192: 193: #define EM_V800 36 /* NEC V800 series */ 194: #define EM_FR20 37 /* Fujitsu FR20 */ 195: #define EM_RH32 38 /* TRW RH-32 */ 196: #define EM_RCE 39 /* Motorola RCE */ 197: #define EM_ARM 40 /* ARM */ 198: #define EM_FAKE_ALPHA 41 /* Digital Alpha */ 199: #define EM_SH 42 /* Hitachi SH */ 200: #define EM_SPARCV9 43 /* SPARC v9 64-bit */ 201: #define EM_TRICORE 44 /* Siemens Tricore */ 202: #define EM_ARC 45 /* Argonaut RISC Core */ 203: #define EM_H8_300 46 /* Hitachi H8/300 */ 204: #define EM_H8_300H 47 /* Hitachi H8/300H */ 205: #define EM_H8S 48 /* Hitachi H8S */ 206: #define EM_H8_500 49 /* Hitachi H8/500 */ 207: #define EM_IA_64 50 /* Intel Merced */ 208: #define EM_MIPS_X 51 /* Stanford MIPS-X */ 209: #define EM_COLDFIRE 52 /* Motorola Coldfire */ 210: #define EM_68HC12 53 /* Motorola M68HC12 */ 211: #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ 212: #define EM_PCP 55 /* Siemens PCP */ 213: #define EM_NCPU 56 /* Sony nCPU embeeded RISC */ 214: #define EM_NDR1 57 /* Denso NDR1 microprocessor */ 215: #define EM_STARCORE 58 /* Motorola Start*Core processor */ 216: #define EM_ME16 59 /* Toyota ME16 processor */ 217: #define EM_ST100 60 /* STMicroelectronic ST100 processor */ 218: #define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ 219: #define EM_X86_64 62 /* AMD x86-64 architecture */ 220: #define EM_PDSP 63 /* Sony DSP Processor */ 221: 222: #define EM_FX66 66 /* Siemens FX66 microcontroller */ 223: #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ 224: #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */ 225: #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ 226: #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ 227: #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ 228: #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ 229: #define EM_SVX 73 /* Silicon Graphics SVx */ 230: #define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ 231: #define EM_VAX 75 /* Digital VAX */ 232: #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ 233: #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ 234: #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ 235: #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ 236: #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ 237: #define EM_HUANY 81 /* Harvard University machine-independent object files */ 238: #define EM_PRISM 82 /* SiTera Prism */ 239: #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ 240: #define EM_FR30 84 /* Fujitsu FR30 */ 241: #define EM_D10V 85 /* Mitsubishi D10V */ 242: #define EM_D30V 86 /* Mitsubishi D30V */ 243: #define EM_V850 87 /* NEC v850 */ 244: #define EM_M32R 88 /* Mitsubishi M32R */ 245: #define EM_MN10300 89 /* Matsushita MN10300 */ 246: #define EM_MN10200 90 /* Matsushita MN10200 */ 247: #define EM_PJ 91 /* picoJava */ 248: #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ 249: #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ 250: #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ 251: #define EM_NUM 95 252: 253: /* If it is necessary to assign new unofficial EM_* values, please 254: pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the 255: chances of collision with official or non-GNU unofficial values. */ 256: 257: #define EM_ALPHA 0x9026 258: 259: /* Legal values for e_version (version). */ 260: 261: #define EV_NONE 0 /* Invalid ELF version */ 262: #define EV_CURRENT 1 /* Current version */ 263: #define EV_NUM 2 264: 265: /* Section header. */ 266: 267: typedef struct 268: { 269: Elf32_Word sh_name; /* Section name (string tbl index) */ 270: Elf32_Word sh_type; /* Section type */ 271: Elf32_Word sh_flags; /* Section flags */ 272: Elf32_Addr sh_addr; /* Section virtual addr at execution */ 273: Elf32_Off sh_offset; /* Section file offset */ 274: Elf32_Word sh_size; /* Section size in bytes */ 275: Elf32_Word sh_link; /* Link to another section */ 276: Elf32_Word sh_info; /* Additional section information */ 277: Elf32_Word sh_addralign; /* Section alignment */ 278: Elf32_Word sh_entsize; /* Entry size if section holds table */ 279: } Elf32_Shdr; 280: 281: typedef struct 282: { 283: Elf64_Word sh_name; /* Section name (string tbl index) */ 284: Elf64_Word sh_type; /* Section type */ 285: Elf64_Xword sh_flags; /* Section flags */ 286: Elf64_Addr sh_addr; /* Section virtual addr at execution */ 287: Elf64_Off sh_offset; /* Section file offset */ 288: Elf64_Xword sh_size; /* Section size in bytes */ 289: Elf64_Word sh_link; /* Link to another section */ 290: Elf64_Word sh_info; /* Additional section information */ 291: Elf64_Xword sh_addralign; /* Section alignment */ 292: Elf64_Xword sh_entsize; /* Entry size if section holds table */ 293: } Elf64_Shdr; 294: 295: /* Special section indices. */ 296: 297: #define SHN_UNDEF 0 /* Undefined section */ 298: #define SHN_LORESERVE 0xff00 /* Start of reserved indices */ 299: #define SHN_LOPROC 0xff00 /* Start of processor-specific */ 300: #define SHN_BEFORE 0xff00 /* Order section before all others 301: (Solaris). */ 302: #define SHN_AFTER 0xff01 /* Order section after all others 303: (Solaris). */ 304: #define SHN_HIPROC 0xff1f /* End of processor-specific */ 305: #define SHN_LOOS 0xff20 /* Start of OS-specific */ 306: #define SHN_HIOS 0xff3f /* End of OS-specific */ 307: #define SHN_ABS 0xfff1 /* Associated symbol is absolute */ 308: #define SHN_COMMON 0xfff2 /* Associated symbol is common */ 309: #define SHN_XINDEX 0xffff /* Index is in extra table. */ 310: #define SHN_HIRESERVE 0xffff /* End of reserved indices */ 311: 312: /* Legal values for sh_type (section type). */ 313: 314: #define SHT_NULL 0 /* Section header table entry unused */ 315: #define SHT_PROGBITS 1 /* Program data */ 316: #define SHT_SYMTAB 2 /* Symbol table */ 317: #define SHT_STRTAB 3 /* String table */ 318: #define SHT_RELA 4 /* Relocation entries with addends */ 319: #define SHT_HASH 5 /* Symbol hash table */ 320: #define SHT_DYNAMIC 6 /* Dynamic linking information */ 321: #define SHT_NOTE 7 /* Notes */ 322: #define SHT_NOBITS 8 /* Program space with no data (bss) */ 323: #define SHT_REL 9 /* Relocation entries, no addends */ 324: #define SHT_SHLIB 10 /* Reserved */ 325: #define SHT_DYNSYM 11 /* Dynamic linker symbol table */ 326: #define SHT_INIT_ARRAY 14 /* Array of constructors */ 327: #define SHT_FINI_ARRAY 15 /* Array of destructors */ 328: #define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ 329: #define SHT_GROUP 17 /* Section group */ 330: #define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */ 331: #define SHT_NUM 19 /* Number of defined types. */ 332: #define SHT_LOOS 0x60000000 /* Start OS-specific. */ 333: #define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */ 334: #define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */ 335: #define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */ 336: #define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */ 337: #define SHT_SUNW_move 0x6ffffffa 338: #define SHT_SUNW_COMDAT 0x6ffffffb 339: #define SHT_SUNW_syminfo 0x6ffffffc 340: #define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */ 341: #define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */ 342: #define SHT_GNU_versym 0x6fffffff /* Version symbol table. */ 343: #define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */ 344: #define SHT_HIOS 0x6fffffff /* End OS-specific type */ 345: #define SHT_LOPROC 0x70000000 /* Start of processor-specific */ 346: #define SHT_HIPROC 0x7fffffff /* End of processor-specific */ 347: #define SHT_LOUSER 0x80000000 /* Start of application-specific */ 348: #define SHT_HIUSER 0x8fffffff /* End of application-specific */ 349: 350: /* Legal values for sh_flags (section flags). */ 351: 352: #define SHF_WRITE (1 << 0) /* Writable */ 353: #define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ 354: #define SHF_EXECINSTR (1 << 2) /* Executable */ 355: #define SHF_MERGE (1 << 4) /* Might be merged */ 356: #define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ 357: #define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ 358: #define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ 359: #define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling 360: required */ 361: #define SHF_GROUP (1 << 9) /* Section is member of a group. */ 362: #define SHF_TLS (1 << 10) /* Section hold thread-local data. */ 363: #define SHF_MASKOS 0x0ff00000 /* OS-specific. */ 364: #define SHF_MASKPROC 0xf0000000 /* Processor-specific */ 365: #define SHF_ORDERED (1 << 30) /* Special ordering requirement 366: (Solaris). */ 367: #define SHF_EXCLUDE (1 << 31) /* Section is excluded unless 368: referenced or allocated (Solaris).*/ 369: 370: /* Section group handling. */ 371: #define GRP_COMDAT 0x1 /* Mark group as COMDAT. */ 372: 373: /* Symbol table entry. */ 374: 375: typedef struct 376: { 377: Elf32_Word st_name; /* Symbol name (string tbl index) */ 378: Elf32_Addr st_value; /* Symbol value */ 379: Elf32_Word st_size; /* Symbol size */ 380: unsigned char st_info; /* Symbol type and binding */ 381: unsigned char st_other; /* Symbol visibility */ 382: Elf32_Section st_shndx; /* Section index */ 383: } Elf32_Sym; 384: 385: typedef struct 386: { 387: Elf64_Word st_name; /* Symbol name (string tbl index) */ 388: unsigned char st_info; /* Symbol type and binding */ 389: unsigned char st_other; /* Symbol visibility */ 390: Elf64_Section st_shndx; /* Section index */ 391: Elf64_Addr st_value; /* Symbol value */ 392: Elf64_Xword st_size; /* Symbol size */ 393: } Elf64_Sym; 394: 395: /* The syminfo section if available contains additional information about 396: every dynamic symbol. */ 397: 398: typedef struct 399: { 400: Elf32_Half si_boundto; /* Direct bindings, symbol bound to */ 401: Elf32_Half si_flags; /* Per symbol flags */ 402: } Elf32_Syminfo; 403: 404: typedef struct 405: { 406: Elf64_Half si_boundto; /* Direct bindings, symbol bound to */ 407: Elf64_Half si_flags; /* Per symbol flags */ 408: } Elf64_Syminfo; 409: 410: /* Possible values for si_boundto. */ 411: #define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */ 412: #define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */ 413: #define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */ 414: 415: /* Possible bitmasks for si_flags. */ 416: #define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */ 417: #define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */ 418: #define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */ 419: #define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy 420: loaded */ 421: /* Syminfo version values. */ 422: #define SYMINFO_NONE 0 423: #define SYMINFO_CURRENT 1 424: #define SYMINFO_NUM 2 425: 426: 427: /* How to extract and insert information held in the st_info field. */ 428: 429: #define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) 430: #define ELF32_ST_TYPE(val) ((val) & 0xf) 431: #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 432: 433: /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ 434: #define ELF64_ST_BIND(val) ELF32_ST_BIND (val) 435: #define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) 436: #define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) 437: 438: /* Legal values for ST_BIND subfield of st_info (symbol binding). */ 439: 440: #define STB_LOCAL 0 /* Local symbol */ 441: #define STB_GLOBAL 1 /* Global symbol */ 442: #define STB_WEAK 2 /* Weak symbol */ 443: #define STB_NUM 3 /* Number of defined types. */ 444: #define STB_LOOS 10 /* Start of OS-specific */ 445: #define STB_HIOS 12 /* End of OS-specific */ 446: #define STB_LOPROC 13 /* Start of processor-specific */ 447: #define STB_HIPROC 15 /* End of processor-specific */ 448: 449: /* Legal values for ST_TYPE subfield of st_info (symbol type). */ 450: 451: #define STT_NOTYPE 0 /* Symbol type is unspecified */ 452: #define STT_OBJECT 1 /* Symbol is a data object */ 453: #define STT_FUNC 2 /* Symbol is a code object */ 454: #define STT_SECTION 3 /* Symbol associated with a section */ 455: #define STT_FILE 4 /* Symbol's name is file name */ 456: #define STT_COMMON 5 /* Symbol is a common data object */ 457: #define STT_TLS 6