elfcpp.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008
  1. // elfcpp.h -- main header file 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 the external interface for elfcpp.
  26. #ifndef ELFCPP_H
  27. #define ELFCPP_H
  28. #include "elfcpp_swap.h"
  29. #include <stdint.h>
  30. namespace elfcpp
  31. {
  32. // Basic ELF types.
  33. // These types are always the same size.
  34. typedef uint16_t Elf_Half;
  35. typedef uint32_t Elf_Word;
  36. typedef int32_t Elf_Sword;
  37. typedef uint64_t Elf_Xword;
  38. typedef int64_t Elf_Sxword;
  39. // These types vary in size depending on the ELF file class. The
  40. // template parameter should be 32 or 64.
  41. template<int size>
  42. struct Elf_types;
  43. template<>
  44. struct Elf_types<32>
  45. {
  46. typedef uint32_t Elf_Addr;
  47. typedef uint32_t Elf_Off;
  48. typedef uint32_t Elf_WXword;
  49. typedef int32_t Elf_Swxword;
  50. };
  51. template<>
  52. struct Elf_types<64>
  53. {
  54. typedef uint64_t Elf_Addr;
  55. typedef uint64_t Elf_Off;
  56. typedef uint64_t Elf_WXword;
  57. typedef int64_t Elf_Swxword;
  58. };
  59. // Offsets within the Ehdr e_ident field.
  60. const int EI_MAG0 = 0;
  61. const int EI_MAG1 = 1;
  62. const int EI_MAG2 = 2;
  63. const int EI_MAG3 = 3;
  64. const int EI_CLASS = 4;
  65. const int EI_DATA = 5;
  66. const int EI_VERSION = 6;
  67. const int EI_OSABI = 7;
  68. const int EI_ABIVERSION = 8;
  69. const int EI_PAD = 9;
  70. const int EI_NIDENT = 16;
  71. // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
  72. const int ELFMAG0 = 0x7f;
  73. const int ELFMAG1 = 'E';
  74. const int ELFMAG2 = 'L';
  75. const int ELFMAG3 = 'F';
  76. // The valid values found in Ehdr e_ident[EI_CLASS].
  77. enum
  78. {
  79. ELFCLASSNONE = 0,
  80. ELFCLASS32 = 1,
  81. ELFCLASS64 = 2
  82. };
  83. // The valid values found in Ehdr e_ident[EI_DATA].
  84. enum
  85. {
  86. ELFDATANONE = 0,
  87. ELFDATA2LSB = 1,
  88. ELFDATA2MSB = 2
  89. };
  90. // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
  91. enum
  92. {
  93. EV_NONE = 0,
  94. EV_CURRENT = 1
  95. };
  96. // The valid values found in Ehdr e_ident[EI_OSABI].
  97. enum ELFOSABI
  98. {
  99. ELFOSABI_NONE = 0,
  100. ELFOSABI_HPUX = 1,
  101. ELFOSABI_NETBSD = 2,
  102. ELFOSABI_GNU = 3,
  103. // ELFOSABI_LINUX is an alias for ELFOSABI_GNU.
  104. ELFOSABI_LINUX = 3,
  105. ELFOSABI_SOLARIS = 6,
  106. ELFOSABI_AIX = 7,
  107. ELFOSABI_IRIX = 8,
  108. ELFOSABI_FREEBSD = 9,
  109. ELFOSABI_TRU64 = 10,
  110. ELFOSABI_MODESTO = 11,
  111. ELFOSABI_OPENBSD = 12,
  112. ELFOSABI_OPENVMS = 13,
  113. ELFOSABI_NSK = 14,
  114. ELFOSABI_AROS = 15,
  115. // A GNU extension for the ARM.
  116. ELFOSABI_ARM = 97,
  117. // A GNU extension for the MSP.
  118. ELFOSABI_STANDALONE = 255
  119. };
  120. // The valid values found in the Ehdr e_type field.
  121. enum ET
  122. {
  123. ET_NONE = 0,
  124. ET_REL = 1,
  125. ET_EXEC = 2,
  126. ET_DYN = 3,
  127. ET_CORE = 4,
  128. ET_LOOS = 0xfe00,
  129. ET_HIOS = 0xfeff,
  130. ET_LOPROC = 0xff00,
  131. ET_HIPROC = 0xffff
  132. };
  133. // The valid values found in the Ehdr e_machine field.
  134. enum EM
  135. {
  136. EM_NONE = 0,
  137. EM_M32 = 1,
  138. EM_SPARC = 2,
  139. EM_386 = 3,
  140. EM_68K = 4,
  141. EM_88K = 5,
  142. EM_IAMCU = 6,
  143. EM_860 = 7,
  144. EM_MIPS = 8,
  145. EM_S370 = 9,
  146. EM_MIPS_RS3_LE = 10,
  147. // 11 was the old Sparc V9 ABI.
  148. // 12 through 14 are reserved.
  149. EM_PARISC = 15,
  150. // 16 is reserved.
  151. // Some old PowerPC object files use 17.
  152. EM_VPP500 = 17,
  153. EM_SPARC32PLUS = 18,
  154. EM_960 = 19,
  155. EM_PPC = 20,
  156. EM_PPC64 = 21,
  157. EM_S390 = 22,
  158. // 23 through 35 are served.
  159. EM_V800 = 36,
  160. EM_FR20 = 37,
  161. EM_RH32 = 38,
  162. EM_RCE = 39,
  163. EM_ARM = 40,
  164. EM_ALPHA = 41,
  165. EM_SH = 42,
  166. EM_SPARCV9 = 43,
  167. EM_TRICORE = 44,
  168. EM_ARC = 45,
  169. EM_H8_300 = 46,
  170. EM_H8_300H = 47,
  171. EM_H8S = 48,
  172. EM_H8_500 = 49,
  173. EM_IA_64 = 50,
  174. EM_MIPS_X = 51,
  175. EM_COLDFIRE = 52,
  176. EM_68HC12 = 53,
  177. EM_MMA = 54,
  178. EM_PCP = 55,
  179. EM_NCPU = 56,
  180. EM_NDR1 = 57,
  181. EM_STARCORE = 58,
  182. EM_ME16 = 59,
  183. EM_ST100 = 60,
  184. EM_TINYJ = 61,
  185. EM_X86_64 = 62,
  186. EM_PDSP = 63,
  187. EM_PDP10 = 64,
  188. EM_PDP11 = 65,
  189. EM_FX66 = 66,
  190. EM_ST9PLUS = 67,
  191. EM_ST7 = 68,
  192. EM_68HC16 = 69,
  193. EM_68HC11 = 70,
  194. EM_68HC08 = 71,
  195. EM_68HC05 = 72,
  196. EM_SVX = 73,
  197. EM_ST19 = 74,
  198. EM_VAX = 75,
  199. EM_CRIS = 76,
  200. EM_JAVELIN = 77,
  201. EM_FIREPATH = 78,
  202. EM_ZSP = 79,
  203. EM_MMIX = 80,
  204. EM_HUANY = 81,
  205. EM_PRISM = 82,
  206. EM_AVR = 83,
  207. EM_FR30 = 84,
  208. EM_D10V = 85,
  209. EM_D30V = 86,
  210. EM_V850 = 87,
  211. EM_M32R = 88,
  212. EM_MN10300 = 89,
  213. EM_MN10200 = 90,
  214. EM_PJ = 91,
  215. EM_OR1K = 92,
  216. EM_ARC_A5 = 93,
  217. EM_XTENSA = 94,
  218. EM_VIDEOCORE = 95,
  219. EM_TMM_GPP = 96,
  220. EM_NS32K = 97,
  221. EM_TPC = 98,
  222. // Some old picoJava object files use 99 (EM_PJ is correct).
  223. EM_SNP1K = 99,
  224. EM_ST200 = 100,
  225. EM_IP2K = 101,
  226. EM_MAX = 102,
  227. EM_CR = 103,
  228. EM_F2MC16 = 104,
  229. EM_MSP430 = 105,
  230. EM_BLACKFIN = 106,
  231. EM_SE_C33 = 107,
  232. EM_SEP = 108,
  233. EM_ARCA = 109,
  234. EM_UNICORE = 110,
  235. EM_ALTERA_NIOS2 = 113,
  236. EM_CRX = 114,
  237. EM_AARCH64 = 183,
  238. EM_TILEGX = 191,
  239. // The Morph MT.
  240. EM_MT = 0x2530,
  241. // DLX.
  242. EM_DLX = 0x5aa5,
  243. // FRV.
  244. EM_FRV = 0x5441,
  245. // Infineon Technologies 16-bit microcontroller with C166-V2 core.
  246. EM_X16X = 0x4688,
  247. // Xstorym16
  248. EM_XSTORMY16 = 0xad45,
  249. // Renesas M32C
  250. EM_M32C = 0xfeb0,
  251. // Vitesse IQ2000
  252. EM_IQ2000 = 0xfeba,
  253. // NIOS
  254. EM_NIOS32 = 0xfebb
  255. // Old AVR objects used 0x1057 (EM_AVR is correct).
  256. // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
  257. // Old FR30 objects used 0x3330 (EM_FR30 is correct).
  258. // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OR1K is correct).
  259. // Old D10V objects used 0x7650 (EM_D10V is correct).
  260. // Old D30V objects used 0x7676 (EM_D30V is correct).
  261. // Old IP2X objects used 0x8217 (EM_IP2K is correct).
  262. // Old PowerPC objects used 0x9025 (EM_PPC is correct).
  263. // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
  264. // Old M32R objects used 0x9041 (EM_M32R is correct).
  265. // Old V850 objects used 0x9080 (EM_V850 is correct).
  266. // Old S/390 objects used 0xa390 (EM_S390 is correct).
  267. // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
  268. // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
  269. // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
  270. };
  271. // A special value found in the Ehdr e_phnum field.
  272. enum
  273. {
  274. // Number of program segments stored in sh_info field of first
  275. // section headre.
  276. PN_XNUM = 0xffff
  277. };
  278. // Special section indices.
  279. enum
  280. {
  281. SHN_UNDEF = 0,
  282. SHN_LORESERVE = 0xff00,
  283. SHN_LOPROC = 0xff00,
  284. SHN_HIPROC = 0xff1f,
  285. SHN_LOOS = 0xff20,
  286. SHN_HIOS = 0xff3f,
  287. SHN_ABS = 0xfff1,
  288. SHN_COMMON = 0xfff2,
  289. SHN_XINDEX = 0xffff,
  290. SHN_HIRESERVE = 0xffff,
  291. // Provide for initial and final section ordering in conjunction
  292. // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
  293. SHN_BEFORE = 0xff00,
  294. SHN_AFTER = 0xff01,
  295. // x86_64 specific large common symbol.
  296. SHN_X86_64_LCOMMON = 0xff02
  297. };
  298. // The valid values found in the Shdr sh_type field.
  299. enum SHT
  300. {
  301. SHT_NULL = 0,
  302. SHT_PROGBITS = 1,
  303. SHT_SYMTAB = 2,
  304. SHT_STRTAB = 3,
  305. SHT_RELA = 4,
  306. SHT_HASH = 5,
  307. SHT_DYNAMIC = 6,
  308. SHT_NOTE = 7,
  309. SHT_NOBITS = 8,
  310. SHT_REL = 9,
  311. SHT_SHLIB = 10,
  312. SHT_DYNSYM = 11,
  313. SHT_INIT_ARRAY = 14,
  314. SHT_FINI_ARRAY = 15,
  315. SHT_PREINIT_ARRAY = 16,
  316. SHT_GROUP = 17,
  317. SHT_SYMTAB_SHNDX = 18,
  318. SHT_LOOS = 0x60000000,
  319. SHT_HIOS = 0x6fffffff,
  320. SHT_LOPROC = 0x70000000,
  321. SHT_HIPROC = 0x7fffffff,
  322. SHT_LOUSER = 0x80000000,
  323. SHT_HIUSER = 0xffffffff,
  324. // The remaining values are not in the standard.
  325. // Incremental build data.
  326. SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700,
  327. SHT_GNU_INCREMENTAL_SYMTAB = 0x6fff4701,
  328. SHT_GNU_INCREMENTAL_RELOCS = 0x6fff4702,
  329. SHT_GNU_INCREMENTAL_GOT_PLT = 0x6fff4703,
  330. // Object attributes.
  331. SHT_GNU_ATTRIBUTES = 0x6ffffff5,
  332. // GNU style dynamic hash table.
  333. SHT_GNU_HASH = 0x6ffffff6,
  334. // List of prelink dependencies.
  335. SHT_GNU_LIBLIST = 0x6ffffff7,
  336. // Versions defined by file.
  337. SHT_SUNW_verdef = 0x6ffffffd,
  338. SHT_GNU_verdef = 0x6ffffffd,
  339. // Versions needed by file.
  340. SHT_SUNW_verneed = 0x6ffffffe,
  341. SHT_GNU_verneed = 0x6ffffffe,
  342. // Symbol versions,
  343. SHT_SUNW_versym = 0x6fffffff,
  344. SHT_GNU_versym = 0x6fffffff,
  345. SHT_SPARC_GOTDATA = 0x70000000,
  346. // ARM-specific section types.
  347. // Exception Index table.
  348. SHT_ARM_EXIDX = 0x70000001,
  349. // BPABI DLL dynamic linking pre-emption map.
  350. SHT_ARM_PREEMPTMAP = 0x70000002,
  351. // Object file compatibility attributes.
  352. SHT_ARM_ATTRIBUTES = 0x70000003,
  353. // Support for debugging overlaid programs.
  354. SHT_ARM_DEBUGOVERLAY = 0x70000004,
  355. SHT_ARM_OVERLAYSECTION = 0x70000005,
  356. // x86_64 unwind information.
  357. SHT_X86_64_UNWIND = 0x70000001,
  358. // MIPS-specific section types.
  359. // Section contains register usage information.
  360. SHT_MIPS_REGINFO = 0x70000006,
  361. // Section contains miscellaneous options.
  362. SHT_MIPS_OPTIONS = 0x7000000d,
  363. // AARCH64-specific section type.
  364. SHT_AARCH64_ATTRIBUTES = 0x70000003,
  365. // Link editor is to sort the entries in this section based on the
  366. // address specified in the associated symbol table entry.
  367. SHT_ORDERED = 0x7fffffff
  368. };
  369. // The valid bit flags found in the Shdr sh_flags field.
  370. enum SHF
  371. {
  372. SHF_WRITE = 0x1,
  373. SHF_ALLOC = 0x2,
  374. SHF_EXECINSTR = 0x4,
  375. SHF_MERGE = 0x10,
  376. SHF_STRINGS = 0x20,
  377. SHF_INFO_LINK = 0x40,
  378. SHF_LINK_ORDER = 0x80,
  379. SHF_OS_NONCONFORMING = 0x100,
  380. SHF_GROUP = 0x200,
  381. SHF_TLS = 0x400,
  382. SHF_COMPRESSED = 0x800,
  383. SHF_MASKOS = 0x0ff00000,
  384. SHF_MASKPROC = 0xf0000000,
  385. // Indicates this section requires ordering in relation to
  386. // other sections of the same type. Ordered sections are
  387. // combined within the section pointed to by the sh_link entry.
  388. // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
  389. // sorted section is to precede or follow, respectively, all
  390. // other sections in the set being ordered.
  391. SHF_ORDERED = 0x40000000,
  392. // This section is excluded from input to the link-edit of an
  393. // executable or shared object. This flag is ignored if SHF_ALLOC
  394. // is also set, or if relocations exist against the section.
  395. SHF_EXCLUDE = 0x80000000,
  396. // Section with data that is GP relative addressable.
  397. SHF_MIPS_GPREL = 0x10000000,
  398. // x86_64 specific large section.
  399. SHF_X86_64_LARGE = 0x10000000
  400. };
  401. // Values which appear in the first Elf_WXword of the section data
  402. // of a SHF_COMPRESSED section.
  403. enum
  404. {
  405. ELFCOMPRESS_ZLIB = 1,
  406. ELFCOMPRESS_LOOS = 0x60000000,
  407. ELFCOMPRESS_HIOS = 0x6fffffff,
  408. ELFCOMPRESS_LOPROC = 0x70000000,
  409. ELFCOMPRESS_HIPROC = 0x7fffffff,
  410. };
  411. // Bit flags which appear in the first 32-bit word of the section data
  412. // of a SHT_GROUP section.
  413. enum
  414. {
  415. GRP_COMDAT = 0x1,
  416. GRP_MASKOS = 0x0ff00000,
  417. GRP_MASKPROC = 0xf0000000
  418. };
  419. // The valid values found in the Phdr p_type field.
  420. enum PT
  421. {
  422. PT_NULL = 0,
  423. PT_LOAD = 1,
  424. PT_DYNAMIC = 2,
  425. PT_INTERP = 3,
  426. PT_NOTE = 4,
  427. PT_SHLIB = 5,
  428. PT_PHDR = 6,
  429. PT_TLS = 7,
  430. PT_LOOS = 0x60000000,
  431. PT_HIOS = 0x6fffffff,
  432. PT_LOPROC = 0x70000000,
  433. PT_HIPROC = 0x7fffffff,
  434. // The remaining values are not in the standard.
  435. // Frame unwind information.
  436. PT_GNU_EH_FRAME = 0x6474e550,
  437. PT_SUNW_EH_FRAME = 0x6474e550,
  438. // Stack flags.
  439. PT_GNU_STACK = 0x6474e551,
  440. // Read only after relocation.
  441. PT_GNU_RELRO = 0x6474e552,
  442. // Platform architecture compatibility information
  443. PT_ARM_ARCHEXT = 0x70000000,
  444. // Exception unwind tables
  445. PT_ARM_EXIDX = 0x70000001,
  446. // Register usage information. Identifies one .reginfo section.
  447. PT_MIPS_REGINFO =0x70000000,
  448. // Runtime procedure table.
  449. PT_MIPS_RTPROC = 0x70000001,
  450. // .MIPS.options section.
  451. PT_MIPS_OPTIONS = 0x70000002,
  452. // .MIPS.abiflags section.
  453. PT_MIPS_ABIFLAGS = 0x70000003,
  454. // Platform architecture compatibility information
  455. PT_AARCH64_ARCHEXT = 0x70000000,
  456. // Exception unwind tables
  457. PT_AARCH64_UNWIND = 0x70000001
  458. };
  459. // The valid bit flags found in the Phdr p_flags field.
  460. enum PF
  461. {
  462. PF_X = 0x1,
  463. PF_W = 0x2,
  464. PF_R = 0x4,
  465. PF_MASKOS = 0x0ff00000,
  466. PF_MASKPROC = 0xf0000000
  467. };
  468. // Symbol binding from Sym st_info field.
  469. enum STB
  470. {
  471. STB_LOCAL = 0,
  472. STB_GLOBAL = 1,
  473. STB_WEAK = 2,
  474. STB_LOOS = 10,
  475. STB_GNU_UNIQUE = 10,
  476. STB_HIOS = 12,
  477. STB_LOPROC = 13,
  478. STB_HIPROC = 15
  479. };
  480. // Symbol types from Sym st_info field.
  481. enum STT
  482. {
  483. STT_NOTYPE = 0,
  484. STT_OBJECT = 1,
  485. STT_FUNC = 2,
  486. STT_SECTION = 3,
  487. STT_FILE = 4,
  488. STT_COMMON = 5,
  489. STT_TLS = 6,
  490. // GNU extension: symbol value points to a function which is called
  491. // at runtime to determine the final value of the symbol.
  492. STT_GNU_IFUNC = 10,
  493. STT_LOOS = 10,
  494. STT_HIOS = 12,
  495. STT_LOPROC = 13,
  496. STT_HIPROC = 15,
  497. // The section type that must be used for register symbols on
  498. // Sparc. These symbols initialize a global register.
  499. STT_SPARC_REGISTER = 13,
  500. // ARM: a THUMB function. This is not defined in ARM ELF Specification but
  501. // used by the GNU tool-chain.
  502. STT_ARM_TFUNC = 13
  503. };
  504. inline STB
  505. elf_st_bind(unsigned char info)
  506. {
  507. return static_cast<STB>(info >> 4);
  508. }
  509. inline STT
  510. elf_st_type(unsigned char info)
  511. {
  512. return static_cast<STT>(info & 0xf);
  513. }
  514. inline unsigned char
  515. elf_st_info(STB bind, STT type)
  516. {
  517. return ((static_cast<unsigned char>(bind) << 4)
  518. + (static_cast<unsigned char>(type) & 0xf));
  519. }
  520. // Symbol visibility from Sym st_other field.
  521. enum STV
  522. {
  523. STV_DEFAULT = 0,
  524. STV_INTERNAL = 1,
  525. STV_HIDDEN = 2,
  526. STV_PROTECTED = 3
  527. };
  528. inline STV
  529. elf_st_visibility(unsigned char other)
  530. {
  531. return static_cast<STV>(other & 0x3);
  532. }
  533. inline unsigned char
  534. elf_st_nonvis(unsigned char other)
  535. {
  536. return static_cast<STV>(other >> 2);
  537. }
  538. inline unsigned char
  539. elf_st_other(STV vis, unsigned char nonvis)
  540. {
  541. return ((nonvis << 2)
  542. + (static_cast<unsigned char>(vis) & 3));
  543. }
  544. // Reloc information from Rel/Rela r_info field.
  545. template<int size>
  546. unsigned int
  547. elf_r_sym(typename Elf_types<size>::Elf_WXword);
  548. template<>
  549. inline unsigned int
  550. elf_r_sym<32>(Elf_Word v)
  551. {
  552. return v >> 8;
  553. }
  554. template<>
  555. inline unsigned int
  556. elf_r_sym<64>(Elf_Xword v)
  557. {
  558. return v >> 32;
  559. }
  560. template<int size>
  561. unsigned int
  562. elf_r_type(typename Elf_types<size>::Elf_WXword);
  563. template<>
  564. inline unsigned int
  565. elf_r_type<32>(Elf_Word v)
  566. {
  567. return v & 0xff;
  568. }
  569. template<>
  570. inline unsigned int
  571. elf_r_type<64>(Elf_Xword v)
  572. {
  573. return v & 0xffffffff;
  574. }
  575. template<int size>
  576. typename Elf_types<size>::Elf_WXword
  577. elf_r_info(unsigned int s, unsigned int t);
  578. template<>
  579. inline Elf_Word
  580. elf_r_info<32>(unsigned int s, unsigned int t)
  581. {
  582. return (s << 8) + (t & 0xff);
  583. }
  584. template<>
  585. inline Elf_Xword
  586. elf_r_info<64>(unsigned int s, unsigned int t)
  587. {
  588. return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
  589. }
  590. // Dynamic tags found in the PT_DYNAMIC segment.
  591. enum DT
  592. {
  593. DT_NULL = 0,
  594. DT_NEEDED = 1,
  595. DT_PLTRELSZ = 2,
  596. DT_PLTGOT = 3,
  597. DT_HASH = 4,
  598. DT_STRTAB = 5,
  599. DT_SYMTAB = 6,
  600. DT_RELA = 7,
  601. DT_RELASZ = 8,
  602. DT_RELAENT = 9,
  603. DT_STRSZ = 10,
  604. DT_SYMENT = 11,
  605. DT_INIT = 12,
  606. DT_FINI = 13,
  607. DT_SONAME = 14,
  608. DT_RPATH = 15,
  609. DT_SYMBOLIC = 16,
  610. DT_REL = 17,
  611. DT_RELSZ = 18,
  612. DT_RELENT = 19,
  613. DT_PLTREL = 20,
  614. DT_DEBUG = 21,
  615. DT_TEXTREL = 22,
  616. DT_JMPREL = 23,
  617. DT_BIND_NOW = 24,
  618. DT_INIT_ARRAY = 25,
  619. DT_FINI_ARRAY = 26,
  620. DT_INIT_ARRAYSZ = 27,
  621. DT_FINI_ARRAYSZ = 28,
  622. DT_RUNPATH = 29,
  623. DT_FLAGS = 30,
  624. // This is used to mark a range of dynamic tags. It is not really
  625. // a tag value.
  626. DT_ENCODING = 32,
  627. DT_PREINIT_ARRAY = 32,
  628. DT_PREINIT_ARRAYSZ = 33,
  629. DT_LOOS = 0x6000000d,
  630. DT_HIOS = 0x6ffff000,
  631. DT_LOPROC = 0x70000000,
  632. DT_HIPROC = 0x7fffffff,
  633. // The remaining values are extensions used by GNU or Solaris.
  634. DT_VALRNGLO = 0x6ffffd00,
  635. DT_GNU_PRELINKED = 0x6ffffdf5,
  636. DT_GNU_CONFLICTSZ = 0x6ffffdf6,
  637. DT_GNU_LIBLISTSZ = 0x6ffffdf7,
  638. DT_CHECKSUM = 0x6ffffdf8,
  639. DT_PLTPADSZ = 0x6ffffdf9,
  640. DT_MOVEENT = 0x6ffffdfa,
  641. DT_MOVESZ = 0x6ffffdfb,
  642. DT_FEATURE = 0x6ffffdfc,
  643. DT_POSFLAG_1 = 0x6ffffdfd,
  644. DT_SYMINSZ = 0x6ffffdfe,
  645. DT_SYMINENT = 0x6ffffdff,
  646. DT_VALRNGHI = 0x6ffffdff,
  647. DT_ADDRRNGLO = 0x6ffffe00,
  648. DT_GNU_HASH = 0x6ffffef5,
  649. DT_TLSDESC_PLT = 0x6ffffef6,
  650. DT_TLSDESC_GOT = 0x6ffffef7,
  651. DT_GNU_CONFLICT = 0x6ffffef8,
  652. DT_GNU_LIBLIST = 0x6ffffef9,
  653. DT_CONFIG = 0x6ffffefa,
  654. DT_DEPAUDIT = 0x6ffffefb,
  655. DT_AUDIT = 0x6ffffefc,
  656. DT_PLTPAD = 0x6ffffefd,
  657. DT_MOVETAB = 0x6ffffefe,
  658. DT_SYMINFO = 0x6ffffeff,
  659. DT_ADDRRNGHI = 0x6ffffeff,
  660. DT_RELACOUNT = 0x6ffffff9,
  661. DT_RELCOUNT = 0x6ffffffa,
  662. DT_FLAGS_1 = 0x6ffffffb,
  663. DT_VERDEF = 0x6ffffffc,
  664. DT_VERDEFNUM = 0x6ffffffd,
  665. DT_VERNEED = 0x6ffffffe,
  666. DT_VERNEEDNUM = 0x6fffffff,
  667. DT_VERSYM = 0x6ffffff0,
  668. // Specify the value of _GLOBAL_OFFSET_TABLE_.
  669. DT_PPC_GOT = 0x70000000,
  670. // Specify the start of the .glink section.
  671. DT_PPC64_GLINK = 0x70000000,
  672. // Specify the start and size of the .opd section.
  673. DT_PPC64_OPD = 0x70000001,
  674. DT_PPC64_OPDSZ = 0x70000002,
  675. // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
  676. // symbol table. One dynamic entry exists for every STT_SPARC_REGISTER
  677. // symbol in the symbol table.
  678. DT_SPARC_REGISTER = 0x70000001,
  679. // MIPS specific dynamic array tags.
  680. // 32 bit version number for runtime linker interface.
  681. DT_MIPS_RLD_VERSION = 0x70000001,
  682. // Time stamp.
  683. DT_MIPS_TIME_STAMP = 0x70000002,
  684. // Checksum of external strings and common sizes.
  685. DT_MIPS_ICHECKSUM = 0x70000003,
  686. // Index of version string in string table.
  687. DT_MIPS_IVERSION = 0x70000004,
  688. // 32 bits of flags.
  689. DT_MIPS_FLAGS = 0x70000005,
  690. // Base address of the segment.
  691. DT_MIPS_BASE_ADDRESS = 0x70000006,
  692. // ???
  693. DT_MIPS_MSYM = 0x70000007,
  694. // Address of .conflict section.
  695. DT_MIPS_CONFLICT = 0x70000008,
  696. // Address of .liblist section.
  697. DT_MIPS_LIBLIST = 0x70000009,
  698. // Number of local global offset table entries.
  699. DT_MIPS_LOCAL_GOTNO = 0x7000000a,
  700. // Number of entries in the .conflict section.
  701. DT_MIPS_CONFLICTNO = 0x7000000b,
  702. // Number of entries in the .liblist section.
  703. DT_MIPS_LIBLISTNO = 0x70000010,
  704. // Number of entries in the .dynsym section.
  705. DT_MIPS_SYMTABNO = 0x70000011,
  706. // Index of first external dynamic symbol not referenced locally.
  707. DT_MIPS_UNREFEXTNO = 0x70000012,
  708. // Index of first dynamic symbol in global offset table.
  709. DT_MIPS_GOTSYM = 0x70000013,
  710. // Number of page table entries in global offset table.
  711. DT_MIPS_HIPAGENO = 0x70000014,
  712. // Address of run time loader map, used for debugging.
  713. DT_MIPS_RLD_MAP = 0x70000016,
  714. // Delta C++ class definition.
  715. DT_MIPS_DELTA_CLASS = 0x70000017,
  716. // Number of entries in DT_MIPS_DELTA_CLASS.
  717. DT_MIPS_DELTA_CLASS_NO = 0x70000018,
  718. // Delta C++ class instances.
  719. DT_MIPS_DELTA_INSTANCE = 0x70000019,
  720. // Number of entries in DT_MIPS_DELTA_INSTANCE.
  721. DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a,
  722. // Delta relocations.
  723. DT_MIPS_DELTA_RELOC = 0x7000001b,
  724. // Number of entries in DT_MIPS_DELTA_RELOC.
  725. DT_MIPS_DELTA_RELOC_NO = 0x7000001c,
  726. // Delta symbols that Delta relocations refer to.
  727. DT_MIPS_DELTA_SYM = 0x7000001d,
  728. // Number of entries in DT_MIPS_DELTA_SYM.
  729. DT_MIPS_DELTA_SYM_NO = 0x7000001e,
  730. // Delta symbols that hold class declarations.
  731. DT_MIPS_DELTA_CLASSSYM = 0x70000020,
  732. // Number of entries in DT_MIPS_DELTA_CLASSSYM.
  733. DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021,
  734. // Flags indicating information about C++ flavor.
  735. DT_MIPS_CXX_FLAGS = 0x70000022,
  736. // Pixie information (???).
  737. DT_MIPS_PIXIE_INIT = 0x70000023,
  738. // Address of .MIPS.symlib
  739. DT_MIPS_SYMBOL_LIB = 0x70000024,
  740. // The GOT index of the first PTE for a segment
  741. DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025,
  742. // The GOT index of the first PTE for a local symbol
  743. DT_MIPS_LOCAL_GOTIDX = 0x70000026,
  744. // The GOT index of the first PTE for a hidden symbol
  745. DT_MIPS_HIDDEN_GOTIDX = 0x70000027,
  746. // The GOT index of the first PTE for a protected symbol
  747. DT_MIPS_PROTECTED_GOTIDX = 0x70000028,
  748. // Address of `.MIPS.options'.
  749. DT_MIPS_OPTIONS = 0x70000029,
  750. // Address of `.interface'.
  751. DT_MIPS_INTERFACE = 0x7000002a,
  752. // ???
  753. DT_MIPS_DYNSTR_ALIGN = 0x7000002b,
  754. // Size of the .interface section.
  755. DT_MIPS_INTERFACE_SIZE = 0x7000002c,
  756. // Size of rld_text_resolve function stored in the GOT.
  757. DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d,
  758. // Default suffix of DSO to be added by rld on dlopen() calls.
  759. DT_MIPS_PERF_SUFFIX = 0x7000002e,
  760. // Size of compact relocation section (O32).
  761. DT_MIPS_COMPACT_SIZE = 0x7000002f,
  762. // GP value for auxiliary GOTs.
  763. DT_MIPS_GP_VALUE = 0x70000030,
  764. // Address of auxiliary .dynamic.
  765. DT_MIPS_AUX_DYNAMIC = 0x70000031,
  766. // Address of the base of the PLTGOT.
  767. DT_MIPS_PLTGOT = 0x70000032,
  768. // Points to the base of a writable PLT.
  769. DT_MIPS_RWPLT = 0x70000034,
  770. DT_AUXILIARY = 0x7ffffffd,
  771. DT_USED = 0x7ffffffe,
  772. DT_FILTER = 0x7fffffff
  773. };
  774. // Flags found in the DT_FLAGS dynamic element.
  775. enum DF
  776. {
  777. DF_ORIGIN = 0x1,
  778. DF_SYMBOLIC = 0x2,
  779. DF_TEXTREL = 0x4,
  780. DF_BIND_NOW = 0x8,
  781. DF_STATIC_TLS = 0x10
  782. };
  783. // Flags found in the DT_FLAGS_1 dynamic element.
  784. enum DF_1
  785. {
  786. DF_1_NOW = 0x1,
  787. DF_1_GLOBAL = 0x2,
  788. DF_1_GROUP = 0x4,
  789. DF_1_NODELETE = 0x8,
  790. DF_1_LOADFLTR = 0x10,
  791. DF_1_INITFIRST = 0x20,
  792. DF_1_NOOPEN = 0x40,
  793. DF_1_ORIGIN = 0x80,
  794. DF_1_DIRECT = 0x100,
  795. DF_1_TRANS = 0x200,
  796. DF_1_INTERPOSE = 0x400,
  797. DF_1_NODEFLIB = 0x800,
  798. DF_1_NODUMP = 0x1000,
  799. DF_1_CONLFAT = 0x2000
  800. };
  801. // Version numbers which appear in the vd_version field of a Verdef
  802. // structure.
  803. const int VER_DEF_NONE = 0;
  804. const int VER_DEF_CURRENT = 1;
  805. // Version numbers which appear in the vn_version field of a Verneed
  806. // structure.
  807. const int VER_NEED_NONE = 0;
  808. const int VER_NEED_CURRENT = 1;
  809. // Bit flags which appear in vd_flags of Verdef and vna_flags of
  810. // Vernaux.
  811. const int VER_FLG_BASE = 0x1;
  812. const int VER_FLG_WEAK = 0x2;
  813. const int VER_FLG_INFO = 0x4;
  814. // Special constants found in the SHT_GNU_versym entries.
  815. const int VER_NDX_LOCAL = 0;
  816. const int VER_NDX_GLOBAL = 1;
  817. // A SHT_GNU_versym section holds 16-bit words. This bit is set if
  818. // the symbol is hidden and can only be seen when referenced using an
  819. // explicit version number. This is a GNU extension.
  820. const int VERSYM_HIDDEN = 0x8000;
  821. // This is the mask for the rest of the data in a word read from a
  822. // SHT_GNU_versym section.
  823. const int VERSYM_VERSION = 0x7fff;
  824. // Note descriptor type codes for notes in a non-core file with an
  825. // empty name.
  826. enum
  827. {
  828. // A version string.
  829. NT_VERSION = 1,
  830. // An architecture string.
  831. NT_ARCH = 2
  832. };
  833. // Note descriptor type codes for notes in a non-core file with the
  834. // name "GNU".
  835. enum
  836. {
  837. // The minimum ABI level. This is used by the dynamic linker to
  838. // describe the minimal kernel version on which a shared library may
  839. // be used. Th value should be four words. Word 0 is an OS
  840. // descriptor (see below). Word 1 is the major version of the ABI.
  841. // Word 2 is the minor version. Word 3 is the subminor version.
  842. NT_GNU_ABI_TAG = 1,
  843. // Hardware capabilities information. Word 0 is the number of
  844. // entries. Word 1 is a bitmask of enabled entries. The rest of
  845. // the descriptor is a series of entries, where each entry is a
  846. // single byte followed by a nul terminated string. The byte gives
  847. // the bit number to test if enabled in the bitmask.
  848. NT_GNU_HWCAP = 2,
  849. // The build ID as set by the linker's --build-id option. The
  850. // format of the descriptor depends on the build ID style.
  851. NT_GNU_BUILD_ID = 3,
  852. // The version of gold used to link. Th descriptor is just a
  853. // string.
  854. NT_GNU_GOLD_VERSION = 4
  855. };
  856. // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
  857. enum
  858. {
  859. ELF_NOTE_OS_LINUX = 0,
  860. ELF_NOTE_OS_GNU = 1,
  861. ELF_NOTE_OS_SOLARIS2 = 2,
  862. ELF_NOTE_OS_FREEBSD = 3,
  863. ELF_NOTE_OS_NETBSD = 4,
  864. ELF_NOTE_OS_SYLLABLE = 5
  865. };
  866. } // End namespace elfcpp.
  867. // Include internal details after defining the types.
  868. #include "elfcpp_internal.h"
  869. namespace elfcpp
  870. {
  871. // The offset of the ELF file header in the ELF file.
  872. const int file_header_offset = 0;
  873. // ELF structure sizes.
  874. template<int size>
  875. struct Elf_sizes
  876. {
  877. // Size of ELF file header.
  878. static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
  879. // Size of ELF segment header.
  880. static const int phdr_size = sizeof(internal::Phdr_data<size>);
  881. // Size of ELF section header.
  882. static const int shdr_size = sizeof(internal::Shdr_data<size>);
  883. // Size of ELF compression header.
  884. static const int chdr_size = sizeof(internal::Chdr_data<size>);
  885. // Size of ELF symbol table entry.
  886. static const int sym_size = sizeof(internal::Sym_data<size>);
  887. // Sizes of ELF reloc entries.
  888. static const int rel_size = sizeof(internal::Rel_data<size>);
  889. static const int rela_size = sizeof(internal::Rela_data<size>);
  890. // Size of ELF dynamic entry.
  891. static const int dyn_size = sizeof(internal::Dyn_data<size>);
  892. // Size of ELF version structures.
  893. static const int verdef_size = sizeof(internal::Verdef_data);
  894. static const int verdaux_size = sizeof(internal::Verdaux_data);
  895. static const int verneed_size = sizeof(internal::Verneed_data);
  896. static const int vernaux_size = sizeof(internal::Vernaux_data);
  897. };
  898. // Accessor class for the ELF file header.
  899. template<int size, bool big_endian>
  900. class Ehdr
  901. {
  902. public:
  903. Ehdr(const unsigned char* p)
  904. : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
  905. { }
  906. template<typename File>
  907. Ehdr(File* file, typename File::Location loc)
  908. : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
  909. file->view(loc.file_offset, loc.data_size).data()))
  910. { }
  911. const unsigned char*
  912. get_e_ident() const
  913. { return this->p_->e_ident; }
  914. Elf_Half
  915. get_e_type() const
  916. { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
  917. Elf_Half
  918. get_e_machine() const
  919. { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
  920. Elf_Word
  921. get_e_version() const
  922. { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
  923. typename Elf_types<size>::Elf_Addr
  924. get_e_entry() const
  925. { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
  926. typename Elf_types<size>::Elf_Off
  927. get_e_phoff() const
  928. { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
  929. typename Elf_types<size>::Elf_Off
  930. get_e_shoff() const
  931. { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
  932. Elf_Word
  933. get_e_flags() const
  934. { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
  935. Elf_Half
  936. get_e_ehsize() const
  937. { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
  938. Elf_Half
  939. get_e_phentsize() const
  940. { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
  941. Elf_Half
  942. get_e_phnum() const
  943. { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
  944. Elf_Half
  945. get_e_shentsize() const
  946. { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
  947. Elf_Half
  948. get_e_shnum() const
  949. { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
  950. Elf_Half
  951. get_e_shstrndx() const
  952. { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
  953. private:
  954. const internal::Ehdr_data<size>* p_;
  955. };
  956. // Write class for the ELF file header.
  957. template<int size, bool big_endian>
  958. class Ehdr_write
  959. {
  960. public:
  961. Ehdr_write(unsigned char* p)
  962. : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
  963. { }
  964. void
  965. put_e_ident(const unsigned char v[EI_NIDENT]) const
  966. { memcpy(this->p_->e_ident, v, EI_NIDENT); }
  967. void
  968. put_e_type(Elf_Half v)
  969. { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
  970. void
  971. put_e_machine(Elf_Half v)
  972. { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
  973. void
  974. put_e_version(Elf_Word v)
  975. { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
  976. void
  977. put_e_entry(typename Elf_types<size>::Elf_Addr v)
  978. { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
  979. void
  980. put_e_phoff(typename Elf_types<size>::Elf_Off v)
  981. { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
  982. void
  983. put_e_shoff(typename Elf_types<size>::Elf_Off v)
  984. { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
  985. void
  986. put_e_flags(Elf_Word v)
  987. { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
  988. void
  989. put_e_ehsize(Elf_Half v)
  990. { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
  991. void
  992. put_e_phentsize(Elf_Half v)
  993. { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
  994. void
  995. put_e_phnum(Elf_Half v)
  996. { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
  997. void
  998. put_e_shentsize(Elf_Half v)
  999. { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
  1000. void
  1001. put_e_shnum(Elf_Half v)
  1002. { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
  1003. void
  1004. put_e_shstrndx(Elf_Half v)
  1005. { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
  1006. private:
  1007. internal::Ehdr_data<size>* p_;
  1008. };
  1009. // Accessor class for an ELF section header.
  1010. template<int size, bool big_endian>
  1011. class Shdr
  1012. {
  1013. public:
  1014. Shdr(const unsigned char* p)
  1015. : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
  1016. { }
  1017. template<typename File>
  1018. Shdr(File* file, typename File::Location loc)
  1019. : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
  1020. file->view(loc.file_offset, loc.data_size).data()))
  1021. { }
  1022. Elf_Word
  1023. get_sh_name() const
  1024. { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
  1025. Elf_Word
  1026. get_sh_type() const
  1027. { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
  1028. typename Elf_types<size>::Elf_WXword
  1029. get_sh_flags() const
  1030. { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
  1031. typename Elf_types<size>::Elf_Addr
  1032. get_sh_addr() const
  1033. { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
  1034. typename Elf_types<size>::Elf_Off
  1035. get_sh_offset() const
  1036. { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
  1037. typename Elf_types<size>::Elf_WXword
  1038. get_sh_size() const
  1039. { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
  1040. Elf_Word
  1041. get_sh_link() const
  1042. { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
  1043. Elf_Word
  1044. get_sh_info() const
  1045. { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
  1046. typename Elf_types<size>::Elf_WXword
  1047. get_sh_addralign() const
  1048. { return
  1049. Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
  1050. typename Elf_types<size>::Elf_WXword
  1051. get_sh_entsize() const
  1052. { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
  1053. private:
  1054. const internal::Shdr_data<size>* p_;
  1055. };
  1056. // Write class for an ELF section header.
  1057. template<int size, bool big_endian>
  1058. class Shdr_write
  1059. {
  1060. public:
  1061. Shdr_write(unsigned char* p)
  1062. : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
  1063. { }
  1064. void
  1065. put_sh_name(Elf_Word v)
  1066. { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
  1067. void
  1068. put_sh_type(Elf_Word v)
  1069. { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
  1070. void
  1071. put_sh_flags(typename Elf_types<size>::Elf_WXword v)
  1072. { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
  1073. void
  1074. put_sh_addr(typename Elf_types<size>::Elf_Addr v)
  1075. { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
  1076. void
  1077. put_sh_offset(typename Elf_types<size>::Elf_Off v)
  1078. { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
  1079. void
  1080. put_sh_size(typename Elf_types<size>::Elf_WXword v)
  1081. { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
  1082. void
  1083. put_sh_link(Elf_Word v)
  1084. { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
  1085. void
  1086. put_sh_info(Elf_Word v)
  1087. { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
  1088. void
  1089. put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
  1090. { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
  1091. void
  1092. put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
  1093. { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
  1094. private:
  1095. internal::Shdr_data<size>* p_;
  1096. };
  1097. // Accessor class for an ELF compression header.
  1098. template<int size, bool big_endian>
  1099. class Chdr
  1100. {
  1101. public:
  1102. Chdr(const unsigned char* p)
  1103. : p_(reinterpret_cast<const internal::Chdr_data<size>*>(p))
  1104. { }
  1105. template<typename File>
  1106. Chdr(File* file, typename File::Location loc)
  1107. : p_(reinterpret_cast<const internal::Chdr_data<size>*>(
  1108. file->view(loc.file_offset, loc.data_size).data()))
  1109. { }
  1110. Elf_Word
  1111. get_ch_type() const
  1112. { return Convert<size, big_endian>::convert_host(this->p_->ch_type); }
  1113. typename Elf_types<size>::Elf_WXword
  1114. get_ch_size() const
  1115. { return Convert<size, big_endian>::convert_host(this->p_->ch_size); }
  1116. typename Elf_types<size>::Elf_WXword
  1117. get_ch_addralign() const
  1118. { return
  1119. Convert<size, big_endian>::convert_host(this->p_->ch_addralign); }
  1120. private:
  1121. const internal::Chdr_data<size>* p_;
  1122. };
  1123. // Write class for an ELF compression header.
  1124. template<int size, bool big_endian>
  1125. class Chdr_write
  1126. {
  1127. public:
  1128. Chdr_write(unsigned char* p)
  1129. : p_(reinterpret_cast<internal::Chdr_data<size>*>(p))
  1130. { }
  1131. void
  1132. put_ch_type(typename Elf_types<size>::Elf_WXword v)
  1133. { this->p_->ch_type = Convert<size, big_endian>::convert_host(v); }
  1134. void
  1135. put_ch_size(typename Elf_types<size>::Elf_WXword v)
  1136. { this->p_->ch_size = Convert<size, big_endian>::convert_host(v); }
  1137. void
  1138. put_ch_addralign(typename Elf_types<size>::Elf_WXword v)
  1139. { this->p_->ch_addralign = Convert<size, big_endian>::convert_host(v); }
  1140. private:
  1141. internal::Chdr_data<size>* p_;
  1142. };
  1143. // Accessor class for an ELF segment header.
  1144. template<int size, bool big_endian>
  1145. class Phdr
  1146. {
  1147. public:
  1148. Phdr(const unsigned char* p)
  1149. : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
  1150. { }
  1151. template<typename File>
  1152. Phdr(File* file, typename File::Location loc)
  1153. : p_(reinterpret_cast<internal::Phdr_data<size>*>(
  1154. file->view(loc.file_offset, loc.data_size).data()))
  1155. { }
  1156. Elf_Word
  1157. get_p_type() const
  1158. { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
  1159. typename Elf_types<size>::Elf_Off
  1160. get_p_offset() const
  1161. { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
  1162. typename Elf_types<size>::Elf_Addr
  1163. get_p_vaddr() const
  1164. { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
  1165. typename Elf_types<size>::Elf_Addr
  1166. get_p_paddr() const
  1167. { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
  1168. typename Elf_types<size>::Elf_WXword
  1169. get_p_filesz() const
  1170. { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
  1171. typename Elf_types<size>::Elf_WXword
  1172. get_p_memsz() const
  1173. { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
  1174. Elf_Word
  1175. get_p_flags() const
  1176. { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
  1177. typename Elf_types<size>::Elf_WXword
  1178. get_p_align() const
  1179. { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
  1180. private:
  1181. const internal::Phdr_data<size>* p_;
  1182. };
  1183. // Write class for an ELF segment header.
  1184. template<int size, bool big_endian>
  1185. class Phdr_write
  1186. {
  1187. public:
  1188. Phdr_write(unsigned char* p)
  1189. : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
  1190. { }
  1191. void
  1192. put_p_type(Elf_Word v)
  1193. { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
  1194. void
  1195. put_p_offset(typename Elf_types<size>::Elf_Off v)
  1196. { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
  1197. void
  1198. put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
  1199. { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
  1200. void
  1201. put_p_paddr(typename Elf_types<size>::Elf_Addr v)
  1202. { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
  1203. void
  1204. put_p_filesz(typename Elf_types<size>::Elf_WXword v)
  1205. { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
  1206. void
  1207. put_p_memsz(typename Elf_types<size>::Elf_WXword v)
  1208. { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
  1209. void
  1210. put_p_flags(Elf_Word v)
  1211. { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
  1212. void
  1213. put_p_align(typename Elf_types<size>::Elf_WXword v)
  1214. { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
  1215. private:
  1216. internal::Phdr_data<size>* p_;
  1217. };
  1218. // Accessor class for an ELF symbol table entry.
  1219. template<int size, bool big_endian>
  1220. class Sym
  1221. {
  1222. public:
  1223. Sym(const unsigned char* p)
  1224. : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
  1225. { }
  1226. template<typename File>
  1227. Sym(File* file, typename File::Location loc)
  1228. : p_(reinterpret_cast<const internal::Sym_data<size>*>(
  1229. file->view(loc.file_offset, loc.data_size).data()))
  1230. { }
  1231. Elf_Word
  1232. get_st_name() const
  1233. { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
  1234. typename Elf_types<size>::Elf_Addr
  1235. get_st_value() const
  1236. { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
  1237. typename Elf_types<size>::Elf_WXword
  1238. get_st_size() const
  1239. { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
  1240. unsigned char
  1241. get_st_info() const
  1242. { return this->p_->st_info; }
  1243. STB
  1244. get_st_bind() const
  1245. { return elf_st_bind(this->get_st_info()); }
  1246. STT
  1247. get_st_type() const
  1248. { return elf_st_type(this->get_st_info()); }
  1249. unsigned char
  1250. get_st_other() const
  1251. { return this->p_->st_other; }
  1252. STV
  1253. get_st_visibility() const
  1254. { return elf_st_visibility(this->get_st_other()); }
  1255. unsigned char
  1256. get_st_nonvis() const
  1257. { return elf_st_nonvis(this->get_st_other()); }
  1258. Elf_Half
  1259. get_st_shndx() const
  1260. { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
  1261. private:
  1262. const internal::Sym_data<size>* p_;
  1263. };
  1264. // Writer class for an ELF symbol table entry.
  1265. template<int size, bool big_endian>
  1266. class Sym_write
  1267. {
  1268. public:
  1269. Sym_write(unsigned char* p)
  1270. : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
  1271. { }
  1272. void
  1273. put_st_name(Elf_Word v)
  1274. { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
  1275. void
  1276. put_st_value(typename Elf_types<size>::Elf_Addr v)
  1277. { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
  1278. void
  1279. put_st_size(typename Elf_types<size>::Elf_WXword v)
  1280. { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
  1281. void
  1282. put_st_info(unsigned char v)
  1283. { this->p_->st_info = v; }
  1284. void
  1285. put_st_info(STB bind, STT type)
  1286. { this->p_->st_info = elf_st_info(bind, type); }
  1287. void
  1288. put_st_other(unsigned char v)
  1289. { this->p_->st_other = v; }
  1290. void
  1291. put_st_other(STV vis, unsigned char nonvis)
  1292. { this->p_->st_other = elf_st_other(vis, nonvis); }
  1293. void
  1294. put_st_shndx(Elf_Half v)
  1295. { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
  1296. Sym<size, big_endian>
  1297. sym()
  1298. { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
  1299. private:
  1300. internal::Sym_data<size>* p_;
  1301. };
  1302. // Accessor classes for an ELF REL relocation entry.
  1303. template<int size, bool big_endian>
  1304. class Rel
  1305. {
  1306. public:
  1307. Rel(const unsigned char* p)
  1308. : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
  1309. { }
  1310. template<typename File>
  1311. Rel(File* file, typename File::Location loc)
  1312. : p_(reinterpret_cast<const internal::Rel_data<size>*>(
  1313. file->view(loc.file_offset, loc.data_size).data()))
  1314. { }
  1315. typename Elf_types<size>::Elf_Addr
  1316. get_r_offset() const
  1317. { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
  1318. typename Elf_types<size>::Elf_WXword
  1319. get_r_info() const
  1320. { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
  1321. private:
  1322. const internal::Rel_data<size>* p_;
  1323. };
  1324. // Writer class for an ELF Rel relocation.
  1325. template<int size, bool big_endian>
  1326. class Rel_write
  1327. {
  1328. public:
  1329. Rel_write(unsigned char* p)
  1330. : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
  1331. { }
  1332. void
  1333. put_r_offset(typename Elf_types<size>::Elf_Addr v)
  1334. { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
  1335. void
  1336. put_r_info(typename Elf_types<size>::Elf_WXword v)
  1337. { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
  1338. private:
  1339. internal::Rel_data<size>* p_;
  1340. };
  1341. // Accessor class for an ELF Rela relocation.
  1342. template<int size, bool big_endian>
  1343. class Rela
  1344. {
  1345. public:
  1346. Rela(const unsigned char* p)
  1347. : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
  1348. { }
  1349. template<typename File>
  1350. Rela(File* file, typename File::Location loc)
  1351. : p_(reinterpret_cast<const internal::Rela_data<size>*>(
  1352. file->view(loc.file_offset, loc.data_size).data()))
  1353. { }
  1354. typename Elf_types<size>::Elf_Addr
  1355. get_r_offset() const
  1356. { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
  1357. typename Elf_types<size>::Elf_WXword
  1358. get_r_info() const
  1359. { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
  1360. typename Elf_types<size>::Elf_Swxword
  1361. get_r_addend() const
  1362. { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
  1363. private:
  1364. const internal::Rela_data<size>* p_;
  1365. };
  1366. // Writer class for an ELF Rela relocation.
  1367. template<int size, bool big_endian>
  1368. class Rela_write
  1369. {
  1370. public:
  1371. Rela_write(unsigned char* p)
  1372. : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
  1373. { }
  1374. void
  1375. put_r_offset(typename Elf_types<size>::Elf_Addr v)
  1376. { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
  1377. void
  1378. put_r_info(typename Elf_types<size>::Elf_WXword v)
  1379. { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
  1380. void
  1381. put_r_addend(typename Elf_types<size>::Elf_Swxword v)
  1382. { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
  1383. private:
  1384. internal::Rela_data<size>* p_;
  1385. };
  1386. // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
  1387. // PT_DYNAMIC segment.
  1388. template<int size, bool big_endian>
  1389. class Dyn
  1390. {
  1391. public:
  1392. Dyn(const unsigned char* p)
  1393. : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
  1394. { }
  1395. template<typename File>
  1396. Dyn(File* file, typename File::Location loc)
  1397. : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
  1398. file->view(loc.file_offset, loc.data_size).data()))
  1399. { }
  1400. typename Elf_types<size>::Elf_Swxword
  1401. get_d_tag() const
  1402. { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
  1403. typename Elf_types<size>::Elf_WXword
  1404. get_d_val() const
  1405. { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
  1406. typename Elf_types<size>::Elf_Addr
  1407. get_d_ptr() const
  1408. { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
  1409. private:
  1410. const internal::Dyn_data<size>* p_;
  1411. };
  1412. // Write class for an entry in the SHT_DYNAMIC section.
  1413. template<int size, bool big_endian>
  1414. class Dyn_write
  1415. {
  1416. public:
  1417. Dyn_write(unsigned char* p)
  1418. : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
  1419. { }
  1420. void
  1421. put_d_tag(typename Elf_types<size>::Elf_Swxword v)
  1422. { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
  1423. void
  1424. put_d_val(typename Elf_types<size>::Elf_WXword v)
  1425. { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
  1426. void
  1427. put_d_ptr(typename Elf_types<size>::Elf_Addr v)
  1428. { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
  1429. private:
  1430. internal::Dyn_data<size>* p_;
  1431. };
  1432. // Accessor classes for entries in the ELF SHT_GNU_verdef section.
  1433. template<int size, bool big_endian>
  1434. class Verdef
  1435. {
  1436. public:
  1437. Verdef(const unsigned char* p)
  1438. : p_(reinterpret_cast<const internal::Verdef_data*>(p))
  1439. { }
  1440. template<typename File>
  1441. Verdef(File* file, typename File::Location loc)
  1442. : p_(reinterpret_cast<const internal::Verdef_data*>(
  1443. file->view(loc.file_offset, loc.data_size).data()))
  1444. { }
  1445. Elf_Half
  1446. get_vd_version() const
  1447. { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
  1448. Elf_Half
  1449. get_vd_flags() const
  1450. { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
  1451. Elf_Half
  1452. get_vd_ndx() const
  1453. { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
  1454. Elf_Half
  1455. get_vd_cnt() const
  1456. { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
  1457. Elf_Word
  1458. get_vd_hash() const
  1459. { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
  1460. Elf_Word
  1461. get_vd_aux() const
  1462. { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
  1463. Elf_Word
  1464. get_vd_next() const
  1465. { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
  1466. private:
  1467. const internal::Verdef_data* p_;
  1468. };
  1469. template<int size, bool big_endian>
  1470. class Verdef_write
  1471. {
  1472. public:
  1473. Verdef_write(unsigned char* p)
  1474. : p_(reinterpret_cast<internal::Verdef_data*>(p))
  1475. { }
  1476. void
  1477. set_vd_version(Elf_Half v)
  1478. { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
  1479. void
  1480. set_vd_flags(Elf_Half v)
  1481. { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
  1482. void
  1483. set_vd_ndx(Elf_Half v)
  1484. { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
  1485. void
  1486. set_vd_cnt(Elf_Half v)
  1487. { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
  1488. void
  1489. set_vd_hash(Elf_Word v)
  1490. { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
  1491. void
  1492. set_vd_aux(Elf_Word v)
  1493. { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
  1494. void
  1495. set_vd_next(Elf_Word v)
  1496. { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
  1497. private:
  1498. internal::Verdef_data* p_;
  1499. };
  1500. // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
  1501. // section.
  1502. template<int size, bool big_endian>
  1503. class Verdaux
  1504. {
  1505. public:
  1506. Verdaux(const unsigned char* p)
  1507. : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
  1508. { }
  1509. template<typename File>
  1510. Verdaux(File* file, typename File::Location loc)
  1511. : p_(reinterpret_cast<const internal::Verdaux_data*>(
  1512. file->view(loc.file_offset, loc.data_size).data()))
  1513. { }
  1514. Elf_Word
  1515. get_vda_name() const
  1516. { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
  1517. Elf_Word
  1518. get_vda_next() const
  1519. { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
  1520. private:
  1521. const internal::Verdaux_data* p_;
  1522. };
  1523. template<int size, bool big_endian>
  1524. class Verdaux_write
  1525. {
  1526. public:
  1527. Verdaux_write(unsigned char* p)
  1528. : p_(reinterpret_cast<internal::Verdaux_data*>(p))
  1529. { }
  1530. void
  1531. set_vda_name(Elf_Word v)
  1532. { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
  1533. void
  1534. set_vda_next(Elf_Word v)
  1535. { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
  1536. private:
  1537. internal::Verdaux_data* p_;
  1538. };
  1539. // Accessor classes for entries in the ELF SHT_GNU_verneed section.
  1540. template<int size, bool big_endian>
  1541. class Verneed
  1542. {
  1543. public:
  1544. Verneed(const unsigned char* p)
  1545. : p_(reinterpret_cast<const internal::Verneed_data*>(p))
  1546. { }
  1547. template<typename File>
  1548. Verneed(File* file, typename File::Location loc)
  1549. : p_(reinterpret_cast<const internal::Verneed_data*>(
  1550. file->view(loc.file_offset, loc.data_size).data()))
  1551. { }
  1552. Elf_Half
  1553. get_vn_version() const
  1554. { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
  1555. Elf_Half
  1556. get_vn_cnt() const
  1557. { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
  1558. Elf_Word
  1559. get_vn_file() const
  1560. { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
  1561. Elf_Word
  1562. get_vn_aux() const
  1563. { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
  1564. Elf_Word
  1565. get_vn_next() const
  1566. { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
  1567. private:
  1568. const internal::Verneed_data* p_;
  1569. };
  1570. template<int size, bool big_endian>
  1571. class Verneed_write
  1572. {
  1573. public:
  1574. Verneed_write(unsigned char* p)
  1575. : p_(reinterpret_cast<internal::Verneed_data*>(p))
  1576. { }
  1577. void
  1578. set_vn_version(Elf_Half v)
  1579. { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
  1580. void
  1581. set_vn_cnt(Elf_Half v)
  1582. { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
  1583. void
  1584. set_vn_file(Elf_Word v)
  1585. { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
  1586. void
  1587. set_vn_aux(Elf_Word v)
  1588. { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
  1589. void
  1590. set_vn_next(Elf_Word v)
  1591. { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
  1592. private:
  1593. internal::Verneed_data* p_;
  1594. };
  1595. // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
  1596. // section.
  1597. template<int size, bool big_endian>
  1598. class Vernaux
  1599. {
  1600. public:
  1601. Vernaux(const unsigned char* p)
  1602. : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
  1603. { }
  1604. template<typename File>
  1605. Vernaux(File* file, typename File::Location loc)
  1606. : p_(reinterpret_cast<const internal::Vernaux_data*>(
  1607. file->view(loc.file_offset, loc.data_size).data()))
  1608. { }
  1609. Elf_Word
  1610. get_vna_hash() const
  1611. { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
  1612. Elf_Half
  1613. get_vna_flags() const
  1614. { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
  1615. Elf_Half
  1616. get_vna_other() const
  1617. { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
  1618. Elf_Word
  1619. get_vna_name() const
  1620. { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
  1621. Elf_Word
  1622. get_vna_next() const
  1623. { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
  1624. private:
  1625. const internal::Vernaux_data* p_;
  1626. };
  1627. template<int size, bool big_endian>
  1628. class Vernaux_write
  1629. {
  1630. public:
  1631. Vernaux_write(unsigned char* p)
  1632. : p_(reinterpret_cast<internal::Vernaux_data*>(p))
  1633. { }
  1634. void
  1635. set_vna_hash(Elf_Word v)
  1636. { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
  1637. void
  1638. set_vna_flags(Elf_Half v)
  1639. { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
  1640. void
  1641. set_vna_other(Elf_Half v)
  1642. { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
  1643. void
  1644. set_vna_name(Elf_Word v)
  1645. { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
  1646. void
  1647. set_vna_next(Elf_Word v)
  1648. { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
  1649. private:
  1650. internal::Vernaux_data* p_;
  1651. };
  1652. } // End namespace elfcpp.
  1653. #endif // !defined(ELFPCP_H)