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