xref: /netbsd-src/external/gpl3/binutils/dist/elfcpp/elfcpp.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1 // elfcpp.h -- main header file for elfcpp    -*- C++ -*-
2 
3 // Copyright (C) 2006-2024 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_GNU = 3,
133   // ELFOSABI_LINUX is an alias for ELFOSABI_GNU.
134   ELFOSABI_LINUX = 3,
135   ELFOSABI_SOLARIS = 6,
136   ELFOSABI_AIX = 7,
137   ELFOSABI_IRIX = 8,
138   ELFOSABI_FREEBSD = 9,
139   ELFOSABI_TRU64 = 10,
140   ELFOSABI_MODESTO = 11,
141   ELFOSABI_OPENBSD = 12,
142   ELFOSABI_OPENVMS = 13,
143   ELFOSABI_NSK = 14,
144   ELFOSABI_AROS = 15,
145   // A GNU extension for the ARM.
146   ELFOSABI_ARM = 97,
147   // A GNU extension for the MSP.
148   ELFOSABI_STANDALONE = 255
149 };
150 
151 // The valid values found in the Ehdr e_type field.
152 
153 enum ET
154 {
155   ET_NONE = 0,
156   ET_REL = 1,
157   ET_EXEC = 2,
158   ET_DYN = 3,
159   ET_CORE = 4,
160   ET_LOOS = 0xfe00,
161   ET_HIOS = 0xfeff,
162   ET_LOPROC = 0xff00,
163   ET_HIPROC = 0xffff
164 };
165 
166 // The valid values found in the Ehdr e_machine field.
167 
168 enum EM
169 {
170   EM_NONE = 0,
171   EM_M32 = 1,
172   EM_SPARC = 2,
173   EM_386 = 3,
174   EM_68K = 4,
175   EM_88K = 5,
176   EM_IAMCU = 6,
177   EM_860 = 7,
178   EM_MIPS = 8,
179   EM_S370 = 9,
180   EM_MIPS_RS3_LE = 10,
181   // 11 was the old Sparc V9 ABI.
182   // 12 through 14 are reserved.
183   EM_PARISC = 15,
184   // 16 is reserved.
185   // Some old PowerPC object files use 17.
186   EM_VPP500 = 17,
187   EM_SPARC32PLUS = 18,
188   EM_960 = 19,
189   EM_PPC = 20,
190   EM_PPC64 = 21,
191   EM_S390 = 22,
192   // 23 through 35 are served.
193   EM_V800 = 36,
194   EM_FR20 = 37,
195   EM_RH32 = 38,
196   EM_RCE = 39,
197   EM_ARM = 40,
198   EM_ALPHA = 41,
199   EM_SH = 42,
200   EM_SPARCV9 = 43,
201   EM_TRICORE = 44,
202   EM_ARC = 45,
203   EM_H8_300 = 46,
204   EM_H8_300H = 47,
205   EM_H8S = 48,
206   EM_H8_500 = 49,
207   EM_IA_64 = 50,
208   EM_MIPS_X = 51,
209   EM_COLDFIRE = 52,
210   EM_68HC12 = 53,
211   EM_MMA = 54,
212   EM_PCP = 55,
213   EM_NCPU = 56,
214   EM_NDR1 = 57,
215   EM_STARCORE = 58,
216   EM_ME16 = 59,
217   EM_ST100 = 60,
218   EM_TINYJ = 61,
219   EM_X86_64 = 62,
220   EM_PDSP = 63,
221   EM_PDP10 = 64,
222   EM_PDP11 = 65,
223   EM_FX66 = 66,
224   EM_ST9PLUS = 67,
225   EM_ST7 = 68,
226   EM_68HC16 = 69,
227   EM_68HC11 = 70,
228   EM_68HC08 = 71,
229   EM_68HC05 = 72,
230   EM_SVX = 73,
231   EM_ST19 = 74,
232   EM_VAX = 75,
233   EM_CRIS = 76,
234   EM_JAVELIN = 77,
235   EM_FIREPATH = 78,
236   EM_ZSP = 79,
237   EM_MMIX = 80,
238   EM_HUANY = 81,
239   EM_PRISM = 82,
240   EM_AVR = 83,
241   EM_FR30 = 84,
242   EM_D10V = 85,
243   EM_D30V = 86,
244   EM_V850 = 87,
245   EM_M32R = 88,
246   EM_MN10300 = 89,
247   EM_MN10200 = 90,
248   EM_PJ = 91,
249   EM_OR1K = 92,
250   EM_ARC_A5 = 93,
251   EM_XTENSA = 94,
252   EM_VIDEOCORE = 95,
253   EM_TMM_GPP = 96,
254   EM_NS32K = 97,
255   EM_TPC = 98,
256   // Some old picoJava object files use 99 (EM_PJ is correct).
257   EM_SNP1K = 99,
258   EM_ST200 = 100,
259   EM_IP2K = 101,
260   EM_MAX = 102,
261   EM_CR = 103,
262   EM_F2MC16 = 104,
263   EM_MSP430 = 105,
264   EM_BLACKFIN = 106,
265   EM_SE_C33 = 107,
266   EM_SEP = 108,
267   EM_ARCA = 109,
268   EM_UNICORE = 110,
269   EM_ALTERA_NIOS2 = 113,
270   EM_CRX = 114,
271   EM_TI_PRU = 144,
272   EM_AARCH64 = 183,
273   EM_TILEGX = 191,
274   // The Morph MT.
275   EM_MT = 0x2530,
276   // DLX.
277   EM_DLX = 0x5aa5,
278   // FRV.
279   EM_FRV = 0x5441,
280   // Infineon Technologies 16-bit microcontroller with C166-V2 core.
281   EM_X16X = 0x4688,
282   // Xstorym16
283   EM_XSTORMY16 = 0xad45,
284   // Renesas M32C
285   EM_M32C = 0xfeb0,
286   // Vitesse IQ2000
287   EM_IQ2000 = 0xfeba,
288   // NIOS
289   EM_NIOS32 = 0xfebb
290   // Old AVR objects used 0x1057 (EM_AVR is correct).
291   // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
292   // Old FR30 objects used 0x3330 (EM_FR30 is correct).
293   // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OR1K is correct).
294   // Old D10V objects used 0x7650 (EM_D10V is correct).
295   // Old D30V objects used 0x7676 (EM_D30V is correct).
296   // Old IP2X objects used 0x8217 (EM_IP2K is correct).
297   // Old PowerPC objects used 0x9025 (EM_PPC is correct).
298   // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
299   // Old M32R objects used 0x9041 (EM_M32R is correct).
300   // Old V850 objects used 0x9080 (EM_V850 is correct).
301   // Old S/390 objects used 0xa390 (EM_S390 is correct).
302   // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
303   // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
304   // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
305 };
306 
307 // A special value found in the Ehdr e_phnum field.
308 
309 enum
310 {
311   // Number of program segments stored in sh_info field of first
312   // section headre.
313   PN_XNUM = 0xffff
314 };
315 
316 // Special section indices.
317 
318 enum
319 {
320   SHN_UNDEF = 0,
321   SHN_LORESERVE = 0xff00,
322   SHN_LOPROC = 0xff00,
323   SHN_HIPROC = 0xff1f,
324   SHN_LOOS = 0xff20,
325   SHN_HIOS = 0xff3f,
326   SHN_ABS = 0xfff1,
327   SHN_COMMON = 0xfff2,
328   SHN_XINDEX = 0xffff,
329   SHN_HIRESERVE = 0xffff,
330 
331   // Provide for initial and final section ordering in conjunction
332   // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
333   SHN_BEFORE = 0xff00,
334   SHN_AFTER = 0xff01,
335 
336   // x86_64 specific large common symbol.
337   SHN_X86_64_LCOMMON = 0xff02
338 };
339 
340 // The valid values found in the Shdr sh_type field.
341 
342 enum SHT
343 {
344   SHT_NULL = 0,
345   SHT_PROGBITS = 1,
346   SHT_SYMTAB = 2,
347   SHT_STRTAB = 3,
348   SHT_RELA = 4,
349   SHT_HASH = 5,
350   SHT_DYNAMIC = 6,
351   SHT_NOTE = 7,
352   SHT_NOBITS = 8,
353   SHT_REL = 9,
354   SHT_SHLIB = 10,
355   SHT_DYNSYM = 11,
356   SHT_INIT_ARRAY = 14,
357   SHT_FINI_ARRAY = 15,
358   SHT_PREINIT_ARRAY = 16,
359   SHT_GROUP = 17,
360   SHT_SYMTAB_SHNDX = 18,
361   SHT_LOOS = 0x60000000,
362   SHT_HIOS = 0x6fffffff,
363   SHT_LOPROC = 0x70000000,
364   SHT_HIPROC = 0x7fffffff,
365   SHT_LOUSER = 0x80000000,
366   SHT_HIUSER = 0xffffffff,
367   // The remaining values are not in the standard.
368   // Incremental build data.
369   SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700,
370   SHT_GNU_INCREMENTAL_SYMTAB = 0x6fff4701,
371   SHT_GNU_INCREMENTAL_RELOCS = 0x6fff4702,
372   SHT_GNU_INCREMENTAL_GOT_PLT = 0x6fff4703,
373   // Object attributes.
374   SHT_GNU_ATTRIBUTES = 0x6ffffff5,
375   // GNU style dynamic hash table.
376   SHT_GNU_HASH = 0x6ffffff6,
377   // List of prelink dependencies.
378   SHT_GNU_LIBLIST = 0x6ffffff7,
379   // Versions defined by file.
380   SHT_SUNW_verdef = 0x6ffffffd,
381   SHT_GNU_verdef = 0x6ffffffd,
382   // Versions needed by file.
383   SHT_SUNW_verneed = 0x6ffffffe,
384   SHT_GNU_verneed = 0x6ffffffe,
385   // Symbol versions,
386   SHT_SUNW_versym = 0x6fffffff,
387   SHT_GNU_versym = 0x6fffffff,
388 
389   SHT_SPARC_GOTDATA = 0x70000000,
390 
391   // ARM-specific section types.
392   // Exception Index table.
393   SHT_ARM_EXIDX = 0x70000001,
394   // BPABI DLL dynamic linking pre-emption map.
395   SHT_ARM_PREEMPTMAP = 0x70000002,
396   // Object file compatibility attributes.
397   SHT_ARM_ATTRIBUTES = 0x70000003,
398   // Support for debugging overlaid programs.
399   SHT_ARM_DEBUGOVERLAY = 0x70000004,
400   SHT_ARM_OVERLAYSECTION = 0x70000005,
401 
402   // x86_64 unwind information.
403   SHT_X86_64_UNWIND = 0x70000001,
404 
405   // MIPS-specific section types.
406   // Section contains register usage information.
407   SHT_MIPS_REGINFO = 0x70000006,
408   // Section contains miscellaneous options.
409   SHT_MIPS_OPTIONS = 0x7000000d,
410   // ABI related flags section.
411   SHT_MIPS_ABIFLAGS = 0x7000002a,
412 
413   // AARCH64-specific section type.
414   SHT_AARCH64_ATTRIBUTES = 0x70000003,
415 
416   // CSKY-specific section types.
417   // Object file compatibility attributes.
418   SHT_CSKY_ATTRIBUTES = 0x70000001,
419 
420   // Link editor is to sort the entries in this section based on the
421   // address specified in the associated symbol table entry.
422   SHT_ORDERED = 0x7fffffff
423 };
424 
425 // The valid bit flags found in the Shdr sh_flags field.
426 
427 enum SHF
428 {
429   SHF_WRITE = 0x1,
430   SHF_ALLOC = 0x2,
431   SHF_EXECINSTR = 0x4,
432   SHF_MERGE = 0x10,
433   SHF_STRINGS = 0x20,
434   SHF_INFO_LINK = 0x40,
435   SHF_LINK_ORDER = 0x80,
436   SHF_OS_NONCONFORMING = 0x100,
437   SHF_GROUP = 0x200,
438   SHF_TLS = 0x400,
439   SHF_COMPRESSED = 0x800,
440   SHF_MASKOS = 0x0ff00000,
441   SHF_GNU_RETAIN = 0x200000,
442   SHF_MASKPROC = 0xf0000000,
443 
444   // Indicates this section requires ordering in relation to
445   // other sections of the same type.  Ordered sections are
446   // combined within the section pointed to by the sh_link entry.
447   // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
448   // sorted section is to precede or follow, respectively, all
449   // other sections in the set being ordered.
450   SHF_ORDERED = 0x40000000,
451   // This section is excluded from input to the link-edit of an
452   // executable or shared object.  This flag is ignored if SHF_ALLOC
453   // is also set, or if relocations exist against the section.
454   SHF_EXCLUDE = 0x80000000,
455 
456   // Section with data that is GP relative addressable.
457   SHF_MIPS_GPREL = 0x10000000,
458 
459   // x86_64 specific large section.
460   SHF_X86_64_LARGE = 0x10000000
461 };
462 
463 // Values which appear in the first Elf_WXword of the section data
464 // of a SHF_COMPRESSED section.
465 enum
466 {
467   ELFCOMPRESS_ZLIB = 1,
468   ELFCOMPRESS_ZSTD = 2,
469   ELFCOMPRESS_LOOS = 0x60000000,
470   ELFCOMPRESS_HIOS = 0x6fffffff,
471   ELFCOMPRESS_LOPROC = 0x70000000,
472   ELFCOMPRESS_HIPROC = 0x7fffffff,
473 };
474 
475 // Bit flags which appear in the first 32-bit word of the section data
476 // of a SHT_GROUP section.
477 
478 enum
479 {
480   GRP_COMDAT = 0x1,
481   GRP_MASKOS = 0x0ff00000,
482   GRP_MASKPROC = 0xf0000000
483 };
484 
485 // The valid values found in the Phdr p_type field.
486 
487 enum PT
488 {
489   PT_NULL = 0,
490   PT_LOAD = 1,
491   PT_DYNAMIC = 2,
492   PT_INTERP = 3,
493   PT_NOTE = 4,
494   PT_SHLIB = 5,
495   PT_PHDR = 6,
496   PT_TLS = 7,
497   PT_LOOS = 0x60000000,
498   PT_HIOS = 0x6fffffff,
499   PT_LOPROC = 0x70000000,
500   PT_HIPROC = 0x7fffffff,
501   // The remaining values are not in the standard.
502   // Frame unwind information.
503   PT_GNU_EH_FRAME = 0x6474e550,
504   PT_SUNW_EH_FRAME = 0x6474e550,
505   // Stack flags.
506   PT_GNU_STACK = 0x6474e551,
507   // Read only after relocation.
508   PT_GNU_RELRO = 0x6474e552,
509   // Platform architecture compatibility information
510   PT_ARM_ARCHEXT = 0x70000000,
511   // Exception unwind tables
512   PT_ARM_EXIDX = 0x70000001,
513   // Register usage information.  Identifies one .reginfo section.
514   PT_MIPS_REGINFO =0x70000000,
515   // Runtime procedure table.
516   PT_MIPS_RTPROC = 0x70000001,
517   // .MIPS.options section.
518   PT_MIPS_OPTIONS = 0x70000002,
519   // .MIPS.abiflags section.
520   PT_MIPS_ABIFLAGS = 0x70000003,
521   // Platform architecture compatibility information
522   PT_AARCH64_ARCHEXT = 0x70000000,
523   // Exception unwind tables
524   PT_AARCH64_UNWIND = 0x70000001,
525   // 4k page table size
526   PT_S390_PGSTE = 0x70000000,
527 };
528 
529 // The valid bit flags found in the Phdr p_flags field.
530 
531 enum PF
532 {
533   PF_X = 0x1,
534   PF_W = 0x2,
535   PF_R = 0x4,
536   PF_MASKOS = 0x0ff00000,
537   PF_MASKPROC = 0xf0000000
538 };
539 
540 // Symbol binding from Sym st_info field.
541 
542 enum STB
543 {
544   STB_LOCAL = 0,
545   STB_GLOBAL = 1,
546   STB_WEAK = 2,
547   STB_LOOS = 10,
548   STB_GNU_UNIQUE = 10,
549   STB_HIOS = 12,
550   STB_LOPROC = 13,
551   STB_HIPROC = 15
552 };
553 
554 // Symbol types from Sym st_info field.
555 
556 enum STT
557 {
558   STT_NOTYPE = 0,
559   STT_OBJECT = 1,
560   STT_FUNC = 2,
561   STT_SECTION = 3,
562   STT_FILE = 4,
563   STT_COMMON = 5,
564   STT_TLS = 6,
565 
566   // GNU extension: symbol value points to a function which is called
567   // at runtime to determine the final value of the symbol.
568   STT_GNU_IFUNC = 10,
569 
570   STT_LOOS = 10,
571   STT_HIOS = 12,
572   STT_LOPROC = 13,
573   STT_HIPROC = 15,
574 
575   // The section type that must be used for register symbols on
576   // Sparc.  These symbols initialize a global register.
577   STT_SPARC_REGISTER = 13,
578 
579   // ARM: a THUMB function.  This is not defined in ARM ELF Specification but
580   // used by the GNU tool-chain.
581   STT_ARM_TFUNC = 13
582 };
583 
584 inline STB
585 elf_st_bind(unsigned char info)
586 {
587   return static_cast<STB>(info >> 4);
588 }
589 
590 inline STT
591 elf_st_type(unsigned char info)
592 {
593   return static_cast<STT>(info & 0xf);
594 }
595 
596 inline unsigned char
597 elf_st_info(STB bind, STT type)
598 {
599   return ((static_cast<unsigned char>(bind) << 4)
600 	  + (static_cast<unsigned char>(type) & 0xf));
601 }
602 
603 // Symbol visibility from Sym st_other field.
604 
605 enum STV
606 {
607   STV_DEFAULT = 0,
608   STV_INTERNAL = 1,
609   STV_HIDDEN = 2,
610   STV_PROTECTED = 3
611 };
612 
613 inline STV
614 elf_st_visibility(unsigned char other)
615 {
616   return static_cast<STV>(other & 0x3);
617 }
618 
619 inline unsigned char
620 elf_st_nonvis(unsigned char other)
621 {
622   return static_cast<STV>(other >> 2);
623 }
624 
625 inline unsigned char
626 elf_st_other(STV vis, unsigned char nonvis)
627 {
628   return ((nonvis << 2)
629 	  + (static_cast<unsigned char>(vis) & 3));
630 }
631 
632 // Reloc information from Rel/Rela r_info field.
633 
634 template<int size>
635 unsigned int
636 elf_r_sym(typename Elf_types<size>::Elf_WXword);
637 
638 template<>
639 inline unsigned int
640 elf_r_sym<32>(Elf_Word v)
641 {
642   return v >> 8;
643 }
644 
645 template<>
646 inline unsigned int
647 elf_r_sym<64>(Elf_Xword v)
648 {
649   return v >> 32;
650 }
651 
652 template<int size>
653 unsigned int
654 elf_r_type(typename Elf_types<size>::Elf_WXword);
655 
656 template<>
657 inline unsigned int
658 elf_r_type<32>(Elf_Word v)
659 {
660   return v & 0xff;
661 }
662 
663 template<>
664 inline unsigned int
665 elf_r_type<64>(Elf_Xword v)
666 {
667   return v & 0xffffffff;
668 }
669 
670 template<int size>
671 typename Elf_types<size>::Elf_WXword
672 elf_r_info(unsigned int s, unsigned int t);
673 
674 template<>
675 inline Elf_Word
676 elf_r_info<32>(unsigned int s, unsigned int t)
677 {
678   return (s << 8) + (t & 0xff);
679 }
680 
681 template<>
682 inline Elf_Xword
683 elf_r_info<64>(unsigned int s, unsigned int t)
684 {
685   return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
686 }
687 
688 // Dynamic tags found in the PT_DYNAMIC segment.
689 
690 enum DT
691 {
692   DT_NULL = 0,
693   DT_NEEDED = 1,
694   DT_PLTRELSZ = 2,
695   DT_PLTGOT = 3,
696   DT_HASH = 4,
697   DT_STRTAB = 5,
698   DT_SYMTAB = 6,
699   DT_RELA = 7,
700   DT_RELASZ = 8,
701   DT_RELAENT = 9,
702   DT_STRSZ = 10,
703   DT_SYMENT = 11,
704   DT_INIT = 12,
705   DT_FINI = 13,
706   DT_SONAME = 14,
707   DT_RPATH = 15,
708   DT_SYMBOLIC = 16,
709   DT_REL = 17,
710   DT_RELSZ = 18,
711   DT_RELENT = 19,
712   DT_PLTREL = 20,
713   DT_DEBUG = 21,
714   DT_TEXTREL = 22,
715   DT_JMPREL = 23,
716   DT_BIND_NOW = 24,
717   DT_INIT_ARRAY = 25,
718   DT_FINI_ARRAY = 26,
719   DT_INIT_ARRAYSZ = 27,
720   DT_FINI_ARRAYSZ = 28,
721   DT_RUNPATH = 29,
722   DT_FLAGS = 30,
723 
724   // This is used to mark a range of dynamic tags.  It is not really
725   // a tag value.
726   DT_ENCODING = 32,
727 
728   DT_PREINIT_ARRAY = 32,
729   DT_PREINIT_ARRAYSZ = 33,
730   DT_LOOS = 0x6000000d,
731   DT_HIOS = 0x6ffff000,
732   DT_LOPROC = 0x70000000,
733   DT_HIPROC = 0x7fffffff,
734 
735   // The remaining values are extensions used by GNU or Solaris.
736   DT_VALRNGLO = 0x6ffffd00,
737   DT_GNU_FLAGS_1 = 0x6ffffdf4,
738   DT_GNU_PRELINKED = 0x6ffffdf5,
739   DT_GNU_CONFLICTSZ = 0x6ffffdf6,
740   DT_GNU_LIBLISTSZ = 0x6ffffdf7,
741   DT_CHECKSUM = 0x6ffffdf8,
742   DT_PLTPADSZ = 0x6ffffdf9,
743   DT_MOVEENT = 0x6ffffdfa,
744   DT_MOVESZ = 0x6ffffdfb,
745   DT_FEATURE = 0x6ffffdfc,
746   DT_POSFLAG_1 = 0x6ffffdfd,
747   DT_SYMINSZ = 0x6ffffdfe,
748   DT_SYMINENT = 0x6ffffdff,
749   DT_VALRNGHI = 0x6ffffdff,
750 
751   DT_ADDRRNGLO = 0x6ffffe00,
752   DT_GNU_HASH = 0x6ffffef5,
753   DT_TLSDESC_PLT = 0x6ffffef6,
754   DT_TLSDESC_GOT = 0x6ffffef7,
755   DT_GNU_CONFLICT = 0x6ffffef8,
756   DT_GNU_LIBLIST = 0x6ffffef9,
757   DT_CONFIG = 0x6ffffefa,
758   DT_DEPAUDIT = 0x6ffffefb,
759   DT_AUDIT = 0x6ffffefc,
760   DT_PLTPAD = 0x6ffffefd,
761   DT_MOVETAB = 0x6ffffefe,
762   DT_SYMINFO = 0x6ffffeff,
763   DT_ADDRRNGHI = 0x6ffffeff,
764 
765   DT_RELACOUNT = 0x6ffffff9,
766   DT_RELCOUNT = 0x6ffffffa,
767   DT_FLAGS_1 = 0x6ffffffb,
768   DT_VERDEF = 0x6ffffffc,
769   DT_VERDEFNUM = 0x6ffffffd,
770   DT_VERNEED = 0x6ffffffe,
771   DT_VERNEEDNUM = 0x6fffffff,
772 
773   DT_VERSYM = 0x6ffffff0,
774 
775   // Specify the value of _GLOBAL_OFFSET_TABLE_.
776   DT_PPC_GOT = 0x70000000,
777 
778   // Specify whether various optimisations are possible.
779   DT_PPC_OPT = 0x70000001,
780 
781   // Specify the start of the .glink section.
782   DT_PPC64_GLINK = 0x70000000,
783 
784   // Specify the start and size of the .opd section.
785   DT_PPC64_OPD = 0x70000001,
786   DT_PPC64_OPDSZ = 0x70000002,
787 
788   // Specify whether various optimisations are possible.
789   DT_PPC64_OPT = 0x70000003,
790 
791   // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
792   // symbol table.  One dynamic entry exists for every STT_SPARC_REGISTER
793   // symbol in the symbol table.
794   DT_SPARC_REGISTER = 0x70000001,
795 
796   // MIPS specific dynamic array tags.
797   // 32 bit version number for runtime linker interface.
798   DT_MIPS_RLD_VERSION = 0x70000001,
799   // Time stamp.
800   DT_MIPS_TIME_STAMP = 0x70000002,
801   // Checksum of external strings and common sizes.
802   DT_MIPS_ICHECKSUM = 0x70000003,
803   // Index of version string in string table.
804   DT_MIPS_IVERSION = 0x70000004,
805   // 32 bits of flags.
806   DT_MIPS_FLAGS = 0x70000005,
807   // Base address of the segment.
808   DT_MIPS_BASE_ADDRESS = 0x70000006,
809   // ???
810   DT_MIPS_MSYM = 0x70000007,
811   // Address of .conflict section.
812   DT_MIPS_CONFLICT = 0x70000008,
813   // Address of .liblist section.
814   DT_MIPS_LIBLIST = 0x70000009,
815   // Number of local global offset table entries.
816   DT_MIPS_LOCAL_GOTNO = 0x7000000a,
817   // Number of entries in the .conflict section.
818   DT_MIPS_CONFLICTNO = 0x7000000b,
819   // Number of entries in the .liblist section.
820   DT_MIPS_LIBLISTNO = 0x70000010,
821   // Number of entries in the .dynsym section.
822   DT_MIPS_SYMTABNO = 0x70000011,
823   // Index of first external dynamic symbol not referenced locally.
824   DT_MIPS_UNREFEXTNO = 0x70000012,
825   // Index of first dynamic symbol in global offset table.
826   DT_MIPS_GOTSYM = 0x70000013,
827   // Number of page table entries in global offset table.
828   DT_MIPS_HIPAGENO = 0x70000014,
829   // Address of run time loader map, used for debugging.
830   DT_MIPS_RLD_MAP = 0x70000016,
831   // Delta C++ class definition.
832   DT_MIPS_DELTA_CLASS = 0x70000017,
833   // Number of entries in DT_MIPS_DELTA_CLASS.
834   DT_MIPS_DELTA_CLASS_NO = 0x70000018,
835   // Delta C++ class instances.
836   DT_MIPS_DELTA_INSTANCE = 0x70000019,
837   // Number of entries in DT_MIPS_DELTA_INSTANCE.
838   DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a,
839   // Delta relocations.
840   DT_MIPS_DELTA_RELOC = 0x7000001b,
841   // Number of entries in DT_MIPS_DELTA_RELOC.
842   DT_MIPS_DELTA_RELOC_NO = 0x7000001c,
843   // Delta symbols that Delta relocations refer to.
844   DT_MIPS_DELTA_SYM = 0x7000001d,
845   // Number of entries in DT_MIPS_DELTA_SYM.
846   DT_MIPS_DELTA_SYM_NO = 0x7000001e,
847   // Delta symbols that hold class declarations.
848   DT_MIPS_DELTA_CLASSSYM = 0x70000020,
849   // Number of entries in DT_MIPS_DELTA_CLASSSYM.
850   DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021,
851   // Flags indicating information about C++ flavor.
852   DT_MIPS_CXX_FLAGS = 0x70000022,
853   // Pixie information (???).
854   DT_MIPS_PIXIE_INIT = 0x70000023,
855   // Address of .MIPS.symlib
856   DT_MIPS_SYMBOL_LIB = 0x70000024,
857   // The GOT index of the first PTE for a segment
858   DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025,
859   // The GOT index of the first PTE for a local symbol
860   DT_MIPS_LOCAL_GOTIDX = 0x70000026,
861   // The GOT index of the first PTE for a hidden symbol
862   DT_MIPS_HIDDEN_GOTIDX = 0x70000027,
863   // The GOT index of the first PTE for a protected symbol
864   DT_MIPS_PROTECTED_GOTIDX = 0x70000028,
865   // Address of `.MIPS.options'.
866   DT_MIPS_OPTIONS = 0x70000029,
867   // Address of `.interface'.
868   DT_MIPS_INTERFACE = 0x7000002a,
869   // ???
870   DT_MIPS_DYNSTR_ALIGN = 0x7000002b,
871   // Size of the .interface section.
872   DT_MIPS_INTERFACE_SIZE = 0x7000002c,
873   // Size of rld_text_resolve function stored in the GOT.
874   DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d,
875   // Default suffix of DSO to be added by rld on dlopen() calls.
876   DT_MIPS_PERF_SUFFIX = 0x7000002e,
877   // Size of compact relocation section (O32).
878   DT_MIPS_COMPACT_SIZE = 0x7000002f,
879   // GP value for auxiliary GOTs.
880   DT_MIPS_GP_VALUE = 0x70000030,
881   // Address of auxiliary .dynamic.
882   DT_MIPS_AUX_DYNAMIC = 0x70000031,
883   // Address of the base of the PLTGOT.
884   DT_MIPS_PLTGOT = 0x70000032,
885   // Points to the base of a writable PLT.
886   DT_MIPS_RWPLT = 0x70000034,
887   // Relative offset of run time loader map, used for debugging.
888   DT_MIPS_RLD_MAP_REL = 0x70000035,
889 
890   DT_AUXILIARY = 0x7ffffffd,
891   DT_USED = 0x7ffffffe,
892   DT_FILTER = 0x7fffffff
893 };
894 
895 // Flags found in the DT_FLAGS dynamic element.
896 
897 enum DF
898 {
899   DF_ORIGIN = 0x1,
900   DF_SYMBOLIC = 0x2,
901   DF_TEXTREL = 0x4,
902   DF_BIND_NOW = 0x8,
903   DF_STATIC_TLS = 0x10
904 };
905 
906 // Flags found in the DT_FLAGS_1 dynamic element.
907 
908 enum DF_1
909 {
910   DF_1_NOW = 0x1,
911   DF_1_GLOBAL = 0x2,
912   DF_1_GROUP = 0x4,
913   DF_1_NODELETE = 0x8,
914   DF_1_LOADFLTR = 0x10,
915   DF_1_INITFIRST = 0x20,
916   DF_1_NOOPEN = 0x40,
917   DF_1_ORIGIN = 0x80,
918   DF_1_DIRECT = 0x100,
919   DF_1_TRANS = 0x200,
920   DF_1_INTERPOSE = 0x400,
921   DF_1_NODEFLIB = 0x800,
922   DF_1_NODUMP = 0x1000,
923   DF_1_CONLFAT = 0x2000,
924   DF_1_PIE = 0x08000000
925 };
926 
927 // Flags found in the DT_GNU_FLAGS_1 dynamic element.
928 enum DF_GNU_1
929 {
930   DF_GNU_1_UNIQUE = 0x1,
931 };
932 
933 // Version numbers which appear in the vd_version field of a Verdef
934 // structure.
935 
936 const int VER_DEF_NONE = 0;
937 const int VER_DEF_CURRENT = 1;
938 
939 // Version numbers which appear in the vn_version field of a Verneed
940 // structure.
941 
942 const int VER_NEED_NONE = 0;
943 const int VER_NEED_CURRENT = 1;
944 
945 // Bit flags which appear in vd_flags of Verdef and vna_flags of
946 // Vernaux.
947 
948 const int VER_FLG_BASE = 0x1;
949 const int VER_FLG_WEAK = 0x2;
950 const int VER_FLG_INFO = 0x4;
951 
952 // Special constants found in the SHT_GNU_versym entries.
953 
954 const int VER_NDX_LOCAL = 0;
955 const int VER_NDX_GLOBAL = 1;
956 
957 // A SHT_GNU_versym section holds 16-bit words.  This bit is set if
958 // the symbol is hidden and can only be seen when referenced using an
959 // explicit version number.  This is a GNU extension.
960 
961 const int VERSYM_HIDDEN = 0x8000;
962 
963 // This is the mask for the rest of the data in a word read from a
964 // SHT_GNU_versym section.
965 
966 const int VERSYM_VERSION = 0x7fff;
967 
968 // Note descriptor type codes for notes in a non-core file with an
969 // empty name.
970 
971 enum
972 {
973   // A version string.
974   NT_VERSION = 1,
975   // An architecture string.
976   NT_ARCH = 2
977 };
978 
979 // Note descriptor type codes for notes in a non-core file with the
980 // name "GNU".
981 
982 enum
983 {
984   // The minimum ABI level.  This is used by the dynamic linker to
985   // describe the minimal kernel version on which a shared library may
986   // be used.  Th value should be four words.  Word 0 is an OS
987   // descriptor (see below).  Word 1 is the major version of the ABI.
988   // Word 2 is the minor version.  Word 3 is the subminor version.
989   NT_GNU_ABI_TAG = 1,
990   // Hardware capabilities information.  Word 0 is the number of
991   // entries.  Word 1 is a bitmask of enabled entries.  The rest of
992   // the descriptor is a series of entries, where each entry is a
993   // single byte followed by a nul terminated string.  The byte gives
994   // the bit number to test if enabled in the bitmask.
995   NT_GNU_HWCAP = 2,
996   // The build ID as set by the linker's --build-id option.  The
997   // format of the descriptor depends on the build ID style.
998   NT_GNU_BUILD_ID = 3,
999   // The version of gold used to link.  Th descriptor is just a
1000   // string.
1001   NT_GNU_GOLD_VERSION = 4,
1002   // Program property note, as described in "Linux Extensions to the gABI".
1003   NT_GNU_PROPERTY_TYPE_0 = 5,
1004   // FDO .note.package notes as defined on https://systemd.io/ELF_PACKAGE_METADATA/
1005   FDO_PACKAGING_METADATA = 0xcafe1a7e
1006 };
1007 
1008 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
1009 
1010 enum
1011 {
1012   ELF_NOTE_OS_LINUX = 0,
1013   ELF_NOTE_OS_GNU = 1,
1014   ELF_NOTE_OS_SOLARIS2 = 2,
1015   ELF_NOTE_OS_FREEBSD = 3,
1016   ELF_NOTE_OS_NETBSD = 4,
1017   ELF_NOTE_OS_SYLLABLE = 5
1018 };
1019 
1020 // Program property types for NT_GNU_PROPERTY_TYPE_0.
1021 
1022 enum
1023 {
1024   GNU_PROPERTY_STACK_SIZE = 1,
1025   GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
1026   GNU_PROPERTY_LOPROC = 0xc0000000,
1027   GNU_PROPERTY_X86_COMPAT_ISA_1_USED = 0xc0000000,
1028   GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED = 0xc0000001,
1029   GNU_PROPERTY_X86_UINT32_AND_LO = 0xc0000002,
1030   GNU_PROPERTY_X86_UINT32_AND_HI = 0xc0007fff,
1031   GNU_PROPERTY_X86_UINT32_OR_LO = 0xc0008000,
1032   GNU_PROPERTY_X86_UINT32_OR_HI = 0xc000ffff,
1033   GNU_PROPERTY_X86_UINT32_OR_AND_LO = 0xc0010000,
1034   GNU_PROPERTY_X86_UINT32_OR_AND_HI = 0xc0017fff,
1035   GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 0,
1036   GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0,
1037   GNU_PROPERTY_X86_FEATURE_1_AND = GNU_PROPERTY_X86_UINT32_AND_LO + 0,
1038   GNU_PROPERTY_X86_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 2,
1039   GNU_PROPERTY_X86_FEATURE_2_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 1,
1040   GNU_PROPERTY_X86_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2,
1041   GNU_PROPERTY_X86_FEATURE_2_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1,
1042   GNU_PROPERTY_HIPROC = 0xdfffffff,
1043   GNU_PROPERTY_LOUSER = 0xe0000000,
1044   GNU_PROPERTY_HIUSER = 0xffffffff
1045 };
1046 
1047 } // End namespace elfcpp.
1048 
1049 // Include internal details after defining the types.
1050 #include "elfcpp_internal.h"
1051 
1052 namespace elfcpp
1053 {
1054 
1055 // The offset of the ELF file header in the ELF file.
1056 
1057 const int file_header_offset = 0;
1058 
1059 // ELF structure sizes.
1060 
1061 template<int size>
1062 struct Elf_sizes
1063 {
1064   // Size of ELF file header.
1065   static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
1066   // Size of ELF segment header.
1067   static const int phdr_size = sizeof(internal::Phdr_data<size>);
1068   // Size of ELF section header.
1069   static const int shdr_size = sizeof(internal::Shdr_data<size>);
1070   // Size of ELF compression header.
1071   static const int chdr_size = sizeof(internal::Chdr_data<size>);
1072   // Size of ELF symbol table entry.
1073   static const int sym_size = sizeof(internal::Sym_data<size>);
1074   // Sizes of ELF reloc entries.
1075   static const int rel_size = sizeof(internal::Rel_data<size>);
1076   static const int rela_size = sizeof(internal::Rela_data<size>);
1077   // Size of ELF dynamic entry.
1078   static const int dyn_size = sizeof(internal::Dyn_data<size>);
1079   // Size of ELF version structures.
1080   static const int verdef_size = sizeof(internal::Verdef_data);
1081   static const int verdaux_size = sizeof(internal::Verdaux_data);
1082   static const int verneed_size = sizeof(internal::Verneed_data);
1083   static const int vernaux_size = sizeof(internal::Vernaux_data);
1084 };
1085 
1086 // Accessor class for the ELF file header.
1087 
1088 template<int size, bool big_endian>
1089 class Ehdr
1090 {
1091  public:
1092   Ehdr(const unsigned char* p)
1093     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
1094   { }
1095 
1096   template<typename File>
1097   Ehdr(File* file, typename File::Location loc)
1098     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
1099 	   file->view(loc.file_offset, loc.data_size).data()))
1100   { }
1101 
1102   const unsigned char*
1103   get_e_ident() const
1104   { return this->p_->e_ident; }
1105 
1106   unsigned char
1107   get_ei_osabi() const
1108   { return this->p_->e_ident[EI_OSABI]; }
1109 
1110   unsigned char
1111   get_ei_abiversion() const
1112   { return this->p_->e_ident[EI_ABIVERSION]; }
1113 
1114   Elf_Half
1115   get_e_type() const
1116   { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
1117 
1118   Elf_Half
1119   get_e_machine() const
1120   { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
1121 
1122   Elf_Word
1123   get_e_version() const
1124   { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
1125 
1126   typename Elf_types<size>::Elf_Addr
1127   get_e_entry() const
1128   { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
1129 
1130   typename Elf_types<size>::Elf_Off
1131   get_e_phoff() const
1132   { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
1133 
1134   typename Elf_types<size>::Elf_Off
1135   get_e_shoff() const
1136   { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
1137 
1138   Elf_Word
1139   get_e_flags() const
1140   { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
1141 
1142   Elf_Half
1143   get_e_ehsize() const
1144   { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
1145 
1146   Elf_Half
1147   get_e_phentsize() const
1148   { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
1149 
1150   Elf_Half
1151   get_e_phnum() const
1152   { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
1153 
1154   Elf_Half
1155   get_e_shentsize() const
1156   { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
1157 
1158   Elf_Half
1159   get_e_shnum() const
1160   { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
1161 
1162   Elf_Half
1163   get_e_shstrndx() const
1164   { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
1165 
1166  private:
1167   const internal::Ehdr_data<size>* p_;
1168 };
1169 
1170 // Write class for the ELF file header.
1171 
1172 template<int size, bool big_endian>
1173 class Ehdr_write
1174 {
1175  public:
1176   Ehdr_write(unsigned char* p)
1177     : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
1178   { }
1179 
1180   void
1181   put_e_ident(const unsigned char v[EI_NIDENT]) const
1182   { memcpy(this->p_->e_ident, v, EI_NIDENT); }
1183 
1184   void
1185   put_e_type(Elf_Half v)
1186   { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
1187 
1188   void
1189   put_e_machine(Elf_Half v)
1190   { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
1191 
1192   void
1193   put_e_version(Elf_Word v)
1194   { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
1195 
1196   void
1197   put_e_entry(typename Elf_types<size>::Elf_Addr v)
1198   { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
1199 
1200   void
1201   put_e_phoff(typename Elf_types<size>::Elf_Off v)
1202   { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
1203 
1204   void
1205   put_e_shoff(typename Elf_types<size>::Elf_Off v)
1206   { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
1207 
1208   void
1209   put_e_flags(Elf_Word v)
1210   { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
1211 
1212   void
1213   put_e_ehsize(Elf_Half v)
1214   { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
1215 
1216   void
1217   put_e_phentsize(Elf_Half v)
1218   { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
1219 
1220   void
1221   put_e_phnum(Elf_Half v)
1222   { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
1223 
1224   void
1225   put_e_shentsize(Elf_Half v)
1226   { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
1227 
1228   void
1229   put_e_shnum(Elf_Half v)
1230   { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
1231 
1232   void
1233   put_e_shstrndx(Elf_Half v)
1234   { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
1235 
1236  private:
1237   internal::Ehdr_data<size>* p_;
1238 };
1239 
1240 // Accessor class for an ELF section header.
1241 
1242 template<int size, bool big_endian>
1243 class Shdr
1244 {
1245  public:
1246   Shdr(const unsigned char* p)
1247     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
1248   { }
1249 
1250   template<typename File>
1251   Shdr(File* file, typename File::Location loc)
1252     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
1253 	   file->view(loc.file_offset, loc.data_size).data()))
1254   { }
1255 
1256   Elf_Word
1257   get_sh_name() const
1258   { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
1259 
1260   Elf_Word
1261   get_sh_type() const
1262   { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
1263 
1264   typename Elf_types<size>::Elf_WXword
1265   get_sh_flags() const
1266   { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
1267 
1268   typename Elf_types<size>::Elf_Addr
1269   get_sh_addr() const
1270   { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
1271 
1272   typename Elf_types<size>::Elf_Off
1273   get_sh_offset() const
1274   { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
1275 
1276   typename Elf_types<size>::Elf_WXword
1277   get_sh_size() const
1278   { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
1279 
1280   Elf_Word
1281   get_sh_link() const
1282   { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
1283 
1284   Elf_Word
1285   get_sh_info() const
1286   { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
1287 
1288   typename Elf_types<size>::Elf_WXword
1289   get_sh_addralign() const
1290   { return
1291       Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
1292 
1293   typename Elf_types<size>::Elf_WXword
1294   get_sh_entsize() const
1295   { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
1296 
1297  private:
1298   const internal::Shdr_data<size>* p_;
1299 };
1300 
1301 // Write class for an ELF section header.
1302 
1303 template<int size, bool big_endian>
1304 class Shdr_write
1305 {
1306  public:
1307   Shdr_write(unsigned char* p)
1308     : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
1309   { }
1310 
1311   void
1312   put_sh_name(Elf_Word v)
1313   { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
1314 
1315   void
1316   put_sh_type(Elf_Word v)
1317   { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
1318 
1319   void
1320   put_sh_flags(typename Elf_types<size>::Elf_WXword v)
1321   { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
1322 
1323   void
1324   put_sh_addr(typename Elf_types<size>::Elf_Addr v)
1325   { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
1326 
1327   void
1328   put_sh_offset(typename Elf_types<size>::Elf_Off v)
1329   { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
1330 
1331   void
1332   put_sh_size(typename Elf_types<size>::Elf_WXword v)
1333   { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
1334 
1335   void
1336   put_sh_link(Elf_Word v)
1337   { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
1338 
1339   void
1340   put_sh_info(Elf_Word v)
1341   { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
1342 
1343   void
1344   put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
1345   { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
1346 
1347   void
1348   put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
1349   { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
1350 
1351  private:
1352   internal::Shdr_data<size>* p_;
1353 };
1354 
1355 // Accessor class for an ELF compression header.
1356 
1357 template<int size, bool big_endian>
1358 class Chdr
1359 {
1360  public:
1361   Chdr(const unsigned char* p)
1362     : p_(reinterpret_cast<const internal::Chdr_data<size>*>(p))
1363   { }
1364 
1365   template<typename File>
1366   Chdr(File* file, typename File::Location loc)
1367     : p_(reinterpret_cast<const internal::Chdr_data<size>*>(
1368 	   file->view(loc.file_offset, loc.data_size).data()))
1369   { }
1370 
1371   Elf_Word
1372   get_ch_type() const
1373   { return Convert<size, big_endian>::convert_host(this->p_->ch_type); }
1374 
1375   typename Elf_types<size>::Elf_WXword
1376   get_ch_size() const
1377   { return Convert<size, big_endian>::convert_host(this->p_->ch_size); }
1378 
1379   typename Elf_types<size>::Elf_WXword
1380   get_ch_addralign() const
1381   { return
1382       Convert<size, big_endian>::convert_host(this->p_->ch_addralign); }
1383 
1384  private:
1385   const internal::Chdr_data<size>* p_;
1386 };
1387 
1388 // Write class for an ELF compression header.
1389 
1390 template<int size, bool big_endian>
1391 class Chdr_write
1392 {
1393  public:
1394   Chdr_write(unsigned char* p)
1395     : p_(reinterpret_cast<internal::Chdr_data<size>*>(p))
1396   { }
1397 
1398   void
1399   put_ch_type(typename Elf_types<size>::Elf_WXword v)
1400   { this->p_->ch_type = Convert<size, big_endian>::convert_host(v); }
1401 
1402   void
1403   put_ch_size(typename Elf_types<size>::Elf_WXword v)
1404   { this->p_->ch_size = Convert<size, big_endian>::convert_host(v); }
1405 
1406   void
1407   put_ch_addralign(typename Elf_types<size>::Elf_WXword v)
1408   { this->p_->ch_addralign = Convert<size, big_endian>::convert_host(v); }
1409 
1410   void
1411   put_ch_reserved(Elf_Word);
1412 
1413  private:
1414   internal::Chdr_data<size>* p_;
1415 };
1416 
1417 template<>
1418 inline void
1419 elfcpp::Chdr_write<64, true>::put_ch_reserved(Elf_Word v)
1420 {
1421   this->p_->ch_reserved = v;
1422 }
1423 
1424 template<>
1425 inline void
1426 elfcpp::Chdr_write<64, false>::put_ch_reserved(Elf_Word v)
1427 {
1428   this->p_->ch_reserved = v;
1429 }
1430 
1431 // Accessor class for an ELF segment header.
1432 
1433 template<int size, bool big_endian>
1434 class Phdr
1435 {
1436  public:
1437   Phdr(const unsigned char* p)
1438     : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
1439   { }
1440 
1441   template<typename File>
1442   Phdr(File* file, typename File::Location loc)
1443     : p_(reinterpret_cast<internal::Phdr_data<size>*>(
1444 	   file->view(loc.file_offset, loc.data_size).data()))
1445   { }
1446 
1447   Elf_Word
1448   get_p_type() const
1449   { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
1450 
1451   typename Elf_types<size>::Elf_Off
1452   get_p_offset() const
1453   { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
1454 
1455   typename Elf_types<size>::Elf_Addr
1456   get_p_vaddr() const
1457   { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
1458 
1459   typename Elf_types<size>::Elf_Addr
1460   get_p_paddr() const
1461   { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
1462 
1463   typename Elf_types<size>::Elf_WXword
1464   get_p_filesz() const
1465   { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
1466 
1467   typename Elf_types<size>::Elf_WXword
1468   get_p_memsz() const
1469   { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
1470 
1471   Elf_Word
1472   get_p_flags() const
1473   { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
1474 
1475   typename Elf_types<size>::Elf_WXword
1476   get_p_align() const
1477   { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
1478 
1479  private:
1480   const internal::Phdr_data<size>* p_;
1481 };
1482 
1483 // Write class for an ELF segment header.
1484 
1485 template<int size, bool big_endian>
1486 class Phdr_write
1487 {
1488  public:
1489   Phdr_write(unsigned char* p)
1490     : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
1491   { }
1492 
1493   void
1494   put_p_type(Elf_Word v)
1495   { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
1496 
1497   void
1498   put_p_offset(typename Elf_types<size>::Elf_Off v)
1499   { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
1500 
1501   void
1502   put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
1503   { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
1504 
1505   void
1506   put_p_paddr(typename Elf_types<size>::Elf_Addr v)
1507   { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
1508 
1509   void
1510   put_p_filesz(typename Elf_types<size>::Elf_WXword v)
1511   { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
1512 
1513   void
1514   put_p_memsz(typename Elf_types<size>::Elf_WXword v)
1515   { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
1516 
1517   void
1518   put_p_flags(Elf_Word v)
1519   { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
1520 
1521   void
1522   put_p_align(typename Elf_types<size>::Elf_WXword v)
1523   { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
1524 
1525  private:
1526   internal::Phdr_data<size>* p_;
1527 };
1528 
1529 // Accessor class for an ELF symbol table entry.
1530 
1531 template<int size, bool big_endian>
1532 class Sym
1533 {
1534  public:
1535   Sym(const unsigned char* p)
1536     : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
1537   { }
1538 
1539   template<typename File>
1540   Sym(File* file, typename File::Location loc)
1541     : p_(reinterpret_cast<const internal::Sym_data<size>*>(
1542 	   file->view(loc.file_offset, loc.data_size).data()))
1543   { }
1544 
1545   Elf_Word
1546   get_st_name() const
1547   { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
1548 
1549   typename Elf_types<size>::Elf_Addr
1550   get_st_value() const
1551   { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
1552 
1553   typename Elf_types<size>::Elf_WXword
1554   get_st_size() const
1555   { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
1556 
1557   unsigned char
1558   get_st_info() const
1559   { return this->p_->st_info; }
1560 
1561   STB
1562   get_st_bind() const
1563   { return elf_st_bind(this->get_st_info()); }
1564 
1565   STT
1566   get_st_type() const
1567   { return elf_st_type(this->get_st_info()); }
1568 
1569   unsigned char
1570   get_st_other() const
1571   { return this->p_->st_other; }
1572 
1573   STV
1574   get_st_visibility() const
1575   { return elf_st_visibility(this->get_st_other()); }
1576 
1577   unsigned char
1578   get_st_nonvis() const
1579   { return elf_st_nonvis(this->get_st_other()); }
1580 
1581   Elf_Half
1582   get_st_shndx() const
1583   { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
1584 
1585  private:
1586   const internal::Sym_data<size>* p_;
1587 };
1588 
1589 // Writer class for an ELF symbol table entry.
1590 
1591 template<int size, bool big_endian>
1592 class Sym_write
1593 {
1594  public:
1595   Sym_write(unsigned char* p)
1596     : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
1597   { }
1598 
1599   void
1600   put_st_name(Elf_Word v)
1601   { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
1602 
1603   void
1604   put_st_value(typename Elf_types<size>::Elf_Addr v)
1605   { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
1606 
1607   void
1608   put_st_size(typename Elf_types<size>::Elf_WXword v)
1609   { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
1610 
1611   void
1612   put_st_info(unsigned char v)
1613   { this->p_->st_info = v; }
1614 
1615   void
1616   put_st_info(STB bind, STT type)
1617   { this->p_->st_info = elf_st_info(bind, type); }
1618 
1619   void
1620   put_st_other(unsigned char v)
1621   { this->p_->st_other = v; }
1622 
1623   void
1624   put_st_other(STV vis, unsigned char nonvis)
1625   { this->p_->st_other = elf_st_other(vis, nonvis); }
1626 
1627   void
1628   put_st_shndx(Elf_Half v)
1629   { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
1630 
1631   Sym<size, big_endian>
1632   sym()
1633   { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
1634 
1635  private:
1636   internal::Sym_data<size>* p_;
1637 };
1638 
1639 // Accessor classes for an ELF REL relocation entry.
1640 
1641 template<int size, bool big_endian>
1642 class Rel
1643 {
1644  public:
1645   Rel(const unsigned char* p)
1646     : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
1647   { }
1648 
1649   template<typename File>
1650   Rel(File* file, typename File::Location loc)
1651     : p_(reinterpret_cast<const internal::Rel_data<size>*>(
1652 	   file->view(loc.file_offset, loc.data_size).data()))
1653   { }
1654 
1655   typename Elf_types<size>::Elf_Addr
1656   get_r_offset() const
1657   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1658 
1659   typename Elf_types<size>::Elf_WXword
1660   get_r_info() const
1661   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1662 
1663  private:
1664   const internal::Rel_data<size>* p_;
1665 };
1666 
1667 // Writer class for an ELF Rel relocation.
1668 
1669 template<int size, bool big_endian>
1670 class Rel_write
1671 {
1672  public:
1673   Rel_write(unsigned char* p)
1674     : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
1675   { }
1676 
1677   void
1678   put_r_offset(typename Elf_types<size>::Elf_Addr v)
1679   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1680 
1681   void
1682   put_r_info(typename Elf_types<size>::Elf_WXword v)
1683   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1684 
1685  private:
1686   internal::Rel_data<size>* p_;
1687 };
1688 
1689 // Accessor class for an ELF Rela relocation.
1690 
1691 template<int size, bool big_endian>
1692 class Rela
1693 {
1694  public:
1695   Rela(const unsigned char* p)
1696     : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
1697   { }
1698 
1699   template<typename File>
1700   Rela(File* file, typename File::Location loc)
1701     : p_(reinterpret_cast<const internal::Rela_data<size>*>(
1702 	   file->view(loc.file_offset, loc.data_size).data()))
1703   { }
1704 
1705   typename Elf_types<size>::Elf_Addr
1706   get_r_offset() const
1707   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1708 
1709   typename Elf_types<size>::Elf_WXword
1710   get_r_info() const
1711   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1712 
1713   typename Elf_types<size>::Elf_Swxword
1714   get_r_addend() const
1715   { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
1716 
1717  private:
1718   const internal::Rela_data<size>* p_;
1719 };
1720 
1721 // Writer class for an ELF Rela relocation.
1722 
1723 template<int size, bool big_endian>
1724 class Rela_write
1725 {
1726  public:
1727   Rela_write(unsigned char* p)
1728     : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
1729   { }
1730 
1731   void
1732   put_r_offset(typename Elf_types<size>::Elf_Addr v)
1733   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1734 
1735   void
1736   put_r_info(typename Elf_types<size>::Elf_WXword v)
1737   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1738 
1739   void
1740   put_r_addend(typename Elf_types<size>::Elf_Swxword v)
1741   { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
1742 
1743  private:
1744   internal::Rela_data<size>* p_;
1745 };
1746 
1747 // MIPS-64 has a non-standard relocation layout.
1748 
1749 template<bool big_endian>
1750 class Mips64_rel
1751 {
1752  public:
1753   Mips64_rel(const unsigned char* p)
1754     : p_(reinterpret_cast<const internal::Mips64_rel_data*>(p))
1755   { }
1756 
1757   template<typename File>
1758   Mips64_rel(File* file, typename File::Location loc)
1759     : p_(reinterpret_cast<const internal::Mips64_rel_data*>(
1760 	   file->view(loc.file_offset, loc.data_size).data()))
1761   { }
1762 
1763   typename Elf_types<64>::Elf_Addr
1764   get_r_offset() const
1765   { return Convert<64, big_endian>::convert_host(this->p_->r_offset); }
1766 
1767   Elf_Word
1768   get_r_sym() const
1769   { return Convert<32, big_endian>::convert_host(this->p_->r_sym); }
1770 
1771   unsigned char
1772   get_r_ssym() const
1773   { return this->p_->r_ssym; }
1774 
1775   unsigned char
1776   get_r_type() const
1777   { return this->p_->r_type; }
1778 
1779   unsigned char
1780   get_r_type2() const
1781   { return this->p_->r_type2; }
1782 
1783   unsigned char
1784   get_r_type3() const
1785   { return this->p_->r_type3; }
1786 
1787  private:
1788   const internal::Mips64_rel_data* p_;
1789 };
1790 
1791 template<bool big_endian>
1792 class Mips64_rel_write
1793 {
1794  public:
1795   Mips64_rel_write(unsigned char* p)
1796     : p_(reinterpret_cast<internal::Mips64_rel_data*>(p))
1797   { }
1798 
1799   void
1800   put_r_offset(typename Elf_types<64>::Elf_Addr v)
1801   { this->p_->r_offset = Convert<64, big_endian>::convert_host(v); }
1802 
1803   void
1804   put_r_sym(Elf_Word v)
1805   { this->p_->r_sym = Convert<32, big_endian>::convert_host(v); }
1806 
1807   void
1808   put_r_ssym(unsigned char v)
1809   { this->p_->r_ssym = v; }
1810 
1811   void
1812   put_r_type(unsigned char v)
1813   { this->p_->r_type = v; }
1814 
1815   void
1816   put_r_type2(unsigned char v)
1817   { this->p_->r_type2 = v; }
1818 
1819   void
1820   put_r_type3(unsigned char v)
1821   { this->p_->r_type3 = v; }
1822 
1823  private:
1824   internal::Mips64_rel_data* p_;
1825 };
1826 
1827 template<bool big_endian>
1828 class Mips64_rela
1829 {
1830  public:
1831   Mips64_rela(const unsigned char* p)
1832     : p_(reinterpret_cast<const internal::Mips64_rela_data*>(p))
1833   { }
1834 
1835   template<typename File>
1836   Mips64_rela(File* file, typename File::Location loc)
1837     : p_(reinterpret_cast<const internal::Mips64_rela_data*>(
1838 	   file->view(loc.file_offset, loc.data_size).data()))
1839   { }
1840 
1841   typename Elf_types<64>::Elf_Addr
1842   get_r_offset() const
1843   { return Convert<64, big_endian>::convert_host(this->p_->r_offset); }
1844 
1845   Elf_Word
1846   get_r_sym() const
1847   { return Convert<32, big_endian>::convert_host(this->p_->r_sym); }
1848 
1849   unsigned char
1850   get_r_ssym() const
1851   { return this->p_->r_ssym; }
1852 
1853   unsigned char
1854   get_r_type() const
1855   { return this->p_->r_type; }
1856 
1857   unsigned char
1858   get_r_type2() const
1859   { return this->p_->r_type2; }
1860 
1861   unsigned char
1862   get_r_type3() const
1863   { return this->p_->r_type3; }
1864 
1865   typename Elf_types<64>::Elf_Swxword
1866   get_r_addend() const
1867   { return Convert<64, big_endian>::convert_host(this->p_->r_addend); }
1868 
1869  private:
1870   const internal::Mips64_rela_data* p_;
1871 };
1872 
1873 template<bool big_endian>
1874 class Mips64_rela_write
1875 {
1876  public:
1877   Mips64_rela_write(unsigned char* p)
1878     : p_(reinterpret_cast<internal::Mips64_rela_data*>(p))
1879   { }
1880 
1881   void
1882   put_r_offset(typename Elf_types<64>::Elf_Addr v)
1883   { this->p_->r_offset = Convert<64, big_endian>::convert_host(v); }
1884 
1885   void
1886   put_r_sym(Elf_Word v)
1887   { this->p_->r_sym = Convert<32, big_endian>::convert_host(v); }
1888 
1889   void
1890   put_r_ssym(unsigned char v)
1891   { this->p_->r_ssym = v; }
1892 
1893   void
1894   put_r_type(unsigned char v)
1895   { this->p_->r_type = v; }
1896 
1897   void
1898   put_r_type2(unsigned char v)
1899   { this->p_->r_type2 = v; }
1900 
1901   void
1902   put_r_type3(unsigned char v)
1903   { this->p_->r_type3 = v; }
1904 
1905   void
1906   put_r_addend(typename Elf_types<64>::Elf_Swxword v)
1907   { this->p_->r_addend = Convert<64, big_endian>::convert_host(v); }
1908 
1909  private:
1910   internal::Mips64_rela_data* p_;
1911 };
1912 
1913 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1914 // PT_DYNAMIC segment.
1915 
1916 template<int size, bool big_endian>
1917 class Dyn
1918 {
1919  public:
1920   Dyn(const unsigned char* p)
1921     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
1922   { }
1923 
1924   template<typename File>
1925   Dyn(File* file, typename File::Location loc)
1926     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
1927 	   file->view(loc.file_offset, loc.data_size).data()))
1928   { }
1929 
1930   typename Elf_types<size>::Elf_Swxword
1931   get_d_tag() const
1932   { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
1933 
1934   typename Elf_types<size>::Elf_WXword
1935   get_d_val() const
1936   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1937 
1938   typename Elf_types<size>::Elf_Addr
1939   get_d_ptr() const
1940   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1941 
1942  private:
1943   const internal::Dyn_data<size>* p_;
1944 };
1945 
1946 // Write class for an entry in the SHT_DYNAMIC section.
1947 
1948 template<int size, bool big_endian>
1949 class Dyn_write
1950 {
1951  public:
1952   Dyn_write(unsigned char* p)
1953     : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
1954   { }
1955 
1956   void
1957   put_d_tag(typename Elf_types<size>::Elf_Swxword v)
1958   { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
1959 
1960   void
1961   put_d_val(typename Elf_types<size>::Elf_WXword v)
1962   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1963 
1964   void
1965   put_d_ptr(typename Elf_types<size>::Elf_Addr v)
1966   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1967 
1968  private:
1969   internal::Dyn_data<size>* p_;
1970 };
1971 
1972 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1973 
1974 template<int size, bool big_endian>
1975 class Verdef
1976 {
1977  public:
1978   Verdef(const unsigned char* p)
1979     : p_(reinterpret_cast<const internal::Verdef_data*>(p))
1980   { }
1981 
1982   template<typename File>
1983   Verdef(File* file, typename File::Location loc)
1984     : p_(reinterpret_cast<const internal::Verdef_data*>(
1985 	   file->view(loc.file_offset, loc.data_size).data()))
1986   { }
1987 
1988   Elf_Half
1989   get_vd_version() const
1990   { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
1991 
1992   Elf_Half
1993   get_vd_flags() const
1994   { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
1995 
1996   Elf_Half
1997   get_vd_ndx() const
1998   { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
1999 
2000   Elf_Half
2001   get_vd_cnt() const
2002   { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
2003 
2004   Elf_Word
2005   get_vd_hash() const
2006   { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
2007 
2008   Elf_Word
2009   get_vd_aux() const
2010   { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
2011 
2012   Elf_Word
2013   get_vd_next() const
2014   { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
2015 
2016  private:
2017   const internal::Verdef_data* p_;
2018 };
2019 
2020 template<int size, bool big_endian>
2021 class Verdef_write
2022 {
2023  public:
2024   Verdef_write(unsigned char* p)
2025     : p_(reinterpret_cast<internal::Verdef_data*>(p))
2026   { }
2027 
2028   void
2029   set_vd_version(Elf_Half v)
2030   { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
2031 
2032   void
2033   set_vd_flags(Elf_Half v)
2034   { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
2035 
2036   void
2037   set_vd_ndx(Elf_Half v)
2038   { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
2039 
2040   void
2041   set_vd_cnt(Elf_Half v)
2042   { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
2043 
2044   void
2045   set_vd_hash(Elf_Word v)
2046   { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
2047 
2048   void
2049   set_vd_aux(Elf_Word v)
2050   { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
2051 
2052   void
2053   set_vd_next(Elf_Word v)
2054   { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
2055 
2056  private:
2057   internal::Verdef_data* p_;
2058 };
2059 
2060 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
2061 // section.
2062 
2063 template<int size, bool big_endian>
2064 class Verdaux
2065 {
2066  public:
2067   Verdaux(const unsigned char* p)
2068     : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
2069   { }
2070 
2071   template<typename File>
2072   Verdaux(File* file, typename File::Location loc)
2073     : p_(reinterpret_cast<const internal::Verdaux_data*>(
2074 	   file->view(loc.file_offset, loc.data_size).data()))
2075   { }
2076 
2077   Elf_Word
2078   get_vda_name() const
2079   { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
2080 
2081   Elf_Word
2082   get_vda_next() const
2083   { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
2084 
2085  private:
2086   const internal::Verdaux_data* p_;
2087 };
2088 
2089 template<int size, bool big_endian>
2090 class Verdaux_write
2091 {
2092  public:
2093   Verdaux_write(unsigned char* p)
2094     : p_(reinterpret_cast<internal::Verdaux_data*>(p))
2095   { }
2096 
2097   void
2098   set_vda_name(Elf_Word v)
2099   { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
2100 
2101   void
2102   set_vda_next(Elf_Word v)
2103   { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
2104 
2105  private:
2106   internal::Verdaux_data* p_;
2107 };
2108 
2109 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
2110 
2111 template<int size, bool big_endian>
2112 class Verneed
2113 {
2114  public:
2115   Verneed(const unsigned char* p)
2116     : p_(reinterpret_cast<const internal::Verneed_data*>(p))
2117   { }
2118 
2119   template<typename File>
2120   Verneed(File* file, typename File::Location loc)
2121     : p_(reinterpret_cast<const internal::Verneed_data*>(
2122 	   file->view(loc.file_offset, loc.data_size).data()))
2123   { }
2124 
2125   Elf_Half
2126   get_vn_version() const
2127   { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
2128 
2129   Elf_Half
2130   get_vn_cnt() const
2131   { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
2132 
2133   Elf_Word
2134   get_vn_file() const
2135   { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
2136 
2137   Elf_Word
2138   get_vn_aux() const
2139   { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
2140 
2141   Elf_Word
2142   get_vn_next() const
2143   { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
2144 
2145  private:
2146   const internal::Verneed_data* p_;
2147 };
2148 
2149 template<int size, bool big_endian>
2150 class Verneed_write
2151 {
2152  public:
2153   Verneed_write(unsigned char* p)
2154     : p_(reinterpret_cast<internal::Verneed_data*>(p))
2155   { }
2156 
2157   void
2158   set_vn_version(Elf_Half v)
2159   { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
2160 
2161   void
2162   set_vn_cnt(Elf_Half v)
2163   { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
2164 
2165   void
2166   set_vn_file(Elf_Word v)
2167   { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
2168 
2169   void
2170   set_vn_aux(Elf_Word v)
2171   { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
2172 
2173   void
2174   set_vn_next(Elf_Word v)
2175   { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
2176 
2177  private:
2178   internal::Verneed_data* p_;
2179 };
2180 
2181 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
2182 // section.
2183 
2184 template<int size, bool big_endian>
2185 class Vernaux
2186 {
2187  public:
2188   Vernaux(const unsigned char* p)
2189     : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
2190   { }
2191 
2192   template<typename File>
2193   Vernaux(File* file, typename File::Location loc)
2194     : p_(reinterpret_cast<const internal::Vernaux_data*>(
2195 	   file->view(loc.file_offset, loc.data_size).data()))
2196   { }
2197 
2198   Elf_Word
2199   get_vna_hash() const
2200   { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
2201 
2202   Elf_Half
2203   get_vna_flags() const
2204   { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
2205 
2206   Elf_Half
2207   get_vna_other() const
2208   { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
2209 
2210   Elf_Word
2211   get_vna_name() const
2212   { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
2213 
2214   Elf_Word
2215   get_vna_next() const
2216   { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
2217 
2218  private:
2219   const internal::Vernaux_data* p_;
2220 };
2221 
2222 template<int size, bool big_endian>
2223 class Vernaux_write
2224 {
2225  public:
2226   Vernaux_write(unsigned char* p)
2227     : p_(reinterpret_cast<internal::Vernaux_data*>(p))
2228   { }
2229 
2230   void
2231   set_vna_hash(Elf_Word v)
2232   { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
2233 
2234   void
2235   set_vna_flags(Elf_Half v)
2236   { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
2237 
2238   void
2239   set_vna_other(Elf_Half v)
2240   { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
2241 
2242   void
2243   set_vna_name(Elf_Word v)
2244   { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
2245 
2246   void
2247   set_vna_next(Elf_Word v)
2248   { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
2249 
2250  private:
2251   internal::Vernaux_data* p_;
2252 };
2253 
2254 } // End namespace elfcpp.
2255 
2256 #endif // !defined(ELFPCP_H)
2257