elfcpp_internal.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // elfcpp_internal.h -- internals for elfcpp -*- C++ -*-
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of elfcpp.
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Library General Public License
  7. // as published by the Free Software Foundation; either version 2, or
  8. // (at your option) any later version.
  9. // In addition to the permissions in the GNU Library General Public
  10. // License, the Free Software Foundation gives you unlimited
  11. // permission to link the compiled version of this file into
  12. // combinations with other programs, and to distribute those
  13. // combinations without any restriction coming from the use of this
  14. // file. (The Library Public License restrictions do apply in other
  15. // respects; for example, they cover modification of the file, and
  16. /// distribution when not linked into a combined executable.)
  17. // This program is distributed in the hope that it will be useful, but
  18. // WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. // Library General Public License for more details.
  21. // You should have received a copy of the GNU Library General Public
  22. // License along with this program; if not, write to the Free Software
  23. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  24. // 02110-1301, USA.
  25. // This is included by elfcpp.h, the external interface, but holds
  26. // information which we want to keep private.
  27. #ifndef ELFCPP_INTERNAL_H
  28. #define ELFCPP_INTERNAL_H
  29. namespace elfcpp
  30. {
  31. namespace internal
  32. {
  33. // The ELF file header.
  34. template<int size>
  35. struct Ehdr_data
  36. {
  37. unsigned char e_ident[EI_NIDENT];
  38. Elf_Half e_type;
  39. Elf_Half e_machine;
  40. Elf_Word e_version;
  41. typename Elf_types<size>::Elf_Addr e_entry;
  42. typename Elf_types<size>::Elf_Off e_phoff;
  43. typename Elf_types<size>::Elf_Off e_shoff;
  44. Elf_Word e_flags;
  45. Elf_Half e_ehsize;
  46. Elf_Half e_phentsize;
  47. Elf_Half e_phnum;
  48. Elf_Half e_shentsize;
  49. Elf_Half e_shnum;
  50. Elf_Half e_shstrndx;
  51. };
  52. // An ELF section header.
  53. template<int size>
  54. struct Shdr_data
  55. {
  56. Elf_Word sh_name;
  57. Elf_Word sh_type;
  58. typename Elf_types<size>::Elf_WXword sh_flags;
  59. typename Elf_types<size>::Elf_Addr sh_addr;
  60. typename Elf_types<size>::Elf_Off sh_offset;
  61. typename Elf_types<size>::Elf_WXword sh_size;
  62. Elf_Word sh_link;
  63. Elf_Word sh_info;
  64. typename Elf_types<size>::Elf_WXword sh_addralign;
  65. typename Elf_types<size>::Elf_WXword sh_entsize;
  66. };
  67. // An ELF compression header.
  68. template<int size>
  69. struct Chdr_data;
  70. template<>
  71. struct Chdr_data<32>
  72. {
  73. Elf_Word ch_type;
  74. Elf_Word ch_size;
  75. Elf_Word ch_addralign;
  76. };
  77. template<>
  78. struct Chdr_data<64>
  79. {
  80. Elf_Word ch_type;
  81. Elf_Word ch_reserved;
  82. Elf_Xword ch_size;
  83. Elf_Xword ch_addralign;
  84. };
  85. // An ELF segment header. We use template specialization for the
  86. // 32-bit and 64-bit versions because the fields are in a different
  87. // order.
  88. template<int size>
  89. struct Phdr_data;
  90. template<>
  91. struct Phdr_data<32>
  92. {
  93. Elf_Word p_type;
  94. Elf_types<32>::Elf_Off p_offset;
  95. Elf_types<32>::Elf_Addr p_vaddr;
  96. Elf_types<32>::Elf_Addr p_paddr;
  97. Elf_Word p_filesz;
  98. Elf_Word p_memsz;
  99. Elf_Word p_flags;
  100. Elf_Word p_align;
  101. };
  102. template<>
  103. struct Phdr_data<64>
  104. {
  105. Elf_Word p_type;
  106. Elf_Word p_flags;
  107. Elf_types<64>::Elf_Off p_offset;
  108. Elf_types<64>::Elf_Addr p_vaddr;
  109. Elf_types<64>::Elf_Addr p_paddr;
  110. Elf_Xword p_filesz;
  111. Elf_Xword p_memsz;
  112. Elf_Xword p_align;
  113. };
  114. // An ELF symbol table entry. We use template specialization for the
  115. // 32-bit and 64-bit versions because the fields are in a different
  116. // order.
  117. template<int size>
  118. struct Sym_data;
  119. template<>
  120. struct Sym_data<32>
  121. {
  122. Elf_Word st_name;
  123. Elf_types<32>::Elf_Addr st_value;
  124. Elf_Word st_size;
  125. unsigned char st_info;
  126. unsigned char st_other;
  127. Elf_Half st_shndx;
  128. };
  129. template<>
  130. struct Sym_data<64>
  131. {
  132. Elf_Word st_name;
  133. unsigned char st_info;
  134. unsigned char st_other;
  135. Elf_Half st_shndx;
  136. Elf_types<64>::Elf_Addr st_value;
  137. Elf_Xword st_size;
  138. };
  139. // ELF relocation table entries.
  140. template<int size>
  141. struct Rel_data
  142. {
  143. typename Elf_types<size>::Elf_Addr r_offset;
  144. typename Elf_types<size>::Elf_WXword r_info;
  145. };
  146. template<int size>
  147. struct Rela_data
  148. {
  149. typename Elf_types<size>::Elf_Addr r_offset;
  150. typename Elf_types<size>::Elf_WXword r_info;
  151. typename Elf_types<size>::Elf_Swxword r_addend;
  152. };
  153. // An entry in the ELF SHT_DYNAMIC section aka PT_DYNAMIC segment.
  154. template<int size>
  155. struct Dyn_data
  156. {
  157. typename Elf_types<size>::Elf_Swxword d_tag;
  158. typename Elf_types<size>::Elf_WXword d_val;
  159. };
  160. // An entry in a SHT_GNU_verdef section. This structure is the same
  161. // in 32-bit and 64-bit ELF files.
  162. struct Verdef_data
  163. {
  164. // Version number of structure (VER_DEF_*).
  165. Elf_Half vd_version;
  166. // Bit flags (VER_FLG_*).
  167. Elf_Half vd_flags;
  168. // Version index.
  169. Elf_Half vd_ndx;
  170. // Number of auxiliary Verdaux entries.
  171. Elf_Half vd_cnt;
  172. // Hash of name.
  173. Elf_Word vd_hash;
  174. // Byte offset to first Verdaux entry.
  175. Elf_Word vd_aux;
  176. // Byte offset to next Verdef entry.
  177. Elf_Word vd_next;
  178. };
  179. // An auxiliary entry in a SHT_GNU_verdef section. This structure is
  180. // the same in 32-bit and 64-bit ELF files.
  181. struct Verdaux_data
  182. {
  183. // Offset in string table of version name.
  184. Elf_Word vda_name;
  185. // Byte offset to next Verdaux entry.
  186. Elf_Word vda_next;
  187. };
  188. // An entry in a SHT_GNU_verneed section. This structure is the same
  189. // in 32-bit and 64-bit ELF files.
  190. struct Verneed_data
  191. {
  192. // Version number of structure (VER_NEED_*).
  193. Elf_Half vn_version;
  194. // Number of auxiliary Vernaux entries.
  195. Elf_Half vn_cnt;
  196. // Offset in string table of library name.
  197. Elf_Word vn_file;
  198. // Byte offset to first Vernaux entry.
  199. Elf_Word vn_aux;
  200. // Byt eoffset to next Verneed entry.
  201. Elf_Word vn_next;
  202. };
  203. // An auxiliary entry in a SHT_GNU_verneed section. This structure is
  204. // the same in 32-bit and 64-bit ELF files.
  205. struct Vernaux_data
  206. {
  207. // Hash of dependency name.
  208. Elf_Word vna_hash;
  209. // Bit flags (VER_FLG_*).
  210. Elf_Half vna_flags;
  211. // Version index used in SHT_GNU_versym entries.
  212. Elf_Half vna_other;
  213. // Offset in string table of version name.
  214. Elf_Word vna_name;
  215. // Byte offset to next Vernaux entry.
  216. Elf_Word vna_next;
  217. };
  218. } // End namespace internal.
  219. } // End namespace elfcpp.
  220. #endif // !defined(ELFCPP_INTERNAL_H)