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 100

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

powered by: WebSVN 2.1.0

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