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