OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [elfcpp/] [elfcpp.h] - Blame information for rev 161

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.