types_elf.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef COURGETTE_ELF_TYPES_H_ 6#define COURGETTE_ELF_TYPES_H_ 7 8// 9// This header defines various types from the ELF file spec, but no code 10// related to using them. 11// 12 13typedef uint32 Elf32_Addr; // Unsigned program address 14typedef uint16 Elf32_Half; // Unsigned medium integer 15typedef uint32 Elf32_Off; // Unsigned file offset 16typedef int32 Elf32_Sword; // Signed large integer 17typedef uint32 Elf32_Word; // Unsigned large integer 18 19 20// The header at the top of the file 21struct Elf32_Ehdr { 22 unsigned char e_ident[16]; 23 Elf32_Half e_type; 24 Elf32_Half e_machine; 25 Elf32_Word e_version; 26 Elf32_Addr e_entry; 27 Elf32_Off e_phoff; 28 Elf32_Off e_shoff; 29 Elf32_Word e_flags; 30 Elf32_Half e_ehsize; 31 Elf32_Half e_phentsize; 32 Elf32_Half e_phnum; 33 Elf32_Half e_shentsize; 34 Elf32_Half e_shnum; 35 Elf32_Half e_shstrndx; 36}; 37 38// values for header->e_type 39enum e_type_values { 40 ET_NONE = 0, // No file type 41 ET_REL = 1, // Relocatable file 42 ET_EXEC = 2, // Executable file 43 ET_DYN = 3, // Shared object file 44 ET_CORE = 4, // Core file 45 ET_LOPROC = 0xff00, // Processor-specific 46 ET_HIPROC = 0xfff // Processor-specific 47}; 48 49// values for header->e_machine 50enum e_machine_values { 51 EM_NONE = 0, // No machine 52 EM_386 = 3, // Intel Architecture 53 EM_x86_64 = 62, // Intel x86-64 Architecture 54 // Other values skipped 55}; 56 57// A section header in the section header table 58struct Elf32_Shdr { 59 Elf32_Word sh_name; 60 Elf32_Word sh_type; 61 Elf32_Word sh_flags; 62 Elf32_Addr sh_addr; 63 Elf32_Off sh_offset; 64 Elf32_Word sh_size; 65 Elf32_Word sh_link; 66 Elf32_Word sh_info; 67 Elf32_Word sh_addralign; 68 Elf32_Word sh_entsize; 69}; 70 71// Values for the section type field in a section header 72enum sh_type_values { 73 SHT_NULL = 0, 74 SHT_PROGBITS = 1, 75 SHT_SYMTAB = 2, 76 SHT_STRTAB = 3, 77 SHT_RELA = 4, 78 SHT_HASH = 5, 79 SHT_DYNAMIC = 6, 80 SHT_NOTE = 7, 81 SHT_NOBITS = 8, 82 SHT_REL = 9, 83 SHT_SHLIB = 10, 84 SHT_DYNSYM = 11, 85 SHT_LOPROC = 0x70000000, 86 SHT_HIPROC = 0x7fffffff, 87 SHT_LOUSER = 0x80000000, 88 SHT_HIUSER = 0xffffffff, 89}; 90 91struct Elf32_Phdr { 92 Elf32_Word p_type; 93 Elf32_Off p_offset; 94 Elf32_Addr p_vaddr; 95 Elf32_Addr p_paddr; 96 Elf32_Word p_filesz; 97 Elf32_Word p_memsz; 98 Elf32_Word p_flags; 99 Elf32_Word p_align; 100}; 101 102// Values for the segment type field in a program segment header 103enum ph_type_values { 104 PT_NULL = 0, 105 PT_LOAD = 1, 106 PT_DYNAMIC = 2, 107 PT_INTERP = 3, 108 PT_NOTE = 4, 109 PT_SHLIB = 5, 110 PT_PHDR = 6, 111 PT_LOPROC = 0x70000000, 112 PT_HIPROC = 0x7fffffff 113}; 114 115struct Elf32_Rel { 116 Elf32_Addr r_offset; 117 Elf32_Word r_info; 118}; 119 120struct Elf32_Rela { 121 Elf32_Addr r_offset; 122 Elf32_Word r_info; 123 Elf32_Sword r_addend; 124}; 125 126enum elf32_rel_386_type_values { 127 R_386_NONE = 0, 128 R_386_32 = 1, 129 R_386_PC32 = 2, 130 R_386_GOT32 = 3, 131 R_386_PLT32 = 4, 132 R_386_COPY = 5, 133 R_386_GLOB_DAT = 6, 134 R_386_JMP_SLOT = 7, 135 R_386_RELATIVE = 8, 136 R_386_GOTOFF = 9, 137 R_386_GOTPC = 10, 138 R_386_TLS_TPOFF = 14, 139}; 140 141#endif // COURGETTE_ELF_TYPES_H_ 142