types_elf.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifndef COURGETTE_TYPES_ELF_H_
  5. #define COURGETTE_TYPES_ELF_H_
  6. #include <stdint.h>
  7. //
  8. // This header defines various types from the ELF file spec, but no code
  9. // related to using them.
  10. //
  11. typedef uint32_t Elf32_Addr; // Unsigned program address
  12. typedef uint16_t Elf32_Half; // Unsigned medium integer
  13. typedef uint32_t Elf32_Off; // Unsigned file offset
  14. typedef int32_t Elf32_Sword; // Signed large integer
  15. typedef uint32_t Elf32_Word; // Unsigned large integer
  16. // The header at the top of the file
  17. struct Elf32_Ehdr {
  18. unsigned char e_ident[16];
  19. Elf32_Half e_type;
  20. Elf32_Half e_machine;
  21. Elf32_Word e_version;
  22. Elf32_Addr e_entry;
  23. Elf32_Off e_phoff;
  24. Elf32_Off e_shoff;
  25. Elf32_Word e_flags;
  26. Elf32_Half e_ehsize;
  27. Elf32_Half e_phentsize;
  28. Elf32_Half e_phnum;
  29. Elf32_Half e_shentsize;
  30. Elf32_Half e_shnum;
  31. Elf32_Half e_shstrndx;
  32. };
  33. // Indexes for header->e_ident[].
  34. enum e_ident_indexes {
  35. EI_MAG0 = 0, // File identification.
  36. EI_MAG1 = 1, // File identification.
  37. EI_MAG2 = 2, // File identification.
  38. EI_MAG3 = 3, // File identification.
  39. EI_CLASS = 4, // File class.
  40. EI_DATA = 5, // Data encoding.
  41. EI_VERSION = 6, // File version.
  42. EI_OSABI = 7, // Operating system/ABI identification.
  43. EI_ABIVERSION = 8, // ABI version.
  44. EI_PAD = 9, // Start of padding bytes.
  45. EI_NIDENT = 16 // Size of e_ident[].
  46. };
  47. // Values for header->e_ident[EI_CLASS].
  48. enum e_ident_class_values {
  49. ELFCLASSNONE = 0, // Invalid class.
  50. ELFCLASS32 = 1, // 32-bit objects.
  51. ELFCLASS64 = 2 // 64-bit objects.
  52. };
  53. // Values for header->e_ident[EI_DATA].
  54. enum e_ident_data_values {
  55. ELFDATANONE = 0, // Unknown data format.
  56. ELFDATA2LSB = 1, // Two's complement, little-endian.
  57. ELFDATA2MSB = 2, // Two's complement, big-endian.
  58. };
  59. // values for header->e_type
  60. enum e_type_values {
  61. ET_NONE = 0, // No file type
  62. ET_REL = 1, // Relocatable file
  63. ET_EXEC = 2, // Executable file
  64. ET_DYN = 3, // Shared object file
  65. ET_CORE = 4, // Core file
  66. ET_LOPROC = 0xff00, // Processor-specific
  67. ET_HIPROC = 0xfff // Processor-specific
  68. };
  69. // values for header->e_machine
  70. enum e_machine_values {
  71. EM_NONE = 0, // No machine
  72. EM_386 = 3, // Intel Architecture
  73. EM_ARM = 40, // ARM Architecture
  74. EM_x86_64 = 62, // Intel x86-64 Architecture
  75. // Other values skipped
  76. };
  77. enum { SHN_UNDEF = 0 };
  78. // A section header in the section header table
  79. struct Elf32_Shdr {
  80. Elf32_Word sh_name;
  81. Elf32_Word sh_type;
  82. Elf32_Word sh_flags;
  83. Elf32_Addr sh_addr;
  84. Elf32_Off sh_offset;
  85. Elf32_Word sh_size;
  86. Elf32_Word sh_link;
  87. Elf32_Word sh_info;
  88. Elf32_Word sh_addralign;
  89. Elf32_Word sh_entsize;
  90. };
  91. // Values for the section type field in a section header
  92. enum sh_type_values {
  93. SHT_NULL = 0,
  94. SHT_PROGBITS = 1,
  95. SHT_SYMTAB = 2,
  96. SHT_STRTAB = 3,
  97. SHT_RELA = 4,
  98. SHT_HASH = 5,
  99. SHT_DYNAMIC = 6,
  100. SHT_NOTE = 7,
  101. SHT_NOBITS = 8,
  102. SHT_REL = 9,
  103. SHT_SHLIB = 10,
  104. SHT_DYNSYM = 11,
  105. SHT_INIT_ARRAY = 14,
  106. SHT_FINI_ARRAY = 15,
  107. SHT_LOPROC = 0x70000000,
  108. SHT_HIPROC = 0x7fffffff,
  109. SHT_LOUSER = 0x80000000,
  110. SHT_HIUSER = 0xffffffff,
  111. };
  112. struct Elf32_Phdr {
  113. Elf32_Word p_type;
  114. Elf32_Off p_offset;
  115. Elf32_Addr p_vaddr;
  116. Elf32_Addr p_paddr;
  117. Elf32_Word p_filesz;
  118. Elf32_Word p_memsz;
  119. Elf32_Word p_flags;
  120. Elf32_Word p_align;
  121. };
  122. // Values for the segment type field in a program segment header
  123. enum ph_type_values {
  124. PT_NULL = 0,
  125. PT_LOAD = 1,
  126. PT_DYNAMIC = 2,
  127. PT_INTERP = 3,
  128. PT_NOTE = 4,
  129. PT_SHLIB = 5,
  130. PT_PHDR = 6,
  131. PT_LOPROC = 0x70000000,
  132. PT_HIPROC = 0x7fffffff
  133. };
  134. struct Elf32_Rel {
  135. Elf32_Addr r_offset;
  136. Elf32_Word r_info;
  137. };
  138. struct Elf32_Rela {
  139. Elf32_Addr r_offset;
  140. Elf32_Word r_info;
  141. Elf32_Sword r_addend;
  142. };
  143. enum elf32_rel_386_type_values {
  144. R_386_NONE = 0,
  145. R_386_32 = 1,
  146. R_386_PC32 = 2,
  147. R_386_GOT32 = 3,
  148. R_386_PLT32 = 4,
  149. R_386_COPY = 5,
  150. R_386_GLOB_DAT = 6,
  151. R_386_JMP_SLOT = 7,
  152. R_386_RELATIVE = 8,
  153. R_386_GOTOFF = 9,
  154. R_386_GOTPC = 10,
  155. R_386_TLS_TPOFF = 14,
  156. };
  157. #endif // COURGETTE_TYPES_ELF_H_