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