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