* elfcpp.h (NT_VERSION, NT_ARCH): Define as enum constants.
[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 // Note descriptor type codes for notes in a non-core file with an
698 // empty name.
699
700 enum
701 {
702   // A version string.
703   NT_VERSION = 1,
704   // An architecture string.
705   NT_ARCH = 2
706 };
707
708 // Note descriptor type codes for notes in a non-core file with the
709 // name "GNU".
710
711 enum
712 {
713   // The minimum ABI level.  This is used by the dynamic linker to
714   // describe the minimal kernel version on which a shared library may
715   // be used.  Th value should be four words.  Word 0 is an OS
716   // descriptor (see below).  Word 1 is the major version of the ABI.
717   // Word 2 is the minor version.  Word 3 is the subminor version.
718   NT_GNU_ABI_TAG = 1,
719   // Hardware capabilities information.  Word 0 is the number of
720   // entries.  Word 1 is a bitmask of enabled entries.  The rest of
721   // the descriptor is a series of entries, where each entry is a
722   // single byte followed by a nul terminated string.  The byte gives
723   // the bit number to test if enabled in the bitmask.
724   NT_GNU_HWCAP = 2,
725   // The build ID as set by the linker's --build-id option.  The
726   // format of the descriptor depends on the build ID style.
727   NT_GNU_BUILD_ID = 3,
728   // The version of gold used to link.  Th descriptor is just a
729   // string.
730   NT_GNU_GOLD_VERSION = 4
731 };
732
733 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
734
735 enum
736 {
737   ELF_NOTE_OS_LINUX = 0,
738   ELF_NOTE_OS_GNU = 1,
739   ELF_NOTE_OS_SOLARIS2 = 2,
740   ELF_NOTE_OS_FREEBSD = 3,
741   ELF_NOTE_OS_NETBSD = 4,
742   ELF_NOTE_OS_SYLLABLE = 5
743 };
744
745 } // End namespace elfcpp.
746
747 // Include internal details after defining the types.
748 #include "elfcpp_internal.h"
749
750 namespace elfcpp
751 {
752
753 // The offset of the ELF file header in the ELF file.
754
755 const int file_header_offset = 0;
756
757 // ELF structure sizes.
758
759 template<int size>
760 struct Elf_sizes
761 {
762   // Size of ELF file header.
763   static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
764   // Size of ELF segment header.
765   static const int phdr_size = sizeof(internal::Phdr_data<size>);
766   // Size of ELF section header.
767   static const int shdr_size = sizeof(internal::Shdr_data<size>);
768   // Size of ELF symbol table entry.
769   static const int sym_size = sizeof(internal::Sym_data<size>);
770   // Sizes of ELF reloc entries.
771   static const int rel_size = sizeof(internal::Rel_data<size>);
772   static const int rela_size = sizeof(internal::Rela_data<size>);
773   // Size of ELF dynamic entry.
774   static const int dyn_size = sizeof(internal::Dyn_data<size>);
775   // Size of ELF version structures.
776   static const int verdef_size = sizeof(internal::Verdef_data);
777   static const int verdaux_size = sizeof(internal::Verdaux_data);
778   static const int verneed_size = sizeof(internal::Verneed_data);
779   static const int vernaux_size = sizeof(internal::Vernaux_data);
780 };
781
782 // Accessor class for the ELF file header.
783
784 template<int size, bool big_endian>
785 class Ehdr
786 {
787  public:
788   Ehdr(const unsigned char* p)
789     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
790   { }
791
792   template<typename File>
793   Ehdr(File* file, typename File::Location loc)
794     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
795            file->view(loc.file_offset, loc.data_size).data()))
796   { }
797
798   const unsigned char*
799   get_e_ident() const
800   { return this->p_->e_ident; }
801
802   Elf_Half
803   get_e_type() const
804   { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
805
806   Elf_Half
807   get_e_machine() const
808   { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
809
810   Elf_Word
811   get_e_version() const
812   { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
813
814   typename Elf_types<size>::Elf_Addr
815   get_e_entry() const
816   { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
817
818   typename Elf_types<size>::Elf_Off
819   get_e_phoff() const
820   { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
821
822   typename Elf_types<size>::Elf_Off
823   get_e_shoff() const
824   { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
825
826   Elf_Word
827   get_e_flags() const
828   { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
829
830   Elf_Half
831   get_e_ehsize() const
832   { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
833
834   Elf_Half
835   get_e_phentsize() const
836   { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
837
838   Elf_Half
839   get_e_phnum() const
840   { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
841
842   Elf_Half
843   get_e_shentsize() const
844   { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
845
846   Elf_Half
847   get_e_shnum() const
848   { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
849
850   Elf_Half
851   get_e_shstrndx() const
852   { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
853
854  private:
855   const internal::Ehdr_data<size>* p_;
856 };
857
858 // Write class for the ELF file header.
859
860 template<int size, bool big_endian>
861 class Ehdr_write
862 {
863  public:
864   Ehdr_write(unsigned char* p)
865     : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
866   { }
867
868   void
869   put_e_ident(const unsigned char v[EI_NIDENT]) const
870   { memcpy(this->p_->e_ident, v, EI_NIDENT); }
871
872   void
873   put_e_type(Elf_Half v)
874   { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
875   
876   void
877   put_e_machine(Elf_Half v)
878   { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
879
880   void
881   put_e_version(Elf_Word v)
882   { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
883
884   void
885   put_e_entry(typename Elf_types<size>::Elf_Addr v)
886   { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
887
888   void
889   put_e_phoff(typename Elf_types<size>::Elf_Off v)
890   { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
891
892   void
893   put_e_shoff(typename Elf_types<size>::Elf_Off v)
894   { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
895
896   void
897   put_e_flags(Elf_Word v)
898   { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
899
900   void
901   put_e_ehsize(Elf_Half v)
902   { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
903
904   void
905   put_e_phentsize(Elf_Half v)
906   { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
907
908   void
909   put_e_phnum(Elf_Half v)
910   { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
911
912   void
913   put_e_shentsize(Elf_Half v)
914   { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
915
916   void
917   put_e_shnum(Elf_Half v)
918   { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
919
920   void
921   put_e_shstrndx(Elf_Half v)
922   { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
923
924  private:
925   internal::Ehdr_data<size>* p_;
926 };
927
928 // Accessor class for an ELF section header.
929
930 template<int size, bool big_endian>
931 class Shdr
932 {
933  public:
934   Shdr(const unsigned char* p)
935     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
936   { }
937
938   template<typename File>
939   Shdr(File* file, typename File::Location loc)
940     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
941            file->view(loc.file_offset, loc.data_size).data()))
942   { }
943
944   Elf_Word
945   get_sh_name() const
946   { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
947
948   Elf_Word
949   get_sh_type() const
950   { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
951
952   typename Elf_types<size>::Elf_WXword
953   get_sh_flags() const
954   { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
955
956   typename Elf_types<size>::Elf_Addr
957   get_sh_addr() const
958   { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
959
960   typename Elf_types<size>::Elf_Off
961   get_sh_offset() const
962   { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
963
964   typename Elf_types<size>::Elf_WXword
965   get_sh_size() const
966   { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
967
968   Elf_Word
969   get_sh_link() const
970   { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
971
972   Elf_Word
973   get_sh_info() const
974   { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
975
976   typename Elf_types<size>::Elf_WXword
977   get_sh_addralign() const
978   { return
979       Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
980
981   typename Elf_types<size>::Elf_WXword
982   get_sh_entsize() const
983   { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
984
985  private:
986   const internal::Shdr_data<size>* p_;
987 };
988
989 // Write class for an ELF section header.
990
991 template<int size, bool big_endian>
992 class Shdr_write
993 {
994  public:
995   Shdr_write(unsigned char* p)
996     : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
997   { }
998
999   void
1000   put_sh_name(Elf_Word v)
1001   { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
1002
1003   void
1004   put_sh_type(Elf_Word v)
1005   { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
1006
1007   void
1008   put_sh_flags(typename Elf_types<size>::Elf_WXword v)
1009   { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
1010
1011   void
1012   put_sh_addr(typename Elf_types<size>::Elf_Addr v)
1013   { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
1014
1015   void
1016   put_sh_offset(typename Elf_types<size>::Elf_Off v)
1017   { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
1018
1019   void
1020   put_sh_size(typename Elf_types<size>::Elf_WXword v)
1021   { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
1022
1023   void
1024   put_sh_link(Elf_Word v)
1025   { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
1026
1027   void
1028   put_sh_info(Elf_Word v)
1029   { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
1030
1031   void
1032   put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
1033   { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
1034
1035   void
1036   put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
1037   { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
1038
1039  private:
1040   internal::Shdr_data<size>* p_;
1041 };
1042
1043 // Accessor class for an ELF segment header.
1044
1045 template<int size, bool big_endian>
1046 class Phdr
1047 {
1048  public:
1049   Phdr(const unsigned char* p)
1050     : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
1051   { }
1052
1053   template<typename File>
1054   Phdr(File* file, typename File::Location loc)
1055     : p_(reinterpret_cast<internal::Phdr_data<size>*>(
1056            file->view(loc.file_offset, loc.data_size).data()))
1057   { }
1058
1059   Elf_Word
1060   get_p_type() const
1061   { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
1062
1063   typename Elf_types<size>::Elf_Off
1064   get_p_offset() const
1065   { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
1066
1067   typename Elf_types<size>::Elf_Addr
1068   get_p_vaddr() const
1069   { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
1070
1071   typename Elf_types<size>::Elf_Addr
1072   get_p_paddr() const
1073   { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
1074
1075   typename Elf_types<size>::Elf_WXword
1076   get_p_filesz() const
1077   { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
1078
1079   typename Elf_types<size>::Elf_WXword
1080   get_p_memsz() const
1081   { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
1082
1083   Elf_Word
1084   get_p_flags() const
1085   { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
1086
1087   typename Elf_types<size>::Elf_WXword
1088   get_p_align() const
1089   { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
1090
1091  private:
1092   const internal::Phdr_data<size>* p_;
1093 };
1094
1095 // Write class for an ELF segment header.
1096
1097 template<int size, bool big_endian>
1098 class Phdr_write
1099 {
1100  public:
1101   Phdr_write(unsigned char* p)
1102     : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
1103   { }
1104
1105   void
1106   put_p_type(Elf_Word v)
1107   { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
1108
1109   void
1110   put_p_offset(typename Elf_types<size>::Elf_Off v)
1111   { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
1112
1113   void
1114   put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
1115   { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
1116
1117   void
1118   put_p_paddr(typename Elf_types<size>::Elf_Addr v)
1119   { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
1120
1121   void
1122   put_p_filesz(typename Elf_types<size>::Elf_WXword v)
1123   { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
1124
1125   void
1126   put_p_memsz(typename Elf_types<size>::Elf_WXword v)
1127   { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
1128
1129   void
1130   put_p_flags(Elf_Word v)
1131   { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
1132
1133   void
1134   put_p_align(typename Elf_types<size>::Elf_WXword v)
1135   { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
1136
1137  private:
1138   internal::Phdr_data<size>* p_;
1139 };
1140
1141 // Accessor class for an ELF symbol table entry.
1142
1143 template<int size, bool big_endian>
1144 class Sym
1145 {
1146  public:
1147   Sym(const unsigned char* p)
1148     : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
1149   { }
1150
1151   template<typename File>
1152   Sym(File* file, typename File::Location loc)
1153     : p_(reinterpret_cast<const internal::Sym_data<size>*>(
1154            file->view(loc.file_offset, loc.data_size).data()))
1155   { }
1156
1157   Elf_Word
1158   get_st_name() const
1159   { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
1160
1161   typename Elf_types<size>::Elf_Addr
1162   get_st_value() const
1163   { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
1164
1165   typename Elf_types<size>::Elf_WXword
1166   get_st_size() const
1167   { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
1168
1169   unsigned char
1170   get_st_info() const
1171   { return this->p_->st_info; }
1172
1173   STB
1174   get_st_bind() const
1175   { return elf_st_bind(this->get_st_info()); }
1176
1177   STT
1178   get_st_type() const
1179   { return elf_st_type(this->get_st_info()); }
1180
1181   unsigned char
1182   get_st_other() const
1183   { return this->p_->st_other; }
1184
1185   STV
1186   get_st_visibility() const
1187   { return elf_st_visibility(this->get_st_other()); }
1188
1189   unsigned char
1190   get_st_nonvis() const
1191   { return elf_st_nonvis(this->get_st_other()); }
1192
1193   Elf_Half
1194   get_st_shndx() const
1195   { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
1196
1197  private:
1198   const internal::Sym_data<size>* p_;
1199 };
1200
1201 // Writer class for an ELF symbol table entry.
1202
1203 template<int size, bool big_endian>
1204 class Sym_write
1205 {
1206  public:
1207   Sym_write(unsigned char* p)
1208     : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
1209   { }
1210
1211   void
1212   put_st_name(Elf_Word v)
1213   { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
1214
1215   void
1216   put_st_value(typename Elf_types<size>::Elf_Addr v)
1217   { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
1218
1219   void
1220   put_st_size(typename Elf_types<size>::Elf_WXword v)
1221   { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
1222
1223   void
1224   put_st_info(unsigned char v)
1225   { this->p_->st_info = v; }
1226
1227   void
1228   put_st_info(STB bind, STT type)
1229   { this->p_->st_info = elf_st_info(bind, type); }
1230
1231   void
1232   put_st_other(unsigned char v)
1233   { this->p_->st_other = v; }
1234
1235   void
1236   put_st_other(STV vis, unsigned char nonvis)
1237   { this->p_->st_other = elf_st_other(vis, nonvis); }
1238
1239   void
1240   put_st_shndx(Elf_Half v)
1241   { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
1242
1243   Sym<size, big_endian>
1244   sym()
1245   { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
1246
1247  private:
1248   internal::Sym_data<size>* p_;
1249 };
1250
1251 // Accessor classes for an ELF REL relocation entry.
1252
1253 template<int size, bool big_endian>
1254 class Rel
1255 {
1256  public:
1257   Rel(const unsigned char* p)
1258     : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
1259   { }
1260
1261   template<typename File>
1262   Rel(File* file, typename File::Location loc)
1263     : p_(reinterpret_cast<const internal::Rel_data<size>*>(
1264            file->view(loc.file_offset, loc.data_size).data()))
1265   { }
1266
1267   typename Elf_types<size>::Elf_Addr
1268   get_r_offset() const
1269   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1270
1271   typename Elf_types<size>::Elf_WXword
1272   get_r_info() const
1273   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1274
1275  private:
1276   const internal::Rel_data<size>* p_;
1277 };
1278
1279 // Writer class for an ELF Rel relocation.
1280
1281 template<int size, bool big_endian>
1282 class Rel_write
1283 {
1284  public:
1285   Rel_write(unsigned char* p)
1286     : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
1287   { }
1288
1289   void
1290   put_r_offset(typename Elf_types<size>::Elf_Addr v)
1291   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1292
1293   void
1294   put_r_info(typename Elf_types<size>::Elf_WXword v)
1295   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1296
1297  private:
1298   internal::Rel_data<size>* p_;
1299 };
1300
1301 // Accessor class for an ELF Rela relocation.
1302
1303 template<int size, bool big_endian>
1304 class Rela
1305 {
1306  public:
1307   Rela(const unsigned char* p)
1308     : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
1309   { }
1310
1311   template<typename File>
1312   Rela(File* file, typename File::Location loc)
1313     : p_(reinterpret_cast<const internal::Rela_data<size>*>(
1314            file->view(loc.file_offset, loc.data_size).data()))
1315   { }
1316
1317   typename Elf_types<size>::Elf_Addr
1318   get_r_offset() const
1319   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1320
1321   typename Elf_types<size>::Elf_WXword
1322   get_r_info() const
1323   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1324
1325   typename Elf_types<size>::Elf_Swxword
1326   get_r_addend() const
1327   { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
1328
1329  private:
1330   const internal::Rela_data<size>* p_;
1331 };
1332
1333 // Writer class for an ELF Rela relocation.
1334
1335 template<int size, bool big_endian>
1336 class Rela_write
1337 {
1338  public:
1339   Rela_write(unsigned char* p)
1340     : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
1341   { }
1342
1343   void
1344   put_r_offset(typename Elf_types<size>::Elf_Addr v)
1345   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1346
1347   void
1348   put_r_info(typename Elf_types<size>::Elf_WXword v)
1349   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1350
1351   void
1352   put_r_addend(typename Elf_types<size>::Elf_Swxword v)
1353   { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
1354
1355  private:
1356   internal::Rela_data<size>* p_;
1357 };
1358
1359 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1360 // PT_DYNAMIC segment.
1361
1362 template<int size, bool big_endian>
1363 class Dyn
1364 {
1365  public:
1366   Dyn(const unsigned char* p)
1367     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
1368   { }
1369
1370   template<typename File>
1371   Dyn(File* file, typename File::Location loc)
1372     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
1373            file->view(loc.file_offset, loc.data_size).data()))
1374   { }
1375
1376   typename Elf_types<size>::Elf_Swxword
1377   get_d_tag() const
1378   { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
1379
1380   typename Elf_types<size>::Elf_WXword
1381   get_d_val() const
1382   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1383
1384   typename Elf_types<size>::Elf_Addr
1385   get_d_ptr() const
1386   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1387
1388  private:
1389   const internal::Dyn_data<size>* p_;
1390 };
1391
1392 // Write class for an entry in the SHT_DYNAMIC section.
1393
1394 template<int size, bool big_endian>
1395 class Dyn_write
1396 {
1397  public:
1398   Dyn_write(unsigned char* p)
1399     : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
1400   { }
1401
1402   void
1403   put_d_tag(typename Elf_types<size>::Elf_Swxword v)
1404   { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
1405
1406   void
1407   put_d_val(typename Elf_types<size>::Elf_WXword v)
1408   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1409
1410   void
1411   put_d_ptr(typename Elf_types<size>::Elf_Addr v)
1412   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1413
1414  private:
1415   internal::Dyn_data<size>* p_;
1416 };
1417
1418 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1419
1420 template<int size, bool big_endian>
1421 class Verdef
1422 {
1423  public:
1424   Verdef(const unsigned char* p)
1425     : p_(reinterpret_cast<const internal::Verdef_data*>(p))
1426   { }
1427
1428   template<typename File>
1429   Verdef(File* file, typename File::Location loc)
1430     : p_(reinterpret_cast<const internal::Verdef_data*>(
1431            file->view(loc.file_offset, loc.data_size).data()))
1432   { }
1433
1434   Elf_Half
1435   get_vd_version() const
1436   { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
1437
1438   Elf_Half
1439   get_vd_flags() const
1440   { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
1441
1442   Elf_Half
1443   get_vd_ndx() const
1444   { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
1445
1446   Elf_Half
1447   get_vd_cnt() const
1448   { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
1449
1450   Elf_Word
1451   get_vd_hash() const
1452   { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
1453
1454   Elf_Word
1455   get_vd_aux() const
1456   { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
1457
1458   Elf_Word
1459   get_vd_next() const
1460   { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
1461
1462  private:
1463   const internal::Verdef_data* p_;
1464 };
1465
1466 template<int size, bool big_endian>
1467 class Verdef_write
1468 {
1469  public:
1470   Verdef_write(unsigned char* p)
1471     : p_(reinterpret_cast<internal::Verdef_data*>(p))
1472   { }
1473
1474   void
1475   set_vd_version(Elf_Half v)
1476   { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
1477
1478   void
1479   set_vd_flags(Elf_Half v)
1480   { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
1481
1482   void
1483   set_vd_ndx(Elf_Half v)
1484   { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
1485
1486   void
1487   set_vd_cnt(Elf_Half v)
1488   { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
1489
1490   void
1491   set_vd_hash(Elf_Word v)
1492   { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
1493
1494   void
1495   set_vd_aux(Elf_Word v)
1496   { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
1497
1498   void
1499   set_vd_next(Elf_Word v)
1500   { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
1501
1502  private:
1503   internal::Verdef_data* p_;
1504 };
1505
1506 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1507 // section.
1508
1509 template<int size, bool big_endian>
1510 class Verdaux
1511 {
1512  public:
1513   Verdaux(const unsigned char* p)
1514     : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
1515   { }
1516
1517   template<typename File>
1518   Verdaux(File* file, typename File::Location loc)
1519     : p_(reinterpret_cast<const internal::Verdaux_data*>(
1520            file->view(loc.file_offset, loc.data_size).data()))
1521   { }
1522
1523   Elf_Word
1524   get_vda_name() const
1525   { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
1526
1527   Elf_Word
1528   get_vda_next() const
1529   { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
1530
1531  private:
1532   const internal::Verdaux_data* p_;
1533 };
1534
1535 template<int size, bool big_endian>
1536 class Verdaux_write
1537 {
1538  public:
1539   Verdaux_write(unsigned char* p)
1540     : p_(reinterpret_cast<internal::Verdaux_data*>(p))
1541   { }
1542
1543   void
1544   set_vda_name(Elf_Word v)
1545   { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
1546
1547   void
1548   set_vda_next(Elf_Word v)
1549   { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
1550
1551  private:
1552   internal::Verdaux_data* p_;
1553 };
1554
1555 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1556
1557 template<int size, bool big_endian>
1558 class Verneed
1559 {
1560  public:
1561   Verneed(const unsigned char* p)
1562     : p_(reinterpret_cast<const internal::Verneed_data*>(p))
1563   { }
1564
1565   template<typename File>
1566   Verneed(File* file, typename File::Location loc)
1567     : p_(reinterpret_cast<const internal::Verneed_data*>(
1568            file->view(loc.file_offset, loc.data_size).data()))
1569   { }
1570
1571   Elf_Half
1572   get_vn_version() const
1573   { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
1574
1575   Elf_Half
1576   get_vn_cnt() const
1577   { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
1578
1579   Elf_Word
1580   get_vn_file() const
1581   { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
1582
1583   Elf_Word
1584   get_vn_aux() const
1585   { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
1586
1587   Elf_Word
1588   get_vn_next() const
1589   { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
1590
1591  private:
1592   const internal::Verneed_data* p_;
1593 };
1594
1595 template<int size, bool big_endian>
1596 class Verneed_write
1597 {
1598  public:
1599   Verneed_write(unsigned char* p)
1600     : p_(reinterpret_cast<internal::Verneed_data*>(p))
1601   { }
1602
1603   void
1604   set_vn_version(Elf_Half v)
1605   { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
1606
1607   void
1608   set_vn_cnt(Elf_Half v)
1609   { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
1610
1611   void
1612   set_vn_file(Elf_Word v)
1613   { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
1614
1615   void
1616   set_vn_aux(Elf_Word v)
1617   { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
1618
1619   void
1620   set_vn_next(Elf_Word v)
1621   { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
1622
1623  private:
1624   internal::Verneed_data* p_;
1625 };
1626
1627 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1628 // section.
1629
1630 template<int size, bool big_endian>
1631 class Vernaux
1632 {
1633  public:
1634   Vernaux(const unsigned char* p)
1635     : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
1636   { }
1637
1638   template<typename File>
1639   Vernaux(File* file, typename File::Location loc)
1640     : p_(reinterpret_cast<const internal::Vernaux_data*>(
1641            file->view(loc.file_offset, loc.data_size).data()))
1642   { }
1643
1644   Elf_Word
1645   get_vna_hash() const
1646   { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
1647
1648   Elf_Half
1649   get_vna_flags() const
1650   { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
1651
1652   Elf_Half
1653   get_vna_other() const
1654   { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
1655
1656   Elf_Word
1657   get_vna_name() const
1658   { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
1659
1660   Elf_Word
1661   get_vna_next() const
1662   { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
1663
1664  private:
1665   const internal::Vernaux_data* p_;
1666 };
1667
1668 template<int size, bool big_endian>
1669 class Vernaux_write
1670 {
1671  public:
1672   Vernaux_write(unsigned char* p)
1673     : p_(reinterpret_cast<internal::Vernaux_data*>(p))
1674   { }
1675
1676   void
1677   set_vna_hash(Elf_Word v)
1678   { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
1679
1680   void
1681   set_vna_flags(Elf_Half v)
1682   { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
1683
1684   void
1685   set_vna_other(Elf_Half v)
1686   { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
1687
1688   void
1689   set_vna_name(Elf_Word v)
1690   { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
1691
1692   void
1693   set_vna_next(Elf_Word v)
1694   { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
1695
1696  private:
1697   internal::Vernaux_data* p_;
1698 };
1699
1700 } // End namespace elfcpp.
1701
1702 #endif // !defined(ELFPCP_H)