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