Merge remote branch 'origin/master'
[binutils/dougsmingw.git] / elfcpp / elfcpp.h
blob52b8b2534ee8671e445bb15b238eccdf7688c0e0
1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of elfcpp.
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.
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.)
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.
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.
32 // This is the external interface for elfcpp.
34 #ifndef ELFCPP_H
35 #define ELFCPP_H
37 #include "elfcpp_swap.h"
39 #include <stdint.h>
41 namespace elfcpp
44 // Basic ELF types.
46 // These types are always the same size.
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;
54 // These types vary in size depending on the ELF file class. The
55 // template parameter should be 32 or 64.
57 template<int size>
58 struct Elf_types;
60 template<>
61 struct Elf_types<32>
63 typedef uint32_t Elf_Addr;
64 typedef uint32_t Elf_Off;
65 typedef uint32_t Elf_WXword;
66 typedef int32_t Elf_Swxword;
69 template<>
70 struct Elf_types<64>
72 typedef uint64_t Elf_Addr;
73 typedef uint64_t Elf_Off;
74 typedef uint64_t Elf_WXword;
75 typedef int64_t Elf_Swxword;
78 // Offsets within the Ehdr e_ident field.
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;
92 // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
94 const int ELFMAG0 = 0x7f;
95 const int ELFMAG1 = 'E';
96 const int ELFMAG2 = 'L';
97 const int ELFMAG3 = 'F';
99 // The valid values found in Ehdr e_ident[EI_CLASS].
101 enum
103 ELFCLASSNONE = 0,
104 ELFCLASS32 = 1,
105 ELFCLASS64 = 2
108 // The valid values found in Ehdr e_ident[EI_DATA].
110 enum
112 ELFDATANONE = 0,
113 ELFDATA2LSB = 1,
114 ELFDATA2MSB = 2
117 // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
119 enum
121 EV_NONE = 0,
122 EV_CURRENT = 1
125 // The valid values found in Ehdr e_ident[EI_OSABI].
127 enum ELFOSABI
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
152 // The valid values found in the Ehdr e_type field.
154 enum ET
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
167 // The valid values found in the Ehdr e_machine field.
169 enum EM
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).
305 // A special value found in the Ehdr e_phnum field.
307 enum
309 // Number of program segments stored in sh_info field of first
310 // section headre.
311 PN_XNUM = 0xffff
314 // Special section indices.
316 enum
318 SHN_UNDEF = 0,
319 SHN_LORESERVE = 0xff00,
320 SHN_LOPROC = 0xff00,
321 SHN_HIPROC = 0xff1f,
322 SHN_LOOS = 0xff20,
323 SHN_HIOS = 0xff3f,
324 SHN_ABS = 0xfff1,
325 SHN_COMMON = 0xfff2,
326 SHN_XINDEX = 0xffff,
327 SHN_HIRESERVE = 0xffff,
329 // Provide for initial and final section ordering in conjunction
330 // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
331 SHN_BEFORE = 0xff00,
332 SHN_AFTER = 0xff01,
334 // x86_64 specific large common symbol.
335 SHN_X86_64_LCOMMON = 0xff02
338 // The valid values found in the Shdr sh_type field.
340 enum SHT
342 SHT_NULL = 0,
343 SHT_PROGBITS = 1,
344 SHT_SYMTAB = 2,
345 SHT_STRTAB = 3,
346 SHT_RELA = 4,
347 SHT_HASH = 5,
348 SHT_DYNAMIC = 6,
349 SHT_NOTE = 7,
350 SHT_NOBITS = 8,
351 SHT_REL = 9,
352 SHT_SHLIB = 10,
353 SHT_DYNSYM = 11,
354 SHT_INIT_ARRAY = 14,
355 SHT_FINI_ARRAY = 15,
356 SHT_PREINIT_ARRAY = 16,
357 SHT_GROUP = 17,
358 SHT_SYMTAB_SHNDX = 18,
359 SHT_LOOS = 0x60000000,
360 SHT_HIOS = 0x6fffffff,
361 SHT_LOPROC = 0x70000000,
362 SHT_HIPROC = 0x7fffffff,
363 SHT_LOUSER = 0x80000000,
364 SHT_HIUSER = 0xffffffff,
365 // The remaining values are not in the standard.
366 // Incremental build data.
367 SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700,
368 // Object attributes.
369 SHT_GNU_ATTRIBUTES = 0x6ffffff5,
370 // GNU style dynamic hash table.
371 SHT_GNU_HASH = 0x6ffffff6,
372 // List of prelink dependencies.
373 SHT_GNU_LIBLIST = 0x6ffffff7,
374 // Versions defined by file.
375 SHT_SUNW_verdef = 0x6ffffffd,
376 SHT_GNU_verdef = 0x6ffffffd,
377 // Versions needed by file.
378 SHT_SUNW_verneed = 0x6ffffffe,
379 SHT_GNU_verneed = 0x6ffffffe,
380 // Symbol versions,
381 SHT_SUNW_versym = 0x6fffffff,
382 SHT_GNU_versym = 0x6fffffff,
384 SHT_SPARC_GOTDATA = 0x70000000,
386 // ARM-specific section types.
387 // Exception Index table.
388 SHT_ARM_EXIDX = 0x70000001,
389 // BPABI DLL dynamic linking pre-emption map.
390 SHT_ARM_PREEMPTMAP = 0x70000002,
391 // Object file compatibility attributes.
392 SHT_ARM_ATTRIBUTES = 0x70000003,
393 // Support for debugging overlaid programs.
394 SHT_ARM_DEBUGOVERLAY = 0x70000004,
395 SHT_ARM_OVERLAYSECTION = 0x70000005,
397 // x86_64 unwind information.
398 SHT_X86_64_UNWIND = 0x70000001,
400 // Link editor is to sort the entries in this section based on the
401 // address specified in the associated symbol table entry.
402 SHT_ORDERED = 0x7fffffff
405 // The valid bit flags found in the Shdr sh_flags field.
407 enum SHF
409 SHF_WRITE = 0x1,
410 SHF_ALLOC = 0x2,
411 SHF_EXECINSTR = 0x4,
412 SHF_MERGE = 0x10,
413 SHF_STRINGS = 0x20,
414 SHF_INFO_LINK = 0x40,
415 SHF_LINK_ORDER = 0x80,
416 SHF_OS_NONCONFORMING = 0x100,
417 SHF_GROUP = 0x200,
418 SHF_TLS = 0x400,
419 SHF_MASKOS = 0x0ff00000,
420 SHF_MASKPROC = 0xf0000000,
422 // Indicates this section requires ordering in relation to
423 // other sections of the same type. Ordered sections are
424 // combined within the section pointed to by the sh_link entry.
425 // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
426 // sorted section is to precede or follow, respectively, all
427 // other sections in the set being ordered.
428 SHF_ORDERED = 0x40000000,
429 // This section is excluded from input to the link-edit of an
430 // executable or shared object. This flag is ignored if SHF_ALLOC
431 // is also set, or if relocations exist against the section.
432 SHF_EXCLUDE = 0x80000000,
434 // x86_64 specific large section.
435 SHF_X86_64_LARGE = 0x10000000
438 // Bit flags which appear in the first 32-bit word of the section data
439 // of a SHT_GROUP section.
441 enum
443 GRP_COMDAT = 0x1,
444 GRP_MASKOS = 0x0ff00000,
445 GRP_MASKPROC = 0xf0000000
448 // The valid values found in the Phdr p_type field.
450 enum PT
452 PT_NULL = 0,
453 PT_LOAD = 1,
454 PT_DYNAMIC = 2,
455 PT_INTERP = 3,
456 PT_NOTE = 4,
457 PT_SHLIB = 5,
458 PT_PHDR = 6,
459 PT_TLS = 7,
460 PT_LOOS = 0x60000000,
461 PT_HIOS = 0x6fffffff,
462 PT_LOPROC = 0x70000000,
463 PT_HIPROC = 0x7fffffff,
464 // The remaining values are not in the standard.
465 // Frame unwind information.
466 PT_GNU_EH_FRAME = 0x6474e550,
467 PT_SUNW_EH_FRAME = 0x6474e550,
468 // Stack flags.
469 PT_GNU_STACK = 0x6474e551,
470 // Read only after relocation.
471 PT_GNU_RELRO = 0x6474e552,
472 // Platform architecture compatibility information
473 PT_ARM_ARCHEXT = 0x70000000,
474 // Exception unwind tables
475 PT_ARM_EXIDX = 0x70000001
478 // The valid bit flags found in the Phdr p_flags field.
480 enum PF
482 PF_X = 0x1,
483 PF_W = 0x2,
484 PF_R = 0x4,
485 PF_MASKOS = 0x0ff00000,
486 PF_MASKPROC = 0xf0000000
489 // Symbol binding from Sym st_info field.
491 enum STB
493 STB_LOCAL = 0,
494 STB_GLOBAL = 1,
495 STB_WEAK = 2,
496 STB_LOOS = 10,
497 STB_GNU_UNIQUE = 10,
498 STB_HIOS = 12,
499 STB_LOPROC = 13,
500 STB_HIPROC = 15
503 // Symbol types from Sym st_info field.
505 enum STT
507 STT_NOTYPE = 0,
508 STT_OBJECT = 1,
509 STT_FUNC = 2,
510 STT_SECTION = 3,
511 STT_FILE = 4,
512 STT_COMMON = 5,
513 STT_TLS = 6,
514 STT_LOOS = 10,
515 STT_GNU_IFUNC = 10,
516 STT_HIOS = 12,
517 STT_LOPROC = 13,
518 STT_HIPROC = 15,
520 // The section type that must be used for register symbols on
521 // Sparc. These symbols initialize a global register.
522 STT_SPARC_REGISTER = 13,
524 // ARM: a THUMB function. This is not defined in ARM ELF Specification but
525 // used by the GNU tool-chain.
526 STT_ARM_TFUNC = 13
529 inline STB
530 elf_st_bind(unsigned char info)
532 return static_cast<STB>(info >> 4);
535 inline STT
536 elf_st_type(unsigned char info)
538 return static_cast<STT>(info & 0xf);
541 inline unsigned char
542 elf_st_info(STB bind, STT type)
544 return ((static_cast<unsigned char>(bind) << 4)
545 + (static_cast<unsigned char>(type) & 0xf));
548 // Symbol visibility from Sym st_other field.
550 enum STV
552 STV_DEFAULT = 0,
553 STV_INTERNAL = 1,
554 STV_HIDDEN = 2,
555 STV_PROTECTED = 3
558 inline STV
559 elf_st_visibility(unsigned char other)
561 return static_cast<STV>(other & 0x3);
564 inline unsigned char
565 elf_st_nonvis(unsigned char other)
567 return static_cast<STV>(other >> 2);
570 inline unsigned char
571 elf_st_other(STV vis, unsigned char nonvis)
573 return ((nonvis << 2)
574 + (static_cast<unsigned char>(vis) & 3));
577 // Reloc information from Rel/Rela r_info field.
579 template<int size>
580 unsigned int
581 elf_r_sym(typename Elf_types<size>::Elf_WXword);
583 template<>
584 inline unsigned int
585 elf_r_sym<32>(Elf_Word v)
587 return v >> 8;
590 template<>
591 inline unsigned int
592 elf_r_sym<64>(Elf_Xword v)
594 return v >> 32;
597 template<int size>
598 unsigned int
599 elf_r_type(typename Elf_types<size>::Elf_WXword);
601 template<>
602 inline unsigned int
603 elf_r_type<32>(Elf_Word v)
605 return v & 0xff;
608 template<>
609 inline unsigned int
610 elf_r_type<64>(Elf_Xword v)
612 return v & 0xffffffff;
615 template<int size>
616 typename Elf_types<size>::Elf_WXword
617 elf_r_info(unsigned int s, unsigned int t);
619 template<>
620 inline Elf_Word
621 elf_r_info<32>(unsigned int s, unsigned int t)
623 return (s << 8) + (t & 0xff);
626 template<>
627 inline Elf_Xword
628 elf_r_info<64>(unsigned int s, unsigned int t)
630 return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
633 // Dynamic tags found in the PT_DYNAMIC segment.
635 enum DT
637 DT_NULL = 0,
638 DT_NEEDED = 1,
639 DT_PLTRELSZ = 2,
640 DT_PLTGOT = 3,
641 DT_HASH = 4,
642 DT_STRTAB = 5,
643 DT_SYMTAB = 6,
644 DT_RELA = 7,
645 DT_RELASZ = 8,
646 DT_RELAENT = 9,
647 DT_STRSZ = 10,
648 DT_SYMENT = 11,
649 DT_INIT = 12,
650 DT_FINI = 13,
651 DT_SONAME = 14,
652 DT_RPATH = 15,
653 DT_SYMBOLIC = 16,
654 DT_REL = 17,
655 DT_RELSZ = 18,
656 DT_RELENT = 19,
657 DT_PLTREL = 20,
658 DT_DEBUG = 21,
659 DT_TEXTREL = 22,
660 DT_JMPREL = 23,
661 DT_BIND_NOW = 24,
662 DT_INIT_ARRAY = 25,
663 DT_FINI_ARRAY = 26,
664 DT_INIT_ARRAYSZ = 27,
665 DT_FINI_ARRAYSZ = 28,
666 DT_RUNPATH = 29,
667 DT_FLAGS = 30,
669 // This is used to mark a range of dynamic tags. It is not really
670 // a tag value.
671 DT_ENCODING = 32,
673 DT_PREINIT_ARRAY = 32,
674 DT_PREINIT_ARRAYSZ = 33,
675 DT_LOOS = 0x6000000d,
676 DT_HIOS = 0x6ffff000,
677 DT_LOPROC = 0x70000000,
678 DT_HIPROC = 0x7fffffff,
680 // The remaining values are extensions used by GNU or Solaris.
681 DT_VALRNGLO = 0x6ffffd00,
682 DT_GNU_PRELINKED = 0x6ffffdf5,
683 DT_GNU_CONFLICTSZ = 0x6ffffdf6,
684 DT_GNU_LIBLISTSZ = 0x6ffffdf7,
685 DT_CHECKSUM = 0x6ffffdf8,
686 DT_PLTPADSZ = 0x6ffffdf9,
687 DT_MOVEENT = 0x6ffffdfa,
688 DT_MOVESZ = 0x6ffffdfb,
689 DT_FEATURE = 0x6ffffdfc,
690 DT_POSFLAG_1 = 0x6ffffdfd,
691 DT_SYMINSZ = 0x6ffffdfe,
692 DT_SYMINENT = 0x6ffffdff,
693 DT_VALRNGHI = 0x6ffffdff,
695 DT_ADDRRNGLO = 0x6ffffe00,
696 DT_GNU_HASH = 0x6ffffef5,
697 DT_TLSDESC_PLT = 0x6ffffef6,
698 DT_TLSDESC_GOT = 0x6ffffef7,
699 DT_GNU_CONFLICT = 0x6ffffef8,
700 DT_GNU_LIBLIST = 0x6ffffef9,
701 DT_CONFIG = 0x6ffffefa,
702 DT_DEPAUDIT = 0x6ffffefb,
703 DT_AUDIT = 0x6ffffefc,
704 DT_PLTPAD = 0x6ffffefd,
705 DT_MOVETAB = 0x6ffffefe,
706 DT_SYMINFO = 0x6ffffeff,
707 DT_ADDRRNGHI = 0x6ffffeff,
709 DT_RELACOUNT = 0x6ffffff9,
710 DT_RELCOUNT = 0x6ffffffa,
711 DT_FLAGS_1 = 0x6ffffffb,
712 DT_VERDEF = 0x6ffffffc,
713 DT_VERDEFNUM = 0x6ffffffd,
714 DT_VERNEED = 0x6ffffffe,
715 DT_VERNEEDNUM = 0x6fffffff,
717 DT_VERSYM = 0x6ffffff0,
719 // Specify the value of _GLOBAL_OFFSET_TABLE_.
720 DT_PPC_GOT = 0x70000000,
722 // Specify the start of the .glink section.
723 DT_PPC64_GLINK = 0x70000000,
725 // Specify the start and size of the .opd section.
726 DT_PPC64_OPD = 0x70000001,
727 DT_PPC64_OPDSZ = 0x70000002,
729 // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
730 // symbol table. One dynamic entry exists for every STT_SPARC_REGISTER
731 // symbol in the symbol table.
732 DT_SPARC_REGISTER = 0x70000001,
734 DT_AUXILIARY = 0x7ffffffd,
735 DT_USED = 0x7ffffffe,
736 DT_FILTER = 0x7fffffff
739 // Flags found in the DT_FLAGS dynamic element.
741 enum DF
743 DF_ORIGIN = 0x1,
744 DF_SYMBOLIC = 0x2,
745 DF_TEXTREL = 0x4,
746 DF_BIND_NOW = 0x8,
747 DF_STATIC_TLS = 0x10
750 // Flags found in the DT_FLAGS_1 dynamic element.
752 enum DF_1
754 DF_1_NOW = 0x1,
755 DF_1_GLOBAL = 0x2,
756 DF_1_GROUP = 0x4,
757 DF_1_NODELETE = 0x8,
758 DF_1_LOADFLTR = 0x10,
759 DF_1_INITFIRST = 0x20,
760 DF_1_NOOPEN = 0x40,
761 DF_1_ORIGIN = 0x80,
762 DF_1_DIRECT = 0x100,
763 DF_1_TRANS = 0x200,
764 DF_1_INTERPOSE = 0x400,
765 DF_1_NODEFLIB = 0x800,
766 DF_1_NODUMP = 0x1000,
767 DF_1_CONLFAT = 0x2000
770 // Version numbers which appear in the vd_version field of a Verdef
771 // structure.
773 const int VER_DEF_NONE = 0;
774 const int VER_DEF_CURRENT = 1;
776 // Version numbers which appear in the vn_version field of a Verneed
777 // structure.
779 const int VER_NEED_NONE = 0;
780 const int VER_NEED_CURRENT = 1;
782 // Bit flags which appear in vd_flags of Verdef and vna_flags of
783 // Vernaux.
785 const int VER_FLG_BASE = 0x1;
786 const int VER_FLG_WEAK = 0x2;
787 const int VER_FLG_INFO = 0x4;
789 // Special constants found in the SHT_GNU_versym entries.
791 const int VER_NDX_LOCAL = 0;
792 const int VER_NDX_GLOBAL = 1;
794 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
795 // the symbol is hidden and can only be seen when referenced using an
796 // explicit version number. This is a GNU extension.
798 const int VERSYM_HIDDEN = 0x8000;
800 // This is the mask for the rest of the data in a word read from a
801 // SHT_GNU_versym section.
803 const int VERSYM_VERSION = 0x7fff;
805 // Note descriptor type codes for notes in a non-core file with an
806 // empty name.
808 enum
810 // A version string.
811 NT_VERSION = 1,
812 // An architecture string.
813 NT_ARCH = 2
816 // Note descriptor type codes for notes in a non-core file with the
817 // name "GNU".
819 enum
821 // The minimum ABI level. This is used by the dynamic linker to
822 // describe the minimal kernel version on which a shared library may
823 // be used. Th value should be four words. Word 0 is an OS
824 // descriptor (see below). Word 1 is the major version of the ABI.
825 // Word 2 is the minor version. Word 3 is the subminor version.
826 NT_GNU_ABI_TAG = 1,
827 // Hardware capabilities information. Word 0 is the number of
828 // entries. Word 1 is a bitmask of enabled entries. The rest of
829 // the descriptor is a series of entries, where each entry is a
830 // single byte followed by a nul terminated string. The byte gives
831 // the bit number to test if enabled in the bitmask.
832 NT_GNU_HWCAP = 2,
833 // The build ID as set by the linker's --build-id option. The
834 // format of the descriptor depends on the build ID style.
835 NT_GNU_BUILD_ID = 3,
836 // The version of gold used to link. Th descriptor is just a
837 // string.
838 NT_GNU_GOLD_VERSION = 4
841 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
843 enum
845 ELF_NOTE_OS_LINUX = 0,
846 ELF_NOTE_OS_GNU = 1,
847 ELF_NOTE_OS_SOLARIS2 = 2,
848 ELF_NOTE_OS_FREEBSD = 3,
849 ELF_NOTE_OS_NETBSD = 4,
850 ELF_NOTE_OS_SYLLABLE = 5
853 } // End namespace elfcpp.
855 // Include internal details after defining the types.
856 #include "elfcpp_internal.h"
858 namespace elfcpp
861 // The offset of the ELF file header in the ELF file.
863 const int file_header_offset = 0;
865 // ELF structure sizes.
867 template<int size>
868 struct Elf_sizes
870 // Size of ELF file header.
871 static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
872 // Size of ELF segment header.
873 static const int phdr_size = sizeof(internal::Phdr_data<size>);
874 // Size of ELF section header.
875 static const int shdr_size = sizeof(internal::Shdr_data<size>);
876 // Size of ELF symbol table entry.
877 static const int sym_size = sizeof(internal::Sym_data<size>);
878 // Sizes of ELF reloc entries.
879 static const int rel_size = sizeof(internal::Rel_data<size>);
880 static const int rela_size = sizeof(internal::Rela_data<size>);
881 // Size of ELF dynamic entry.
882 static const int dyn_size = sizeof(internal::Dyn_data<size>);
883 // Size of ELF version structures.
884 static const int verdef_size = sizeof(internal::Verdef_data);
885 static const int verdaux_size = sizeof(internal::Verdaux_data);
886 static const int verneed_size = sizeof(internal::Verneed_data);
887 static const int vernaux_size = sizeof(internal::Vernaux_data);
890 // Accessor class for the ELF file header.
892 template<int size, bool big_endian>
893 class Ehdr
895 public:
896 Ehdr(const unsigned char* p)
897 : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
900 template<typename File>
901 Ehdr(File* file, typename File::Location loc)
902 : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
903 file->view(loc.file_offset, loc.data_size).data()))
906 const unsigned char*
907 get_e_ident() const
908 { return this->p_->e_ident; }
910 Elf_Half
911 get_e_type() const
912 { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
914 Elf_Half
915 get_e_machine() const
916 { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
918 Elf_Word
919 get_e_version() const
920 { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
922 typename Elf_types<size>::Elf_Addr
923 get_e_entry() const
924 { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
926 typename Elf_types<size>::Elf_Off
927 get_e_phoff() const
928 { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
930 typename Elf_types<size>::Elf_Off
931 get_e_shoff() const
932 { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
934 Elf_Word
935 get_e_flags() const
936 { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
938 Elf_Half
939 get_e_ehsize() const
940 { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
942 Elf_Half
943 get_e_phentsize() const
944 { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
946 Elf_Half
947 get_e_phnum() const
948 { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
950 Elf_Half
951 get_e_shentsize() const
952 { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
954 Elf_Half
955 get_e_shnum() const
956 { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
958 Elf_Half
959 get_e_shstrndx() const
960 { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
962 private:
963 const internal::Ehdr_data<size>* p_;
966 // Write class for the ELF file header.
968 template<int size, bool big_endian>
969 class Ehdr_write
971 public:
972 Ehdr_write(unsigned char* p)
973 : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
976 void
977 put_e_ident(const unsigned char v[EI_NIDENT]) const
978 { memcpy(this->p_->e_ident, v, EI_NIDENT); }
980 void
981 put_e_type(Elf_Half v)
982 { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
984 void
985 put_e_machine(Elf_Half v)
986 { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
988 void
989 put_e_version(Elf_Word v)
990 { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
992 void
993 put_e_entry(typename Elf_types<size>::Elf_Addr v)
994 { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
996 void
997 put_e_phoff(typename Elf_types<size>::Elf_Off v)
998 { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
1000 void
1001 put_e_shoff(typename Elf_types<size>::Elf_Off v)
1002 { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
1004 void
1005 put_e_flags(Elf_Word v)
1006 { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
1008 void
1009 put_e_ehsize(Elf_Half v)
1010 { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
1012 void
1013 put_e_phentsize(Elf_Half v)
1014 { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
1016 void
1017 put_e_phnum(Elf_Half v)
1018 { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
1020 void
1021 put_e_shentsize(Elf_Half v)
1022 { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
1024 void
1025 put_e_shnum(Elf_Half v)
1026 { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
1028 void
1029 put_e_shstrndx(Elf_Half v)
1030 { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
1032 private:
1033 internal::Ehdr_data<size>* p_;
1036 // Accessor class for an ELF section header.
1038 template<int size, bool big_endian>
1039 class Shdr
1041 public:
1042 Shdr(const unsigned char* p)
1043 : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
1046 template<typename File>
1047 Shdr(File* file, typename File::Location loc)
1048 : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
1049 file->view(loc.file_offset, loc.data_size).data()))
1052 Elf_Word
1053 get_sh_name() const
1054 { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
1056 Elf_Word
1057 get_sh_type() const
1058 { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
1060 typename Elf_types<size>::Elf_WXword
1061 get_sh_flags() const
1062 { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
1064 typename Elf_types<size>::Elf_Addr
1065 get_sh_addr() const
1066 { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
1068 typename Elf_types<size>::Elf_Off
1069 get_sh_offset() const
1070 { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
1072 typename Elf_types<size>::Elf_WXword
1073 get_sh_size() const
1074 { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
1076 Elf_Word
1077 get_sh_link() const
1078 { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
1080 Elf_Word
1081 get_sh_info() const
1082 { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
1084 typename Elf_types<size>::Elf_WXword
1085 get_sh_addralign() const
1086 { return
1087 Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
1089 typename Elf_types<size>::Elf_WXword
1090 get_sh_entsize() const
1091 { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
1093 private:
1094 const internal::Shdr_data<size>* p_;
1097 // Write class for an ELF section header.
1099 template<int size, bool big_endian>
1100 class Shdr_write
1102 public:
1103 Shdr_write(unsigned char* p)
1104 : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
1107 void
1108 put_sh_name(Elf_Word v)
1109 { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
1111 void
1112 put_sh_type(Elf_Word v)
1113 { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
1115 void
1116 put_sh_flags(typename Elf_types<size>::Elf_WXword v)
1117 { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
1119 void
1120 put_sh_addr(typename Elf_types<size>::Elf_Addr v)
1121 { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
1123 void
1124 put_sh_offset(typename Elf_types<size>::Elf_Off v)
1125 { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
1127 void
1128 put_sh_size(typename Elf_types<size>::Elf_WXword v)
1129 { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
1131 void
1132 put_sh_link(Elf_Word v)
1133 { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
1135 void
1136 put_sh_info(Elf_Word v)
1137 { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
1139 void
1140 put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
1141 { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
1143 void
1144 put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
1145 { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
1147 private:
1148 internal::Shdr_data<size>* p_;
1151 // Accessor class for an ELF segment header.
1153 template<int size, bool big_endian>
1154 class Phdr
1156 public:
1157 Phdr(const unsigned char* p)
1158 : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
1161 template<typename File>
1162 Phdr(File* file, typename File::Location loc)
1163 : p_(reinterpret_cast<internal::Phdr_data<size>*>(
1164 file->view(loc.file_offset, loc.data_size).data()))
1167 Elf_Word
1168 get_p_type() const
1169 { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
1171 typename Elf_types<size>::Elf_Off
1172 get_p_offset() const
1173 { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
1175 typename Elf_types<size>::Elf_Addr
1176 get_p_vaddr() const
1177 { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
1179 typename Elf_types<size>::Elf_Addr
1180 get_p_paddr() const
1181 { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
1183 typename Elf_types<size>::Elf_WXword
1184 get_p_filesz() const
1185 { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
1187 typename Elf_types<size>::Elf_WXword
1188 get_p_memsz() const
1189 { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
1191 Elf_Word
1192 get_p_flags() const
1193 { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
1195 typename Elf_types<size>::Elf_WXword
1196 get_p_align() const
1197 { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
1199 private:
1200 const internal::Phdr_data<size>* p_;
1203 // Write class for an ELF segment header.
1205 template<int size, bool big_endian>
1206 class Phdr_write
1208 public:
1209 Phdr_write(unsigned char* p)
1210 : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
1213 void
1214 put_p_type(Elf_Word v)
1215 { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
1217 void
1218 put_p_offset(typename Elf_types<size>::Elf_Off v)
1219 { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
1221 void
1222 put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
1223 { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
1225 void
1226 put_p_paddr(typename Elf_types<size>::Elf_Addr v)
1227 { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
1229 void
1230 put_p_filesz(typename Elf_types<size>::Elf_WXword v)
1231 { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
1233 void
1234 put_p_memsz(typename Elf_types<size>::Elf_WXword v)
1235 { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
1237 void
1238 put_p_flags(Elf_Word v)
1239 { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
1241 void
1242 put_p_align(typename Elf_types<size>::Elf_WXword v)
1243 { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
1245 private:
1246 internal::Phdr_data<size>* p_;
1249 // Accessor class for an ELF symbol table entry.
1251 template<int size, bool big_endian>
1252 class Sym
1254 public:
1255 Sym(const unsigned char* p)
1256 : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
1259 template<typename File>
1260 Sym(File* file, typename File::Location loc)
1261 : p_(reinterpret_cast<const internal::Sym_data<size>*>(
1262 file->view(loc.file_offset, loc.data_size).data()))
1265 Elf_Word
1266 get_st_name() const
1267 { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
1269 typename Elf_types<size>::Elf_Addr
1270 get_st_value() const
1271 { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
1273 typename Elf_types<size>::Elf_WXword
1274 get_st_size() const
1275 { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
1277 unsigned char
1278 get_st_info() const
1279 { return this->p_->st_info; }
1282 get_st_bind() const
1283 { return elf_st_bind(this->get_st_info()); }
1286 get_st_type() const
1287 { return elf_st_type(this->get_st_info()); }
1289 unsigned char
1290 get_st_other() const
1291 { return this->p_->st_other; }
1294 get_st_visibility() const
1295 { return elf_st_visibility(this->get_st_other()); }
1297 unsigned char
1298 get_st_nonvis() const
1299 { return elf_st_nonvis(this->get_st_other()); }
1301 Elf_Half
1302 get_st_shndx() const
1303 { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
1305 private:
1306 const internal::Sym_data<size>* p_;
1309 // Writer class for an ELF symbol table entry.
1311 template<int size, bool big_endian>
1312 class Sym_write
1314 public:
1315 Sym_write(unsigned char* p)
1316 : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
1319 void
1320 put_st_name(Elf_Word v)
1321 { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
1323 void
1324 put_st_value(typename Elf_types<size>::Elf_Addr v)
1325 { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
1327 void
1328 put_st_size(typename Elf_types<size>::Elf_WXword v)
1329 { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
1331 void
1332 put_st_info(unsigned char v)
1333 { this->p_->st_info = v; }
1335 void
1336 put_st_info(STB bind, STT type)
1337 { this->p_->st_info = elf_st_info(bind, type); }
1339 void
1340 put_st_other(unsigned char v)
1341 { this->p_->st_other = v; }
1343 void
1344 put_st_other(STV vis, unsigned char nonvis)
1345 { this->p_->st_other = elf_st_other(vis, nonvis); }
1347 void
1348 put_st_shndx(Elf_Half v)
1349 { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
1351 Sym<size, big_endian>
1352 sym()
1353 { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
1355 private:
1356 internal::Sym_data<size>* p_;
1359 // Accessor classes for an ELF REL relocation entry.
1361 template<int size, bool big_endian>
1362 class Rel
1364 public:
1365 Rel(const unsigned char* p)
1366 : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
1369 template<typename File>
1370 Rel(File* file, typename File::Location loc)
1371 : p_(reinterpret_cast<const internal::Rel_data<size>*>(
1372 file->view(loc.file_offset, loc.data_size).data()))
1375 typename Elf_types<size>::Elf_Addr
1376 get_r_offset() const
1377 { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1379 typename Elf_types<size>::Elf_WXword
1380 get_r_info() const
1381 { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1383 private:
1384 const internal::Rel_data<size>* p_;
1387 // Writer class for an ELF Rel relocation.
1389 template<int size, bool big_endian>
1390 class Rel_write
1392 public:
1393 Rel_write(unsigned char* p)
1394 : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
1397 void
1398 put_r_offset(typename Elf_types<size>::Elf_Addr v)
1399 { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1401 void
1402 put_r_info(typename Elf_types<size>::Elf_WXword v)
1403 { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1405 private:
1406 internal::Rel_data<size>* p_;
1409 // Accessor class for an ELF Rela relocation.
1411 template<int size, bool big_endian>
1412 class Rela
1414 public:
1415 Rela(const unsigned char* p)
1416 : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
1419 template<typename File>
1420 Rela(File* file, typename File::Location loc)
1421 : p_(reinterpret_cast<const internal::Rela_data<size>*>(
1422 file->view(loc.file_offset, loc.data_size).data()))
1425 typename Elf_types<size>::Elf_Addr
1426 get_r_offset() const
1427 { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1429 typename Elf_types<size>::Elf_WXword
1430 get_r_info() const
1431 { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1433 typename Elf_types<size>::Elf_Swxword
1434 get_r_addend() const
1435 { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
1437 private:
1438 const internal::Rela_data<size>* p_;
1441 // Writer class for an ELF Rela relocation.
1443 template<int size, bool big_endian>
1444 class Rela_write
1446 public:
1447 Rela_write(unsigned char* p)
1448 : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
1451 void
1452 put_r_offset(typename Elf_types<size>::Elf_Addr v)
1453 { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1455 void
1456 put_r_info(typename Elf_types<size>::Elf_WXword v)
1457 { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1459 void
1460 put_r_addend(typename Elf_types<size>::Elf_Swxword v)
1461 { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
1463 private:
1464 internal::Rela_data<size>* p_;
1467 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1468 // PT_DYNAMIC segment.
1470 template<int size, bool big_endian>
1471 class Dyn
1473 public:
1474 Dyn(const unsigned char* p)
1475 : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
1478 template<typename File>
1479 Dyn(File* file, typename File::Location loc)
1480 : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
1481 file->view(loc.file_offset, loc.data_size).data()))
1484 typename Elf_types<size>::Elf_Swxword
1485 get_d_tag() const
1486 { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
1488 typename Elf_types<size>::Elf_WXword
1489 get_d_val() const
1490 { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1492 typename Elf_types<size>::Elf_Addr
1493 get_d_ptr() const
1494 { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1496 private:
1497 const internal::Dyn_data<size>* p_;
1500 // Write class for an entry in the SHT_DYNAMIC section.
1502 template<int size, bool big_endian>
1503 class Dyn_write
1505 public:
1506 Dyn_write(unsigned char* p)
1507 : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
1510 void
1511 put_d_tag(typename Elf_types<size>::Elf_Swxword v)
1512 { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
1514 void
1515 put_d_val(typename Elf_types<size>::Elf_WXword v)
1516 { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1518 void
1519 put_d_ptr(typename Elf_types<size>::Elf_Addr v)
1520 { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1522 private:
1523 internal::Dyn_data<size>* p_;
1526 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1528 template<int size, bool big_endian>
1529 class Verdef
1531 public:
1532 Verdef(const unsigned char* p)
1533 : p_(reinterpret_cast<const internal::Verdef_data*>(p))
1536 template<typename File>
1537 Verdef(File* file, typename File::Location loc)
1538 : p_(reinterpret_cast<const internal::Verdef_data*>(
1539 file->view(loc.file_offset, loc.data_size).data()))
1542 Elf_Half
1543 get_vd_version() const
1544 { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
1546 Elf_Half
1547 get_vd_flags() const
1548 { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
1550 Elf_Half
1551 get_vd_ndx() const
1552 { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
1554 Elf_Half
1555 get_vd_cnt() const
1556 { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
1558 Elf_Word
1559 get_vd_hash() const
1560 { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
1562 Elf_Word
1563 get_vd_aux() const
1564 { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
1566 Elf_Word
1567 get_vd_next() const
1568 { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
1570 private:
1571 const internal::Verdef_data* p_;
1574 template<int size, bool big_endian>
1575 class Verdef_write
1577 public:
1578 Verdef_write(unsigned char* p)
1579 : p_(reinterpret_cast<internal::Verdef_data*>(p))
1582 void
1583 set_vd_version(Elf_Half v)
1584 { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
1586 void
1587 set_vd_flags(Elf_Half v)
1588 { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
1590 void
1591 set_vd_ndx(Elf_Half v)
1592 { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
1594 void
1595 set_vd_cnt(Elf_Half v)
1596 { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
1598 void
1599 set_vd_hash(Elf_Word v)
1600 { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
1602 void
1603 set_vd_aux(Elf_Word v)
1604 { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
1606 void
1607 set_vd_next(Elf_Word v)
1608 { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
1610 private:
1611 internal::Verdef_data* p_;
1614 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1615 // section.
1617 template<int size, bool big_endian>
1618 class Verdaux
1620 public:
1621 Verdaux(const unsigned char* p)
1622 : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
1625 template<typename File>
1626 Verdaux(File* file, typename File::Location loc)
1627 : p_(reinterpret_cast<const internal::Verdaux_data*>(
1628 file->view(loc.file_offset, loc.data_size).data()))
1631 Elf_Word
1632 get_vda_name() const
1633 { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
1635 Elf_Word
1636 get_vda_next() const
1637 { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
1639 private:
1640 const internal::Verdaux_data* p_;
1643 template<int size, bool big_endian>
1644 class Verdaux_write
1646 public:
1647 Verdaux_write(unsigned char* p)
1648 : p_(reinterpret_cast<internal::Verdaux_data*>(p))
1651 void
1652 set_vda_name(Elf_Word v)
1653 { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
1655 void
1656 set_vda_next(Elf_Word v)
1657 { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
1659 private:
1660 internal::Verdaux_data* p_;
1663 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1665 template<int size, bool big_endian>
1666 class Verneed
1668 public:
1669 Verneed(const unsigned char* p)
1670 : p_(reinterpret_cast<const internal::Verneed_data*>(p))
1673 template<typename File>
1674 Verneed(File* file, typename File::Location loc)
1675 : p_(reinterpret_cast<const internal::Verneed_data*>(
1676 file->view(loc.file_offset, loc.data_size).data()))
1679 Elf_Half
1680 get_vn_version() const
1681 { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
1683 Elf_Half
1684 get_vn_cnt() const
1685 { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
1687 Elf_Word
1688 get_vn_file() const
1689 { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
1691 Elf_Word
1692 get_vn_aux() const
1693 { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
1695 Elf_Word
1696 get_vn_next() const
1697 { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
1699 private:
1700 const internal::Verneed_data* p_;
1703 template<int size, bool big_endian>
1704 class Verneed_write
1706 public:
1707 Verneed_write(unsigned char* p)
1708 : p_(reinterpret_cast<internal::Verneed_data*>(p))
1711 void
1712 set_vn_version(Elf_Half v)
1713 { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
1715 void
1716 set_vn_cnt(Elf_Half v)
1717 { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
1719 void
1720 set_vn_file(Elf_Word v)
1721 { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
1723 void
1724 set_vn_aux(Elf_Word v)
1725 { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
1727 void
1728 set_vn_next(Elf_Word v)
1729 { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
1731 private:
1732 internal::Verneed_data* p_;
1735 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1736 // section.
1738 template<int size, bool big_endian>
1739 class Vernaux
1741 public:
1742 Vernaux(const unsigned char* p)
1743 : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
1746 template<typename File>
1747 Vernaux(File* file, typename File::Location loc)
1748 : p_(reinterpret_cast<const internal::Vernaux_data*>(
1749 file->view(loc.file_offset, loc.data_size).data()))
1752 Elf_Word
1753 get_vna_hash() const
1754 { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
1756 Elf_Half
1757 get_vna_flags() const
1758 { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
1760 Elf_Half
1761 get_vna_other() const
1762 { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
1764 Elf_Word
1765 get_vna_name() const
1766 { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
1768 Elf_Word
1769 get_vna_next() const
1770 { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
1772 private:
1773 const internal::Vernaux_data* p_;
1776 template<int size, bool big_endian>
1777 class Vernaux_write
1779 public:
1780 Vernaux_write(unsigned char* p)
1781 : p_(reinterpret_cast<internal::Vernaux_data*>(p))
1784 void
1785 set_vna_hash(Elf_Word v)
1786 { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
1788 void
1789 set_vna_flags(Elf_Half v)
1790 { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
1792 void
1793 set_vna_other(Elf_Half v)
1794 { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
1796 void
1797 set_vna_name(Elf_Word v)
1798 { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
1800 void
1801 set_vna_next(Elf_Word v)
1802 { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
1804 private:
1805 internal::Vernaux_data* p_;
1808 } // End namespace elfcpp.
1810 #endif // !defined(ELFPCP_H)