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