xref: /netbsd-src/external/gpl3/binutils.old/dist/elfcpp/elfcpp.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos // elfcpp.h -- main header file for elfcpp    -*- C++ -*-
275fd0b74Schristos 
3*e992f068Schristos // Copyright (C) 2006-2022 Free Software Foundation, Inc.
475fd0b74Schristos // Written by Ian Lance Taylor <iant@google.com>.
575fd0b74Schristos 
675fd0b74Schristos // This file is part of elfcpp.
775fd0b74Schristos 
875fd0b74Schristos // This program is free software; you can redistribute it and/or
975fd0b74Schristos // modify it under the terms of the GNU Library General Public License
1075fd0b74Schristos // as published by the Free Software Foundation; either version 2, or
1175fd0b74Schristos // (at your option) any later version.
1275fd0b74Schristos 
1375fd0b74Schristos // In addition to the permissions in the GNU Library General Public
1475fd0b74Schristos // License, the Free Software Foundation gives you unlimited
1575fd0b74Schristos // permission to link the compiled version of this file into
1675fd0b74Schristos // combinations with other programs, and to distribute those
1775fd0b74Schristos // combinations without any restriction coming from the use of this
1875fd0b74Schristos // file.  (The Library Public License restrictions do apply in other
1975fd0b74Schristos // respects; for example, they cover modification of the file, and
2075fd0b74Schristos // distribution when not linked into a combined executable.)
2175fd0b74Schristos 
2275fd0b74Schristos // This program is distributed in the hope that it will be useful, but
2375fd0b74Schristos // WITHOUT ANY WARRANTY; without even the implied warranty of
2475fd0b74Schristos // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2575fd0b74Schristos // Library General Public License for more details.
2675fd0b74Schristos 
2775fd0b74Schristos // You should have received a copy of the GNU Library General Public
2875fd0b74Schristos // License along with this program; if not, write to the Free Software
2975fd0b74Schristos // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
3075fd0b74Schristos // 02110-1301, USA.
3175fd0b74Schristos 
3275fd0b74Schristos // This is the external interface for elfcpp.
3375fd0b74Schristos 
3475fd0b74Schristos #ifndef ELFCPP_H
3575fd0b74Schristos #define ELFCPP_H
3675fd0b74Schristos 
3775fd0b74Schristos #include "elfcpp_swap.h"
3875fd0b74Schristos 
3975fd0b74Schristos #include <stdint.h>
4075fd0b74Schristos 
4175fd0b74Schristos namespace elfcpp
4275fd0b74Schristos {
4375fd0b74Schristos 
4475fd0b74Schristos // Basic ELF types.
4575fd0b74Schristos 
4675fd0b74Schristos // These types are always the same size.
4775fd0b74Schristos 
4875fd0b74Schristos typedef uint16_t Elf_Half;
4975fd0b74Schristos typedef uint32_t Elf_Word;
5075fd0b74Schristos typedef int32_t Elf_Sword;
5175fd0b74Schristos typedef uint64_t Elf_Xword;
5275fd0b74Schristos typedef int64_t Elf_Sxword;
5375fd0b74Schristos 
5475fd0b74Schristos // These types vary in size depending on the ELF file class.  The
5575fd0b74Schristos // template parameter should be 32 or 64.
5675fd0b74Schristos 
5775fd0b74Schristos template<int size>
5875fd0b74Schristos struct Elf_types;
5975fd0b74Schristos 
6075fd0b74Schristos template<>
6175fd0b74Schristos struct Elf_types<32>
6275fd0b74Schristos {
6375fd0b74Schristos   typedef uint32_t Elf_Addr;
6475fd0b74Schristos   typedef uint32_t Elf_Off;
6575fd0b74Schristos   typedef uint32_t Elf_WXword;
6675fd0b74Schristos   typedef int32_t Elf_Swxword;
6775fd0b74Schristos };
6875fd0b74Schristos 
6975fd0b74Schristos template<>
7075fd0b74Schristos struct Elf_types<64>
7175fd0b74Schristos {
7275fd0b74Schristos   typedef uint64_t Elf_Addr;
7375fd0b74Schristos   typedef uint64_t Elf_Off;
7475fd0b74Schristos   typedef uint64_t Elf_WXword;
7575fd0b74Schristos   typedef int64_t Elf_Swxword;
7675fd0b74Schristos };
7775fd0b74Schristos 
7875fd0b74Schristos // Offsets within the Ehdr e_ident field.
7975fd0b74Schristos 
8075fd0b74Schristos const int EI_MAG0 = 0;
8175fd0b74Schristos const int EI_MAG1 = 1;
8275fd0b74Schristos const int EI_MAG2 = 2;
8375fd0b74Schristos const int EI_MAG3 = 3;
8475fd0b74Schristos const int EI_CLASS = 4;
8575fd0b74Schristos const int EI_DATA = 5;
8675fd0b74Schristos const int EI_VERSION = 6;
8775fd0b74Schristos const int EI_OSABI = 7;
8875fd0b74Schristos const int EI_ABIVERSION = 8;
8975fd0b74Schristos const int EI_PAD = 9;
9075fd0b74Schristos const int EI_NIDENT = 16;
9175fd0b74Schristos 
9275fd0b74Schristos // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
9375fd0b74Schristos 
9475fd0b74Schristos const int ELFMAG0 = 0x7f;
9575fd0b74Schristos const int ELFMAG1 = 'E';
9675fd0b74Schristos const int ELFMAG2 = 'L';
9775fd0b74Schristos const int ELFMAG3 = 'F';
9875fd0b74Schristos 
9975fd0b74Schristos // The valid values found in Ehdr e_ident[EI_CLASS].
10075fd0b74Schristos 
10175fd0b74Schristos enum
10275fd0b74Schristos {
10375fd0b74Schristos   ELFCLASSNONE = 0,
10475fd0b74Schristos   ELFCLASS32 = 1,
10575fd0b74Schristos   ELFCLASS64 = 2
10675fd0b74Schristos };
10775fd0b74Schristos 
10875fd0b74Schristos // The valid values found in Ehdr e_ident[EI_DATA].
10975fd0b74Schristos 
11075fd0b74Schristos enum
11175fd0b74Schristos {
11275fd0b74Schristos   ELFDATANONE = 0,
11375fd0b74Schristos   ELFDATA2LSB = 1,
11475fd0b74Schristos   ELFDATA2MSB = 2
11575fd0b74Schristos };
11675fd0b74Schristos 
11775fd0b74Schristos // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
11875fd0b74Schristos 
11975fd0b74Schristos enum
12075fd0b74Schristos {
12175fd0b74Schristos   EV_NONE = 0,
12275fd0b74Schristos   EV_CURRENT = 1
12375fd0b74Schristos };
12475fd0b74Schristos 
12575fd0b74Schristos // The valid values found in Ehdr e_ident[EI_OSABI].
12675fd0b74Schristos 
12775fd0b74Schristos enum ELFOSABI
12875fd0b74Schristos {
12975fd0b74Schristos   ELFOSABI_NONE = 0,
13075fd0b74Schristos   ELFOSABI_HPUX = 1,
13175fd0b74Schristos   ELFOSABI_NETBSD = 2,
13275fd0b74Schristos   ELFOSABI_GNU = 3,
13375fd0b74Schristos   // ELFOSABI_LINUX is an alias for ELFOSABI_GNU.
13475fd0b74Schristos   ELFOSABI_LINUX = 3,
13575fd0b74Schristos   ELFOSABI_SOLARIS = 6,
13675fd0b74Schristos   ELFOSABI_AIX = 7,
13775fd0b74Schristos   ELFOSABI_IRIX = 8,
13875fd0b74Schristos   ELFOSABI_FREEBSD = 9,
13975fd0b74Schristos   ELFOSABI_TRU64 = 10,
14075fd0b74Schristos   ELFOSABI_MODESTO = 11,
14175fd0b74Schristos   ELFOSABI_OPENBSD = 12,
14275fd0b74Schristos   ELFOSABI_OPENVMS = 13,
14375fd0b74Schristos   ELFOSABI_NSK = 14,
14475fd0b74Schristos   ELFOSABI_AROS = 15,
14575fd0b74Schristos   // A GNU extension for the ARM.
14675fd0b74Schristos   ELFOSABI_ARM = 97,
14775fd0b74Schristos   // A GNU extension for the MSP.
14875fd0b74Schristos   ELFOSABI_STANDALONE = 255
14975fd0b74Schristos };
15075fd0b74Schristos 
15175fd0b74Schristos // The valid values found in the Ehdr e_type field.
15275fd0b74Schristos 
15375fd0b74Schristos enum ET
15475fd0b74Schristos {
15575fd0b74Schristos   ET_NONE = 0,
15675fd0b74Schristos   ET_REL = 1,
15775fd0b74Schristos   ET_EXEC = 2,
15875fd0b74Schristos   ET_DYN = 3,
15975fd0b74Schristos   ET_CORE = 4,
16075fd0b74Schristos   ET_LOOS = 0xfe00,
16175fd0b74Schristos   ET_HIOS = 0xfeff,
16275fd0b74Schristos   ET_LOPROC = 0xff00,
16375fd0b74Schristos   ET_HIPROC = 0xffff
16475fd0b74Schristos };
16575fd0b74Schristos 
16675fd0b74Schristos // The valid values found in the Ehdr e_machine field.
16775fd0b74Schristos 
16875fd0b74Schristos enum EM
16975fd0b74Schristos {
17075fd0b74Schristos   EM_NONE = 0,
17175fd0b74Schristos   EM_M32 = 1,
17275fd0b74Schristos   EM_SPARC = 2,
17375fd0b74Schristos   EM_386 = 3,
17475fd0b74Schristos   EM_68K = 4,
17575fd0b74Schristos   EM_88K = 5,
17675fd0b74Schristos   EM_IAMCU = 6,
17775fd0b74Schristos   EM_860 = 7,
17875fd0b74Schristos   EM_MIPS = 8,
17975fd0b74Schristos   EM_S370 = 9,
18075fd0b74Schristos   EM_MIPS_RS3_LE = 10,
18175fd0b74Schristos   // 11 was the old Sparc V9 ABI.
18275fd0b74Schristos   // 12 through 14 are reserved.
18375fd0b74Schristos   EM_PARISC = 15,
18475fd0b74Schristos   // 16 is reserved.
18575fd0b74Schristos   // Some old PowerPC object files use 17.
18675fd0b74Schristos   EM_VPP500 = 17,
18775fd0b74Schristos   EM_SPARC32PLUS = 18,
18875fd0b74Schristos   EM_960 = 19,
18975fd0b74Schristos   EM_PPC = 20,
19075fd0b74Schristos   EM_PPC64 = 21,
19175fd0b74Schristos   EM_S390 = 22,
19275fd0b74Schristos   // 23 through 35 are served.
19375fd0b74Schristos   EM_V800 = 36,
19475fd0b74Schristos   EM_FR20 = 37,
19575fd0b74Schristos   EM_RH32 = 38,
19675fd0b74Schristos   EM_RCE = 39,
19775fd0b74Schristos   EM_ARM = 40,
19875fd0b74Schristos   EM_ALPHA = 41,
19975fd0b74Schristos   EM_SH = 42,
20075fd0b74Schristos   EM_SPARCV9 = 43,
20175fd0b74Schristos   EM_TRICORE = 44,
20275fd0b74Schristos   EM_ARC = 45,
20375fd0b74Schristos   EM_H8_300 = 46,
20475fd0b74Schristos   EM_H8_300H = 47,
20575fd0b74Schristos   EM_H8S = 48,
20675fd0b74Schristos   EM_H8_500 = 49,
20775fd0b74Schristos   EM_IA_64 = 50,
20875fd0b74Schristos   EM_MIPS_X = 51,
20975fd0b74Schristos   EM_COLDFIRE = 52,
21075fd0b74Schristos   EM_68HC12 = 53,
21175fd0b74Schristos   EM_MMA = 54,
21275fd0b74Schristos   EM_PCP = 55,
21375fd0b74Schristos   EM_NCPU = 56,
21475fd0b74Schristos   EM_NDR1 = 57,
21575fd0b74Schristos   EM_STARCORE = 58,
21675fd0b74Schristos   EM_ME16 = 59,
21775fd0b74Schristos   EM_ST100 = 60,
21875fd0b74Schristos   EM_TINYJ = 61,
21975fd0b74Schristos   EM_X86_64 = 62,
22075fd0b74Schristos   EM_PDSP = 63,
22175fd0b74Schristos   EM_PDP10 = 64,
22275fd0b74Schristos   EM_PDP11 = 65,
22375fd0b74Schristos   EM_FX66 = 66,
22475fd0b74Schristos   EM_ST9PLUS = 67,
22575fd0b74Schristos   EM_ST7 = 68,
22675fd0b74Schristos   EM_68HC16 = 69,
22775fd0b74Schristos   EM_68HC11 = 70,
22875fd0b74Schristos   EM_68HC08 = 71,
22975fd0b74Schristos   EM_68HC05 = 72,
23075fd0b74Schristos   EM_SVX = 73,
23175fd0b74Schristos   EM_ST19 = 74,
23275fd0b74Schristos   EM_VAX = 75,
23375fd0b74Schristos   EM_CRIS = 76,
23475fd0b74Schristos   EM_JAVELIN = 77,
23575fd0b74Schristos   EM_FIREPATH = 78,
23675fd0b74Schristos   EM_ZSP = 79,
23775fd0b74Schristos   EM_MMIX = 80,
23875fd0b74Schristos   EM_HUANY = 81,
23975fd0b74Schristos   EM_PRISM = 82,
24075fd0b74Schristos   EM_AVR = 83,
24175fd0b74Schristos   EM_FR30 = 84,
24275fd0b74Schristos   EM_D10V = 85,
24375fd0b74Schristos   EM_D30V = 86,
24475fd0b74Schristos   EM_V850 = 87,
24575fd0b74Schristos   EM_M32R = 88,
24675fd0b74Schristos   EM_MN10300 = 89,
24775fd0b74Schristos   EM_MN10200 = 90,
24875fd0b74Schristos   EM_PJ = 91,
24975fd0b74Schristos   EM_OR1K = 92,
25075fd0b74Schristos   EM_ARC_A5 = 93,
25175fd0b74Schristos   EM_XTENSA = 94,
25275fd0b74Schristos   EM_VIDEOCORE = 95,
25375fd0b74Schristos   EM_TMM_GPP = 96,
25475fd0b74Schristos   EM_NS32K = 97,
25575fd0b74Schristos   EM_TPC = 98,
25675fd0b74Schristos   // Some old picoJava object files use 99 (EM_PJ is correct).
25775fd0b74Schristos   EM_SNP1K = 99,
25875fd0b74Schristos   EM_ST200 = 100,
25975fd0b74Schristos   EM_IP2K = 101,
26075fd0b74Schristos   EM_MAX = 102,
26175fd0b74Schristos   EM_CR = 103,
26275fd0b74Schristos   EM_F2MC16 = 104,
26375fd0b74Schristos   EM_MSP430 = 105,
26475fd0b74Schristos   EM_BLACKFIN = 106,
26575fd0b74Schristos   EM_SE_C33 = 107,
26675fd0b74Schristos   EM_SEP = 108,
26775fd0b74Schristos   EM_ARCA = 109,
26875fd0b74Schristos   EM_UNICORE = 110,
26975fd0b74Schristos   EM_ALTERA_NIOS2 = 113,
27075fd0b74Schristos   EM_CRX = 114,
271ede78133Schristos   EM_TI_PRU = 144,
27275fd0b74Schristos   EM_AARCH64 = 183,
27375fd0b74Schristos   EM_TILEGX = 191,
27475fd0b74Schristos   // The Morph MT.
27575fd0b74Schristos   EM_MT = 0x2530,
27675fd0b74Schristos   // DLX.
27775fd0b74Schristos   EM_DLX = 0x5aa5,
27875fd0b74Schristos   // FRV.
27975fd0b74Schristos   EM_FRV = 0x5441,
28075fd0b74Schristos   // Infineon Technologies 16-bit microcontroller with C166-V2 core.
28175fd0b74Schristos   EM_X16X = 0x4688,
28275fd0b74Schristos   // Xstorym16
28375fd0b74Schristos   EM_XSTORMY16 = 0xad45,
28475fd0b74Schristos   // Renesas M32C
28575fd0b74Schristos   EM_M32C = 0xfeb0,
28675fd0b74Schristos   // Vitesse IQ2000
28775fd0b74Schristos   EM_IQ2000 = 0xfeba,
28875fd0b74Schristos   // NIOS
28975fd0b74Schristos   EM_NIOS32 = 0xfebb
29075fd0b74Schristos   // Old AVR objects used 0x1057 (EM_AVR is correct).
29175fd0b74Schristos   // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
29275fd0b74Schristos   // Old FR30 objects used 0x3330 (EM_FR30 is correct).
29375fd0b74Schristos   // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OR1K is correct).
29475fd0b74Schristos   // Old D10V objects used 0x7650 (EM_D10V is correct).
29575fd0b74Schristos   // Old D30V objects used 0x7676 (EM_D30V is correct).
29675fd0b74Schristos   // Old IP2X objects used 0x8217 (EM_IP2K is correct).
29775fd0b74Schristos   // Old PowerPC objects used 0x9025 (EM_PPC is correct).
29875fd0b74Schristos   // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
29975fd0b74Schristos   // Old M32R objects used 0x9041 (EM_M32R is correct).
30075fd0b74Schristos   // Old V850 objects used 0x9080 (EM_V850 is correct).
30175fd0b74Schristos   // Old S/390 objects used 0xa390 (EM_S390 is correct).
30275fd0b74Schristos   // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
30375fd0b74Schristos   // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
30475fd0b74Schristos   // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
30575fd0b74Schristos };
30675fd0b74Schristos 
30775fd0b74Schristos // A special value found in the Ehdr e_phnum field.
30875fd0b74Schristos 
30975fd0b74Schristos enum
31075fd0b74Schristos {
31175fd0b74Schristos   // Number of program segments stored in sh_info field of first
31275fd0b74Schristos   // section headre.
31375fd0b74Schristos   PN_XNUM = 0xffff
31475fd0b74Schristos };
31575fd0b74Schristos 
31675fd0b74Schristos // Special section indices.
31775fd0b74Schristos 
31875fd0b74Schristos enum
31975fd0b74Schristos {
32075fd0b74Schristos   SHN_UNDEF = 0,
32175fd0b74Schristos   SHN_LORESERVE = 0xff00,
32275fd0b74Schristos   SHN_LOPROC = 0xff00,
32375fd0b74Schristos   SHN_HIPROC = 0xff1f,
32475fd0b74Schristos   SHN_LOOS = 0xff20,
32575fd0b74Schristos   SHN_HIOS = 0xff3f,
32675fd0b74Schristos   SHN_ABS = 0xfff1,
32775fd0b74Schristos   SHN_COMMON = 0xfff2,
32875fd0b74Schristos   SHN_XINDEX = 0xffff,
32975fd0b74Schristos   SHN_HIRESERVE = 0xffff,
33075fd0b74Schristos 
33175fd0b74Schristos   // Provide for initial and final section ordering in conjunction
33275fd0b74Schristos   // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
33375fd0b74Schristos   SHN_BEFORE = 0xff00,
33475fd0b74Schristos   SHN_AFTER = 0xff01,
33575fd0b74Schristos 
33675fd0b74Schristos   // x86_64 specific large common symbol.
33775fd0b74Schristos   SHN_X86_64_LCOMMON = 0xff02
33875fd0b74Schristos };
33975fd0b74Schristos 
34075fd0b74Schristos // The valid values found in the Shdr sh_type field.
34175fd0b74Schristos 
34275fd0b74Schristos enum SHT
34375fd0b74Schristos {
34475fd0b74Schristos   SHT_NULL = 0,
34575fd0b74Schristos   SHT_PROGBITS = 1,
34675fd0b74Schristos   SHT_SYMTAB = 2,
34775fd0b74Schristos   SHT_STRTAB = 3,
34875fd0b74Schristos   SHT_RELA = 4,
34975fd0b74Schristos   SHT_HASH = 5,
35075fd0b74Schristos   SHT_DYNAMIC = 6,
35175fd0b74Schristos   SHT_NOTE = 7,
35275fd0b74Schristos   SHT_NOBITS = 8,
35375fd0b74Schristos   SHT_REL = 9,
35475fd0b74Schristos   SHT_SHLIB = 10,
35575fd0b74Schristos   SHT_DYNSYM = 11,
35675fd0b74Schristos   SHT_INIT_ARRAY = 14,
35775fd0b74Schristos   SHT_FINI_ARRAY = 15,
35875fd0b74Schristos   SHT_PREINIT_ARRAY = 16,
35975fd0b74Schristos   SHT_GROUP = 17,
36075fd0b74Schristos   SHT_SYMTAB_SHNDX = 18,
36175fd0b74Schristos   SHT_LOOS = 0x60000000,
36275fd0b74Schristos   SHT_HIOS = 0x6fffffff,
36375fd0b74Schristos   SHT_LOPROC = 0x70000000,
36475fd0b74Schristos   SHT_HIPROC = 0x7fffffff,
36575fd0b74Schristos   SHT_LOUSER = 0x80000000,
36675fd0b74Schristos   SHT_HIUSER = 0xffffffff,
36775fd0b74Schristos   // The remaining values are not in the standard.
36875fd0b74Schristos   // Incremental build data.
36975fd0b74Schristos   SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700,
37075fd0b74Schristos   SHT_GNU_INCREMENTAL_SYMTAB = 0x6fff4701,
37175fd0b74Schristos   SHT_GNU_INCREMENTAL_RELOCS = 0x6fff4702,
37275fd0b74Schristos   SHT_GNU_INCREMENTAL_GOT_PLT = 0x6fff4703,
37375fd0b74Schristos   // Object attributes.
37475fd0b74Schristos   SHT_GNU_ATTRIBUTES = 0x6ffffff5,
37575fd0b74Schristos   // GNU style dynamic hash table.
37675fd0b74Schristos   SHT_GNU_HASH = 0x6ffffff6,
37775fd0b74Schristos   // List of prelink dependencies.
37875fd0b74Schristos   SHT_GNU_LIBLIST = 0x6ffffff7,
37975fd0b74Schristos   // Versions defined by file.
38075fd0b74Schristos   SHT_SUNW_verdef = 0x6ffffffd,
38175fd0b74Schristos   SHT_GNU_verdef = 0x6ffffffd,
38275fd0b74Schristos   // Versions needed by file.
38375fd0b74Schristos   SHT_SUNW_verneed = 0x6ffffffe,
38475fd0b74Schristos   SHT_GNU_verneed = 0x6ffffffe,
38575fd0b74Schristos   // Symbol versions,
38675fd0b74Schristos   SHT_SUNW_versym = 0x6fffffff,
38775fd0b74Schristos   SHT_GNU_versym = 0x6fffffff,
38875fd0b74Schristos 
38975fd0b74Schristos   SHT_SPARC_GOTDATA = 0x70000000,
39075fd0b74Schristos 
39175fd0b74Schristos   // ARM-specific section types.
39275fd0b74Schristos   // Exception Index table.
39375fd0b74Schristos   SHT_ARM_EXIDX = 0x70000001,
39475fd0b74Schristos   // BPABI DLL dynamic linking pre-emption map.
39575fd0b74Schristos   SHT_ARM_PREEMPTMAP = 0x70000002,
39675fd0b74Schristos   // Object file compatibility attributes.
39775fd0b74Schristos   SHT_ARM_ATTRIBUTES = 0x70000003,
39875fd0b74Schristos   // Support for debugging overlaid programs.
39975fd0b74Schristos   SHT_ARM_DEBUGOVERLAY = 0x70000004,
40075fd0b74Schristos   SHT_ARM_OVERLAYSECTION = 0x70000005,
40175fd0b74Schristos 
40275fd0b74Schristos   // x86_64 unwind information.
40375fd0b74Schristos   SHT_X86_64_UNWIND = 0x70000001,
40475fd0b74Schristos 
40575fd0b74Schristos   // MIPS-specific section types.
40675fd0b74Schristos   // Section contains register usage information.
40775fd0b74Schristos   SHT_MIPS_REGINFO = 0x70000006,
40875fd0b74Schristos   // Section contains miscellaneous options.
40975fd0b74Schristos   SHT_MIPS_OPTIONS = 0x7000000d,
41075fd0b74Schristos   // ABI related flags section.
41175fd0b74Schristos   SHT_MIPS_ABIFLAGS = 0x7000002a,
41275fd0b74Schristos 
41375fd0b74Schristos   // AARCH64-specific section type.
41475fd0b74Schristos   SHT_AARCH64_ATTRIBUTES = 0x70000003,
41575fd0b74Schristos 
416*e992f068Schristos   // CSKY-specific section types.
417*e992f068Schristos   // Object file compatibility attributes.
418*e992f068Schristos   SHT_CSKY_ATTRIBUTES = 0x70000001,
419*e992f068Schristos 
42075fd0b74Schristos   // Link editor is to sort the entries in this section based on the
42175fd0b74Schristos   // address specified in the associated symbol table entry.
42275fd0b74Schristos   SHT_ORDERED = 0x7fffffff
42375fd0b74Schristos };
42475fd0b74Schristos 
42575fd0b74Schristos // The valid bit flags found in the Shdr sh_flags field.
42675fd0b74Schristos 
42775fd0b74Schristos enum SHF
42875fd0b74Schristos {
42975fd0b74Schristos   SHF_WRITE = 0x1,
43075fd0b74Schristos   SHF_ALLOC = 0x2,
43175fd0b74Schristos   SHF_EXECINSTR = 0x4,
43275fd0b74Schristos   SHF_MERGE = 0x10,
43375fd0b74Schristos   SHF_STRINGS = 0x20,
43475fd0b74Schristos   SHF_INFO_LINK = 0x40,
43575fd0b74Schristos   SHF_LINK_ORDER = 0x80,
43675fd0b74Schristos   SHF_OS_NONCONFORMING = 0x100,
43775fd0b74Schristos   SHF_GROUP = 0x200,
43875fd0b74Schristos   SHF_TLS = 0x400,
43975fd0b74Schristos   SHF_COMPRESSED = 0x800,
44075fd0b74Schristos   SHF_MASKOS = 0x0ff00000,
441*e992f068Schristos   SHF_GNU_RETAIN = 0x200000,
44275fd0b74Schristos   SHF_MASKPROC = 0xf0000000,
44375fd0b74Schristos 
44475fd0b74Schristos   // Indicates this section requires ordering in relation to
44575fd0b74Schristos   // other sections of the same type.  Ordered sections are
44675fd0b74Schristos   // combined within the section pointed to by the sh_link entry.
44775fd0b74Schristos   // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
44875fd0b74Schristos   // sorted section is to precede or follow, respectively, all
44975fd0b74Schristos   // other sections in the set being ordered.
45075fd0b74Schristos   SHF_ORDERED = 0x40000000,
45175fd0b74Schristos   // This section is excluded from input to the link-edit of an
45275fd0b74Schristos   // executable or shared object.  This flag is ignored if SHF_ALLOC
45375fd0b74Schristos   // is also set, or if relocations exist against the section.
45475fd0b74Schristos   SHF_EXCLUDE = 0x80000000,
45575fd0b74Schristos 
45675fd0b74Schristos   // Section with data that is GP relative addressable.
45775fd0b74Schristos   SHF_MIPS_GPREL = 0x10000000,
45875fd0b74Schristos 
45975fd0b74Schristos   // x86_64 specific large section.
46075fd0b74Schristos   SHF_X86_64_LARGE = 0x10000000
46175fd0b74Schristos };
46275fd0b74Schristos 
46375fd0b74Schristos // Values which appear in the first Elf_WXword of the section data
46475fd0b74Schristos // of a SHF_COMPRESSED section.
46575fd0b74Schristos enum
46675fd0b74Schristos {
46775fd0b74Schristos   ELFCOMPRESS_ZLIB = 1,
46875fd0b74Schristos   ELFCOMPRESS_LOOS = 0x60000000,
46975fd0b74Schristos   ELFCOMPRESS_HIOS = 0x6fffffff,
47075fd0b74Schristos   ELFCOMPRESS_LOPROC = 0x70000000,
47175fd0b74Schristos   ELFCOMPRESS_HIPROC = 0x7fffffff,
47275fd0b74Schristos };
47375fd0b74Schristos 
47475fd0b74Schristos // Bit flags which appear in the first 32-bit word of the section data
47575fd0b74Schristos // of a SHT_GROUP section.
47675fd0b74Schristos 
47775fd0b74Schristos enum
47875fd0b74Schristos {
47975fd0b74Schristos   GRP_COMDAT = 0x1,
48075fd0b74Schristos   GRP_MASKOS = 0x0ff00000,
48175fd0b74Schristos   GRP_MASKPROC = 0xf0000000
48275fd0b74Schristos };
48375fd0b74Schristos 
48475fd0b74Schristos // The valid values found in the Phdr p_type field.
48575fd0b74Schristos 
48675fd0b74Schristos enum PT
48775fd0b74Schristos {
48875fd0b74Schristos   PT_NULL = 0,
48975fd0b74Schristos   PT_LOAD = 1,
49075fd0b74Schristos   PT_DYNAMIC = 2,
49175fd0b74Schristos   PT_INTERP = 3,
49275fd0b74Schristos   PT_NOTE = 4,
49375fd0b74Schristos   PT_SHLIB = 5,
49475fd0b74Schristos   PT_PHDR = 6,
49575fd0b74Schristos   PT_TLS = 7,
49675fd0b74Schristos   PT_LOOS = 0x60000000,
49775fd0b74Schristos   PT_HIOS = 0x6fffffff,
49875fd0b74Schristos   PT_LOPROC = 0x70000000,
49975fd0b74Schristos   PT_HIPROC = 0x7fffffff,
50075fd0b74Schristos   // The remaining values are not in the standard.
50175fd0b74Schristos   // Frame unwind information.
50275fd0b74Schristos   PT_GNU_EH_FRAME = 0x6474e550,
50375fd0b74Schristos   PT_SUNW_EH_FRAME = 0x6474e550,
50475fd0b74Schristos   // Stack flags.
50575fd0b74Schristos   PT_GNU_STACK = 0x6474e551,
50675fd0b74Schristos   // Read only after relocation.
50775fd0b74Schristos   PT_GNU_RELRO = 0x6474e552,
50875fd0b74Schristos   // Platform architecture compatibility information
50975fd0b74Schristos   PT_ARM_ARCHEXT = 0x70000000,
51075fd0b74Schristos   // Exception unwind tables
51175fd0b74Schristos   PT_ARM_EXIDX = 0x70000001,
51275fd0b74Schristos   // Register usage information.  Identifies one .reginfo section.
51375fd0b74Schristos   PT_MIPS_REGINFO =0x70000000,
51475fd0b74Schristos   // Runtime procedure table.
51575fd0b74Schristos   PT_MIPS_RTPROC = 0x70000001,
51675fd0b74Schristos   // .MIPS.options section.
51775fd0b74Schristos   PT_MIPS_OPTIONS = 0x70000002,
51875fd0b74Schristos   // .MIPS.abiflags section.
51975fd0b74Schristos   PT_MIPS_ABIFLAGS = 0x70000003,
52075fd0b74Schristos   // Platform architecture compatibility information
52175fd0b74Schristos   PT_AARCH64_ARCHEXT = 0x70000000,
52275fd0b74Schristos   // Exception unwind tables
523ede78133Schristos   PT_AARCH64_UNWIND = 0x70000001,
524ede78133Schristos   // 4k page table size
525ede78133Schristos   PT_S390_PGSTE = 0x70000000,
52675fd0b74Schristos };
52775fd0b74Schristos 
52875fd0b74Schristos // The valid bit flags found in the Phdr p_flags field.
52975fd0b74Schristos 
53075fd0b74Schristos enum PF
53175fd0b74Schristos {
53275fd0b74Schristos   PF_X = 0x1,
53375fd0b74Schristos   PF_W = 0x2,
53475fd0b74Schristos   PF_R = 0x4,
53575fd0b74Schristos   PF_MASKOS = 0x0ff00000,
53675fd0b74Schristos   PF_MASKPROC = 0xf0000000
53775fd0b74Schristos };
53875fd0b74Schristos 
53975fd0b74Schristos // Symbol binding from Sym st_info field.
54075fd0b74Schristos 
54175fd0b74Schristos enum STB
54275fd0b74Schristos {
54375fd0b74Schristos   STB_LOCAL = 0,
54475fd0b74Schristos   STB_GLOBAL = 1,
54575fd0b74Schristos   STB_WEAK = 2,
54675fd0b74Schristos   STB_LOOS = 10,
54775fd0b74Schristos   STB_GNU_UNIQUE = 10,
54875fd0b74Schristos   STB_HIOS = 12,
54975fd0b74Schristos   STB_LOPROC = 13,
55075fd0b74Schristos   STB_HIPROC = 15
55175fd0b74Schristos };
55275fd0b74Schristos 
55375fd0b74Schristos // Symbol types from Sym st_info field.
55475fd0b74Schristos 
55575fd0b74Schristos enum STT
55675fd0b74Schristos {
55775fd0b74Schristos   STT_NOTYPE = 0,
55875fd0b74Schristos   STT_OBJECT = 1,
55975fd0b74Schristos   STT_FUNC = 2,
56075fd0b74Schristos   STT_SECTION = 3,
56175fd0b74Schristos   STT_FILE = 4,
56275fd0b74Schristos   STT_COMMON = 5,
56375fd0b74Schristos   STT_TLS = 6,
56475fd0b74Schristos 
56575fd0b74Schristos   // GNU extension: symbol value points to a function which is called
56675fd0b74Schristos   // at runtime to determine the final value of the symbol.
56775fd0b74Schristos   STT_GNU_IFUNC = 10,
56875fd0b74Schristos 
56975fd0b74Schristos   STT_LOOS = 10,
57075fd0b74Schristos   STT_HIOS = 12,
57175fd0b74Schristos   STT_LOPROC = 13,
57275fd0b74Schristos   STT_HIPROC = 15,
57375fd0b74Schristos 
57475fd0b74Schristos   // The section type that must be used for register symbols on
57575fd0b74Schristos   // Sparc.  These symbols initialize a global register.
57675fd0b74Schristos   STT_SPARC_REGISTER = 13,
57775fd0b74Schristos 
57875fd0b74Schristos   // ARM: a THUMB function.  This is not defined in ARM ELF Specification but
57975fd0b74Schristos   // used by the GNU tool-chain.
58075fd0b74Schristos   STT_ARM_TFUNC = 13
58175fd0b74Schristos };
58275fd0b74Schristos 
58375fd0b74Schristos inline STB
58475fd0b74Schristos elf_st_bind(unsigned char info)
58575fd0b74Schristos {
58675fd0b74Schristos   return static_cast<STB>(info >> 4);
58775fd0b74Schristos }
58875fd0b74Schristos 
58975fd0b74Schristos inline STT
59075fd0b74Schristos elf_st_type(unsigned char info)
59175fd0b74Schristos {
59275fd0b74Schristos   return static_cast<STT>(info & 0xf);
59375fd0b74Schristos }
59475fd0b74Schristos 
59575fd0b74Schristos inline unsigned char
59675fd0b74Schristos elf_st_info(STB bind, STT type)
59775fd0b74Schristos {
59875fd0b74Schristos   return ((static_cast<unsigned char>(bind) << 4)
59975fd0b74Schristos 	  + (static_cast<unsigned char>(type) & 0xf));
60075fd0b74Schristos }
60175fd0b74Schristos 
60275fd0b74Schristos // Symbol visibility from Sym st_other field.
60375fd0b74Schristos 
60475fd0b74Schristos enum STV
60575fd0b74Schristos {
60675fd0b74Schristos   STV_DEFAULT = 0,
60775fd0b74Schristos   STV_INTERNAL = 1,
60875fd0b74Schristos   STV_HIDDEN = 2,
60975fd0b74Schristos   STV_PROTECTED = 3
61075fd0b74Schristos };
61175fd0b74Schristos 
61275fd0b74Schristos inline STV
61375fd0b74Schristos elf_st_visibility(unsigned char other)
61475fd0b74Schristos {
61575fd0b74Schristos   return static_cast<STV>(other & 0x3);
61675fd0b74Schristos }
61775fd0b74Schristos 
61875fd0b74Schristos inline unsigned char
61975fd0b74Schristos elf_st_nonvis(unsigned char other)
62075fd0b74Schristos {
62175fd0b74Schristos   return static_cast<STV>(other >> 2);
62275fd0b74Schristos }
62375fd0b74Schristos 
62475fd0b74Schristos inline unsigned char
62575fd0b74Schristos elf_st_other(STV vis, unsigned char nonvis)
62675fd0b74Schristos {
62775fd0b74Schristos   return ((nonvis << 2)
62875fd0b74Schristos 	  + (static_cast<unsigned char>(vis) & 3));
62975fd0b74Schristos }
63075fd0b74Schristos 
63175fd0b74Schristos // Reloc information from Rel/Rela r_info field.
63275fd0b74Schristos 
63375fd0b74Schristos template<int size>
63475fd0b74Schristos unsigned int
63575fd0b74Schristos elf_r_sym(typename Elf_types<size>::Elf_WXword);
63675fd0b74Schristos 
63775fd0b74Schristos template<>
63875fd0b74Schristos inline unsigned int
63975fd0b74Schristos elf_r_sym<32>(Elf_Word v)
64075fd0b74Schristos {
64175fd0b74Schristos   return v >> 8;
64275fd0b74Schristos }
64375fd0b74Schristos 
64475fd0b74Schristos template<>
64575fd0b74Schristos inline unsigned int
64675fd0b74Schristos elf_r_sym<64>(Elf_Xword v)
64775fd0b74Schristos {
64875fd0b74Schristos   return v >> 32;
64975fd0b74Schristos }
65075fd0b74Schristos 
65175fd0b74Schristos template<int size>
65275fd0b74Schristos unsigned int
65375fd0b74Schristos elf_r_type(typename Elf_types<size>::Elf_WXword);
65475fd0b74Schristos 
65575fd0b74Schristos template<>
65675fd0b74Schristos inline unsigned int
65775fd0b74Schristos elf_r_type<32>(Elf_Word v)
65875fd0b74Schristos {
65975fd0b74Schristos   return v & 0xff;
66075fd0b74Schristos }
66175fd0b74Schristos 
66275fd0b74Schristos template<>
66375fd0b74Schristos inline unsigned int
66475fd0b74Schristos elf_r_type<64>(Elf_Xword v)
66575fd0b74Schristos {
66675fd0b74Schristos   return v & 0xffffffff;
66775fd0b74Schristos }
66875fd0b74Schristos 
66975fd0b74Schristos template<int size>
67075fd0b74Schristos typename Elf_types<size>::Elf_WXword
67175fd0b74Schristos elf_r_info(unsigned int s, unsigned int t);
67275fd0b74Schristos 
67375fd0b74Schristos template<>
67475fd0b74Schristos inline Elf_Word
67575fd0b74Schristos elf_r_info<32>(unsigned int s, unsigned int t)
67675fd0b74Schristos {
67775fd0b74Schristos   return (s << 8) + (t & 0xff);
67875fd0b74Schristos }
67975fd0b74Schristos 
68075fd0b74Schristos template<>
68175fd0b74Schristos inline Elf_Xword
68275fd0b74Schristos elf_r_info<64>(unsigned int s, unsigned int t)
68375fd0b74Schristos {
68475fd0b74Schristos   return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
68575fd0b74Schristos }
68675fd0b74Schristos 
68775fd0b74Schristos // Dynamic tags found in the PT_DYNAMIC segment.
68875fd0b74Schristos 
68975fd0b74Schristos enum DT
69075fd0b74Schristos {
69175fd0b74Schristos   DT_NULL = 0,
69275fd0b74Schristos   DT_NEEDED = 1,
69375fd0b74Schristos   DT_PLTRELSZ = 2,
69475fd0b74Schristos   DT_PLTGOT = 3,
69575fd0b74Schristos   DT_HASH = 4,
69675fd0b74Schristos   DT_STRTAB = 5,
69775fd0b74Schristos   DT_SYMTAB = 6,
69875fd0b74Schristos   DT_RELA = 7,
69975fd0b74Schristos   DT_RELASZ = 8,
70075fd0b74Schristos   DT_RELAENT = 9,
70175fd0b74Schristos   DT_STRSZ = 10,
70275fd0b74Schristos   DT_SYMENT = 11,
70375fd0b74Schristos   DT_INIT = 12,
70475fd0b74Schristos   DT_FINI = 13,
70575fd0b74Schristos   DT_SONAME = 14,
70675fd0b74Schristos   DT_RPATH = 15,
70775fd0b74Schristos   DT_SYMBOLIC = 16,
70875fd0b74Schristos   DT_REL = 17,
70975fd0b74Schristos   DT_RELSZ = 18,
71075fd0b74Schristos   DT_RELENT = 19,
71175fd0b74Schristos   DT_PLTREL = 20,
71275fd0b74Schristos   DT_DEBUG = 21,
71375fd0b74Schristos   DT_TEXTREL = 22,
71475fd0b74Schristos   DT_JMPREL = 23,
71575fd0b74Schristos   DT_BIND_NOW = 24,
71675fd0b74Schristos   DT_INIT_ARRAY = 25,
71775fd0b74Schristos   DT_FINI_ARRAY = 26,
71875fd0b74Schristos   DT_INIT_ARRAYSZ = 27,
71975fd0b74Schristos   DT_FINI_ARRAYSZ = 28,
72075fd0b74Schristos   DT_RUNPATH = 29,
72175fd0b74Schristos   DT_FLAGS = 30,
72275fd0b74Schristos 
72375fd0b74Schristos   // This is used to mark a range of dynamic tags.  It is not really
72475fd0b74Schristos   // a tag value.
72575fd0b74Schristos   DT_ENCODING = 32,
72675fd0b74Schristos 
72775fd0b74Schristos   DT_PREINIT_ARRAY = 32,
72875fd0b74Schristos   DT_PREINIT_ARRAYSZ = 33,
72975fd0b74Schristos   DT_LOOS = 0x6000000d,
73075fd0b74Schristos   DT_HIOS = 0x6ffff000,
73175fd0b74Schristos   DT_LOPROC = 0x70000000,
73275fd0b74Schristos   DT_HIPROC = 0x7fffffff,
73375fd0b74Schristos 
73475fd0b74Schristos   // The remaining values are extensions used by GNU or Solaris.
73575fd0b74Schristos   DT_VALRNGLO = 0x6ffffd00,
736*e992f068Schristos   DT_GNU_FLAGS_1 = 0x6ffffdf4,
73775fd0b74Schristos   DT_GNU_PRELINKED = 0x6ffffdf5,
73875fd0b74Schristos   DT_GNU_CONFLICTSZ = 0x6ffffdf6,
73975fd0b74Schristos   DT_GNU_LIBLISTSZ = 0x6ffffdf7,
74075fd0b74Schristos   DT_CHECKSUM = 0x6ffffdf8,
74175fd0b74Schristos   DT_PLTPADSZ = 0x6ffffdf9,
74275fd0b74Schristos   DT_MOVEENT = 0x6ffffdfa,
74375fd0b74Schristos   DT_MOVESZ = 0x6ffffdfb,
74475fd0b74Schristos   DT_FEATURE = 0x6ffffdfc,
74575fd0b74Schristos   DT_POSFLAG_1 = 0x6ffffdfd,
74675fd0b74Schristos   DT_SYMINSZ = 0x6ffffdfe,
74775fd0b74Schristos   DT_SYMINENT = 0x6ffffdff,
74875fd0b74Schristos   DT_VALRNGHI = 0x6ffffdff,
74975fd0b74Schristos 
75075fd0b74Schristos   DT_ADDRRNGLO = 0x6ffffe00,
75175fd0b74Schristos   DT_GNU_HASH = 0x6ffffef5,
75275fd0b74Schristos   DT_TLSDESC_PLT = 0x6ffffef6,
75375fd0b74Schristos   DT_TLSDESC_GOT = 0x6ffffef7,
75475fd0b74Schristos   DT_GNU_CONFLICT = 0x6ffffef8,
75575fd0b74Schristos   DT_GNU_LIBLIST = 0x6ffffef9,
75675fd0b74Schristos   DT_CONFIG = 0x6ffffefa,
75775fd0b74Schristos   DT_DEPAUDIT = 0x6ffffefb,
75875fd0b74Schristos   DT_AUDIT = 0x6ffffefc,
75975fd0b74Schristos   DT_PLTPAD = 0x6ffffefd,
76075fd0b74Schristos   DT_MOVETAB = 0x6ffffefe,
76175fd0b74Schristos   DT_SYMINFO = 0x6ffffeff,
76275fd0b74Schristos   DT_ADDRRNGHI = 0x6ffffeff,
76375fd0b74Schristos 
76475fd0b74Schristos   DT_RELACOUNT = 0x6ffffff9,
76575fd0b74Schristos   DT_RELCOUNT = 0x6ffffffa,
76675fd0b74Schristos   DT_FLAGS_1 = 0x6ffffffb,
76775fd0b74Schristos   DT_VERDEF = 0x6ffffffc,
76875fd0b74Schristos   DT_VERDEFNUM = 0x6ffffffd,
76975fd0b74Schristos   DT_VERNEED = 0x6ffffffe,
77075fd0b74Schristos   DT_VERNEEDNUM = 0x6fffffff,
77175fd0b74Schristos 
77275fd0b74Schristos   DT_VERSYM = 0x6ffffff0,
77375fd0b74Schristos 
77475fd0b74Schristos   // Specify the value of _GLOBAL_OFFSET_TABLE_.
77575fd0b74Schristos   DT_PPC_GOT = 0x70000000,
77675fd0b74Schristos 
777ede78133Schristos   // Specify whether various optimisations are possible.
778ede78133Schristos   DT_PPC_OPT = 0x70000001,
779ede78133Schristos 
78075fd0b74Schristos   // Specify the start of the .glink section.
78175fd0b74Schristos   DT_PPC64_GLINK = 0x70000000,
78275fd0b74Schristos 
78375fd0b74Schristos   // Specify the start and size of the .opd section.
78475fd0b74Schristos   DT_PPC64_OPD = 0x70000001,
78575fd0b74Schristos   DT_PPC64_OPDSZ = 0x70000002,
78675fd0b74Schristos 
787ede78133Schristos   // Specify whether various optimisations are possible.
788ede78133Schristos   DT_PPC64_OPT = 0x70000003,
789ede78133Schristos 
79075fd0b74Schristos   // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
79175fd0b74Schristos   // symbol table.  One dynamic entry exists for every STT_SPARC_REGISTER
79275fd0b74Schristos   // symbol in the symbol table.
79375fd0b74Schristos   DT_SPARC_REGISTER = 0x70000001,
79475fd0b74Schristos 
79575fd0b74Schristos   // MIPS specific dynamic array tags.
79675fd0b74Schristos   // 32 bit version number for runtime linker interface.
79775fd0b74Schristos   DT_MIPS_RLD_VERSION = 0x70000001,
79875fd0b74Schristos   // Time stamp.
79975fd0b74Schristos   DT_MIPS_TIME_STAMP = 0x70000002,
80075fd0b74Schristos   // Checksum of external strings and common sizes.
80175fd0b74Schristos   DT_MIPS_ICHECKSUM = 0x70000003,
80275fd0b74Schristos   // Index of version string in string table.
80375fd0b74Schristos   DT_MIPS_IVERSION = 0x70000004,
80475fd0b74Schristos   // 32 bits of flags.
80575fd0b74Schristos   DT_MIPS_FLAGS = 0x70000005,
80675fd0b74Schristos   // Base address of the segment.
80775fd0b74Schristos   DT_MIPS_BASE_ADDRESS = 0x70000006,
80875fd0b74Schristos   // ???
80975fd0b74Schristos   DT_MIPS_MSYM = 0x70000007,
81075fd0b74Schristos   // Address of .conflict section.
81175fd0b74Schristos   DT_MIPS_CONFLICT = 0x70000008,
81275fd0b74Schristos   // Address of .liblist section.
81375fd0b74Schristos   DT_MIPS_LIBLIST = 0x70000009,
81475fd0b74Schristos   // Number of local global offset table entries.
81575fd0b74Schristos   DT_MIPS_LOCAL_GOTNO = 0x7000000a,
81675fd0b74Schristos   // Number of entries in the .conflict section.
81775fd0b74Schristos   DT_MIPS_CONFLICTNO = 0x7000000b,
81875fd0b74Schristos   // Number of entries in the .liblist section.
81975fd0b74Schristos   DT_MIPS_LIBLISTNO = 0x70000010,
82075fd0b74Schristos   // Number of entries in the .dynsym section.
82175fd0b74Schristos   DT_MIPS_SYMTABNO = 0x70000011,
82275fd0b74Schristos   // Index of first external dynamic symbol not referenced locally.
82375fd0b74Schristos   DT_MIPS_UNREFEXTNO = 0x70000012,
82475fd0b74Schristos   // Index of first dynamic symbol in global offset table.
82575fd0b74Schristos   DT_MIPS_GOTSYM = 0x70000013,
82675fd0b74Schristos   // Number of page table entries in global offset table.
82775fd0b74Schristos   DT_MIPS_HIPAGENO = 0x70000014,
82875fd0b74Schristos   // Address of run time loader map, used for debugging.
82975fd0b74Schristos   DT_MIPS_RLD_MAP = 0x70000016,
83075fd0b74Schristos   // Delta C++ class definition.
83175fd0b74Schristos   DT_MIPS_DELTA_CLASS = 0x70000017,
83275fd0b74Schristos   // Number of entries in DT_MIPS_DELTA_CLASS.
83375fd0b74Schristos   DT_MIPS_DELTA_CLASS_NO = 0x70000018,
83475fd0b74Schristos   // Delta C++ class instances.
83575fd0b74Schristos   DT_MIPS_DELTA_INSTANCE = 0x70000019,
83675fd0b74Schristos   // Number of entries in DT_MIPS_DELTA_INSTANCE.
83775fd0b74Schristos   DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a,
83875fd0b74Schristos   // Delta relocations.
83975fd0b74Schristos   DT_MIPS_DELTA_RELOC = 0x7000001b,
84075fd0b74Schristos   // Number of entries in DT_MIPS_DELTA_RELOC.
84175fd0b74Schristos   DT_MIPS_DELTA_RELOC_NO = 0x7000001c,
84275fd0b74Schristos   // Delta symbols that Delta relocations refer to.
84375fd0b74Schristos   DT_MIPS_DELTA_SYM = 0x7000001d,
84475fd0b74Schristos   // Number of entries in DT_MIPS_DELTA_SYM.
84575fd0b74Schristos   DT_MIPS_DELTA_SYM_NO = 0x7000001e,
84675fd0b74Schristos   // Delta symbols that hold class declarations.
84775fd0b74Schristos   DT_MIPS_DELTA_CLASSSYM = 0x70000020,
84875fd0b74Schristos   // Number of entries in DT_MIPS_DELTA_CLASSSYM.
84975fd0b74Schristos   DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021,
85075fd0b74Schristos   // Flags indicating information about C++ flavor.
85175fd0b74Schristos   DT_MIPS_CXX_FLAGS = 0x70000022,
85275fd0b74Schristos   // Pixie information (???).
85375fd0b74Schristos   DT_MIPS_PIXIE_INIT = 0x70000023,
85475fd0b74Schristos   // Address of .MIPS.symlib
85575fd0b74Schristos   DT_MIPS_SYMBOL_LIB = 0x70000024,
85675fd0b74Schristos   // The GOT index of the first PTE for a segment
85775fd0b74Schristos   DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025,
85875fd0b74Schristos   // The GOT index of the first PTE for a local symbol
85975fd0b74Schristos   DT_MIPS_LOCAL_GOTIDX = 0x70000026,
86075fd0b74Schristos   // The GOT index of the first PTE for a hidden symbol
86175fd0b74Schristos   DT_MIPS_HIDDEN_GOTIDX = 0x70000027,
86275fd0b74Schristos   // The GOT index of the first PTE for a protected symbol
86375fd0b74Schristos   DT_MIPS_PROTECTED_GOTIDX = 0x70000028,
86475fd0b74Schristos   // Address of `.MIPS.options'.
86575fd0b74Schristos   DT_MIPS_OPTIONS = 0x70000029,
86675fd0b74Schristos   // Address of `.interface'.
86775fd0b74Schristos   DT_MIPS_INTERFACE = 0x7000002a,
86875fd0b74Schristos   // ???
86975fd0b74Schristos   DT_MIPS_DYNSTR_ALIGN = 0x7000002b,
87075fd0b74Schristos   // Size of the .interface section.
87175fd0b74Schristos   DT_MIPS_INTERFACE_SIZE = 0x7000002c,
87275fd0b74Schristos   // Size of rld_text_resolve function stored in the GOT.
87375fd0b74Schristos   DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d,
87475fd0b74Schristos   // Default suffix of DSO to be added by rld on dlopen() calls.
87575fd0b74Schristos   DT_MIPS_PERF_SUFFIX = 0x7000002e,
87675fd0b74Schristos   // Size of compact relocation section (O32).
87775fd0b74Schristos   DT_MIPS_COMPACT_SIZE = 0x7000002f,
87875fd0b74Schristos   // GP value for auxiliary GOTs.
87975fd0b74Schristos   DT_MIPS_GP_VALUE = 0x70000030,
88075fd0b74Schristos   // Address of auxiliary .dynamic.
88175fd0b74Schristos   DT_MIPS_AUX_DYNAMIC = 0x70000031,
88275fd0b74Schristos   // Address of the base of the PLTGOT.
88375fd0b74Schristos   DT_MIPS_PLTGOT = 0x70000032,
88475fd0b74Schristos   // Points to the base of a writable PLT.
88575fd0b74Schristos   DT_MIPS_RWPLT = 0x70000034,
88675fd0b74Schristos   // Relative offset of run time loader map, used for debugging.
88775fd0b74Schristos   DT_MIPS_RLD_MAP_REL = 0x70000035,
88875fd0b74Schristos 
88975fd0b74Schristos   DT_AUXILIARY = 0x7ffffffd,
89075fd0b74Schristos   DT_USED = 0x7ffffffe,
89175fd0b74Schristos   DT_FILTER = 0x7fffffff
89275fd0b74Schristos };
89375fd0b74Schristos 
89475fd0b74Schristos // Flags found in the DT_FLAGS dynamic element.
89575fd0b74Schristos 
89675fd0b74Schristos enum DF
89775fd0b74Schristos {
89875fd0b74Schristos   DF_ORIGIN = 0x1,
89975fd0b74Schristos   DF_SYMBOLIC = 0x2,
90075fd0b74Schristos   DF_TEXTREL = 0x4,
90175fd0b74Schristos   DF_BIND_NOW = 0x8,
90275fd0b74Schristos   DF_STATIC_TLS = 0x10
90375fd0b74Schristos };
90475fd0b74Schristos 
90575fd0b74Schristos // Flags found in the DT_FLAGS_1 dynamic element.
90675fd0b74Schristos 
90775fd0b74Schristos enum DF_1
90875fd0b74Schristos {
90975fd0b74Schristos   DF_1_NOW = 0x1,
91075fd0b74Schristos   DF_1_GLOBAL = 0x2,
91175fd0b74Schristos   DF_1_GROUP = 0x4,
91275fd0b74Schristos   DF_1_NODELETE = 0x8,
91375fd0b74Schristos   DF_1_LOADFLTR = 0x10,
91475fd0b74Schristos   DF_1_INITFIRST = 0x20,
91575fd0b74Schristos   DF_1_NOOPEN = 0x40,
91675fd0b74Schristos   DF_1_ORIGIN = 0x80,
91775fd0b74Schristos   DF_1_DIRECT = 0x100,
91875fd0b74Schristos   DF_1_TRANS = 0x200,
91975fd0b74Schristos   DF_1_INTERPOSE = 0x400,
92075fd0b74Schristos   DF_1_NODEFLIB = 0x800,
92175fd0b74Schristos   DF_1_NODUMP = 0x1000,
922*e992f068Schristos   DF_1_CONLFAT = 0x2000,
923*e992f068Schristos   DF_1_PIE = 0x08000000
924*e992f068Schristos };
925*e992f068Schristos 
926*e992f068Schristos // Flags found in the DT_GNU_FLAGS_1 dynamic element.
927*e992f068Schristos enum DF_GNU_1
928*e992f068Schristos {
929*e992f068Schristos   DF_GNU_1_UNIQUE = 0x1,
93075fd0b74Schristos };
93175fd0b74Schristos 
93275fd0b74Schristos // Version numbers which appear in the vd_version field of a Verdef
93375fd0b74Schristos // structure.
93475fd0b74Schristos 
93575fd0b74Schristos const int VER_DEF_NONE = 0;
93675fd0b74Schristos const int VER_DEF_CURRENT = 1;
93775fd0b74Schristos 
93875fd0b74Schristos // Version numbers which appear in the vn_version field of a Verneed
93975fd0b74Schristos // structure.
94075fd0b74Schristos 
94175fd0b74Schristos const int VER_NEED_NONE = 0;
94275fd0b74Schristos const int VER_NEED_CURRENT = 1;
94375fd0b74Schristos 
94475fd0b74Schristos // Bit flags which appear in vd_flags of Verdef and vna_flags of
94575fd0b74Schristos // Vernaux.
94675fd0b74Schristos 
94775fd0b74Schristos const int VER_FLG_BASE = 0x1;
94875fd0b74Schristos const int VER_FLG_WEAK = 0x2;
94975fd0b74Schristos const int VER_FLG_INFO = 0x4;
95075fd0b74Schristos 
95175fd0b74Schristos // Special constants found in the SHT_GNU_versym entries.
95275fd0b74Schristos 
95375fd0b74Schristos const int VER_NDX_LOCAL = 0;
95475fd0b74Schristos const int VER_NDX_GLOBAL = 1;
95575fd0b74Schristos 
95675fd0b74Schristos // A SHT_GNU_versym section holds 16-bit words.  This bit is set if
95775fd0b74Schristos // the symbol is hidden and can only be seen when referenced using an
95875fd0b74Schristos // explicit version number.  This is a GNU extension.
95975fd0b74Schristos 
96075fd0b74Schristos const int VERSYM_HIDDEN = 0x8000;
96175fd0b74Schristos 
96275fd0b74Schristos // This is the mask for the rest of the data in a word read from a
96375fd0b74Schristos // SHT_GNU_versym section.
96475fd0b74Schristos 
96575fd0b74Schristos const int VERSYM_VERSION = 0x7fff;
96675fd0b74Schristos 
96775fd0b74Schristos // Note descriptor type codes for notes in a non-core file with an
96875fd0b74Schristos // empty name.
96975fd0b74Schristos 
97075fd0b74Schristos enum
97175fd0b74Schristos {
97275fd0b74Schristos   // A version string.
97375fd0b74Schristos   NT_VERSION = 1,
97475fd0b74Schristos   // An architecture string.
97575fd0b74Schristos   NT_ARCH = 2
97675fd0b74Schristos };
97775fd0b74Schristos 
97875fd0b74Schristos // Note descriptor type codes for notes in a non-core file with the
97975fd0b74Schristos // name "GNU".
98075fd0b74Schristos 
98175fd0b74Schristos enum
98275fd0b74Schristos {
98375fd0b74Schristos   // The minimum ABI level.  This is used by the dynamic linker to
98475fd0b74Schristos   // describe the minimal kernel version on which a shared library may
98575fd0b74Schristos   // be used.  Th value should be four words.  Word 0 is an OS
98675fd0b74Schristos   // descriptor (see below).  Word 1 is the major version of the ABI.
98775fd0b74Schristos   // Word 2 is the minor version.  Word 3 is the subminor version.
98875fd0b74Schristos   NT_GNU_ABI_TAG = 1,
98975fd0b74Schristos   // Hardware capabilities information.  Word 0 is the number of
99075fd0b74Schristos   // entries.  Word 1 is a bitmask of enabled entries.  The rest of
99175fd0b74Schristos   // the descriptor is a series of entries, where each entry is a
99275fd0b74Schristos   // single byte followed by a nul terminated string.  The byte gives
99375fd0b74Schristos   // the bit number to test if enabled in the bitmask.
99475fd0b74Schristos   NT_GNU_HWCAP = 2,
99575fd0b74Schristos   // The build ID as set by the linker's --build-id option.  The
99675fd0b74Schristos   // format of the descriptor depends on the build ID style.
99775fd0b74Schristos   NT_GNU_BUILD_ID = 3,
99875fd0b74Schristos   // The version of gold used to link.  Th descriptor is just a
99975fd0b74Schristos   // string.
1000ede78133Schristos   NT_GNU_GOLD_VERSION = 4,
1001ede78133Schristos   // Program property note, as described in "Linux Extensions to the gABI".
1002ede78133Schristos   NT_GNU_PROPERTY_TYPE_0 = 5
100375fd0b74Schristos };
100475fd0b74Schristos 
100575fd0b74Schristos // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
100675fd0b74Schristos 
100775fd0b74Schristos enum
100875fd0b74Schristos {
100975fd0b74Schristos   ELF_NOTE_OS_LINUX = 0,
101075fd0b74Schristos   ELF_NOTE_OS_GNU = 1,
101175fd0b74Schristos   ELF_NOTE_OS_SOLARIS2 = 2,
101275fd0b74Schristos   ELF_NOTE_OS_FREEBSD = 3,
101375fd0b74Schristos   ELF_NOTE_OS_NETBSD = 4,
101475fd0b74Schristos   ELF_NOTE_OS_SYLLABLE = 5
101575fd0b74Schristos };
101675fd0b74Schristos 
1017ede78133Schristos // Program property types for NT_GNU_PROPERTY_TYPE_0.
1018ede78133Schristos 
1019ede78133Schristos enum
1020ede78133Schristos {
1021ede78133Schristos   GNU_PROPERTY_STACK_SIZE = 1,
1022ede78133Schristos   GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
1023ede78133Schristos   GNU_PROPERTY_LOPROC = 0xc0000000,
1024*e992f068Schristos   GNU_PROPERTY_X86_COMPAT_ISA_1_USED = 0xc0000000,
1025*e992f068Schristos   GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED = 0xc0000001,
1026*e992f068Schristos   GNU_PROPERTY_X86_UINT32_AND_LO = 0xc0000002,
1027*e992f068Schristos   GNU_PROPERTY_X86_UINT32_AND_HI = 0xc0007fff,
1028*e992f068Schristos   GNU_PROPERTY_X86_UINT32_OR_LO = 0xc0008000,
1029*e992f068Schristos   GNU_PROPERTY_X86_UINT32_OR_HI = 0xc000ffff,
1030*e992f068Schristos   GNU_PROPERTY_X86_UINT32_OR_AND_LO = 0xc0010000,
1031*e992f068Schristos   GNU_PROPERTY_X86_UINT32_OR_AND_HI = 0xc0017fff,
1032*e992f068Schristos   GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 0,
1033*e992f068Schristos   GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0,
1034*e992f068Schristos   GNU_PROPERTY_X86_FEATURE_1_AND = GNU_PROPERTY_X86_UINT32_AND_LO + 0,
1035*e992f068Schristos   GNU_PROPERTY_X86_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 2,
1036*e992f068Schristos   GNU_PROPERTY_X86_FEATURE_2_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 1,
1037*e992f068Schristos   GNU_PROPERTY_X86_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2,
1038*e992f068Schristos   GNU_PROPERTY_X86_FEATURE_2_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1,
1039ede78133Schristos   GNU_PROPERTY_HIPROC = 0xdfffffff,
1040ede78133Schristos   GNU_PROPERTY_LOUSER = 0xe0000000,
1041ede78133Schristos   GNU_PROPERTY_HIUSER = 0xffffffff
1042ede78133Schristos };
1043ede78133Schristos 
104475fd0b74Schristos } // End namespace elfcpp.
104575fd0b74Schristos 
104675fd0b74Schristos // Include internal details after defining the types.
104775fd0b74Schristos #include "elfcpp_internal.h"
104875fd0b74Schristos 
104975fd0b74Schristos namespace elfcpp
105075fd0b74Schristos {
105175fd0b74Schristos 
105275fd0b74Schristos // The offset of the ELF file header in the ELF file.
105375fd0b74Schristos 
105475fd0b74Schristos const int file_header_offset = 0;
105575fd0b74Schristos 
105675fd0b74Schristos // ELF structure sizes.
105775fd0b74Schristos 
105875fd0b74Schristos template<int size>
105975fd0b74Schristos struct Elf_sizes
106075fd0b74Schristos {
106175fd0b74Schristos   // Size of ELF file header.
106275fd0b74Schristos   static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
106375fd0b74Schristos   // Size of ELF segment header.
106475fd0b74Schristos   static const int phdr_size = sizeof(internal::Phdr_data<size>);
106575fd0b74Schristos   // Size of ELF section header.
106675fd0b74Schristos   static const int shdr_size = sizeof(internal::Shdr_data<size>);
106775fd0b74Schristos   // Size of ELF compression header.
106875fd0b74Schristos   static const int chdr_size = sizeof(internal::Chdr_data<size>);
106975fd0b74Schristos   // Size of ELF symbol table entry.
107075fd0b74Schristos   static const int sym_size = sizeof(internal::Sym_data<size>);
107175fd0b74Schristos   // Sizes of ELF reloc entries.
107275fd0b74Schristos   static const int rel_size = sizeof(internal::Rel_data<size>);
107375fd0b74Schristos   static const int rela_size = sizeof(internal::Rela_data<size>);
107475fd0b74Schristos   // Size of ELF dynamic entry.
107575fd0b74Schristos   static const int dyn_size = sizeof(internal::Dyn_data<size>);
107675fd0b74Schristos   // Size of ELF version structures.
107775fd0b74Schristos   static const int verdef_size = sizeof(internal::Verdef_data);
107875fd0b74Schristos   static const int verdaux_size = sizeof(internal::Verdaux_data);
107975fd0b74Schristos   static const int verneed_size = sizeof(internal::Verneed_data);
108075fd0b74Schristos   static const int vernaux_size = sizeof(internal::Vernaux_data);
108175fd0b74Schristos };
108275fd0b74Schristos 
108375fd0b74Schristos // Accessor class for the ELF file header.
108475fd0b74Schristos 
108575fd0b74Schristos template<int size, bool big_endian>
108675fd0b74Schristos class Ehdr
108775fd0b74Schristos {
108875fd0b74Schristos  public:
108975fd0b74Schristos   Ehdr(const unsigned char* p)
109075fd0b74Schristos     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
109175fd0b74Schristos   { }
109275fd0b74Schristos 
109375fd0b74Schristos   template<typename File>
109475fd0b74Schristos   Ehdr(File* file, typename File::Location loc)
109575fd0b74Schristos     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
109675fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
109775fd0b74Schristos   { }
109875fd0b74Schristos 
109975fd0b74Schristos   const unsigned char*
110075fd0b74Schristos   get_e_ident() const
110175fd0b74Schristos   { return this->p_->e_ident; }
110275fd0b74Schristos 
1103*e992f068Schristos   unsigned char
1104*e992f068Schristos   get_ei_osabi() const
1105*e992f068Schristos   { return this->p_->e_ident[EI_OSABI]; }
1106*e992f068Schristos 
1107*e992f068Schristos   unsigned char
1108*e992f068Schristos   get_ei_abiversion() const
1109*e992f068Schristos   { return this->p_->e_ident[EI_ABIVERSION]; }
1110*e992f068Schristos 
111175fd0b74Schristos   Elf_Half
111275fd0b74Schristos   get_e_type() const
111375fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
111475fd0b74Schristos 
111575fd0b74Schristos   Elf_Half
111675fd0b74Schristos   get_e_machine() const
111775fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
111875fd0b74Schristos 
111975fd0b74Schristos   Elf_Word
112075fd0b74Schristos   get_e_version() const
112175fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
112275fd0b74Schristos 
112375fd0b74Schristos   typename Elf_types<size>::Elf_Addr
112475fd0b74Schristos   get_e_entry() const
112575fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
112675fd0b74Schristos 
112775fd0b74Schristos   typename Elf_types<size>::Elf_Off
112875fd0b74Schristos   get_e_phoff() const
112975fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
113075fd0b74Schristos 
113175fd0b74Schristos   typename Elf_types<size>::Elf_Off
113275fd0b74Schristos   get_e_shoff() const
113375fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
113475fd0b74Schristos 
113575fd0b74Schristos   Elf_Word
113675fd0b74Schristos   get_e_flags() const
113775fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
113875fd0b74Schristos 
113975fd0b74Schristos   Elf_Half
114075fd0b74Schristos   get_e_ehsize() const
114175fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
114275fd0b74Schristos 
114375fd0b74Schristos   Elf_Half
114475fd0b74Schristos   get_e_phentsize() const
114575fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
114675fd0b74Schristos 
114775fd0b74Schristos   Elf_Half
114875fd0b74Schristos   get_e_phnum() const
114975fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
115075fd0b74Schristos 
115175fd0b74Schristos   Elf_Half
115275fd0b74Schristos   get_e_shentsize() const
115375fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
115475fd0b74Schristos 
115575fd0b74Schristos   Elf_Half
115675fd0b74Schristos   get_e_shnum() const
115775fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
115875fd0b74Schristos 
115975fd0b74Schristos   Elf_Half
116075fd0b74Schristos   get_e_shstrndx() const
116175fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
116275fd0b74Schristos 
116375fd0b74Schristos  private:
116475fd0b74Schristos   const internal::Ehdr_data<size>* p_;
116575fd0b74Schristos };
116675fd0b74Schristos 
116775fd0b74Schristos // Write class for the ELF file header.
116875fd0b74Schristos 
116975fd0b74Schristos template<int size, bool big_endian>
117075fd0b74Schristos class Ehdr_write
117175fd0b74Schristos {
117275fd0b74Schristos  public:
117375fd0b74Schristos   Ehdr_write(unsigned char* p)
117475fd0b74Schristos     : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
117575fd0b74Schristos   { }
117675fd0b74Schristos 
117775fd0b74Schristos   void
117875fd0b74Schristos   put_e_ident(const unsigned char v[EI_NIDENT]) const
117975fd0b74Schristos   { memcpy(this->p_->e_ident, v, EI_NIDENT); }
118075fd0b74Schristos 
118175fd0b74Schristos   void
118275fd0b74Schristos   put_e_type(Elf_Half v)
118375fd0b74Schristos   { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
118475fd0b74Schristos 
118575fd0b74Schristos   void
118675fd0b74Schristos   put_e_machine(Elf_Half v)
118775fd0b74Schristos   { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
118875fd0b74Schristos 
118975fd0b74Schristos   void
119075fd0b74Schristos   put_e_version(Elf_Word v)
119175fd0b74Schristos   { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
119275fd0b74Schristos 
119375fd0b74Schristos   void
119475fd0b74Schristos   put_e_entry(typename Elf_types<size>::Elf_Addr v)
119575fd0b74Schristos   { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
119675fd0b74Schristos 
119775fd0b74Schristos   void
119875fd0b74Schristos   put_e_phoff(typename Elf_types<size>::Elf_Off v)
119975fd0b74Schristos   { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
120075fd0b74Schristos 
120175fd0b74Schristos   void
120275fd0b74Schristos   put_e_shoff(typename Elf_types<size>::Elf_Off v)
120375fd0b74Schristos   { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
120475fd0b74Schristos 
120575fd0b74Schristos   void
120675fd0b74Schristos   put_e_flags(Elf_Word v)
120775fd0b74Schristos   { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
120875fd0b74Schristos 
120975fd0b74Schristos   void
121075fd0b74Schristos   put_e_ehsize(Elf_Half v)
121175fd0b74Schristos   { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
121275fd0b74Schristos 
121375fd0b74Schristos   void
121475fd0b74Schristos   put_e_phentsize(Elf_Half v)
121575fd0b74Schristos   { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
121675fd0b74Schristos 
121775fd0b74Schristos   void
121875fd0b74Schristos   put_e_phnum(Elf_Half v)
121975fd0b74Schristos   { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
122075fd0b74Schristos 
122175fd0b74Schristos   void
122275fd0b74Schristos   put_e_shentsize(Elf_Half v)
122375fd0b74Schristos   { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
122475fd0b74Schristos 
122575fd0b74Schristos   void
122675fd0b74Schristos   put_e_shnum(Elf_Half v)
122775fd0b74Schristos   { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
122875fd0b74Schristos 
122975fd0b74Schristos   void
123075fd0b74Schristos   put_e_shstrndx(Elf_Half v)
123175fd0b74Schristos   { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
123275fd0b74Schristos 
123375fd0b74Schristos  private:
123475fd0b74Schristos   internal::Ehdr_data<size>* p_;
123575fd0b74Schristos };
123675fd0b74Schristos 
123775fd0b74Schristos // Accessor class for an ELF section header.
123875fd0b74Schristos 
123975fd0b74Schristos template<int size, bool big_endian>
124075fd0b74Schristos class Shdr
124175fd0b74Schristos {
124275fd0b74Schristos  public:
124375fd0b74Schristos   Shdr(const unsigned char* p)
124475fd0b74Schristos     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
124575fd0b74Schristos   { }
124675fd0b74Schristos 
124775fd0b74Schristos   template<typename File>
124875fd0b74Schristos   Shdr(File* file, typename File::Location loc)
124975fd0b74Schristos     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
125075fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
125175fd0b74Schristos   { }
125275fd0b74Schristos 
125375fd0b74Schristos   Elf_Word
125475fd0b74Schristos   get_sh_name() const
125575fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
125675fd0b74Schristos 
125775fd0b74Schristos   Elf_Word
125875fd0b74Schristos   get_sh_type() const
125975fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
126075fd0b74Schristos 
126175fd0b74Schristos   typename Elf_types<size>::Elf_WXword
126275fd0b74Schristos   get_sh_flags() const
126375fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
126475fd0b74Schristos 
126575fd0b74Schristos   typename Elf_types<size>::Elf_Addr
126675fd0b74Schristos   get_sh_addr() const
126775fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
126875fd0b74Schristos 
126975fd0b74Schristos   typename Elf_types<size>::Elf_Off
127075fd0b74Schristos   get_sh_offset() const
127175fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
127275fd0b74Schristos 
127375fd0b74Schristos   typename Elf_types<size>::Elf_WXword
127475fd0b74Schristos   get_sh_size() const
127575fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
127675fd0b74Schristos 
127775fd0b74Schristos   Elf_Word
127875fd0b74Schristos   get_sh_link() const
127975fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
128075fd0b74Schristos 
128175fd0b74Schristos   Elf_Word
128275fd0b74Schristos   get_sh_info() const
128375fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
128475fd0b74Schristos 
128575fd0b74Schristos   typename Elf_types<size>::Elf_WXword
128675fd0b74Schristos   get_sh_addralign() const
128775fd0b74Schristos   { return
128875fd0b74Schristos       Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
128975fd0b74Schristos 
129075fd0b74Schristos   typename Elf_types<size>::Elf_WXword
129175fd0b74Schristos   get_sh_entsize() const
129275fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
129375fd0b74Schristos 
129475fd0b74Schristos  private:
129575fd0b74Schristos   const internal::Shdr_data<size>* p_;
129675fd0b74Schristos };
129775fd0b74Schristos 
129875fd0b74Schristos // Write class for an ELF section header.
129975fd0b74Schristos 
130075fd0b74Schristos template<int size, bool big_endian>
130175fd0b74Schristos class Shdr_write
130275fd0b74Schristos {
130375fd0b74Schristos  public:
130475fd0b74Schristos   Shdr_write(unsigned char* p)
130575fd0b74Schristos     : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
130675fd0b74Schristos   { }
130775fd0b74Schristos 
130875fd0b74Schristos   void
130975fd0b74Schristos   put_sh_name(Elf_Word v)
131075fd0b74Schristos   { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
131175fd0b74Schristos 
131275fd0b74Schristos   void
131375fd0b74Schristos   put_sh_type(Elf_Word v)
131475fd0b74Schristos   { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
131575fd0b74Schristos 
131675fd0b74Schristos   void
131775fd0b74Schristos   put_sh_flags(typename Elf_types<size>::Elf_WXword v)
131875fd0b74Schristos   { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
131975fd0b74Schristos 
132075fd0b74Schristos   void
132175fd0b74Schristos   put_sh_addr(typename Elf_types<size>::Elf_Addr v)
132275fd0b74Schristos   { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
132375fd0b74Schristos 
132475fd0b74Schristos   void
132575fd0b74Schristos   put_sh_offset(typename Elf_types<size>::Elf_Off v)
132675fd0b74Schristos   { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
132775fd0b74Schristos 
132875fd0b74Schristos   void
132975fd0b74Schristos   put_sh_size(typename Elf_types<size>::Elf_WXword v)
133075fd0b74Schristos   { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
133175fd0b74Schristos 
133275fd0b74Schristos   void
133375fd0b74Schristos   put_sh_link(Elf_Word v)
133475fd0b74Schristos   { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
133575fd0b74Schristos 
133675fd0b74Schristos   void
133775fd0b74Schristos   put_sh_info(Elf_Word v)
133875fd0b74Schristos   { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
133975fd0b74Schristos 
134075fd0b74Schristos   void
134175fd0b74Schristos   put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
134275fd0b74Schristos   { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
134375fd0b74Schristos 
134475fd0b74Schristos   void
134575fd0b74Schristos   put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
134675fd0b74Schristos   { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
134775fd0b74Schristos 
134875fd0b74Schristos  private:
134975fd0b74Schristos   internal::Shdr_data<size>* p_;
135075fd0b74Schristos };
135175fd0b74Schristos 
135275fd0b74Schristos // Accessor class for an ELF compression header.
135375fd0b74Schristos 
135475fd0b74Schristos template<int size, bool big_endian>
135575fd0b74Schristos class Chdr
135675fd0b74Schristos {
135775fd0b74Schristos  public:
135875fd0b74Schristos   Chdr(const unsigned char* p)
135975fd0b74Schristos     : p_(reinterpret_cast<const internal::Chdr_data<size>*>(p))
136075fd0b74Schristos   { }
136175fd0b74Schristos 
136275fd0b74Schristos   template<typename File>
136375fd0b74Schristos   Chdr(File* file, typename File::Location loc)
136475fd0b74Schristos     : p_(reinterpret_cast<const internal::Chdr_data<size>*>(
136575fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
136675fd0b74Schristos   { }
136775fd0b74Schristos 
136875fd0b74Schristos   Elf_Word
136975fd0b74Schristos   get_ch_type() const
137075fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->ch_type); }
137175fd0b74Schristos 
137275fd0b74Schristos   typename Elf_types<size>::Elf_WXword
137375fd0b74Schristos   get_ch_size() const
137475fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->ch_size); }
137575fd0b74Schristos 
137675fd0b74Schristos   typename Elf_types<size>::Elf_WXword
137775fd0b74Schristos   get_ch_addralign() const
137875fd0b74Schristos   { return
137975fd0b74Schristos       Convert<size, big_endian>::convert_host(this->p_->ch_addralign); }
138075fd0b74Schristos 
138175fd0b74Schristos  private:
138275fd0b74Schristos   const internal::Chdr_data<size>* p_;
138375fd0b74Schristos };
138475fd0b74Schristos 
138575fd0b74Schristos // Write class for an ELF compression header.
138675fd0b74Schristos 
138775fd0b74Schristos template<int size, bool big_endian>
138875fd0b74Schristos class Chdr_write
138975fd0b74Schristos {
139075fd0b74Schristos  public:
139175fd0b74Schristos   Chdr_write(unsigned char* p)
139275fd0b74Schristos     : p_(reinterpret_cast<internal::Chdr_data<size>*>(p))
139375fd0b74Schristos   { }
139475fd0b74Schristos 
139575fd0b74Schristos   void
139675fd0b74Schristos   put_ch_type(typename Elf_types<size>::Elf_WXword v)
139775fd0b74Schristos   { this->p_->ch_type = Convert<size, big_endian>::convert_host(v); }
139875fd0b74Schristos 
139975fd0b74Schristos   void
140075fd0b74Schristos   put_ch_size(typename Elf_types<size>::Elf_WXword v)
140175fd0b74Schristos   { this->p_->ch_size = Convert<size, big_endian>::convert_host(v); }
140275fd0b74Schristos 
140375fd0b74Schristos   void
140475fd0b74Schristos   put_ch_addralign(typename Elf_types<size>::Elf_WXword v)
140575fd0b74Schristos   { this->p_->ch_addralign = Convert<size, big_endian>::convert_host(v); }
140675fd0b74Schristos 
1407ede78133Schristos   void
1408ede78133Schristos   put_ch_reserved(Elf_Word);
1409ede78133Schristos 
141075fd0b74Schristos  private:
141175fd0b74Schristos   internal::Chdr_data<size>* p_;
141275fd0b74Schristos };
141375fd0b74Schristos 
1414ede78133Schristos template<>
1415ede78133Schristos inline void
1416ede78133Schristos elfcpp::Chdr_write<64, true>::put_ch_reserved(Elf_Word v)
1417ede78133Schristos {
1418ede78133Schristos   this->p_->ch_reserved = v;
1419ede78133Schristos }
1420ede78133Schristos 
1421ede78133Schristos template<>
1422ede78133Schristos inline void
1423ede78133Schristos elfcpp::Chdr_write<64, false>::put_ch_reserved(Elf_Word v)
1424ede78133Schristos {
1425ede78133Schristos   this->p_->ch_reserved = v;
1426ede78133Schristos }
1427ede78133Schristos 
142875fd0b74Schristos // Accessor class for an ELF segment header.
142975fd0b74Schristos 
143075fd0b74Schristos template<int size, bool big_endian>
143175fd0b74Schristos class Phdr
143275fd0b74Schristos {
143375fd0b74Schristos  public:
143475fd0b74Schristos   Phdr(const unsigned char* p)
143575fd0b74Schristos     : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
143675fd0b74Schristos   { }
143775fd0b74Schristos 
143875fd0b74Schristos   template<typename File>
143975fd0b74Schristos   Phdr(File* file, typename File::Location loc)
144075fd0b74Schristos     : p_(reinterpret_cast<internal::Phdr_data<size>*>(
144175fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
144275fd0b74Schristos   { }
144375fd0b74Schristos 
144475fd0b74Schristos   Elf_Word
144575fd0b74Schristos   get_p_type() const
144675fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
144775fd0b74Schristos 
144875fd0b74Schristos   typename Elf_types<size>::Elf_Off
144975fd0b74Schristos   get_p_offset() const
145075fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
145175fd0b74Schristos 
145275fd0b74Schristos   typename Elf_types<size>::Elf_Addr
145375fd0b74Schristos   get_p_vaddr() const
145475fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
145575fd0b74Schristos 
145675fd0b74Schristos   typename Elf_types<size>::Elf_Addr
145775fd0b74Schristos   get_p_paddr() const
145875fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
145975fd0b74Schristos 
146075fd0b74Schristos   typename Elf_types<size>::Elf_WXword
146175fd0b74Schristos   get_p_filesz() const
146275fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
146375fd0b74Schristos 
146475fd0b74Schristos   typename Elf_types<size>::Elf_WXword
146575fd0b74Schristos   get_p_memsz() const
146675fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
146775fd0b74Schristos 
146875fd0b74Schristos   Elf_Word
146975fd0b74Schristos   get_p_flags() const
147075fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
147175fd0b74Schristos 
147275fd0b74Schristos   typename Elf_types<size>::Elf_WXword
147375fd0b74Schristos   get_p_align() const
147475fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
147575fd0b74Schristos 
147675fd0b74Schristos  private:
147775fd0b74Schristos   const internal::Phdr_data<size>* p_;
147875fd0b74Schristos };
147975fd0b74Schristos 
148075fd0b74Schristos // Write class for an ELF segment header.
148175fd0b74Schristos 
148275fd0b74Schristos template<int size, bool big_endian>
148375fd0b74Schristos class Phdr_write
148475fd0b74Schristos {
148575fd0b74Schristos  public:
148675fd0b74Schristos   Phdr_write(unsigned char* p)
148775fd0b74Schristos     : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
148875fd0b74Schristos   { }
148975fd0b74Schristos 
149075fd0b74Schristos   void
149175fd0b74Schristos   put_p_type(Elf_Word v)
149275fd0b74Schristos   { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
149375fd0b74Schristos 
149475fd0b74Schristos   void
149575fd0b74Schristos   put_p_offset(typename Elf_types<size>::Elf_Off v)
149675fd0b74Schristos   { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
149775fd0b74Schristos 
149875fd0b74Schristos   void
149975fd0b74Schristos   put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
150075fd0b74Schristos   { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
150175fd0b74Schristos 
150275fd0b74Schristos   void
150375fd0b74Schristos   put_p_paddr(typename Elf_types<size>::Elf_Addr v)
150475fd0b74Schristos   { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
150575fd0b74Schristos 
150675fd0b74Schristos   void
150775fd0b74Schristos   put_p_filesz(typename Elf_types<size>::Elf_WXword v)
150875fd0b74Schristos   { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
150975fd0b74Schristos 
151075fd0b74Schristos   void
151175fd0b74Schristos   put_p_memsz(typename Elf_types<size>::Elf_WXword v)
151275fd0b74Schristos   { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
151375fd0b74Schristos 
151475fd0b74Schristos   void
151575fd0b74Schristos   put_p_flags(Elf_Word v)
151675fd0b74Schristos   { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
151775fd0b74Schristos 
151875fd0b74Schristos   void
151975fd0b74Schristos   put_p_align(typename Elf_types<size>::Elf_WXword v)
152075fd0b74Schristos   { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
152175fd0b74Schristos 
152275fd0b74Schristos  private:
152375fd0b74Schristos   internal::Phdr_data<size>* p_;
152475fd0b74Schristos };
152575fd0b74Schristos 
152675fd0b74Schristos // Accessor class for an ELF symbol table entry.
152775fd0b74Schristos 
152875fd0b74Schristos template<int size, bool big_endian>
152975fd0b74Schristos class Sym
153075fd0b74Schristos {
153175fd0b74Schristos  public:
153275fd0b74Schristos   Sym(const unsigned char* p)
153375fd0b74Schristos     : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
153475fd0b74Schristos   { }
153575fd0b74Schristos 
153675fd0b74Schristos   template<typename File>
153775fd0b74Schristos   Sym(File* file, typename File::Location loc)
153875fd0b74Schristos     : p_(reinterpret_cast<const internal::Sym_data<size>*>(
153975fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
154075fd0b74Schristos   { }
154175fd0b74Schristos 
154275fd0b74Schristos   Elf_Word
154375fd0b74Schristos   get_st_name() const
154475fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
154575fd0b74Schristos 
154675fd0b74Schristos   typename Elf_types<size>::Elf_Addr
154775fd0b74Schristos   get_st_value() const
154875fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
154975fd0b74Schristos 
155075fd0b74Schristos   typename Elf_types<size>::Elf_WXword
155175fd0b74Schristos   get_st_size() const
155275fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
155375fd0b74Schristos 
155475fd0b74Schristos   unsigned char
155575fd0b74Schristos   get_st_info() const
155675fd0b74Schristos   { return this->p_->st_info; }
155775fd0b74Schristos 
155875fd0b74Schristos   STB
155975fd0b74Schristos   get_st_bind() const
156075fd0b74Schristos   { return elf_st_bind(this->get_st_info()); }
156175fd0b74Schristos 
156275fd0b74Schristos   STT
156375fd0b74Schristos   get_st_type() const
156475fd0b74Schristos   { return elf_st_type(this->get_st_info()); }
156575fd0b74Schristos 
156675fd0b74Schristos   unsigned char
156775fd0b74Schristos   get_st_other() const
156875fd0b74Schristos   { return this->p_->st_other; }
156975fd0b74Schristos 
157075fd0b74Schristos   STV
157175fd0b74Schristos   get_st_visibility() const
157275fd0b74Schristos   { return elf_st_visibility(this->get_st_other()); }
157375fd0b74Schristos 
157475fd0b74Schristos   unsigned char
157575fd0b74Schristos   get_st_nonvis() const
157675fd0b74Schristos   { return elf_st_nonvis(this->get_st_other()); }
157775fd0b74Schristos 
157875fd0b74Schristos   Elf_Half
157975fd0b74Schristos   get_st_shndx() const
158075fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
158175fd0b74Schristos 
158275fd0b74Schristos  private:
158375fd0b74Schristos   const internal::Sym_data<size>* p_;
158475fd0b74Schristos };
158575fd0b74Schristos 
158675fd0b74Schristos // Writer class for an ELF symbol table entry.
158775fd0b74Schristos 
158875fd0b74Schristos template<int size, bool big_endian>
158975fd0b74Schristos class Sym_write
159075fd0b74Schristos {
159175fd0b74Schristos  public:
159275fd0b74Schristos   Sym_write(unsigned char* p)
159375fd0b74Schristos     : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
159475fd0b74Schristos   { }
159575fd0b74Schristos 
159675fd0b74Schristos   void
159775fd0b74Schristos   put_st_name(Elf_Word v)
159875fd0b74Schristos   { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
159975fd0b74Schristos 
160075fd0b74Schristos   void
160175fd0b74Schristos   put_st_value(typename Elf_types<size>::Elf_Addr v)
160275fd0b74Schristos   { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
160375fd0b74Schristos 
160475fd0b74Schristos   void
160575fd0b74Schristos   put_st_size(typename Elf_types<size>::Elf_WXword v)
160675fd0b74Schristos   { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
160775fd0b74Schristos 
160875fd0b74Schristos   void
160975fd0b74Schristos   put_st_info(unsigned char v)
161075fd0b74Schristos   { this->p_->st_info = v; }
161175fd0b74Schristos 
161275fd0b74Schristos   void
161375fd0b74Schristos   put_st_info(STB bind, STT type)
161475fd0b74Schristos   { this->p_->st_info = elf_st_info(bind, type); }
161575fd0b74Schristos 
161675fd0b74Schristos   void
161775fd0b74Schristos   put_st_other(unsigned char v)
161875fd0b74Schristos   { this->p_->st_other = v; }
161975fd0b74Schristos 
162075fd0b74Schristos   void
162175fd0b74Schristos   put_st_other(STV vis, unsigned char nonvis)
162275fd0b74Schristos   { this->p_->st_other = elf_st_other(vis, nonvis); }
162375fd0b74Schristos 
162475fd0b74Schristos   void
162575fd0b74Schristos   put_st_shndx(Elf_Half v)
162675fd0b74Schristos   { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
162775fd0b74Schristos 
162875fd0b74Schristos   Sym<size, big_endian>
162975fd0b74Schristos   sym()
163075fd0b74Schristos   { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
163175fd0b74Schristos 
163275fd0b74Schristos  private:
163375fd0b74Schristos   internal::Sym_data<size>* p_;
163475fd0b74Schristos };
163575fd0b74Schristos 
163675fd0b74Schristos // Accessor classes for an ELF REL relocation entry.
163775fd0b74Schristos 
163875fd0b74Schristos template<int size, bool big_endian>
163975fd0b74Schristos class Rel
164075fd0b74Schristos {
164175fd0b74Schristos  public:
164275fd0b74Schristos   Rel(const unsigned char* p)
164375fd0b74Schristos     : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
164475fd0b74Schristos   { }
164575fd0b74Schristos 
164675fd0b74Schristos   template<typename File>
164775fd0b74Schristos   Rel(File* file, typename File::Location loc)
164875fd0b74Schristos     : p_(reinterpret_cast<const internal::Rel_data<size>*>(
164975fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
165075fd0b74Schristos   { }
165175fd0b74Schristos 
165275fd0b74Schristos   typename Elf_types<size>::Elf_Addr
165375fd0b74Schristos   get_r_offset() const
165475fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
165575fd0b74Schristos 
165675fd0b74Schristos   typename Elf_types<size>::Elf_WXword
165775fd0b74Schristos   get_r_info() const
165875fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
165975fd0b74Schristos 
166075fd0b74Schristos  private:
166175fd0b74Schristos   const internal::Rel_data<size>* p_;
166275fd0b74Schristos };
166375fd0b74Schristos 
166475fd0b74Schristos // Writer class for an ELF Rel relocation.
166575fd0b74Schristos 
166675fd0b74Schristos template<int size, bool big_endian>
166775fd0b74Schristos class Rel_write
166875fd0b74Schristos {
166975fd0b74Schristos  public:
167075fd0b74Schristos   Rel_write(unsigned char* p)
167175fd0b74Schristos     : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
167275fd0b74Schristos   { }
167375fd0b74Schristos 
167475fd0b74Schristos   void
167575fd0b74Schristos   put_r_offset(typename Elf_types<size>::Elf_Addr v)
167675fd0b74Schristos   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
167775fd0b74Schristos 
167875fd0b74Schristos   void
167975fd0b74Schristos   put_r_info(typename Elf_types<size>::Elf_WXword v)
168075fd0b74Schristos   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
168175fd0b74Schristos 
168275fd0b74Schristos  private:
168375fd0b74Schristos   internal::Rel_data<size>* p_;
168475fd0b74Schristos };
168575fd0b74Schristos 
168675fd0b74Schristos // Accessor class for an ELF Rela relocation.
168775fd0b74Schristos 
168875fd0b74Schristos template<int size, bool big_endian>
168975fd0b74Schristos class Rela
169075fd0b74Schristos {
169175fd0b74Schristos  public:
169275fd0b74Schristos   Rela(const unsigned char* p)
169375fd0b74Schristos     : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
169475fd0b74Schristos   { }
169575fd0b74Schristos 
169675fd0b74Schristos   template<typename File>
169775fd0b74Schristos   Rela(File* file, typename File::Location loc)
169875fd0b74Schristos     : p_(reinterpret_cast<const internal::Rela_data<size>*>(
169975fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
170075fd0b74Schristos   { }
170175fd0b74Schristos 
170275fd0b74Schristos   typename Elf_types<size>::Elf_Addr
170375fd0b74Schristos   get_r_offset() const
170475fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
170575fd0b74Schristos 
170675fd0b74Schristos   typename Elf_types<size>::Elf_WXword
170775fd0b74Schristos   get_r_info() const
170875fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
170975fd0b74Schristos 
171075fd0b74Schristos   typename Elf_types<size>::Elf_Swxword
171175fd0b74Schristos   get_r_addend() const
171275fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
171375fd0b74Schristos 
171475fd0b74Schristos  private:
171575fd0b74Schristos   const internal::Rela_data<size>* p_;
171675fd0b74Schristos };
171775fd0b74Schristos 
171875fd0b74Schristos // Writer class for an ELF Rela relocation.
171975fd0b74Schristos 
172075fd0b74Schristos template<int size, bool big_endian>
172175fd0b74Schristos class Rela_write
172275fd0b74Schristos {
172375fd0b74Schristos  public:
172475fd0b74Schristos   Rela_write(unsigned char* p)
172575fd0b74Schristos     : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
172675fd0b74Schristos   { }
172775fd0b74Schristos 
172875fd0b74Schristos   void
172975fd0b74Schristos   put_r_offset(typename Elf_types<size>::Elf_Addr v)
173075fd0b74Schristos   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
173175fd0b74Schristos 
173275fd0b74Schristos   void
173375fd0b74Schristos   put_r_info(typename Elf_types<size>::Elf_WXword v)
173475fd0b74Schristos   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
173575fd0b74Schristos 
173675fd0b74Schristos   void
173775fd0b74Schristos   put_r_addend(typename Elf_types<size>::Elf_Swxword v)
173875fd0b74Schristos   { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
173975fd0b74Schristos 
174075fd0b74Schristos  private:
174175fd0b74Schristos   internal::Rela_data<size>* p_;
174275fd0b74Schristos };
174375fd0b74Schristos 
174475fd0b74Schristos // MIPS-64 has a non-standard relocation layout.
174575fd0b74Schristos 
174675fd0b74Schristos template<bool big_endian>
174775fd0b74Schristos class Mips64_rel
174875fd0b74Schristos {
174975fd0b74Schristos  public:
175075fd0b74Schristos   Mips64_rel(const unsigned char* p)
175175fd0b74Schristos     : p_(reinterpret_cast<const internal::Mips64_rel_data*>(p))
175275fd0b74Schristos   { }
175375fd0b74Schristos 
175475fd0b74Schristos   template<typename File>
175575fd0b74Schristos   Mips64_rel(File* file, typename File::Location loc)
175675fd0b74Schristos     : p_(reinterpret_cast<const internal::Mips64_rel_data*>(
175775fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
175875fd0b74Schristos   { }
175975fd0b74Schristos 
176075fd0b74Schristos   typename Elf_types<64>::Elf_Addr
176175fd0b74Schristos   get_r_offset() const
176275fd0b74Schristos   { return Convert<64, big_endian>::convert_host(this->p_->r_offset); }
176375fd0b74Schristos 
176475fd0b74Schristos   Elf_Word
176575fd0b74Schristos   get_r_sym() const
176675fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->r_sym); }
176775fd0b74Schristos 
176875fd0b74Schristos   unsigned char
176975fd0b74Schristos   get_r_ssym() const
177075fd0b74Schristos   { return this->p_->r_ssym; }
177175fd0b74Schristos 
177275fd0b74Schristos   unsigned char
177375fd0b74Schristos   get_r_type() const
177475fd0b74Schristos   { return this->p_->r_type; }
177575fd0b74Schristos 
177675fd0b74Schristos   unsigned char
177775fd0b74Schristos   get_r_type2() const
177875fd0b74Schristos   { return this->p_->r_type2; }
177975fd0b74Schristos 
178075fd0b74Schristos   unsigned char
178175fd0b74Schristos   get_r_type3() const
178275fd0b74Schristos   { return this->p_->r_type3; }
178375fd0b74Schristos 
178475fd0b74Schristos  private:
178575fd0b74Schristos   const internal::Mips64_rel_data* p_;
178675fd0b74Schristos };
178775fd0b74Schristos 
178875fd0b74Schristos template<bool big_endian>
178975fd0b74Schristos class Mips64_rel_write
179075fd0b74Schristos {
179175fd0b74Schristos  public:
179275fd0b74Schristos   Mips64_rel_write(unsigned char* p)
179375fd0b74Schristos     : p_(reinterpret_cast<internal::Mips64_rel_data*>(p))
179475fd0b74Schristos   { }
179575fd0b74Schristos 
179675fd0b74Schristos   void
179775fd0b74Schristos   put_r_offset(typename Elf_types<64>::Elf_Addr v)
179875fd0b74Schristos   { this->p_->r_offset = Convert<64, big_endian>::convert_host(v); }
179975fd0b74Schristos 
180075fd0b74Schristos   void
180175fd0b74Schristos   put_r_sym(Elf_Word v)
180275fd0b74Schristos   { this->p_->r_sym = Convert<32, big_endian>::convert_host(v); }
180375fd0b74Schristos 
180475fd0b74Schristos   void
180575fd0b74Schristos   put_r_ssym(unsigned char v)
180675fd0b74Schristos   { this->p_->r_ssym = v; }
180775fd0b74Schristos 
180875fd0b74Schristos   void
180975fd0b74Schristos   put_r_type(unsigned char v)
181075fd0b74Schristos   { this->p_->r_type = v; }
181175fd0b74Schristos 
181275fd0b74Schristos   void
181375fd0b74Schristos   put_r_type2(unsigned char v)
181475fd0b74Schristos   { this->p_->r_type2 = v; }
181575fd0b74Schristos 
181675fd0b74Schristos   void
181775fd0b74Schristos   put_r_type3(unsigned char v)
181875fd0b74Schristos   { this->p_->r_type3 = v; }
181975fd0b74Schristos 
182075fd0b74Schristos  private:
182175fd0b74Schristos   internal::Mips64_rel_data* p_;
182275fd0b74Schristos };
182375fd0b74Schristos 
182475fd0b74Schristos template<bool big_endian>
182575fd0b74Schristos class Mips64_rela
182675fd0b74Schristos {
182775fd0b74Schristos  public:
182875fd0b74Schristos   Mips64_rela(const unsigned char* p)
182975fd0b74Schristos     : p_(reinterpret_cast<const internal::Mips64_rela_data*>(p))
183075fd0b74Schristos   { }
183175fd0b74Schristos 
183275fd0b74Schristos   template<typename File>
183375fd0b74Schristos   Mips64_rela(File* file, typename File::Location loc)
183475fd0b74Schristos     : p_(reinterpret_cast<const internal::Mips64_rela_data*>(
183575fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
183675fd0b74Schristos   { }
183775fd0b74Schristos 
183875fd0b74Schristos   typename Elf_types<64>::Elf_Addr
183975fd0b74Schristos   get_r_offset() const
184075fd0b74Schristos   { return Convert<64, big_endian>::convert_host(this->p_->r_offset); }
184175fd0b74Schristos 
184275fd0b74Schristos   Elf_Word
184375fd0b74Schristos   get_r_sym() const
184475fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->r_sym); }
184575fd0b74Schristos 
184675fd0b74Schristos   unsigned char
184775fd0b74Schristos   get_r_ssym() const
184875fd0b74Schristos   { return this->p_->r_ssym; }
184975fd0b74Schristos 
185075fd0b74Schristos   unsigned char
185175fd0b74Schristos   get_r_type() const
185275fd0b74Schristos   { return this->p_->r_type; }
185375fd0b74Schristos 
185475fd0b74Schristos   unsigned char
185575fd0b74Schristos   get_r_type2() const
185675fd0b74Schristos   { return this->p_->r_type2; }
185775fd0b74Schristos 
185875fd0b74Schristos   unsigned char
185975fd0b74Schristos   get_r_type3() const
186075fd0b74Schristos   { return this->p_->r_type3; }
186175fd0b74Schristos 
186275fd0b74Schristos   typename Elf_types<64>::Elf_Swxword
186375fd0b74Schristos   get_r_addend() const
186475fd0b74Schristos   { return Convert<64, big_endian>::convert_host(this->p_->r_addend); }
186575fd0b74Schristos 
186675fd0b74Schristos  private:
186775fd0b74Schristos   const internal::Mips64_rela_data* p_;
186875fd0b74Schristos };
186975fd0b74Schristos 
187075fd0b74Schristos template<bool big_endian>
187175fd0b74Schristos class Mips64_rela_write
187275fd0b74Schristos {
187375fd0b74Schristos  public:
187475fd0b74Schristos   Mips64_rela_write(unsigned char* p)
187575fd0b74Schristos     : p_(reinterpret_cast<internal::Mips64_rela_data*>(p))
187675fd0b74Schristos   { }
187775fd0b74Schristos 
187875fd0b74Schristos   void
187975fd0b74Schristos   put_r_offset(typename Elf_types<64>::Elf_Addr v)
188075fd0b74Schristos   { this->p_->r_offset = Convert<64, big_endian>::convert_host(v); }
188175fd0b74Schristos 
188275fd0b74Schristos   void
188375fd0b74Schristos   put_r_sym(Elf_Word v)
188475fd0b74Schristos   { this->p_->r_sym = Convert<32, big_endian>::convert_host(v); }
188575fd0b74Schristos 
188675fd0b74Schristos   void
188775fd0b74Schristos   put_r_ssym(unsigned char v)
188875fd0b74Schristos   { this->p_->r_ssym = v; }
188975fd0b74Schristos 
189075fd0b74Schristos   void
189175fd0b74Schristos   put_r_type(unsigned char v)
189275fd0b74Schristos   { this->p_->r_type = v; }
189375fd0b74Schristos 
189475fd0b74Schristos   void
189575fd0b74Schristos   put_r_type2(unsigned char v)
189675fd0b74Schristos   { this->p_->r_type2 = v; }
189775fd0b74Schristos 
189875fd0b74Schristos   void
189975fd0b74Schristos   put_r_type3(unsigned char v)
190075fd0b74Schristos   { this->p_->r_type3 = v; }
190175fd0b74Schristos 
190275fd0b74Schristos   void
190375fd0b74Schristos   put_r_addend(typename Elf_types<64>::Elf_Swxword v)
190475fd0b74Schristos   { this->p_->r_addend = Convert<64, big_endian>::convert_host(v); }
190575fd0b74Schristos 
190675fd0b74Schristos  private:
190775fd0b74Schristos   internal::Mips64_rela_data* p_;
190875fd0b74Schristos };
190975fd0b74Schristos 
191075fd0b74Schristos // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
191175fd0b74Schristos // PT_DYNAMIC segment.
191275fd0b74Schristos 
191375fd0b74Schristos template<int size, bool big_endian>
191475fd0b74Schristos class Dyn
191575fd0b74Schristos {
191675fd0b74Schristos  public:
191775fd0b74Schristos   Dyn(const unsigned char* p)
191875fd0b74Schristos     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
191975fd0b74Schristos   { }
192075fd0b74Schristos 
192175fd0b74Schristos   template<typename File>
192275fd0b74Schristos   Dyn(File* file, typename File::Location loc)
192375fd0b74Schristos     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
192475fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
192575fd0b74Schristos   { }
192675fd0b74Schristos 
192775fd0b74Schristos   typename Elf_types<size>::Elf_Swxword
192875fd0b74Schristos   get_d_tag() const
192975fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
193075fd0b74Schristos 
193175fd0b74Schristos   typename Elf_types<size>::Elf_WXword
193275fd0b74Schristos   get_d_val() const
193375fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
193475fd0b74Schristos 
193575fd0b74Schristos   typename Elf_types<size>::Elf_Addr
193675fd0b74Schristos   get_d_ptr() const
193775fd0b74Schristos   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
193875fd0b74Schristos 
193975fd0b74Schristos  private:
194075fd0b74Schristos   const internal::Dyn_data<size>* p_;
194175fd0b74Schristos };
194275fd0b74Schristos 
194375fd0b74Schristos // Write class for an entry in the SHT_DYNAMIC section.
194475fd0b74Schristos 
194575fd0b74Schristos template<int size, bool big_endian>
194675fd0b74Schristos class Dyn_write
194775fd0b74Schristos {
194875fd0b74Schristos  public:
194975fd0b74Schristos   Dyn_write(unsigned char* p)
195075fd0b74Schristos     : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
195175fd0b74Schristos   { }
195275fd0b74Schristos 
195375fd0b74Schristos   void
195475fd0b74Schristos   put_d_tag(typename Elf_types<size>::Elf_Swxword v)
195575fd0b74Schristos   { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
195675fd0b74Schristos 
195775fd0b74Schristos   void
195875fd0b74Schristos   put_d_val(typename Elf_types<size>::Elf_WXword v)
195975fd0b74Schristos   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
196075fd0b74Schristos 
196175fd0b74Schristos   void
196275fd0b74Schristos   put_d_ptr(typename Elf_types<size>::Elf_Addr v)
196375fd0b74Schristos   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
196475fd0b74Schristos 
196575fd0b74Schristos  private:
196675fd0b74Schristos   internal::Dyn_data<size>* p_;
196775fd0b74Schristos };
196875fd0b74Schristos 
196975fd0b74Schristos // Accessor classes for entries in the ELF SHT_GNU_verdef section.
197075fd0b74Schristos 
197175fd0b74Schristos template<int size, bool big_endian>
197275fd0b74Schristos class Verdef
197375fd0b74Schristos {
197475fd0b74Schristos  public:
197575fd0b74Schristos   Verdef(const unsigned char* p)
197675fd0b74Schristos     : p_(reinterpret_cast<const internal::Verdef_data*>(p))
197775fd0b74Schristos   { }
197875fd0b74Schristos 
197975fd0b74Schristos   template<typename File>
198075fd0b74Schristos   Verdef(File* file, typename File::Location loc)
198175fd0b74Schristos     : p_(reinterpret_cast<const internal::Verdef_data*>(
198275fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
198375fd0b74Schristos   { }
198475fd0b74Schristos 
198575fd0b74Schristos   Elf_Half
198675fd0b74Schristos   get_vd_version() const
198775fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
198875fd0b74Schristos 
198975fd0b74Schristos   Elf_Half
199075fd0b74Schristos   get_vd_flags() const
199175fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
199275fd0b74Schristos 
199375fd0b74Schristos   Elf_Half
199475fd0b74Schristos   get_vd_ndx() const
199575fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
199675fd0b74Schristos 
199775fd0b74Schristos   Elf_Half
199875fd0b74Schristos   get_vd_cnt() const
199975fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
200075fd0b74Schristos 
200175fd0b74Schristos   Elf_Word
200275fd0b74Schristos   get_vd_hash() const
200375fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
200475fd0b74Schristos 
200575fd0b74Schristos   Elf_Word
200675fd0b74Schristos   get_vd_aux() const
200775fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
200875fd0b74Schristos 
200975fd0b74Schristos   Elf_Word
201075fd0b74Schristos   get_vd_next() const
201175fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
201275fd0b74Schristos 
201375fd0b74Schristos  private:
201475fd0b74Schristos   const internal::Verdef_data* p_;
201575fd0b74Schristos };
201675fd0b74Schristos 
201775fd0b74Schristos template<int size, bool big_endian>
201875fd0b74Schristos class Verdef_write
201975fd0b74Schristos {
202075fd0b74Schristos  public:
202175fd0b74Schristos   Verdef_write(unsigned char* p)
202275fd0b74Schristos     : p_(reinterpret_cast<internal::Verdef_data*>(p))
202375fd0b74Schristos   { }
202475fd0b74Schristos 
202575fd0b74Schristos   void
202675fd0b74Schristos   set_vd_version(Elf_Half v)
202775fd0b74Schristos   { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
202875fd0b74Schristos 
202975fd0b74Schristos   void
203075fd0b74Schristos   set_vd_flags(Elf_Half v)
203175fd0b74Schristos   { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
203275fd0b74Schristos 
203375fd0b74Schristos   void
203475fd0b74Schristos   set_vd_ndx(Elf_Half v)
203575fd0b74Schristos   { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
203675fd0b74Schristos 
203775fd0b74Schristos   void
203875fd0b74Schristos   set_vd_cnt(Elf_Half v)
203975fd0b74Schristos   { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
204075fd0b74Schristos 
204175fd0b74Schristos   void
204275fd0b74Schristos   set_vd_hash(Elf_Word v)
204375fd0b74Schristos   { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
204475fd0b74Schristos 
204575fd0b74Schristos   void
204675fd0b74Schristos   set_vd_aux(Elf_Word v)
204775fd0b74Schristos   { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
204875fd0b74Schristos 
204975fd0b74Schristos   void
205075fd0b74Schristos   set_vd_next(Elf_Word v)
205175fd0b74Schristos   { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
205275fd0b74Schristos 
205375fd0b74Schristos  private:
205475fd0b74Schristos   internal::Verdef_data* p_;
205575fd0b74Schristos };
205675fd0b74Schristos 
205775fd0b74Schristos // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
205875fd0b74Schristos // section.
205975fd0b74Schristos 
206075fd0b74Schristos template<int size, bool big_endian>
206175fd0b74Schristos class Verdaux
206275fd0b74Schristos {
206375fd0b74Schristos  public:
206475fd0b74Schristos   Verdaux(const unsigned char* p)
206575fd0b74Schristos     : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
206675fd0b74Schristos   { }
206775fd0b74Schristos 
206875fd0b74Schristos   template<typename File>
206975fd0b74Schristos   Verdaux(File* file, typename File::Location loc)
207075fd0b74Schristos     : p_(reinterpret_cast<const internal::Verdaux_data*>(
207175fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
207275fd0b74Schristos   { }
207375fd0b74Schristos 
207475fd0b74Schristos   Elf_Word
207575fd0b74Schristos   get_vda_name() const
207675fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
207775fd0b74Schristos 
207875fd0b74Schristos   Elf_Word
207975fd0b74Schristos   get_vda_next() const
208075fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
208175fd0b74Schristos 
208275fd0b74Schristos  private:
208375fd0b74Schristos   const internal::Verdaux_data* p_;
208475fd0b74Schristos };
208575fd0b74Schristos 
208675fd0b74Schristos template<int size, bool big_endian>
208775fd0b74Schristos class Verdaux_write
208875fd0b74Schristos {
208975fd0b74Schristos  public:
209075fd0b74Schristos   Verdaux_write(unsigned char* p)
209175fd0b74Schristos     : p_(reinterpret_cast<internal::Verdaux_data*>(p))
209275fd0b74Schristos   { }
209375fd0b74Schristos 
209475fd0b74Schristos   void
209575fd0b74Schristos   set_vda_name(Elf_Word v)
209675fd0b74Schristos   { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
209775fd0b74Schristos 
209875fd0b74Schristos   void
209975fd0b74Schristos   set_vda_next(Elf_Word v)
210075fd0b74Schristos   { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
210175fd0b74Schristos 
210275fd0b74Schristos  private:
210375fd0b74Schristos   internal::Verdaux_data* p_;
210475fd0b74Schristos };
210575fd0b74Schristos 
210675fd0b74Schristos // Accessor classes for entries in the ELF SHT_GNU_verneed section.
210775fd0b74Schristos 
210875fd0b74Schristos template<int size, bool big_endian>
210975fd0b74Schristos class Verneed
211075fd0b74Schristos {
211175fd0b74Schristos  public:
211275fd0b74Schristos   Verneed(const unsigned char* p)
211375fd0b74Schristos     : p_(reinterpret_cast<const internal::Verneed_data*>(p))
211475fd0b74Schristos   { }
211575fd0b74Schristos 
211675fd0b74Schristos   template<typename File>
211775fd0b74Schristos   Verneed(File* file, typename File::Location loc)
211875fd0b74Schristos     : p_(reinterpret_cast<const internal::Verneed_data*>(
211975fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
212075fd0b74Schristos   { }
212175fd0b74Schristos 
212275fd0b74Schristos   Elf_Half
212375fd0b74Schristos   get_vn_version() const
212475fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
212575fd0b74Schristos 
212675fd0b74Schristos   Elf_Half
212775fd0b74Schristos   get_vn_cnt() const
212875fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
212975fd0b74Schristos 
213075fd0b74Schristos   Elf_Word
213175fd0b74Schristos   get_vn_file() const
213275fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
213375fd0b74Schristos 
213475fd0b74Schristos   Elf_Word
213575fd0b74Schristos   get_vn_aux() const
213675fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
213775fd0b74Schristos 
213875fd0b74Schristos   Elf_Word
213975fd0b74Schristos   get_vn_next() const
214075fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
214175fd0b74Schristos 
214275fd0b74Schristos  private:
214375fd0b74Schristos   const internal::Verneed_data* p_;
214475fd0b74Schristos };
214575fd0b74Schristos 
214675fd0b74Schristos template<int size, bool big_endian>
214775fd0b74Schristos class Verneed_write
214875fd0b74Schristos {
214975fd0b74Schristos  public:
215075fd0b74Schristos   Verneed_write(unsigned char* p)
215175fd0b74Schristos     : p_(reinterpret_cast<internal::Verneed_data*>(p))
215275fd0b74Schristos   { }
215375fd0b74Schristos 
215475fd0b74Schristos   void
215575fd0b74Schristos   set_vn_version(Elf_Half v)
215675fd0b74Schristos   { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
215775fd0b74Schristos 
215875fd0b74Schristos   void
215975fd0b74Schristos   set_vn_cnt(Elf_Half v)
216075fd0b74Schristos   { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
216175fd0b74Schristos 
216275fd0b74Schristos   void
216375fd0b74Schristos   set_vn_file(Elf_Word v)
216475fd0b74Schristos   { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
216575fd0b74Schristos 
216675fd0b74Schristos   void
216775fd0b74Schristos   set_vn_aux(Elf_Word v)
216875fd0b74Schristos   { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
216975fd0b74Schristos 
217075fd0b74Schristos   void
217175fd0b74Schristos   set_vn_next(Elf_Word v)
217275fd0b74Schristos   { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
217375fd0b74Schristos 
217475fd0b74Schristos  private:
217575fd0b74Schristos   internal::Verneed_data* p_;
217675fd0b74Schristos };
217775fd0b74Schristos 
217875fd0b74Schristos // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
217975fd0b74Schristos // section.
218075fd0b74Schristos 
218175fd0b74Schristos template<int size, bool big_endian>
218275fd0b74Schristos class Vernaux
218375fd0b74Schristos {
218475fd0b74Schristos  public:
218575fd0b74Schristos   Vernaux(const unsigned char* p)
218675fd0b74Schristos     : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
218775fd0b74Schristos   { }
218875fd0b74Schristos 
218975fd0b74Schristos   template<typename File>
219075fd0b74Schristos   Vernaux(File* file, typename File::Location loc)
219175fd0b74Schristos     : p_(reinterpret_cast<const internal::Vernaux_data*>(
219275fd0b74Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
219375fd0b74Schristos   { }
219475fd0b74Schristos 
219575fd0b74Schristos   Elf_Word
219675fd0b74Schristos   get_vna_hash() const
219775fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
219875fd0b74Schristos 
219975fd0b74Schristos   Elf_Half
220075fd0b74Schristos   get_vna_flags() const
220175fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
220275fd0b74Schristos 
220375fd0b74Schristos   Elf_Half
220475fd0b74Schristos   get_vna_other() const
220575fd0b74Schristos   { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
220675fd0b74Schristos 
220775fd0b74Schristos   Elf_Word
220875fd0b74Schristos   get_vna_name() const
220975fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
221075fd0b74Schristos 
221175fd0b74Schristos   Elf_Word
221275fd0b74Schristos   get_vna_next() const
221375fd0b74Schristos   { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
221475fd0b74Schristos 
221575fd0b74Schristos  private:
221675fd0b74Schristos   const internal::Vernaux_data* p_;
221775fd0b74Schristos };
221875fd0b74Schristos 
221975fd0b74Schristos template<int size, bool big_endian>
222075fd0b74Schristos class Vernaux_write
222175fd0b74Schristos {
222275fd0b74Schristos  public:
222375fd0b74Schristos   Vernaux_write(unsigned char* p)
222475fd0b74Schristos     : p_(reinterpret_cast<internal::Vernaux_data*>(p))
222575fd0b74Schristos   { }
222675fd0b74Schristos 
222775fd0b74Schristos   void
222875fd0b74Schristos   set_vna_hash(Elf_Word v)
222975fd0b74Schristos   { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
223075fd0b74Schristos 
223175fd0b74Schristos   void
223275fd0b74Schristos   set_vna_flags(Elf_Half v)
223375fd0b74Schristos   { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
223475fd0b74Schristos 
223575fd0b74Schristos   void
223675fd0b74Schristos   set_vna_other(Elf_Half v)
223775fd0b74Schristos   { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
223875fd0b74Schristos 
223975fd0b74Schristos   void
224075fd0b74Schristos   set_vna_name(Elf_Word v)
224175fd0b74Schristos   { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
224275fd0b74Schristos 
224375fd0b74Schristos   void
224475fd0b74Schristos   set_vna_next(Elf_Word v)
224575fd0b74Schristos   { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
224675fd0b74Schristos 
224775fd0b74Schristos  private:
224875fd0b74Schristos   internal::Vernaux_data* p_;
224975fd0b74Schristos };
225075fd0b74Schristos 
225175fd0b74Schristos } // End namespace elfcpp.
225275fd0b74Schristos 
225375fd0b74Schristos #endif // !defined(ELFPCP_H)
2254