*** empty log message ***
[deliverable/binutils-gdb.git] / elfcpp / elfcpp.h
CommitLineData
bae7f79e
ILT
1// elfcpp.h -- main header file for elfcpp -*- C++ -*-
2
3// This is the external interface for elfcpp.
4
5#ifndef ELFCPP_H
6#define ELFCPP_H
7
8#include "elfcpp_config.h"
8d9455b4 9#include "elfcpp_swap.h"
bae7f79e
ILT
10
11#include <stdint.h>
12
13namespace elfcpp
14{
15
16// Basic ELF types.
17
18// These types are always the same size.
19
20typedef uint16_t Elf_Half;
21typedef uint32_t Elf_Word;
22typedef int32_t Elf_Sword;
23typedef uint64_t Elf_Xword;
24typedef int64_t Elf_Sxword;
25
26// These types vary in size depending on the ELF file class. The
27// template parameter should be 32 or 64.
28
29template<int size>
39081c14 30struct Elf_types;
bae7f79e
ILT
31
32template<>
33struct Elf_types<32>
34{
35 typedef uint32_t Elf_Addr;
36 typedef uint32_t Elf_Off;
37 typedef uint32_t Elf_WXword;
61ba1cf9 38 typedef int32_t Elf_Swxword;
bae7f79e
ILT
39};
40
41template<>
42struct Elf_types<64>
43{
44 typedef uint64_t Elf_Addr;
45 typedef uint64_t Elf_Off;
46 typedef uint64_t Elf_WXword;
61ba1cf9 47 typedef int64_t Elf_Swxword;
bae7f79e
ILT
48};
49
50// Offsets within the Ehdr e_ident field.
51
52const int EI_MAG0 = 0;
53const int EI_MAG1 = 1;
54const int EI_MAG2 = 2;
55const int EI_MAG3 = 3;
56const int EI_CLASS = 4;
57const int EI_DATA = 5;
58const int EI_VERSION = 6;
59const int EI_OSABI = 7;
60const int EI_ABIVERSION = 8;
61const int EI_PAD = 9;
62const int EI_NIDENT = 16;
63
64// The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
65
66const int ELFMAG0 = 0x7f;
67const int ELFMAG1 = 'E';
68const int ELFMAG2 = 'L';
69const int ELFMAG3 = 'F';
70
71// The valid values found in Ehdr e_ident[EI_CLASS].
72
73enum
74{
75 ELFCLASSNONE = 0,
76 ELFCLASS32 = 1,
77 ELFCLASS64 = 2
78};
79
80// The valid values found in Ehdr e_ident[EI_DATA].
81
82enum
83{
84 ELFDATANONE = 0,
85 ELFDATA2LSB = 1,
86 ELFDATA2MSB = 2
87};
88
89// The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
90
91enum
92{
93 EV_NONE = 0,
94 EV_CURRENT = 1
95};
96
97// The valid values found in Ehdr e_ident[EI_OSABI].
98
99enum ELFOSABI
100{
101 ELFOSABI_NONE = 0,
102 ELFOSABI_HPUX = 1,
103 ELFOSABI_NETBSD = 2,
104 // ELFOSABI_LINUX is not listed in the ELF standard.
105 ELFOSABI_LINUX = 3,
106 // ELFOSABI_HURD is not listed in the ELF standard.
107 ELFOSABI_HURD = 4,
108 ELFOSABI_SOLARIS = 6,
109 ELFOSABI_AIX = 7,
110 ELFOSABI_IRIX = 8,
111 ELFOSABI_FREEBSD = 9,
112 ELFOSABI_TRU64 = 10,
113 ELFOSABI_MODESTO = 11,
114 ELFOSABI_OPENBSD = 12,
115 ELFOSABI_OPENVMS = 13,
116 ELFOSABI_NSK = 14,
117 ELFOSABI_AROS = 15,
118 // A GNU extension for the ARM.
119 ELFOSABI_ARM = 97,
120 // A GNU extension for the MSP.
121 ELFOSABI_STANDALONE = 255
122};
123
124// The valid values found in the Ehdr e_type field.
125
126enum ET
127{
128 ET_NONE = 0,
129 ET_REL = 1,
130 ET_EXEC = 2,
131 ET_DYN = 3,
132 ET_CORE = 4,
133 ET_LOOS = 0xfe00,
134 ET_HIOS = 0xfeff,
135 ET_LOPROC = 0xff00,
136 ET_HIPROC = 0xffff
137};
138
139// The valid values found in the Ehdr e_machine field.
140
141enum EM
142{
143 EM_NONE = 0,
144 EM_M32 = 1,
145 EM_SPARC = 2,
146 EM_386 = 3,
147 EM_68K = 4,
148 EM_88K = 5,
149 // 6 used to be EM_486
150 EM_860 = 7,
151 EM_MIPS = 8,
152 EM_S370 = 9,
153 EM_MIPS_RS3_LE = 10,
154 // 11 was the old Sparc V9 ABI.
155 // 12 through 14 are reserved.
156 EM_PARISC = 15,
157 // 16 is reserved.
158 // Some old PowerPC object files use 17.
159 EM_VPP500 = 17,
160 EM_SPARC32PLUS = 18,
161 EM_960 = 19,
162 EM_PPC = 20,
163 EM_PPC64 = 21,
164 EM_S390 = 22,
165 // 23 through 35 are served.
166 EM_V800 = 36,
167 EM_FR20 = 37,
168 EM_RH32 = 38,
169 EM_RCE = 39,
170 EM_ARM = 40,
171 EM_ALPHA = 41,
172 EM_SH = 42,
173 EM_SPARCV9 = 43,
174 EM_TRICORE = 44,
175 EM_ARC = 45,
176 EM_H8_300 = 46,
177 EM_H8_300H = 47,
178 EM_H8S = 48,
179 EM_H8_500 = 49,
180 EM_IA_64 = 50,
181 EM_MIPS_X = 51,
182 EM_COLDFIRE = 52,
183 EM_68HC12 = 53,
184 EM_MMA = 54,
185 EM_PCP = 55,
186 EM_NCPU = 56,
187 EM_NDR1 = 57,
188 EM_STARCORE = 58,
189 EM_ME16 = 59,
190 EM_ST100 = 60,
191 EM_TINYJ = 61,
192 EM_X86_64 = 62,
193 EM_PDSP = 63,
194 EM_PDP10 = 64,
195 EM_PDP11 = 65,
196 EM_FX66 = 66,
197 EM_ST9PLUS = 67,
198 EM_ST7 = 68,
199 EM_68HC16 = 69,
200 EM_68HC11 = 70,
201 EM_68HC08 = 71,
202 EM_68HC05 = 72,
203 EM_SVX = 73,
204 EM_ST19 = 74,
205 EM_VAX = 75,
206 EM_CRIS = 76,
207 EM_JAVELIN = 77,
208 EM_FIREPATH = 78,
209 EM_ZSP = 79,
210 EM_MMIX = 80,
211 EM_HUANY = 81,
212 EM_PRISM = 82,
213 EM_AVR = 83,
214 EM_FR30 = 84,
215 EM_D10V = 85,
216 EM_D30V = 86,
217 EM_V850 = 87,
218 EM_M32R = 88,
219 EM_MN10300 = 89,
220 EM_MN10200 = 90,
221 EM_PJ = 91,
222 EM_OPENRISC = 92,
223 EM_ARC_A5 = 93,
224 EM_XTENSA = 94,
225 EM_VIDEOCORE = 95,
226 EM_TMM_GPP = 96,
227 EM_NS32K = 97,
228 EM_TPC = 98,
229 // Some old picoJava object files use 99 (EM_PJ is correct).
230 EM_SNP1K = 99,
231 EM_ST200 = 100,
232 EM_IP2K = 101,
233 EM_MAX = 102,
234 EM_CR = 103,
235 EM_F2MC16 = 104,
236 EM_MSP430 = 105,
237 EM_BLACKFIN = 106,
238 EM_SE_C33 = 107,
239 EM_SEP = 108,
240 EM_ARCA = 109,
241 EM_UNICORE = 110,
242 EM_ALTERA_NIOS2 = 113,
243 EM_CRX = 114,
244 // The Morph MT.
245 EM_MT = 0x2530,
246 // DLX.
247 EM_DLX = 0x5aa5,
248 // FRV.
249 EM_FRV = 0x5441,
250 // Infineon Technologies 16-bit microcontroller with C166-V2 core.
251 EM_X16X = 0x4688,
252 // Xstorym16
253 EM_XSTORMY16 = 0xad45,
254 // Renesas M32C
255 EM_M32C = 0xfeb0,
256 // Vitesse IQ2000
257 EM_IQ2000 = 0xfeba,
258 // NIOS
259 EM_NIOS32 = 0xfebb
260 // Old AVR objects used 0x1057 (EM_AVR is correct).
261 // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
262 // Old FR30 objects used 0x3330 (EM_FR30 is correct).
263 // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OPENRISC is correct).
264 // Old D10V objects used 0x7650 (EM_D10V is correct).
265 // Old D30V objects used 0x7676 (EM_D30V is correct).
266 // Old IP2X objects used 0x8217 (EM_IP2K is correct).
267 // Old PowerPC objects used 0x9025 (EM_PPC is correct).
268 // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
269 // Old M32R objects used 0x9041 (EM_M32R is correct).
270 // Old V850 objects used 0x9080 (EM_V850 is correct).
271 // Old S/390 objects used 0xa390 (EM_S390 is correct).
272 // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
273 // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
274 // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
275};
276
277// Special section indices.
278
279enum
280{
281 SHN_UNDEF = 0,
282 SHN_LORESERVE = 0xff00,
283 SHN_LOPROC = 0xff00,
284 SHN_HIPROC = 0xff1f,
285 SHN_LOOS = 0xff20,
286 SHN_HIOS = 0xff3f,
287 SHN_ABS = 0xfff1,
288 SHN_COMMON = 0xfff2,
289 SHN_XINDEX = 0xffff,
290 SHN_HIRESERVE = 0xffff
291};
292
293// The valid values found in the Shdr sh_type field.
294
39081c14 295enum SHT
bae7f79e
ILT
296{
297 SHT_NULL = 0,
298 SHT_PROGBITS = 1,
299 SHT_SYMTAB = 2,
300 SHT_STRTAB = 3,
301 SHT_RELA = 4,
302 SHT_HASH = 5,
303 SHT_DYNAMIC = 6,
304 SHT_NOTE = 7,
305 SHT_NOBITS = 8,
306 SHT_REL = 9,
307 SHT_SHLIB = 10,
308 SHT_DYNSYM = 11,
309 SHT_INIT_ARRAY = 14,
310 SHT_FINI_ARRAY = 15,
311 SHT_PREINIT_ARRAY = 16,
312 SHT_GROUP = 17,
313 SHT_SYMTAB_SHNDX = 18,
314 SHT_LOOS = 0x60000000,
315 SHT_HIOS = 0x6fffffff,
316 SHT_LOPROC = 0x70000000,
317 SHT_HIPROC = 0x7fffffff,
318 SHT_LOUSER = 0x80000000,
319 SHT_HIUSER = 0xffffffff,
320 // The remaining values are not in the standard.
321 // List of prelink dependencies.
322 SHT_GNU_LIBLIST = 0x6ffffff7,
323 // Versions defined by file.
324 SHT_SUNW_verdef = 0x6ffffffd,
325 SHT_GNU_verdef = 0x6ffffffd,
326 // Versions needed by file.
327 SHT_SUNW_verneed = 0x6ffffffe,
328 SHT_GNU_verneed = 0x6ffffffe,
329 // Symbol versions,
330 SHT_SUNW_versym = 0x6fffffff,
331 SHT_GNU_versym = 0x6fffffff,
332};
333
334// The valid bit flags found in the Shdr sh_flags field.
335
39081c14 336enum SHF
bae7f79e
ILT
337{
338 SHF_WRITE = 0x1,
339 SHF_ALLOC = 0x2,
340 SHF_EXECINSTR = 0x4,
341 SHF_MERGE = 0x10,
342 SHF_STRINGS = 0x20,
343 SHF_INFO_LINK = 0x40,
344 SHF_LINK_ORDER = 0x80,
345 SHF_OS_NONCONFORMING = 0x100,
346 SHF_GROUP = 0x200,
347 SHF_TLS = 0x400,
348 SHF_MASKOS = 0x0ff00000,
349 SHF_MASKPROC = 0xf0000000
350};
351
352// Bit flags which appear in the first 32-bit word of the section data
353// of a SHT_GROUP section.
354
355enum
356{
357 GRP_COMDAT = 0x1,
358 GRP_MASKOS = 0x0ff00000,
359 GRP_MASKPROC = 0xf0000000
360};
361
39081c14
ILT
362// The valid values found in the Phdr p_type field.
363
364enum PT
365{
366 PT_NULL = 0,
367 PT_LOAD = 1,
368 PT_DYNAMIC = 2,
369 PT_INTERP = 3,
370 PT_NOTE = 4,
371 PT_SHLIB = 5,
372 PT_PHDR = 6,
373 PT_TLS = 7,
374 PT_LOOS = 0x60000000,
375 PT_HIOS = 0x6fffffff,
376 PT_LOPROC = 0x70000000,
377 PT_HIPROC = 0x7fffffff,
378 // The remaining values are not in the standard.
379 // Frame unwind information.
380 PT_GNU_EH_FRAME = 0x6474e550,
381 PT_SUNW_EH_FRAME = 0x6474e550,
382 // Stack flags.
383 PT_GNU_STACK = 0x6474e551,
384 // Read only after relocation.
385 PT_GNU_RELRO = 0x6474e552
386};
387
388// The valid bit flags found in the Phdr p_flags field.
389
390enum PF
391{
392 PF_X = 0x1,
393 PF_W = 0x2,
394 PF_R = 0x4,
395 PF_MASKOS = 0x0ff00000,
396 PF_MASKPROC = 0xf0000000
397};
398
bae7f79e
ILT
399// Symbol binding from Sym st_info field.
400
401enum STB
402{
403 STB_LOCAL = 0,
404 STB_GLOBAL = 1,
405 STB_WEAK = 2,
406 STB_LOOS = 10,
407 STB_HIOS = 12,
408 STB_LOPROC = 13,
409 STB_HIPROC = 15
410};
411
412// Symbol types from Sym st_info field.
413
414enum STT
415{
416 STT_NOTYPE = 0,
417 STT_OBJECT = 1,
418 STT_FUNC = 2,
419 STT_SECTION = 3,
420 STT_FILE = 4,
421 STT_COMMON = 5,
422 STT_TLS = 6,
423 STT_LOOS = 10,
424 STT_HIOS = 12,
425 STT_LOPROC = 13,
426 STT_HIPROC = 15
427};
428
14bfc3f5
ILT
429inline STB
430elf_st_bind(unsigned char info)
431{
432 return static_cast<STB>(info >> 4);
433}
434
435inline STT
436elf_st_type(unsigned char info)
437{
438 return static_cast<STT>(info & 0xf);
439}
440
441inline unsigned char
442elf_st_info(STB bind, STT type)
443{
444 return ((static_cast<unsigned char>(bind) << 4)
445 + (static_cast<unsigned char>(type) & 0xf));
446}
447
bae7f79e
ILT
448// Symbol visibility from Sym st_other field.
449
450enum STV
451{
452 STV_DEFAULT = 0,
453 STV_INTERNAL = 1,
454 STV_HIDDEN = 2,
455 STV_PROTECTED = 3
456};
457
14bfc3f5
ILT
458inline STV
459elf_st_visibility(unsigned char other)
460{
461 return static_cast<STV>(other & 0x3);
462}
463
464inline unsigned char
465elf_st_nonvis(unsigned char other)
466{
467 return static_cast<STV>(other >> 2);
468}
469
1564db8d
ILT
470inline unsigned char
471elf_st_other(STV vis, unsigned char nonvis)
472{
473 return ((nonvis << 2)
474 + (static_cast<unsigned char>(vis) & 3));
475}
476
61ba1cf9
ILT
477// Reloc information from Rel/Rela r_info field.
478
479template<int size>
480unsigned int
481elf_r_sym(typename Elf_types<size>::Elf_WXword);
482
483template<>
484inline unsigned int
485elf_r_sym<32>(Elf_Word v)
486{
487 return v >> 8;
488}
489
490template<>
491inline unsigned int
492elf_r_sym<64>(Elf_Xword v)
493{
494 return v >> 32;
495}
496
497template<int size>
498unsigned int
499elf_r_type(typename Elf_types<size>::Elf_WXword);
500
501template<>
502inline unsigned int
503elf_r_type<32>(Elf_Word v)
504{
505 return v & 0xff;
506}
507
508template<>
509inline unsigned int
510elf_r_type<64>(Elf_Xword v)
511{
512 return v & 0xffffffff;
513}
514
515template<int size>
516typename Elf_types<size>::Elf_WXword
517elf_r_info(unsigned int s, unsigned int t);
518
519template<>
520inline Elf_Word
521elf_r_info<32>(unsigned int s, unsigned int t)
522{
523 return (s << 8) + (t & 0xff);
524}
525
526template<>
527inline Elf_Xword
528elf_r_info<64>(unsigned int s, unsigned int t)
529{
530 return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
531}
532
dbe717ef
ILT
533// Dynamic tags found in the PT_DYNAMIC segment.
534
535enum DT
536{
537 DT_NULL = 0,
538 DT_NEEDED = 1,
539 DT_PLTRELSZ = 2,
540 DT_PLTGOT = 3,
541 DT_HASH = 4,
542 DT_STRTAB = 5,
543 DT_SYMTAB = 6,
544 DT_RELA = 7,
545 DT_RELASZ = 8,
546 DT_RELAENT = 9,
547 DT_STRSZ = 10,
548 DT_SYMENT = 11,
549 DT_INIT = 12,
550 DT_FINI = 13,
551 DT_SONAME = 14,
552 DT_RPATH = 15,
553 DT_SYMBOLIC = 16,
554 DT_REL = 17,
555 DT_RELSZ = 18,
556 DT_RELENT = 19,
557 DT_PLTREL = 20,
558 DT_DEBUG = 21,
559 DT_TEXTREL = 22,
560 DT_JMPREL = 23,
561 DT_BIND_NOW = 24,
562 DT_INIT_ARRAY = 25,
563 DT_FINI_ARRAY = 26,
564 DT_INIT_ARRAYSZ = 27,
565 DT_FINI_ARRAYSZ = 28,
566 DT_RUNPATH = 29,
567 DT_FLAGS = 30,
568 DT_ENCODING = 32,
569 DT_PREINIT_ARRAY = 33,
570 DT_PREINIT_ARRAYSZ = 33,
571 DT_LOOS = 0x6000000d,
572 DT_HIOS = 0x6ffff000,
573 DT_LOPROC = 0x70000000,
574 DT_HIPROC = 0x7fffffff,
575
576 // The remaining values are extensions used by GNU or Solaris.
577 DT_VALRNGLO = 0x6ffffd00,
578 DT_GNU_PRELINKED = 0x6ffffdf5,
579 DT_GNU_CONFLICTSZ = 0x6ffffdf6,
580 DT_GNU_LIBLISTSZ = 0x6ffffdf7,
581 DT_CHECKSUM = 0x6ffffdf8,
582 DT_PLTPADSZ = 0x6ffffdf9,
583 DT_MOVEENT = 0x6ffffdfa,
584 DT_MOVESZ = 0x6ffffdfb,
585 DT_FEATURE = 0x6ffffdfc,
586 DT_POSFLAG_1 = 0x6ffffdfd,
587 DT_SYMINSZ = 0x6ffffdfe,
588 DT_SYMINENT = 0x6ffffdff,
589 DT_VALRNGHI = 0x6ffffdff,
590
591 DT_ADDRRNGLO = 0x6ffffe00,
592 DT_GNU_HASH = 0x6ffffef5,
593 DT_TLSDESC_PLT = 0x6ffffef6,
594 DT_TLSDESC_GOT = 0x6ffffef7,
595 DT_GNU_CONFLICT = 0x6ffffef8,
596 DT_GNU_LIBLIST = 0x6ffffef9,
597 DT_CONFIG = 0x6ffffefa,
598 DT_DEPAUDIT = 0x6ffffefb,
599 DT_AUDIT = 0x6ffffefc,
600 DT_PLTPAD = 0x6ffffefd,
601 DT_MOVETAB = 0x6ffffefe,
602 DT_SYMINFO = 0x6ffffeff,
603 DT_ADDRRNGHI = 0x6ffffeff,
604
605 DT_RELACOUNT = 0x6ffffff9,
606 DT_RELCOUNT = 0x6ffffffa,
607 DT_FLAGS_1 = 0x6ffffffb,
608 DT_VERDEF = 0x6ffffffc,
609 DT_VERDEFNUM = 0x6ffffffd,
610 DT_VERNEED = 0x6ffffffe,
611 DT_VERNEEDNUM = 0x6fffffff,
612
613 DT_VERSYM = 0x6ffffff0,
614
615 DT_AUXILIARY = 0x7ffffffd,
616 DT_USED = 0x7ffffffe,
617 DT_FILTER = 0x7fffffff
618};
619
620// Flags found in the DT_FLAGS dynamic element.
621
622enum DF
623{
624 DF_ORIGIN = 0x1,
625 DF_SYMBOLIC = 0x2,
626 DF_TEXTREL = 0x4,
627 DF_BIND_NOW = 0x8,
628 DF_STATIC_TLS = 0x10
629};
630
631// Version numbers which appear in the vd_version field of a Verdef
632// structure.
633
634const int VER_DEF_NONE = 0;
635const int VER_DEF_CURRENT = 1;
636
637// Version numbers which appear in the vn_version field of a Verneed
638// structure.
639
640const int VER_NEED_NONE = 0;
641const int VER_NEED_CURRENT = 1;
642
643// Bit flags which appear in vd_flags of Verdef and vna_flags of
644// Vernaux.
645
646const int VER_FLG_BASE = 0x1;
647const int VER_FLG_WEAK = 0x2;
648
649// Special constants found in the SHT_GNU_versym entries.
650
651const int VER_NDX_LOCAL = 0;
652const int VER_NDX_GLOBAL = 1;
653
654// A SHT_GNU_versym section holds 16-bit words. This bit is set if
655// the symbol is hidden and can only be seen when referenced using an
656// explicit version number. This is a GNU extension.
657
658const int VERSYM_HIDDEN = 0x8000;
659
660// This is the mask for the rest of the data in a word read from a
661// SHT_GNU_versym section.
662
663const int VERSYM_VERSION = 0x7fff;
664
bae7f79e
ILT
665} // End namespace elfcpp.
666
667// Include internal details after defining the types.
668#include "elfcpp_internal.h"
669
670namespace elfcpp
671{
672
673// The offset of the ELF file header in the ELF file.
674
675const int file_header_offset = 0;
676
677// ELF structure sizes.
678
679template<int size>
680struct Elf_sizes
681{
682 // Size of ELF file header.
683 static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
61ba1cf9
ILT
684 // Size of ELF segment header.
685 static const int phdr_size = sizeof(internal::Phdr_data<size>);
bae7f79e
ILT
686 // Size of ELF section header.
687 static const int shdr_size = sizeof(internal::Shdr_data<size>);
688 // Size of ELF symbol table entry.
689 static const int sym_size = sizeof(internal::Sym_data<size>);
61ba1cf9
ILT
690 // Sizes of ELF reloc entries.
691 static const int rel_size = sizeof(internal::Rel_data<size>);
692 static const int rela_size = sizeof(internal::Rela_data<size>);
dbe717ef
ILT
693 // Size of ELF dynamic entry.
694 static const int dyn_size = sizeof(internal::Dyn_data<size>);
bae7f79e
ILT
695};
696
697// Accessor class for the ELF file header.
698
699template<int size, bool big_endian>
700class Ehdr
701{
702 public:
703 Ehdr(const unsigned char* p)
704 : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
705 { }
706
645f8123
ILT
707 template<typename File>
708 Ehdr(File* file, typename File::Location loc)
709 : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
710 file->view(loc.file_offset, loc.data_size).data()))
711 { }
712
bae7f79e
ILT
713 const unsigned char*
714 get_e_ident() const
715 { return this->p_->e_ident; }
716
717 Elf_Half
718 get_e_type() const
8d9455b4 719 { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
bae7f79e
ILT
720
721 Elf_Half
722 get_e_machine() const
8d9455b4 723 { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
bae7f79e
ILT
724
725 Elf_Word
726 get_e_version() const
8d9455b4 727 { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
bae7f79e
ILT
728
729 typename Elf_types<size>::Elf_Addr
730 get_e_entry() const
8d9455b4 731 { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
bae7f79e
ILT
732
733 typename Elf_types<size>::Elf_Off
734 get_e_phoff() const
8d9455b4 735 { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
bae7f79e
ILT
736
737 typename Elf_types<size>::Elf_Off
738 get_e_shoff() const
8d9455b4 739 { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
bae7f79e
ILT
740
741 Elf_Word
742 get_e_flags() const
8d9455b4 743 { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
bae7f79e
ILT
744
745 Elf_Half
746 get_e_ehsize() const
8d9455b4 747 { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
bae7f79e
ILT
748
749 Elf_Half
750 get_e_phentsize() const
8d9455b4 751 { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
bae7f79e
ILT
752
753 Elf_Half
754 get_e_phnum() const
8d9455b4 755 { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
bae7f79e
ILT
756
757 Elf_Half
758 get_e_shentsize() const
8d9455b4 759 { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
bae7f79e
ILT
760
761 Elf_Half
762 get_e_shnum() const
8d9455b4 763 { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
bae7f79e
ILT
764
765 Elf_Half
766 get_e_shstrndx() const
8d9455b4 767 { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
bae7f79e
ILT
768
769 private:
770 const internal::Ehdr_data<size>* p_;
771};
772
61ba1cf9
ILT
773// Write class for the ELF file header.
774
775template<int size, bool big_endian>
776class Ehdr_write
777{
778 public:
779 Ehdr_write(unsigned char* p)
780 : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
781 { }
782
783 void
784 put_e_ident(const unsigned char v[EI_NIDENT]) const
785 { memcpy(this->p_->e_ident, v, EI_NIDENT); }
786
787 void
788 put_e_type(Elf_Half v)
8d9455b4 789 { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
790
791 void
792 put_e_machine(Elf_Half v)
8d9455b4 793 { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
794
795 void
796 put_e_version(Elf_Word v)
8d9455b4 797 { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
798
799 void
800 put_e_entry(typename Elf_types<size>::Elf_Addr v)
8d9455b4 801 { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
802
803 void
804 put_e_phoff(typename Elf_types<size>::Elf_Off v)
8d9455b4 805 { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
806
807 void
808 put_e_shoff(typename Elf_types<size>::Elf_Off v)
8d9455b4 809 { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
810
811 void
812 put_e_flags(Elf_Word v)
8d9455b4 813 { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
814
815 void
816 put_e_ehsize(Elf_Half v)
8d9455b4 817 { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
818
819 void
820 put_e_phentsize(Elf_Half v)
8d9455b4 821 { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
822
823 void
824 put_e_phnum(Elf_Half v)
8d9455b4 825 { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
826
827 void
828 put_e_shentsize(Elf_Half v)
8d9455b4 829 { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
830
831 void
832 put_e_shnum(Elf_Half v)
8d9455b4 833 { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
834
835 void
836 put_e_shstrndx(Elf_Half v)
8d9455b4 837 { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
61ba1cf9
ILT
838
839 private:
840 internal::Ehdr_data<size>* p_;
841};
842
bae7f79e
ILT
843// Accessor class for an ELF section header.
844
845template<int size, bool big_endian>
846class Shdr
847{
848 public:
849 Shdr(const unsigned char* p)
850 : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
851 { }
852
645f8123
ILT
853 template<typename File>
854 Shdr(File* file, typename File::Location loc)
855 : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
856 file->view(loc.file_offset, loc.data_size).data()))
857 { }
858
bae7f79e
ILT
859 Elf_Word
860 get_sh_name() const
8d9455b4 861 { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
bae7f79e
ILT
862
863 Elf_Word
864 get_sh_type() const
8d9455b4 865 { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
bae7f79e
ILT
866
867 typename Elf_types<size>::Elf_WXword
868 get_sh_flags() const
8d9455b4 869 { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
bae7f79e
ILT
870
871 typename Elf_types<size>::Elf_Addr
872 get_sh_addr() const
8d9455b4 873 { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
bae7f79e
ILT
874
875 typename Elf_types<size>::Elf_Off
876 get_sh_offset() const
8d9455b4 877 { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
bae7f79e
ILT
878
879 typename Elf_types<size>::Elf_WXword
880 get_sh_size() const
8d9455b4 881 { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
bae7f79e
ILT
882
883 Elf_Word
884 get_sh_link() const
8d9455b4 885 { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
bae7f79e
ILT
886
887 Elf_Word
888 get_sh_info() const
8d9455b4 889 { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
bae7f79e
ILT
890
891 typename Elf_types<size>::Elf_WXword
892 get_sh_addralign() const
893 { return
8d9455b4 894 Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
bae7f79e
ILT
895
896 typename Elf_types<size>::Elf_WXword
897 get_sh_entsize() const
8d9455b4 898 { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
bae7f79e
ILT
899
900 private:
901 const internal::Shdr_data<size>* p_;
902};
903
61ba1cf9
ILT
904// Write class for an ELF section header.
905
906template<int size, bool big_endian>
907class Shdr_write
908{
909 public:
910 Shdr_write(unsigned char* p)
911 : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
912 { }
913
914 void
915 put_sh_name(Elf_Word v)
8d9455b4 916 { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
917
918 void
919 put_sh_type(Elf_Word v)
8d9455b4 920 { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
921
922 void
923 put_sh_flags(typename Elf_types<size>::Elf_WXword v)
8d9455b4 924 { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
925
926 void
927 put_sh_addr(typename Elf_types<size>::Elf_Addr v)
8d9455b4 928 { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
929
930 void
931 put_sh_offset(typename Elf_types<size>::Elf_Off v)
8d9455b4 932 { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
933
934 void
935 put_sh_size(typename Elf_types<size>::Elf_WXword v)
8d9455b4 936 { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
937
938 void
939 put_sh_link(Elf_Word v)
8d9455b4 940 { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
941
942 void
943 put_sh_info(Elf_Word v)
8d9455b4 944 { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
945
946 void
947 put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
8d9455b4 948 { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
949
950 void
951 put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
8d9455b4 952 { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
953
954 private:
955 internal::Shdr_data<size>* p_;
956};
957
39081c14
ILT
958// Accessor class for an ELF segment header.
959
960template<int size, bool big_endian>
961class Phdr
962{
963 public:
964 Phdr(const unsigned char* p)
965 : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
966 { }
967
645f8123
ILT
968 template<typename File>
969 Phdr(File* file, typename File::Location loc)
970 : p_(reinterpret_cast<internal::Phdr_data<size>*>(
971 file->view(loc.file_offset, loc.data_size).data()))
972 { }
973
39081c14
ILT
974 Elf_Word
975 get_p_type() const
8d9455b4 976 { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
39081c14
ILT
977
978 typename Elf_types<size>::Elf_Off
979 get_p_offset() const
8d9455b4 980 { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
39081c14
ILT
981
982 typename Elf_types<size>::Elf_Addr
983 get_p_vaddr() const
8d9455b4 984 { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
39081c14
ILT
985
986 typename Elf_types<size>::Elf_Addr
987 get_p_paddr() const
8d9455b4 988 { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
39081c14
ILT
989
990 typename Elf_types<size>::Elf_WXword
991 get_p_filesz() const
8d9455b4 992 { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
39081c14
ILT
993
994 typename Elf_types<size>::Elf_WXword
995 get_p_memsz() const
8d9455b4 996 { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
39081c14
ILT
997
998 Elf_Word
999 get_p_flags() const
8d9455b4 1000 { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
39081c14
ILT
1001
1002 typename Elf_types<size>::Elf_WXword
1003 get_p_align() const
8d9455b4 1004 { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
39081c14
ILT
1005
1006 private:
1007 const internal::Phdr_data<size>* p_;
1008};
1009
61ba1cf9
ILT
1010// Write class for an ELF segment header.
1011
1012template<int size, bool big_endian>
1013class Phdr_write
1014{
1015 public:
1016 Phdr_write(unsigned char* p)
1017 : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
1018 { }
1019
1020 void
1021 put_p_type(Elf_Word v)
8d9455b4 1022 { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
1023
1024 void
1025 put_p_offset(typename Elf_types<size>::Elf_Off v)
8d9455b4 1026 { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
1027
1028 void
1029 put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
8d9455b4 1030 { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
1031
1032 void
1033 put_p_paddr(typename Elf_types<size>::Elf_Addr v)
8d9455b4 1034 { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
1035
1036 void
1037 put_p_filesz(typename Elf_types<size>::Elf_WXword v)
8d9455b4 1038 { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
1039
1040 void
1041 put_p_memsz(typename Elf_types<size>::Elf_WXword v)
8d9455b4 1042 { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
1043
1044 void
1045 put_p_flags(Elf_Word v)
8d9455b4 1046 { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
61ba1cf9
ILT
1047
1048 void
1049 put_p_align(typename Elf_types<size>::Elf_WXword v)
8d9455b4 1050 { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
61ba1cf9
ILT
1051
1052 private:
1053 internal::Phdr_data<size>* p_;
1054};
1055
bae7f79e
ILT
1056// Accessor class for an ELF symbol table entry.
1057
1058template<int size, bool big_endian>
1059class Sym
1060{
1061 public:
1062 Sym(const unsigned char* p)
1063 : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
1064 { }
1065
645f8123
ILT
1066 template<typename File>
1067 Sym(File* file, typename File::Location loc)
1068 : p_(reinterpret_cast<const internal::Sym_data<size>*>(
1069 file->view(loc.file_offset, loc.data_size).data()))
1070 { }
1071
bae7f79e
ILT
1072 Elf_Word
1073 get_st_name() const
8d9455b4 1074 { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
bae7f79e
ILT
1075
1076 typename Elf_types<size>::Elf_Addr
1077 get_st_value() const
8d9455b4 1078 { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
bae7f79e
ILT
1079
1080 typename Elf_types<size>::Elf_WXword
1081 get_st_size() const
8d9455b4 1082 { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
bae7f79e
ILT
1083
1084 unsigned char
1085 get_st_info() const
1086 { return this->p_->st_info; }
1087
14bfc3f5
ILT
1088 STB
1089 get_st_bind() const
1090 { return elf_st_bind(this->get_st_info()); }
1091
1092 STT
1093 get_st_type() const
1094 { return elf_st_type(this->get_st_info()); }
1095
bae7f79e
ILT
1096 unsigned char
1097 get_st_other() const
1098 { return this->p_->st_other; }
1099
14bfc3f5
ILT
1100 STV
1101 get_st_visibility() const
1102 { return elf_st_visibility(this->get_st_other()); }
1103
1104 unsigned char
1105 get_st_nonvis() const
1106 { return elf_st_nonvis(this->get_st_other()); }
1107
bae7f79e
ILT
1108 Elf_Half
1109 get_st_shndx() const
8d9455b4 1110 { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
bae7f79e
ILT
1111
1112 private:
1113 const internal::Sym_data<size>* p_;
1114};
1115
1564db8d
ILT
1116// Writer class for an ELF symbol table entry.
1117
1118template<int size, bool big_endian>
1119class Sym_write
1120{
1121 public:
1122 Sym_write(unsigned char* p)
1123 : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
1124 { }
1125
1126 void
1127 put_st_name(Elf_Word v)
8d9455b4 1128 { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
1564db8d
ILT
1129
1130 void
1131 put_st_value(typename Elf_types<size>::Elf_Addr v)
8d9455b4 1132 { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
1564db8d
ILT
1133
1134 void
1135 put_st_size(typename Elf_types<size>::Elf_WXword v)
8d9455b4 1136 { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
1564db8d
ILT
1137
1138 void
1139 put_st_info(unsigned char v)
1140 { this->p_->st_info = v; }
1141
1142 void
1143 put_st_info(STB bind, STT type)
1144 { this->p_->st_info = elf_st_info(bind, type); }
1145
1146 void
1147 put_st_other(unsigned char v)
1148 { this->p_->st_other = v; }
1149
1150 void
1151 put_st_other(STV vis, unsigned char nonvis)
1152 { this->p_->st_other = elf_st_other(vis, nonvis); }
1153
1154 void
1155 put_st_shndx(Elf_Half v)
8d9455b4 1156 { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
1564db8d
ILT
1157
1158 Sym<size, big_endian>
1159 sym()
1160 { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
1161
1162 private:
1163 internal::Sym_data<size>* p_;
1164};
1165
c06b7b0b 1166// Accessor classes for an ELF REL relocation entry.
61ba1cf9
ILT
1167
1168template<int size, bool big_endian>
1169class Rel
1170{
1171 public:
1172 Rel(const unsigned char* p)
1173 : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
1174 { }
1175
645f8123
ILT
1176 template<typename File>
1177 Rel(File* file, typename File::Location loc)
1178 : p_(reinterpret_cast<const internal::Rel_data<size>*>(
1179 file->view(loc.file_offset, loc.data_size).data()))
1180 { }
1181
61ba1cf9
ILT
1182 typename Elf_types<size>::Elf_Addr
1183 get_r_offset() const
8d9455b4 1184 { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
61ba1cf9
ILT
1185
1186 typename Elf_types<size>::Elf_WXword
1187 get_r_info() const
8d9455b4 1188 { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
61ba1cf9
ILT
1189
1190 private:
1191 const internal::Rel_data<size>* p_;
1192};
1193
c06b7b0b
ILT
1194// Writer class for an ELF Rel relocation.
1195
1196template<int size, bool big_endian>
1197class Rel_write
1198{
1199 public:
1200 Rel_write(unsigned char* p)
1201 : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
1202 { }
1203
1204 void
1205 put_r_offset(typename Elf_types<size>::Elf_Addr v)
1206 { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1207
1208 void
1209 put_r_info(typename Elf_types<size>::Elf_WXword v)
1210 { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1211
1212 private:
1213 internal::Rel_data<size>* p_;
1214};
1215
1216// Accessor class for an ELF Rela relocation.
1217
61ba1cf9
ILT
1218template<int size, bool big_endian>
1219class Rela
1220{
1221 public:
1222 Rela(const unsigned char* p)
1223 : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
1224 { }
1225
645f8123
ILT
1226 template<typename File>
1227 Rela(File* file, typename File::Location loc)
1228 : p_(reinterpret_cast<const internal::Rela_data<size>*>(
1229 file->view(loc.file_offset, loc.data_size).data()))
1230 { }
1231
61ba1cf9
ILT
1232 typename Elf_types<size>::Elf_Addr
1233 get_r_offset() const
8d9455b4 1234 { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
61ba1cf9
ILT
1235
1236 typename Elf_types<size>::Elf_WXword
1237 get_r_info() const
8d9455b4 1238 { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
61ba1cf9
ILT
1239
1240 typename Elf_types<size>::Elf_Swxword
1241 get_r_addend() const
8d9455b4 1242 { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
61ba1cf9
ILT
1243
1244 private:
1245 const internal::Rela_data<size>* p_;
1246};
1247
c06b7b0b
ILT
1248// Writer class for an ELF Rela relocation.
1249
1250template<int size, bool big_endian>
1251class Rela_write
1252{
1253 public:
1254 Rela_write(unsigned char* p)
1255 : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
1256 { }
1257
1258 void
1259 put_r_offset(typename Elf_types<size>::Elf_Addr v)
1260 { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1261
1262 void
1263 put_r_info(typename Elf_types<size>::Elf_WXword v)
1264 { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1265
1266 void
1267 put_r_addend(typename Elf_types<size>::Elf_Swxword v)
1268 { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
1269
1270 private:
1271 internal::Rela_data<size>* p_;
1272};
1273
dbe717ef
ILT
1274// Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1275// PT_DYNAMIC segment.
1276
1277template<int size, bool big_endian>
1278class Dyn
1279{
1280 public:
1281 Dyn(const unsigned char* p)
1282 : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
1283 { }
1284
1285 template<typename File>
1286 Dyn(File* file, typename File::Location loc)
1287 : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
1288 file->view(loc.file_offset, loc.data_size).data()))
1289 { }
1290
1291 typename Elf_types<size>::Elf_Swxword
1292 get_d_tag() const
1293 { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
1294
1295 typename Elf_types<size>::Elf_WXword
1296 get_d_val() const
1297 { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1298
1299 typename Elf_types<size>::Elf_Addr
1300 get_d_ptr() const
1301 { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1302
1303 private:
1304 const internal::Dyn_data<size>* p_;
1305};
1306
a3ad94ed
ILT
1307// Write class for an entry in the SHT_DYNAMIC section.
1308
1309template<int size, bool big_endian>
1310class Dyn_write
1311{
1312 public:
1313 Dyn_write(unsigned char* p)
1314 : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
1315 { }
1316
1317 void
1318 put_d_tag(typename Elf_types<size>::Elf_Swxword v)
1319 { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
1320
1321 void
1322 put_d_val(typename Elf_types<size>::Elf_WXword v)
1323 { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1324
1325 void
1326 put_d_ptr(typename Elf_types<size>::Elf_Addr v)
1327 { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1328
1329 private:
1330 internal::Dyn_data<size>* p_;
1331};
1332
dbe717ef
ILT
1333// Accessor classes for entries in the ELF SHT_GNU_verdef section.
1334
1335template<int size, bool big_endian>
1336class Verdef
1337{
1338 public:
1339 Verdef(const unsigned char* p)
1340 : p_(reinterpret_cast<const internal::Verdef_data*>(p))
1341 { }
1342
1343 template<typename File>
1344 Verdef(File* file, typename File::Location loc)
1345 : p_(reinterpret_cast<const internal::Verdef_data*>(
1346 file->view(loc.file_offset, loc.data_size).data()))
1347 { }
1348
1349 Elf_Half
1350 get_vd_version() const
1351 { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
1352
1353 Elf_Half
1354 get_vd_flags() const
1355 { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
1356
1357 Elf_Half
1358 get_vd_ndx() const
1359 { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
1360
1361 Elf_Half
1362 get_vd_cnt() const
1363 { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
1364
1365 Elf_Word
1366 get_vd_hash() const
1367 { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
1368
1369 Elf_Word
1370 get_vd_aux() const
1371 { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
1372
1373 Elf_Word
1374 get_vd_next() const
1375 { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
1376
1377 private:
1378 const internal::Verdef_data* p_;
1379};
1380
1381// Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1382// section.
1383
1384template<int size, bool big_endian>
1385class Verdaux
1386{
1387 public:
1388 Verdaux(const unsigned char* p)
1389 : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
1390 { }
1391
1392 template<typename File>
1393 Verdaux(File* file, typename File::Location loc)
1394 : p_(reinterpret_cast<const internal::Verdaux_data*>(
1395 file->view(loc.file_offset, loc.data_size).data()))
1396 { }
1397
1398 Elf_Word
1399 get_vda_name() const
1400 { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
1401
1402 Elf_Word
1403 get_vda_next() const
1404 { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
1405
1406 private:
1407 const internal::Verdaux_data* p_;
1408};
1409
1410// Accessor classes for entries in the ELF SHT_GNU_verneed section.
1411
1412template<int size, bool big_endian>
1413class Verneed
1414{
1415 public:
1416 Verneed(const unsigned char* p)
1417 : p_(reinterpret_cast<const internal::Verneed_data*>(p))
1418 { }
1419
1420 template<typename File>
1421 Verneed(File* file, typename File::Location loc)
1422 : p_(reinterpret_cast<const internal::Verneed_data*>(
1423 file->view(loc.file_offset, loc.data_size).data()))
1424 { }
1425
1426 Elf_Half
1427 get_vn_version() const
1428 { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
1429
1430 Elf_Half
1431 get_vn_cnt() const
1432 { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
1433
1434 Elf_Word
1435 get_vn_file() const
1436 { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
1437
1438 Elf_Word
1439 get_vn_aux() const
1440 { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
1441
1442 Elf_Word
1443 get_vn_next() const
1444 { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
1445
1446 private:
1447 const internal::Verneed_data* p_;
1448};
1449
1450// Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1451// section.
1452
1453template<int size, bool big_endian>
1454class Vernaux
1455{
1456 public:
1457 Vernaux(const unsigned char* p)
1458 : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
1459 { }
1460
1461 template<typename File>
1462 Vernaux(File* file, typename File::Location loc)
1463 : p_(reinterpret_cast<const internal::Vernaux_data*>(
1464 file->view(loc.file_offset, loc.data_size).data()))
1465 { }
1466
1467 Elf_Word
1468 get_vna_hash() const
1469 { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
1470
1471 Elf_Half
1472 get_vna_flags() const
1473 { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
1474
1475 Elf_Half
1476 get_vna_other() const
1477 { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
1478
1479 Elf_Word
1480 get_vna_name() const
1481 { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
1482
1483 Elf_Word
1484 get_vna_next() const
1485 { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
1486
1487 private:
1488 const internal::Vernaux_data* p_;
1489};
1490
1491
bae7f79e
ILT
1492} // End namespace elfcpp.
1493
1494#endif // !defined(ELFPCP_H)
This page took 0.107813 seconds and 4 git commands to generate.