xref: /netbsd-src/external/gpl3/binutils/dist/elfcpp/elfcpp.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
12a6b7db3Sskrll // elfcpp.h -- main header file for elfcpp    -*- C++ -*-
22a6b7db3Sskrll 
3*cb63e24eSchristos // Copyright (C) 2006-2024 Free Software Foundation, Inc.
42a6b7db3Sskrll // Written by Ian Lance Taylor <iant@google.com>.
52a6b7db3Sskrll 
62a6b7db3Sskrll // This file is part of elfcpp.
72a6b7db3Sskrll 
82a6b7db3Sskrll // This program is free software; you can redistribute it and/or
92a6b7db3Sskrll // modify it under the terms of the GNU Library General Public License
102a6b7db3Sskrll // as published by the Free Software Foundation; either version 2, or
112a6b7db3Sskrll // (at your option) any later version.
122a6b7db3Sskrll 
132a6b7db3Sskrll // In addition to the permissions in the GNU Library General Public
142a6b7db3Sskrll // License, the Free Software Foundation gives you unlimited
152a6b7db3Sskrll // permission to link the compiled version of this file into
162a6b7db3Sskrll // combinations with other programs, and to distribute those
172a6b7db3Sskrll // combinations without any restriction coming from the use of this
182a6b7db3Sskrll // file.  (The Library Public License restrictions do apply in other
192a6b7db3Sskrll // respects; for example, they cover modification of the file, and
20be12b8bcSchristos // distribution when not linked into a combined executable.)
212a6b7db3Sskrll 
222a6b7db3Sskrll // This program is distributed in the hope that it will be useful, but
232a6b7db3Sskrll // WITHOUT ANY WARRANTY; without even the implied warranty of
242a6b7db3Sskrll // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
252a6b7db3Sskrll // Library General Public License for more details.
262a6b7db3Sskrll 
272a6b7db3Sskrll // You should have received a copy of the GNU Library General Public
282a6b7db3Sskrll // License along with this program; if not, write to the Free Software
292a6b7db3Sskrll // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
302a6b7db3Sskrll // 02110-1301, USA.
312a6b7db3Sskrll 
322a6b7db3Sskrll // This is the external interface for elfcpp.
332a6b7db3Sskrll 
342a6b7db3Sskrll #ifndef ELFCPP_H
352a6b7db3Sskrll #define ELFCPP_H
362a6b7db3Sskrll 
372a6b7db3Sskrll #include "elfcpp_swap.h"
382a6b7db3Sskrll 
392a6b7db3Sskrll #include <stdint.h>
402a6b7db3Sskrll 
412a6b7db3Sskrll namespace elfcpp
422a6b7db3Sskrll {
432a6b7db3Sskrll 
442a6b7db3Sskrll // Basic ELF types.
452a6b7db3Sskrll 
462a6b7db3Sskrll // These types are always the same size.
472a6b7db3Sskrll 
482a6b7db3Sskrll typedef uint16_t Elf_Half;
492a6b7db3Sskrll typedef uint32_t Elf_Word;
502a6b7db3Sskrll typedef int32_t Elf_Sword;
512a6b7db3Sskrll typedef uint64_t Elf_Xword;
522a6b7db3Sskrll typedef int64_t Elf_Sxword;
532a6b7db3Sskrll 
542a6b7db3Sskrll // These types vary in size depending on the ELF file class.  The
552a6b7db3Sskrll // template parameter should be 32 or 64.
562a6b7db3Sskrll 
572a6b7db3Sskrll template<int size>
582a6b7db3Sskrll struct Elf_types;
592a6b7db3Sskrll 
602a6b7db3Sskrll template<>
612a6b7db3Sskrll struct Elf_types<32>
622a6b7db3Sskrll {
632a6b7db3Sskrll   typedef uint32_t Elf_Addr;
642a6b7db3Sskrll   typedef uint32_t Elf_Off;
652a6b7db3Sskrll   typedef uint32_t Elf_WXword;
662a6b7db3Sskrll   typedef int32_t Elf_Swxword;
672a6b7db3Sskrll };
682a6b7db3Sskrll 
692a6b7db3Sskrll template<>
702a6b7db3Sskrll struct Elf_types<64>
712a6b7db3Sskrll {
722a6b7db3Sskrll   typedef uint64_t Elf_Addr;
732a6b7db3Sskrll   typedef uint64_t Elf_Off;
742a6b7db3Sskrll   typedef uint64_t Elf_WXword;
752a6b7db3Sskrll   typedef int64_t Elf_Swxword;
762a6b7db3Sskrll };
772a6b7db3Sskrll 
782a6b7db3Sskrll // Offsets within the Ehdr e_ident field.
792a6b7db3Sskrll 
802a6b7db3Sskrll const int EI_MAG0 = 0;
812a6b7db3Sskrll const int EI_MAG1 = 1;
822a6b7db3Sskrll const int EI_MAG2 = 2;
832a6b7db3Sskrll const int EI_MAG3 = 3;
842a6b7db3Sskrll const int EI_CLASS = 4;
852a6b7db3Sskrll const int EI_DATA = 5;
862a6b7db3Sskrll const int EI_VERSION = 6;
872a6b7db3Sskrll const int EI_OSABI = 7;
882a6b7db3Sskrll const int EI_ABIVERSION = 8;
892a6b7db3Sskrll const int EI_PAD = 9;
902a6b7db3Sskrll const int EI_NIDENT = 16;
912a6b7db3Sskrll 
922a6b7db3Sskrll // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
932a6b7db3Sskrll 
942a6b7db3Sskrll const int ELFMAG0 = 0x7f;
952a6b7db3Sskrll const int ELFMAG1 = 'E';
962a6b7db3Sskrll const int ELFMAG2 = 'L';
972a6b7db3Sskrll const int ELFMAG3 = 'F';
982a6b7db3Sskrll 
992a6b7db3Sskrll // The valid values found in Ehdr e_ident[EI_CLASS].
1002a6b7db3Sskrll 
1012a6b7db3Sskrll enum
1022a6b7db3Sskrll {
1032a6b7db3Sskrll   ELFCLASSNONE = 0,
1042a6b7db3Sskrll   ELFCLASS32 = 1,
1052a6b7db3Sskrll   ELFCLASS64 = 2
1062a6b7db3Sskrll };
1072a6b7db3Sskrll 
1082a6b7db3Sskrll // The valid values found in Ehdr e_ident[EI_DATA].
1092a6b7db3Sskrll 
1102a6b7db3Sskrll enum
1112a6b7db3Sskrll {
1122a6b7db3Sskrll   ELFDATANONE = 0,
1132a6b7db3Sskrll   ELFDATA2LSB = 1,
1142a6b7db3Sskrll   ELFDATA2MSB = 2
1152a6b7db3Sskrll };
1162a6b7db3Sskrll 
1172a6b7db3Sskrll // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
1182a6b7db3Sskrll 
1192a6b7db3Sskrll enum
1202a6b7db3Sskrll {
1212a6b7db3Sskrll   EV_NONE = 0,
1222a6b7db3Sskrll   EV_CURRENT = 1
1232a6b7db3Sskrll };
1242a6b7db3Sskrll 
1252a6b7db3Sskrll // The valid values found in Ehdr e_ident[EI_OSABI].
1262a6b7db3Sskrll 
1272a6b7db3Sskrll enum ELFOSABI
1282a6b7db3Sskrll {
1292a6b7db3Sskrll   ELFOSABI_NONE = 0,
1302a6b7db3Sskrll   ELFOSABI_HPUX = 1,
1312a6b7db3Sskrll   ELFOSABI_NETBSD = 2,
132883529b6Schristos   ELFOSABI_GNU = 3,
133883529b6Schristos   // ELFOSABI_LINUX is an alias for ELFOSABI_GNU.
1342a6b7db3Sskrll   ELFOSABI_LINUX = 3,
1352a6b7db3Sskrll   ELFOSABI_SOLARIS = 6,
1362a6b7db3Sskrll   ELFOSABI_AIX = 7,
1372a6b7db3Sskrll   ELFOSABI_IRIX = 8,
1382a6b7db3Sskrll   ELFOSABI_FREEBSD = 9,
1392a6b7db3Sskrll   ELFOSABI_TRU64 = 10,
1402a6b7db3Sskrll   ELFOSABI_MODESTO = 11,
1412a6b7db3Sskrll   ELFOSABI_OPENBSD = 12,
1422a6b7db3Sskrll   ELFOSABI_OPENVMS = 13,
1432a6b7db3Sskrll   ELFOSABI_NSK = 14,
1442a6b7db3Sskrll   ELFOSABI_AROS = 15,
1452a6b7db3Sskrll   // A GNU extension for the ARM.
1462a6b7db3Sskrll   ELFOSABI_ARM = 97,
1472a6b7db3Sskrll   // A GNU extension for the MSP.
1482a6b7db3Sskrll   ELFOSABI_STANDALONE = 255
1492a6b7db3Sskrll };
1502a6b7db3Sskrll 
1512a6b7db3Sskrll // The valid values found in the Ehdr e_type field.
1522a6b7db3Sskrll 
1532a6b7db3Sskrll enum ET
1542a6b7db3Sskrll {
1552a6b7db3Sskrll   ET_NONE = 0,
1562a6b7db3Sskrll   ET_REL = 1,
1572a6b7db3Sskrll   ET_EXEC = 2,
1582a6b7db3Sskrll   ET_DYN = 3,
1592a6b7db3Sskrll   ET_CORE = 4,
1602a6b7db3Sskrll   ET_LOOS = 0xfe00,
1612a6b7db3Sskrll   ET_HIOS = 0xfeff,
1622a6b7db3Sskrll   ET_LOPROC = 0xff00,
1632a6b7db3Sskrll   ET_HIPROC = 0xffff
1642a6b7db3Sskrll };
1652a6b7db3Sskrll 
1662a6b7db3Sskrll // The valid values found in the Ehdr e_machine field.
1672a6b7db3Sskrll 
1682a6b7db3Sskrll enum EM
1692a6b7db3Sskrll {
1702a6b7db3Sskrll   EM_NONE = 0,
1712a6b7db3Sskrll   EM_M32 = 1,
1722a6b7db3Sskrll   EM_SPARC = 2,
1732a6b7db3Sskrll   EM_386 = 3,
1742a6b7db3Sskrll   EM_68K = 4,
1752a6b7db3Sskrll   EM_88K = 5,
1769573673dSchristos   EM_IAMCU = 6,
1772a6b7db3Sskrll   EM_860 = 7,
1782a6b7db3Sskrll   EM_MIPS = 8,
1792a6b7db3Sskrll   EM_S370 = 9,
1802a6b7db3Sskrll   EM_MIPS_RS3_LE = 10,
1812a6b7db3Sskrll   // 11 was the old Sparc V9 ABI.
1822a6b7db3Sskrll   // 12 through 14 are reserved.
1832a6b7db3Sskrll   EM_PARISC = 15,
1842a6b7db3Sskrll   // 16 is reserved.
1852a6b7db3Sskrll   // Some old PowerPC object files use 17.
1862a6b7db3Sskrll   EM_VPP500 = 17,
1872a6b7db3Sskrll   EM_SPARC32PLUS = 18,
1882a6b7db3Sskrll   EM_960 = 19,
1892a6b7db3Sskrll   EM_PPC = 20,
1902a6b7db3Sskrll   EM_PPC64 = 21,
1912a6b7db3Sskrll   EM_S390 = 22,
1922a6b7db3Sskrll   // 23 through 35 are served.
1932a6b7db3Sskrll   EM_V800 = 36,
1942a6b7db3Sskrll   EM_FR20 = 37,
1952a6b7db3Sskrll   EM_RH32 = 38,
1962a6b7db3Sskrll   EM_RCE = 39,
1972a6b7db3Sskrll   EM_ARM = 40,
1982a6b7db3Sskrll   EM_ALPHA = 41,
1992a6b7db3Sskrll   EM_SH = 42,
2002a6b7db3Sskrll   EM_SPARCV9 = 43,
2012a6b7db3Sskrll   EM_TRICORE = 44,
2022a6b7db3Sskrll   EM_ARC = 45,
2032a6b7db3Sskrll   EM_H8_300 = 46,
2042a6b7db3Sskrll   EM_H8_300H = 47,
2052a6b7db3Sskrll   EM_H8S = 48,
2062a6b7db3Sskrll   EM_H8_500 = 49,
2072a6b7db3Sskrll   EM_IA_64 = 50,
2082a6b7db3Sskrll   EM_MIPS_X = 51,
2092a6b7db3Sskrll   EM_COLDFIRE = 52,
2102a6b7db3Sskrll   EM_68HC12 = 53,
2112a6b7db3Sskrll   EM_MMA = 54,
2122a6b7db3Sskrll   EM_PCP = 55,
2132a6b7db3Sskrll   EM_NCPU = 56,
2142a6b7db3Sskrll   EM_NDR1 = 57,
2152a6b7db3Sskrll   EM_STARCORE = 58,
2162a6b7db3Sskrll   EM_ME16 = 59,
2172a6b7db3Sskrll   EM_ST100 = 60,
2182a6b7db3Sskrll   EM_TINYJ = 61,
2192a6b7db3Sskrll   EM_X86_64 = 62,
2202a6b7db3Sskrll   EM_PDSP = 63,
2212a6b7db3Sskrll   EM_PDP10 = 64,
2222a6b7db3Sskrll   EM_PDP11 = 65,
2232a6b7db3Sskrll   EM_FX66 = 66,
2242a6b7db3Sskrll   EM_ST9PLUS = 67,
2252a6b7db3Sskrll   EM_ST7 = 68,
2262a6b7db3Sskrll   EM_68HC16 = 69,
2272a6b7db3Sskrll   EM_68HC11 = 70,
2282a6b7db3Sskrll   EM_68HC08 = 71,
2292a6b7db3Sskrll   EM_68HC05 = 72,
2302a6b7db3Sskrll   EM_SVX = 73,
2312a6b7db3Sskrll   EM_ST19 = 74,
2322a6b7db3Sskrll   EM_VAX = 75,
2332a6b7db3Sskrll   EM_CRIS = 76,
2342a6b7db3Sskrll   EM_JAVELIN = 77,
2352a6b7db3Sskrll   EM_FIREPATH = 78,
2362a6b7db3Sskrll   EM_ZSP = 79,
2372a6b7db3Sskrll   EM_MMIX = 80,
2382a6b7db3Sskrll   EM_HUANY = 81,
2392a6b7db3Sskrll   EM_PRISM = 82,
2402a6b7db3Sskrll   EM_AVR = 83,
2412a6b7db3Sskrll   EM_FR30 = 84,
2422a6b7db3Sskrll   EM_D10V = 85,
2432a6b7db3Sskrll   EM_D30V = 86,
2442a6b7db3Sskrll   EM_V850 = 87,
2452a6b7db3Sskrll   EM_M32R = 88,
2462a6b7db3Sskrll   EM_MN10300 = 89,
2472a6b7db3Sskrll   EM_MN10200 = 90,
2482a6b7db3Sskrll   EM_PJ = 91,
2499573673dSchristos   EM_OR1K = 92,
2502a6b7db3Sskrll   EM_ARC_A5 = 93,
2512a6b7db3Sskrll   EM_XTENSA = 94,
2522a6b7db3Sskrll   EM_VIDEOCORE = 95,
2532a6b7db3Sskrll   EM_TMM_GPP = 96,
2542a6b7db3Sskrll   EM_NS32K = 97,
2552a6b7db3Sskrll   EM_TPC = 98,
2562a6b7db3Sskrll   // Some old picoJava object files use 99 (EM_PJ is correct).
2572a6b7db3Sskrll   EM_SNP1K = 99,
2582a6b7db3Sskrll   EM_ST200 = 100,
2592a6b7db3Sskrll   EM_IP2K = 101,
2602a6b7db3Sskrll   EM_MAX = 102,
2612a6b7db3Sskrll   EM_CR = 103,
2622a6b7db3Sskrll   EM_F2MC16 = 104,
2632a6b7db3Sskrll   EM_MSP430 = 105,
2642a6b7db3Sskrll   EM_BLACKFIN = 106,
2652a6b7db3Sskrll   EM_SE_C33 = 107,
2662a6b7db3Sskrll   EM_SEP = 108,
2672a6b7db3Sskrll   EM_ARCA = 109,
2682a6b7db3Sskrll   EM_UNICORE = 110,
2692a6b7db3Sskrll   EM_ALTERA_NIOS2 = 113,
2702a6b7db3Sskrll   EM_CRX = 114,
271fc4f4269Schristos   EM_TI_PRU = 144,
2729573673dSchristos   EM_AARCH64 = 183,
2739573673dSchristos   EM_TILEGX = 191,
2742a6b7db3Sskrll   // The Morph MT.
2752a6b7db3Sskrll   EM_MT = 0x2530,
2762a6b7db3Sskrll   // DLX.
2772a6b7db3Sskrll   EM_DLX = 0x5aa5,
2782a6b7db3Sskrll   // FRV.
2792a6b7db3Sskrll   EM_FRV = 0x5441,
2802a6b7db3Sskrll   // Infineon Technologies 16-bit microcontroller with C166-V2 core.
2812a6b7db3Sskrll   EM_X16X = 0x4688,
2822a6b7db3Sskrll   // Xstorym16
2832a6b7db3Sskrll   EM_XSTORMY16 = 0xad45,
2842a6b7db3Sskrll   // Renesas M32C
2852a6b7db3Sskrll   EM_M32C = 0xfeb0,
2862a6b7db3Sskrll   // Vitesse IQ2000
2872a6b7db3Sskrll   EM_IQ2000 = 0xfeba,
2882a6b7db3Sskrll   // NIOS
2892a6b7db3Sskrll   EM_NIOS32 = 0xfebb
2902a6b7db3Sskrll   // Old AVR objects used 0x1057 (EM_AVR is correct).
2912a6b7db3Sskrll   // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
2922a6b7db3Sskrll   // Old FR30 objects used 0x3330 (EM_FR30 is correct).
2939573673dSchristos   // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OR1K is correct).
2942a6b7db3Sskrll   // Old D10V objects used 0x7650 (EM_D10V is correct).
2952a6b7db3Sskrll   // Old D30V objects used 0x7676 (EM_D30V is correct).
2962a6b7db3Sskrll   // Old IP2X objects used 0x8217 (EM_IP2K is correct).
2972a6b7db3Sskrll   // Old PowerPC objects used 0x9025 (EM_PPC is correct).
2982a6b7db3Sskrll   // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
2992a6b7db3Sskrll   // Old M32R objects used 0x9041 (EM_M32R is correct).
3002a6b7db3Sskrll   // Old V850 objects used 0x9080 (EM_V850 is correct).
3012a6b7db3Sskrll   // Old S/390 objects used 0xa390 (EM_S390 is correct).
3022a6b7db3Sskrll   // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
3032a6b7db3Sskrll   // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
3042a6b7db3Sskrll   // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
3052a6b7db3Sskrll };
3062a6b7db3Sskrll 
307be12b8bcSchristos // A special value found in the Ehdr e_phnum field.
308be12b8bcSchristos 
309be12b8bcSchristos enum
310be12b8bcSchristos {
311be12b8bcSchristos   // Number of program segments stored in sh_info field of first
312be12b8bcSchristos   // section headre.
313be12b8bcSchristos   PN_XNUM = 0xffff
314be12b8bcSchristos };
315be12b8bcSchristos 
3162a6b7db3Sskrll // Special section indices.
3172a6b7db3Sskrll 
3182a6b7db3Sskrll enum
3192a6b7db3Sskrll {
3202a6b7db3Sskrll   SHN_UNDEF = 0,
3212a6b7db3Sskrll   SHN_LORESERVE = 0xff00,
3222a6b7db3Sskrll   SHN_LOPROC = 0xff00,
3232a6b7db3Sskrll   SHN_HIPROC = 0xff1f,
3242a6b7db3Sskrll   SHN_LOOS = 0xff20,
3252a6b7db3Sskrll   SHN_HIOS = 0xff3f,
3262a6b7db3Sskrll   SHN_ABS = 0xfff1,
3272a6b7db3Sskrll   SHN_COMMON = 0xfff2,
3282a6b7db3Sskrll   SHN_XINDEX = 0xffff,
3292a6b7db3Sskrll   SHN_HIRESERVE = 0xffff,
3302a6b7db3Sskrll 
3312a6b7db3Sskrll   // Provide for initial and final section ordering in conjunction
3322a6b7db3Sskrll   // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
3332a6b7db3Sskrll   SHN_BEFORE = 0xff00,
3342a6b7db3Sskrll   SHN_AFTER = 0xff01,
335be12b8bcSchristos 
336be12b8bcSchristos   // x86_64 specific large common symbol.
337be12b8bcSchristos   SHN_X86_64_LCOMMON = 0xff02
3382a6b7db3Sskrll };
3392a6b7db3Sskrll 
3402a6b7db3Sskrll // The valid values found in the Shdr sh_type field.
3412a6b7db3Sskrll 
3422a6b7db3Sskrll enum SHT
3432a6b7db3Sskrll {
3442a6b7db3Sskrll   SHT_NULL = 0,
3452a6b7db3Sskrll   SHT_PROGBITS = 1,
3462a6b7db3Sskrll   SHT_SYMTAB = 2,
3472a6b7db3Sskrll   SHT_STRTAB = 3,
3482a6b7db3Sskrll   SHT_RELA = 4,
3492a6b7db3Sskrll   SHT_HASH = 5,
3502a6b7db3Sskrll   SHT_DYNAMIC = 6,
3512a6b7db3Sskrll   SHT_NOTE = 7,
3522a6b7db3Sskrll   SHT_NOBITS = 8,
3532a6b7db3Sskrll   SHT_REL = 9,
3542a6b7db3Sskrll   SHT_SHLIB = 10,
3552a6b7db3Sskrll   SHT_DYNSYM = 11,
3562a6b7db3Sskrll   SHT_INIT_ARRAY = 14,
3572a6b7db3Sskrll   SHT_FINI_ARRAY = 15,
3582a6b7db3Sskrll   SHT_PREINIT_ARRAY = 16,
3592a6b7db3Sskrll   SHT_GROUP = 17,
3602a6b7db3Sskrll   SHT_SYMTAB_SHNDX = 18,
3612a6b7db3Sskrll   SHT_LOOS = 0x60000000,
3622a6b7db3Sskrll   SHT_HIOS = 0x6fffffff,
3632a6b7db3Sskrll   SHT_LOPROC = 0x70000000,
3642a6b7db3Sskrll   SHT_HIPROC = 0x7fffffff,
3652a6b7db3Sskrll   SHT_LOUSER = 0x80000000,
3662a6b7db3Sskrll   SHT_HIUSER = 0xffffffff,
3672a6b7db3Sskrll   // The remaining values are not in the standard.
368be12b8bcSchristos   // Incremental build data.
369be12b8bcSchristos   SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700,
370be12b8bcSchristos   SHT_GNU_INCREMENTAL_SYMTAB = 0x6fff4701,
371be12b8bcSchristos   SHT_GNU_INCREMENTAL_RELOCS = 0x6fff4702,
372be12b8bcSchristos   SHT_GNU_INCREMENTAL_GOT_PLT = 0x6fff4703,
3732a6b7db3Sskrll   // Object attributes.
3742a6b7db3Sskrll   SHT_GNU_ATTRIBUTES = 0x6ffffff5,
3752a6b7db3Sskrll   // GNU style dynamic hash table.
3762a6b7db3Sskrll   SHT_GNU_HASH = 0x6ffffff6,
3772a6b7db3Sskrll   // List of prelink dependencies.
3782a6b7db3Sskrll   SHT_GNU_LIBLIST = 0x6ffffff7,
3792a6b7db3Sskrll   // Versions defined by file.
3802a6b7db3Sskrll   SHT_SUNW_verdef = 0x6ffffffd,
3812a6b7db3Sskrll   SHT_GNU_verdef = 0x6ffffffd,
3822a6b7db3Sskrll   // Versions needed by file.
3832a6b7db3Sskrll   SHT_SUNW_verneed = 0x6ffffffe,
3842a6b7db3Sskrll   SHT_GNU_verneed = 0x6ffffffe,
3852a6b7db3Sskrll   // Symbol versions,
3862a6b7db3Sskrll   SHT_SUNW_versym = 0x6fffffff,
3872a6b7db3Sskrll   SHT_GNU_versym = 0x6fffffff,
3882a6b7db3Sskrll 
3892a6b7db3Sskrll   SHT_SPARC_GOTDATA = 0x70000000,
3902a6b7db3Sskrll 
391be12b8bcSchristos   // ARM-specific section types.
392be12b8bcSchristos   // Exception Index table.
393be12b8bcSchristos   SHT_ARM_EXIDX = 0x70000001,
394be12b8bcSchristos   // BPABI DLL dynamic linking pre-emption map.
395be12b8bcSchristos   SHT_ARM_PREEMPTMAP = 0x70000002,
396be12b8bcSchristos   // Object file compatibility attributes.
397be12b8bcSchristos   SHT_ARM_ATTRIBUTES = 0x70000003,
398be12b8bcSchristos   // Support for debugging overlaid programs.
399be12b8bcSchristos   SHT_ARM_DEBUGOVERLAY = 0x70000004,
400be12b8bcSchristos   SHT_ARM_OVERLAYSECTION = 0x70000005,
401be12b8bcSchristos 
402be12b8bcSchristos   // x86_64 unwind information.
403be12b8bcSchristos   SHT_X86_64_UNWIND = 0x70000001,
404be12b8bcSchristos 
405883529b6Schristos   // MIPS-specific section types.
4069573673dSchristos   // Section contains register usage information.
407883529b6Schristos   SHT_MIPS_REGINFO = 0x70000006,
4089573673dSchristos   // Section contains miscellaneous options.
4099573673dSchristos   SHT_MIPS_OPTIONS = 0x7000000d,
4108cbf5cb7Schristos   // ABI related flags section.
4118cbf5cb7Schristos   SHT_MIPS_ABIFLAGS = 0x7000002a,
4129573673dSchristos 
4139573673dSchristos   // AARCH64-specific section type.
4149573673dSchristos   SHT_AARCH64_ATTRIBUTES = 0x70000003,
415883529b6Schristos 
4164f645668Schristos   // CSKY-specific section types.
4174f645668Schristos   // Object file compatibility attributes.
4184f645668Schristos   SHT_CSKY_ATTRIBUTES = 0x70000001,
4194f645668Schristos 
4202a6b7db3Sskrll   // Link editor is to sort the entries in this section based on the
4212a6b7db3Sskrll   // address specified in the associated symbol table entry.
422be12b8bcSchristos   SHT_ORDERED = 0x7fffffff
4232a6b7db3Sskrll };
4242a6b7db3Sskrll 
4252a6b7db3Sskrll // The valid bit flags found in the Shdr sh_flags field.
4262a6b7db3Sskrll 
4272a6b7db3Sskrll enum SHF
4282a6b7db3Sskrll {
4292a6b7db3Sskrll   SHF_WRITE = 0x1,
4302a6b7db3Sskrll   SHF_ALLOC = 0x2,
4312a6b7db3Sskrll   SHF_EXECINSTR = 0x4,
4322a6b7db3Sskrll   SHF_MERGE = 0x10,
4332a6b7db3Sskrll   SHF_STRINGS = 0x20,
4342a6b7db3Sskrll   SHF_INFO_LINK = 0x40,
4352a6b7db3Sskrll   SHF_LINK_ORDER = 0x80,
4362a6b7db3Sskrll   SHF_OS_NONCONFORMING = 0x100,
4372a6b7db3Sskrll   SHF_GROUP = 0x200,
4382a6b7db3Sskrll   SHF_TLS = 0x400,
4399573673dSchristos   SHF_COMPRESSED = 0x800,
4402a6b7db3Sskrll   SHF_MASKOS = 0x0ff00000,
4414f645668Schristos   SHF_GNU_RETAIN = 0x200000,
4422a6b7db3Sskrll   SHF_MASKPROC = 0xf0000000,
4432a6b7db3Sskrll 
4442a6b7db3Sskrll   // Indicates this section requires ordering in relation to
4452a6b7db3Sskrll   // other sections of the same type.  Ordered sections are
4462a6b7db3Sskrll   // combined within the section pointed to by the sh_link entry.
4472a6b7db3Sskrll   // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
4482a6b7db3Sskrll   // sorted section is to precede or follow, respectively, all
4492a6b7db3Sskrll   // other sections in the set being ordered.
4502a6b7db3Sskrll   SHF_ORDERED = 0x40000000,
4512a6b7db3Sskrll   // This section is excluded from input to the link-edit of an
4522a6b7db3Sskrll   // executable or shared object.  This flag is ignored if SHF_ALLOC
4532a6b7db3Sskrll   // is also set, or if relocations exist against the section.
4542a6b7db3Sskrll   SHF_EXCLUDE = 0x80000000,
455be12b8bcSchristos 
456883529b6Schristos   // Section with data that is GP relative addressable.
457883529b6Schristos   SHF_MIPS_GPREL = 0x10000000,
458883529b6Schristos 
459be12b8bcSchristos   // x86_64 specific large section.
460be12b8bcSchristos   SHF_X86_64_LARGE = 0x10000000
4612a6b7db3Sskrll };
4622a6b7db3Sskrll 
4639573673dSchristos // Values which appear in the first Elf_WXword of the section data
4649573673dSchristos // of a SHF_COMPRESSED section.
4659573673dSchristos enum
4669573673dSchristos {
4679573673dSchristos   ELFCOMPRESS_ZLIB = 1,
468*cb63e24eSchristos   ELFCOMPRESS_ZSTD = 2,
4699573673dSchristos   ELFCOMPRESS_LOOS = 0x60000000,
4709573673dSchristos   ELFCOMPRESS_HIOS = 0x6fffffff,
4719573673dSchristos   ELFCOMPRESS_LOPROC = 0x70000000,
4729573673dSchristos   ELFCOMPRESS_HIPROC = 0x7fffffff,
4739573673dSchristos };
4749573673dSchristos 
4752a6b7db3Sskrll // Bit flags which appear in the first 32-bit word of the section data
4762a6b7db3Sskrll // of a SHT_GROUP section.
4772a6b7db3Sskrll 
4782a6b7db3Sskrll enum
4792a6b7db3Sskrll {
4802a6b7db3Sskrll   GRP_COMDAT = 0x1,
4812a6b7db3Sskrll   GRP_MASKOS = 0x0ff00000,
4822a6b7db3Sskrll   GRP_MASKPROC = 0xf0000000
4832a6b7db3Sskrll };
4842a6b7db3Sskrll 
4852a6b7db3Sskrll // The valid values found in the Phdr p_type field.
4862a6b7db3Sskrll 
4872a6b7db3Sskrll enum PT
4882a6b7db3Sskrll {
4892a6b7db3Sskrll   PT_NULL = 0,
4902a6b7db3Sskrll   PT_LOAD = 1,
4912a6b7db3Sskrll   PT_DYNAMIC = 2,
4922a6b7db3Sskrll   PT_INTERP = 3,
4932a6b7db3Sskrll   PT_NOTE = 4,
4942a6b7db3Sskrll   PT_SHLIB = 5,
4952a6b7db3Sskrll   PT_PHDR = 6,
4962a6b7db3Sskrll   PT_TLS = 7,
4972a6b7db3Sskrll   PT_LOOS = 0x60000000,
4982a6b7db3Sskrll   PT_HIOS = 0x6fffffff,
4992a6b7db3Sskrll   PT_LOPROC = 0x70000000,
5002a6b7db3Sskrll   PT_HIPROC = 0x7fffffff,
5012a6b7db3Sskrll   // The remaining values are not in the standard.
5022a6b7db3Sskrll   // Frame unwind information.
5032a6b7db3Sskrll   PT_GNU_EH_FRAME = 0x6474e550,
5042a6b7db3Sskrll   PT_SUNW_EH_FRAME = 0x6474e550,
5052a6b7db3Sskrll   // Stack flags.
5062a6b7db3Sskrll   PT_GNU_STACK = 0x6474e551,
5072a6b7db3Sskrll   // Read only after relocation.
508be12b8bcSchristos   PT_GNU_RELRO = 0x6474e552,
509be12b8bcSchristos   // Platform architecture compatibility information
510be12b8bcSchristos   PT_ARM_ARCHEXT = 0x70000000,
511be12b8bcSchristos   // Exception unwind tables
512883529b6Schristos   PT_ARM_EXIDX = 0x70000001,
513883529b6Schristos   // Register usage information.  Identifies one .reginfo section.
514883529b6Schristos   PT_MIPS_REGINFO =0x70000000,
515883529b6Schristos   // Runtime procedure table.
516883529b6Schristos   PT_MIPS_RTPROC = 0x70000001,
517883529b6Schristos   // .MIPS.options section.
5189573673dSchristos   PT_MIPS_OPTIONS = 0x70000002,
5199573673dSchristos   // .MIPS.abiflags section.
5209573673dSchristos   PT_MIPS_ABIFLAGS = 0x70000003,
5219573673dSchristos   // Platform architecture compatibility information
5229573673dSchristos   PT_AARCH64_ARCHEXT = 0x70000000,
5239573673dSchristos   // Exception unwind tables
524fc4f4269Schristos   PT_AARCH64_UNWIND = 0x70000001,
525fc4f4269Schristos   // 4k page table size
526fc4f4269Schristos   PT_S390_PGSTE = 0x70000000,
5272a6b7db3Sskrll };
5282a6b7db3Sskrll 
5292a6b7db3Sskrll // The valid bit flags found in the Phdr p_flags field.
5302a6b7db3Sskrll 
5312a6b7db3Sskrll enum PF
5322a6b7db3Sskrll {
5332a6b7db3Sskrll   PF_X = 0x1,
5342a6b7db3Sskrll   PF_W = 0x2,
5352a6b7db3Sskrll   PF_R = 0x4,
5362a6b7db3Sskrll   PF_MASKOS = 0x0ff00000,
5372a6b7db3Sskrll   PF_MASKPROC = 0xf0000000
5382a6b7db3Sskrll };
5392a6b7db3Sskrll 
5402a6b7db3Sskrll // Symbol binding from Sym st_info field.
5412a6b7db3Sskrll 
5422a6b7db3Sskrll enum STB
5432a6b7db3Sskrll {
5442a6b7db3Sskrll   STB_LOCAL = 0,
5452a6b7db3Sskrll   STB_GLOBAL = 1,
5462a6b7db3Sskrll   STB_WEAK = 2,
5472a6b7db3Sskrll   STB_LOOS = 10,
548be12b8bcSchristos   STB_GNU_UNIQUE = 10,
5492a6b7db3Sskrll   STB_HIOS = 12,
5502a6b7db3Sskrll   STB_LOPROC = 13,
5512a6b7db3Sskrll   STB_HIPROC = 15
5522a6b7db3Sskrll };
5532a6b7db3Sskrll 
5542a6b7db3Sskrll // Symbol types from Sym st_info field.
5552a6b7db3Sskrll 
5562a6b7db3Sskrll enum STT
5572a6b7db3Sskrll {
5582a6b7db3Sskrll   STT_NOTYPE = 0,
5592a6b7db3Sskrll   STT_OBJECT = 1,
5602a6b7db3Sskrll   STT_FUNC = 2,
5612a6b7db3Sskrll   STT_SECTION = 3,
5622a6b7db3Sskrll   STT_FILE = 4,
5632a6b7db3Sskrll   STT_COMMON = 5,
5642a6b7db3Sskrll   STT_TLS = 6,
565883529b6Schristos 
566883529b6Schristos   // GNU extension: symbol value points to a function which is called
567883529b6Schristos   // at runtime to determine the final value of the symbol.
568be12b8bcSchristos   STT_GNU_IFUNC = 10,
569883529b6Schristos 
570883529b6Schristos   STT_LOOS = 10,
5712a6b7db3Sskrll   STT_HIOS = 12,
5722a6b7db3Sskrll   STT_LOPROC = 13,
5732a6b7db3Sskrll   STT_HIPROC = 15,
5742a6b7db3Sskrll 
5752a6b7db3Sskrll   // The section type that must be used for register symbols on
5762a6b7db3Sskrll   // Sparc.  These symbols initialize a global register.
5772a6b7db3Sskrll   STT_SPARC_REGISTER = 13,
578be12b8bcSchristos 
579be12b8bcSchristos   // ARM: a THUMB function.  This is not defined in ARM ELF Specification but
580be12b8bcSchristos   // used by the GNU tool-chain.
581be12b8bcSchristos   STT_ARM_TFUNC = 13
5822a6b7db3Sskrll };
5832a6b7db3Sskrll 
5842a6b7db3Sskrll inline STB
5852a6b7db3Sskrll elf_st_bind(unsigned char info)
5862a6b7db3Sskrll {
5872a6b7db3Sskrll   return static_cast<STB>(info >> 4);
5882a6b7db3Sskrll }
5892a6b7db3Sskrll 
5902a6b7db3Sskrll inline STT
5912a6b7db3Sskrll elf_st_type(unsigned char info)
5922a6b7db3Sskrll {
5932a6b7db3Sskrll   return static_cast<STT>(info & 0xf);
5942a6b7db3Sskrll }
5952a6b7db3Sskrll 
5962a6b7db3Sskrll inline unsigned char
5972a6b7db3Sskrll elf_st_info(STB bind, STT type)
5982a6b7db3Sskrll {
5992a6b7db3Sskrll   return ((static_cast<unsigned char>(bind) << 4)
6002a6b7db3Sskrll 	  + (static_cast<unsigned char>(type) & 0xf));
6012a6b7db3Sskrll }
6022a6b7db3Sskrll 
6032a6b7db3Sskrll // Symbol visibility from Sym st_other field.
6042a6b7db3Sskrll 
6052a6b7db3Sskrll enum STV
6062a6b7db3Sskrll {
6072a6b7db3Sskrll   STV_DEFAULT = 0,
6082a6b7db3Sskrll   STV_INTERNAL = 1,
6092a6b7db3Sskrll   STV_HIDDEN = 2,
6102a6b7db3Sskrll   STV_PROTECTED = 3
6112a6b7db3Sskrll };
6122a6b7db3Sskrll 
6132a6b7db3Sskrll inline STV
6142a6b7db3Sskrll elf_st_visibility(unsigned char other)
6152a6b7db3Sskrll {
6162a6b7db3Sskrll   return static_cast<STV>(other & 0x3);
6172a6b7db3Sskrll }
6182a6b7db3Sskrll 
6192a6b7db3Sskrll inline unsigned char
6202a6b7db3Sskrll elf_st_nonvis(unsigned char other)
6212a6b7db3Sskrll {
6222a6b7db3Sskrll   return static_cast<STV>(other >> 2);
6232a6b7db3Sskrll }
6242a6b7db3Sskrll 
6252a6b7db3Sskrll inline unsigned char
6262a6b7db3Sskrll elf_st_other(STV vis, unsigned char nonvis)
6272a6b7db3Sskrll {
6282a6b7db3Sskrll   return ((nonvis << 2)
6292a6b7db3Sskrll 	  + (static_cast<unsigned char>(vis) & 3));
6302a6b7db3Sskrll }
6312a6b7db3Sskrll 
6322a6b7db3Sskrll // Reloc information from Rel/Rela r_info field.
6332a6b7db3Sskrll 
6342a6b7db3Sskrll template<int size>
6352a6b7db3Sskrll unsigned int
6362a6b7db3Sskrll elf_r_sym(typename Elf_types<size>::Elf_WXword);
6372a6b7db3Sskrll 
6382a6b7db3Sskrll template<>
6392a6b7db3Sskrll inline unsigned int
6402a6b7db3Sskrll elf_r_sym<32>(Elf_Word v)
6412a6b7db3Sskrll {
6422a6b7db3Sskrll   return v >> 8;
6432a6b7db3Sskrll }
6442a6b7db3Sskrll 
6452a6b7db3Sskrll template<>
6462a6b7db3Sskrll inline unsigned int
6472a6b7db3Sskrll elf_r_sym<64>(Elf_Xword v)
6482a6b7db3Sskrll {
6492a6b7db3Sskrll   return v >> 32;
6502a6b7db3Sskrll }
6512a6b7db3Sskrll 
6522a6b7db3Sskrll template<int size>
6532a6b7db3Sskrll unsigned int
6542a6b7db3Sskrll elf_r_type(typename Elf_types<size>::Elf_WXword);
6552a6b7db3Sskrll 
6562a6b7db3Sskrll template<>
6572a6b7db3Sskrll inline unsigned int
6582a6b7db3Sskrll elf_r_type<32>(Elf_Word v)
6592a6b7db3Sskrll {
6602a6b7db3Sskrll   return v & 0xff;
6612a6b7db3Sskrll }
6622a6b7db3Sskrll 
6632a6b7db3Sskrll template<>
6642a6b7db3Sskrll inline unsigned int
6652a6b7db3Sskrll elf_r_type<64>(Elf_Xword v)
6662a6b7db3Sskrll {
6672a6b7db3Sskrll   return v & 0xffffffff;
6682a6b7db3Sskrll }
6692a6b7db3Sskrll 
6702a6b7db3Sskrll template<int size>
6712a6b7db3Sskrll typename Elf_types<size>::Elf_WXword
6722a6b7db3Sskrll elf_r_info(unsigned int s, unsigned int t);
6732a6b7db3Sskrll 
6742a6b7db3Sskrll template<>
6752a6b7db3Sskrll inline Elf_Word
6762a6b7db3Sskrll elf_r_info<32>(unsigned int s, unsigned int t)
6772a6b7db3Sskrll {
6782a6b7db3Sskrll   return (s << 8) + (t & 0xff);
6792a6b7db3Sskrll }
6802a6b7db3Sskrll 
6812a6b7db3Sskrll template<>
6822a6b7db3Sskrll inline Elf_Xword
6832a6b7db3Sskrll elf_r_info<64>(unsigned int s, unsigned int t)
6842a6b7db3Sskrll {
6852a6b7db3Sskrll   return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
6862a6b7db3Sskrll }
6872a6b7db3Sskrll 
6882a6b7db3Sskrll // Dynamic tags found in the PT_DYNAMIC segment.
6892a6b7db3Sskrll 
6902a6b7db3Sskrll enum DT
6912a6b7db3Sskrll {
6922a6b7db3Sskrll   DT_NULL = 0,
6932a6b7db3Sskrll   DT_NEEDED = 1,
6942a6b7db3Sskrll   DT_PLTRELSZ = 2,
6952a6b7db3Sskrll   DT_PLTGOT = 3,
6962a6b7db3Sskrll   DT_HASH = 4,
6972a6b7db3Sskrll   DT_STRTAB = 5,
6982a6b7db3Sskrll   DT_SYMTAB = 6,
6992a6b7db3Sskrll   DT_RELA = 7,
7002a6b7db3Sskrll   DT_RELASZ = 8,
7012a6b7db3Sskrll   DT_RELAENT = 9,
7022a6b7db3Sskrll   DT_STRSZ = 10,
7032a6b7db3Sskrll   DT_SYMENT = 11,
7042a6b7db3Sskrll   DT_INIT = 12,
7052a6b7db3Sskrll   DT_FINI = 13,
7062a6b7db3Sskrll   DT_SONAME = 14,
7072a6b7db3Sskrll   DT_RPATH = 15,
7082a6b7db3Sskrll   DT_SYMBOLIC = 16,
7092a6b7db3Sskrll   DT_REL = 17,
7102a6b7db3Sskrll   DT_RELSZ = 18,
7112a6b7db3Sskrll   DT_RELENT = 19,
7122a6b7db3Sskrll   DT_PLTREL = 20,
7132a6b7db3Sskrll   DT_DEBUG = 21,
7142a6b7db3Sskrll   DT_TEXTREL = 22,
7152a6b7db3Sskrll   DT_JMPREL = 23,
7162a6b7db3Sskrll   DT_BIND_NOW = 24,
7172a6b7db3Sskrll   DT_INIT_ARRAY = 25,
7182a6b7db3Sskrll   DT_FINI_ARRAY = 26,
7192a6b7db3Sskrll   DT_INIT_ARRAYSZ = 27,
7202a6b7db3Sskrll   DT_FINI_ARRAYSZ = 28,
7212a6b7db3Sskrll   DT_RUNPATH = 29,
7222a6b7db3Sskrll   DT_FLAGS = 30,
723be12b8bcSchristos 
724be12b8bcSchristos   // This is used to mark a range of dynamic tags.  It is not really
725be12b8bcSchristos   // a tag value.
7262a6b7db3Sskrll   DT_ENCODING = 32,
727be12b8bcSchristos 
728be12b8bcSchristos   DT_PREINIT_ARRAY = 32,
7292a6b7db3Sskrll   DT_PREINIT_ARRAYSZ = 33,
7302a6b7db3Sskrll   DT_LOOS = 0x6000000d,
7312a6b7db3Sskrll   DT_HIOS = 0x6ffff000,
7322a6b7db3Sskrll   DT_LOPROC = 0x70000000,
7332a6b7db3Sskrll   DT_HIPROC = 0x7fffffff,
7342a6b7db3Sskrll 
7352a6b7db3Sskrll   // The remaining values are extensions used by GNU or Solaris.
7362a6b7db3Sskrll   DT_VALRNGLO = 0x6ffffd00,
7374f645668Schristos   DT_GNU_FLAGS_1 = 0x6ffffdf4,
7382a6b7db3Sskrll   DT_GNU_PRELINKED = 0x6ffffdf5,
7392a6b7db3Sskrll   DT_GNU_CONFLICTSZ = 0x6ffffdf6,
7402a6b7db3Sskrll   DT_GNU_LIBLISTSZ = 0x6ffffdf7,
7412a6b7db3Sskrll   DT_CHECKSUM = 0x6ffffdf8,
7422a6b7db3Sskrll   DT_PLTPADSZ = 0x6ffffdf9,
7432a6b7db3Sskrll   DT_MOVEENT = 0x6ffffdfa,
7442a6b7db3Sskrll   DT_MOVESZ = 0x6ffffdfb,
7452a6b7db3Sskrll   DT_FEATURE = 0x6ffffdfc,
7462a6b7db3Sskrll   DT_POSFLAG_1 = 0x6ffffdfd,
7472a6b7db3Sskrll   DT_SYMINSZ = 0x6ffffdfe,
7482a6b7db3Sskrll   DT_SYMINENT = 0x6ffffdff,
7492a6b7db3Sskrll   DT_VALRNGHI = 0x6ffffdff,
7502a6b7db3Sskrll 
7512a6b7db3Sskrll   DT_ADDRRNGLO = 0x6ffffe00,
7522a6b7db3Sskrll   DT_GNU_HASH = 0x6ffffef5,
7532a6b7db3Sskrll   DT_TLSDESC_PLT = 0x6ffffef6,
7542a6b7db3Sskrll   DT_TLSDESC_GOT = 0x6ffffef7,
7552a6b7db3Sskrll   DT_GNU_CONFLICT = 0x6ffffef8,
7562a6b7db3Sskrll   DT_GNU_LIBLIST = 0x6ffffef9,
7572a6b7db3Sskrll   DT_CONFIG = 0x6ffffefa,
7582a6b7db3Sskrll   DT_DEPAUDIT = 0x6ffffefb,
7592a6b7db3Sskrll   DT_AUDIT = 0x6ffffefc,
7602a6b7db3Sskrll   DT_PLTPAD = 0x6ffffefd,
7612a6b7db3Sskrll   DT_MOVETAB = 0x6ffffefe,
7622a6b7db3Sskrll   DT_SYMINFO = 0x6ffffeff,
7632a6b7db3Sskrll   DT_ADDRRNGHI = 0x6ffffeff,
7642a6b7db3Sskrll 
7652a6b7db3Sskrll   DT_RELACOUNT = 0x6ffffff9,
7662a6b7db3Sskrll   DT_RELCOUNT = 0x6ffffffa,
7672a6b7db3Sskrll   DT_FLAGS_1 = 0x6ffffffb,
7682a6b7db3Sskrll   DT_VERDEF = 0x6ffffffc,
7692a6b7db3Sskrll   DT_VERDEFNUM = 0x6ffffffd,
7702a6b7db3Sskrll   DT_VERNEED = 0x6ffffffe,
7712a6b7db3Sskrll   DT_VERNEEDNUM = 0x6fffffff,
7722a6b7db3Sskrll 
7732a6b7db3Sskrll   DT_VERSYM = 0x6ffffff0,
7742a6b7db3Sskrll 
7752a6b7db3Sskrll   // Specify the value of _GLOBAL_OFFSET_TABLE_.
7762a6b7db3Sskrll   DT_PPC_GOT = 0x70000000,
7772a6b7db3Sskrll 
778fc4f4269Schristos   // Specify whether various optimisations are possible.
779fc4f4269Schristos   DT_PPC_OPT = 0x70000001,
780fc4f4269Schristos 
7812a6b7db3Sskrll   // Specify the start of the .glink section.
7822a6b7db3Sskrll   DT_PPC64_GLINK = 0x70000000,
7832a6b7db3Sskrll 
7842a6b7db3Sskrll   // Specify the start and size of the .opd section.
7852a6b7db3Sskrll   DT_PPC64_OPD = 0x70000001,
7862a6b7db3Sskrll   DT_PPC64_OPDSZ = 0x70000002,
7872a6b7db3Sskrll 
788fc4f4269Schristos   // Specify whether various optimisations are possible.
789fc4f4269Schristos   DT_PPC64_OPT = 0x70000003,
790fc4f4269Schristos 
7912a6b7db3Sskrll   // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
7922a6b7db3Sskrll   // symbol table.  One dynamic entry exists for every STT_SPARC_REGISTER
7932a6b7db3Sskrll   // symbol in the symbol table.
7942a6b7db3Sskrll   DT_SPARC_REGISTER = 0x70000001,
7952a6b7db3Sskrll 
796883529b6Schristos   // MIPS specific dynamic array tags.
797883529b6Schristos   // 32 bit version number for runtime linker interface.
798883529b6Schristos   DT_MIPS_RLD_VERSION = 0x70000001,
799883529b6Schristos   // Time stamp.
800883529b6Schristos   DT_MIPS_TIME_STAMP = 0x70000002,
801883529b6Schristos   // Checksum of external strings and common sizes.
802883529b6Schristos   DT_MIPS_ICHECKSUM = 0x70000003,
803883529b6Schristos   // Index of version string in string table.
804883529b6Schristos   DT_MIPS_IVERSION = 0x70000004,
805883529b6Schristos   // 32 bits of flags.
806883529b6Schristos   DT_MIPS_FLAGS = 0x70000005,
807883529b6Schristos   // Base address of the segment.
808883529b6Schristos   DT_MIPS_BASE_ADDRESS = 0x70000006,
809883529b6Schristos   // ???
810883529b6Schristos   DT_MIPS_MSYM = 0x70000007,
811883529b6Schristos   // Address of .conflict section.
812883529b6Schristos   DT_MIPS_CONFLICT = 0x70000008,
813883529b6Schristos   // Address of .liblist section.
814883529b6Schristos   DT_MIPS_LIBLIST = 0x70000009,
815883529b6Schristos   // Number of local global offset table entries.
816883529b6Schristos   DT_MIPS_LOCAL_GOTNO = 0x7000000a,
817883529b6Schristos   // Number of entries in the .conflict section.
818883529b6Schristos   DT_MIPS_CONFLICTNO = 0x7000000b,
819883529b6Schristos   // Number of entries in the .liblist section.
820883529b6Schristos   DT_MIPS_LIBLISTNO = 0x70000010,
821883529b6Schristos   // Number of entries in the .dynsym section.
822883529b6Schristos   DT_MIPS_SYMTABNO = 0x70000011,
823883529b6Schristos   // Index of first external dynamic symbol not referenced locally.
824883529b6Schristos   DT_MIPS_UNREFEXTNO = 0x70000012,
825883529b6Schristos   // Index of first dynamic symbol in global offset table.
826883529b6Schristos   DT_MIPS_GOTSYM = 0x70000013,
827883529b6Schristos   // Number of page table entries in global offset table.
828883529b6Schristos   DT_MIPS_HIPAGENO = 0x70000014,
829883529b6Schristos   // Address of run time loader map, used for debugging.
830883529b6Schristos   DT_MIPS_RLD_MAP = 0x70000016,
831883529b6Schristos   // Delta C++ class definition.
832883529b6Schristos   DT_MIPS_DELTA_CLASS = 0x70000017,
833883529b6Schristos   // Number of entries in DT_MIPS_DELTA_CLASS.
834883529b6Schristos   DT_MIPS_DELTA_CLASS_NO = 0x70000018,
835883529b6Schristos   // Delta C++ class instances.
836883529b6Schristos   DT_MIPS_DELTA_INSTANCE = 0x70000019,
837883529b6Schristos   // Number of entries in DT_MIPS_DELTA_INSTANCE.
838883529b6Schristos   DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a,
839883529b6Schristos   // Delta relocations.
840883529b6Schristos   DT_MIPS_DELTA_RELOC = 0x7000001b,
841883529b6Schristos   // Number of entries in DT_MIPS_DELTA_RELOC.
842883529b6Schristos   DT_MIPS_DELTA_RELOC_NO = 0x7000001c,
843883529b6Schristos   // Delta symbols that Delta relocations refer to.
844883529b6Schristos   DT_MIPS_DELTA_SYM = 0x7000001d,
845883529b6Schristos   // Number of entries in DT_MIPS_DELTA_SYM.
846883529b6Schristos   DT_MIPS_DELTA_SYM_NO = 0x7000001e,
847883529b6Schristos   // Delta symbols that hold class declarations.
848883529b6Schristos   DT_MIPS_DELTA_CLASSSYM = 0x70000020,
849883529b6Schristos   // Number of entries in DT_MIPS_DELTA_CLASSSYM.
850883529b6Schristos   DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021,
851883529b6Schristos   // Flags indicating information about C++ flavor.
852883529b6Schristos   DT_MIPS_CXX_FLAGS = 0x70000022,
853883529b6Schristos   // Pixie information (???).
854883529b6Schristos   DT_MIPS_PIXIE_INIT = 0x70000023,
855883529b6Schristos   // Address of .MIPS.symlib
856883529b6Schristos   DT_MIPS_SYMBOL_LIB = 0x70000024,
857883529b6Schristos   // The GOT index of the first PTE for a segment
858883529b6Schristos   DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025,
859883529b6Schristos   // The GOT index of the first PTE for a local symbol
860883529b6Schristos   DT_MIPS_LOCAL_GOTIDX = 0x70000026,
861883529b6Schristos   // The GOT index of the first PTE for a hidden symbol
862883529b6Schristos   DT_MIPS_HIDDEN_GOTIDX = 0x70000027,
863883529b6Schristos   // The GOT index of the first PTE for a protected symbol
864883529b6Schristos   DT_MIPS_PROTECTED_GOTIDX = 0x70000028,
865883529b6Schristos   // Address of `.MIPS.options'.
866883529b6Schristos   DT_MIPS_OPTIONS = 0x70000029,
867883529b6Schristos   // Address of `.interface'.
868883529b6Schristos   DT_MIPS_INTERFACE = 0x7000002a,
869883529b6Schristos   // ???
870883529b6Schristos   DT_MIPS_DYNSTR_ALIGN = 0x7000002b,
871883529b6Schristos   // Size of the .interface section.
872883529b6Schristos   DT_MIPS_INTERFACE_SIZE = 0x7000002c,
873883529b6Schristos   // Size of rld_text_resolve function stored in the GOT.
874883529b6Schristos   DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d,
875883529b6Schristos   // Default suffix of DSO to be added by rld on dlopen() calls.
876883529b6Schristos   DT_MIPS_PERF_SUFFIX = 0x7000002e,
877883529b6Schristos   // Size of compact relocation section (O32).
878883529b6Schristos   DT_MIPS_COMPACT_SIZE = 0x7000002f,
879883529b6Schristos   // GP value for auxiliary GOTs.
880883529b6Schristos   DT_MIPS_GP_VALUE = 0x70000030,
881883529b6Schristos   // Address of auxiliary .dynamic.
882883529b6Schristos   DT_MIPS_AUX_DYNAMIC = 0x70000031,
883883529b6Schristos   // Address of the base of the PLTGOT.
884883529b6Schristos   DT_MIPS_PLTGOT = 0x70000032,
885883529b6Schristos   // Points to the base of a writable PLT.
886883529b6Schristos   DT_MIPS_RWPLT = 0x70000034,
8878cbf5cb7Schristos   // Relative offset of run time loader map, used for debugging.
8888cbf5cb7Schristos   DT_MIPS_RLD_MAP_REL = 0x70000035,
889883529b6Schristos 
8902a6b7db3Sskrll   DT_AUXILIARY = 0x7ffffffd,
8912a6b7db3Sskrll   DT_USED = 0x7ffffffe,
8922a6b7db3Sskrll   DT_FILTER = 0x7fffffff
8932a6b7db3Sskrll };
8942a6b7db3Sskrll 
8952a6b7db3Sskrll // Flags found in the DT_FLAGS dynamic element.
8962a6b7db3Sskrll 
8972a6b7db3Sskrll enum DF
8982a6b7db3Sskrll {
8992a6b7db3Sskrll   DF_ORIGIN = 0x1,
9002a6b7db3Sskrll   DF_SYMBOLIC = 0x2,
9012a6b7db3Sskrll   DF_TEXTREL = 0x4,
9022a6b7db3Sskrll   DF_BIND_NOW = 0x8,
9032a6b7db3Sskrll   DF_STATIC_TLS = 0x10
9042a6b7db3Sskrll };
9052a6b7db3Sskrll 
9062a6b7db3Sskrll // Flags found in the DT_FLAGS_1 dynamic element.
9072a6b7db3Sskrll 
9082a6b7db3Sskrll enum DF_1
9092a6b7db3Sskrll {
9102a6b7db3Sskrll   DF_1_NOW = 0x1,
9112a6b7db3Sskrll   DF_1_GLOBAL = 0x2,
9122a6b7db3Sskrll   DF_1_GROUP = 0x4,
9132a6b7db3Sskrll   DF_1_NODELETE = 0x8,
9142a6b7db3Sskrll   DF_1_LOADFLTR = 0x10,
9152a6b7db3Sskrll   DF_1_INITFIRST = 0x20,
9162a6b7db3Sskrll   DF_1_NOOPEN = 0x40,
9172a6b7db3Sskrll   DF_1_ORIGIN = 0x80,
9182a6b7db3Sskrll   DF_1_DIRECT = 0x100,
9192a6b7db3Sskrll   DF_1_TRANS = 0x200,
9202a6b7db3Sskrll   DF_1_INTERPOSE = 0x400,
9212a6b7db3Sskrll   DF_1_NODEFLIB = 0x800,
9222a6b7db3Sskrll   DF_1_NODUMP = 0x1000,
9234f645668Schristos   DF_1_CONLFAT = 0x2000,
9244f645668Schristos   DF_1_PIE = 0x08000000
9254f645668Schristos };
9264f645668Schristos 
9274f645668Schristos // Flags found in the DT_GNU_FLAGS_1 dynamic element.
9284f645668Schristos enum DF_GNU_1
9294f645668Schristos {
9304f645668Schristos   DF_GNU_1_UNIQUE = 0x1,
9312a6b7db3Sskrll };
9322a6b7db3Sskrll 
9332a6b7db3Sskrll // Version numbers which appear in the vd_version field of a Verdef
9342a6b7db3Sskrll // structure.
9352a6b7db3Sskrll 
9362a6b7db3Sskrll const int VER_DEF_NONE = 0;
9372a6b7db3Sskrll const int VER_DEF_CURRENT = 1;
9382a6b7db3Sskrll 
9392a6b7db3Sskrll // Version numbers which appear in the vn_version field of a Verneed
9402a6b7db3Sskrll // structure.
9412a6b7db3Sskrll 
9422a6b7db3Sskrll const int VER_NEED_NONE = 0;
9432a6b7db3Sskrll const int VER_NEED_CURRENT = 1;
9442a6b7db3Sskrll 
9452a6b7db3Sskrll // Bit flags which appear in vd_flags of Verdef and vna_flags of
9462a6b7db3Sskrll // Vernaux.
9472a6b7db3Sskrll 
9482a6b7db3Sskrll const int VER_FLG_BASE = 0x1;
9492a6b7db3Sskrll const int VER_FLG_WEAK = 0x2;
950be12b8bcSchristos const int VER_FLG_INFO = 0x4;
9512a6b7db3Sskrll 
9522a6b7db3Sskrll // Special constants found in the SHT_GNU_versym entries.
9532a6b7db3Sskrll 
9542a6b7db3Sskrll const int VER_NDX_LOCAL = 0;
9552a6b7db3Sskrll const int VER_NDX_GLOBAL = 1;
9562a6b7db3Sskrll 
9572a6b7db3Sskrll // A SHT_GNU_versym section holds 16-bit words.  This bit is set if
9582a6b7db3Sskrll // the symbol is hidden and can only be seen when referenced using an
9592a6b7db3Sskrll // explicit version number.  This is a GNU extension.
9602a6b7db3Sskrll 
9612a6b7db3Sskrll const int VERSYM_HIDDEN = 0x8000;
9622a6b7db3Sskrll 
9632a6b7db3Sskrll // This is the mask for the rest of the data in a word read from a
9642a6b7db3Sskrll // SHT_GNU_versym section.
9652a6b7db3Sskrll 
9662a6b7db3Sskrll const int VERSYM_VERSION = 0x7fff;
9672a6b7db3Sskrll 
9682a6b7db3Sskrll // Note descriptor type codes for notes in a non-core file with an
9692a6b7db3Sskrll // empty name.
9702a6b7db3Sskrll 
9712a6b7db3Sskrll enum
9722a6b7db3Sskrll {
9732a6b7db3Sskrll   // A version string.
9742a6b7db3Sskrll   NT_VERSION = 1,
9752a6b7db3Sskrll   // An architecture string.
9762a6b7db3Sskrll   NT_ARCH = 2
9772a6b7db3Sskrll };
9782a6b7db3Sskrll 
9792a6b7db3Sskrll // Note descriptor type codes for notes in a non-core file with the
9802a6b7db3Sskrll // name "GNU".
9812a6b7db3Sskrll 
9822a6b7db3Sskrll enum
9832a6b7db3Sskrll {
9842a6b7db3Sskrll   // The minimum ABI level.  This is used by the dynamic linker to
9852a6b7db3Sskrll   // describe the minimal kernel version on which a shared library may
9862a6b7db3Sskrll   // be used.  Th value should be four words.  Word 0 is an OS
9872a6b7db3Sskrll   // descriptor (see below).  Word 1 is the major version of the ABI.
9882a6b7db3Sskrll   // Word 2 is the minor version.  Word 3 is the subminor version.
9892a6b7db3Sskrll   NT_GNU_ABI_TAG = 1,
9902a6b7db3Sskrll   // Hardware capabilities information.  Word 0 is the number of
9912a6b7db3Sskrll   // entries.  Word 1 is a bitmask of enabled entries.  The rest of
9922a6b7db3Sskrll   // the descriptor is a series of entries, where each entry is a
9932a6b7db3Sskrll   // single byte followed by a nul terminated string.  The byte gives
9942a6b7db3Sskrll   // the bit number to test if enabled in the bitmask.
9952a6b7db3Sskrll   NT_GNU_HWCAP = 2,
9962a6b7db3Sskrll   // The build ID as set by the linker's --build-id option.  The
9972a6b7db3Sskrll   // format of the descriptor depends on the build ID style.
9982a6b7db3Sskrll   NT_GNU_BUILD_ID = 3,
9992a6b7db3Sskrll   // The version of gold used to link.  Th descriptor is just a
10002a6b7db3Sskrll   // string.
1001c1a20988Schristos   NT_GNU_GOLD_VERSION = 4,
1002c1a20988Schristos   // Program property note, as described in "Linux Extensions to the gABI".
1003*cb63e24eSchristos   NT_GNU_PROPERTY_TYPE_0 = 5,
1004*cb63e24eSchristos   // FDO .note.package notes as defined on https://systemd.io/ELF_PACKAGE_METADATA/
1005*cb63e24eSchristos   FDO_PACKAGING_METADATA = 0xcafe1a7e
10062a6b7db3Sskrll };
10072a6b7db3Sskrll 
10082a6b7db3Sskrll // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
10092a6b7db3Sskrll 
10102a6b7db3Sskrll enum
10112a6b7db3Sskrll {
10122a6b7db3Sskrll   ELF_NOTE_OS_LINUX = 0,
10132a6b7db3Sskrll   ELF_NOTE_OS_GNU = 1,
10142a6b7db3Sskrll   ELF_NOTE_OS_SOLARIS2 = 2,
10152a6b7db3Sskrll   ELF_NOTE_OS_FREEBSD = 3,
10162a6b7db3Sskrll   ELF_NOTE_OS_NETBSD = 4,
10172a6b7db3Sskrll   ELF_NOTE_OS_SYLLABLE = 5
10182a6b7db3Sskrll };
10192a6b7db3Sskrll 
1020c1a20988Schristos // Program property types for NT_GNU_PROPERTY_TYPE_0.
1021c1a20988Schristos 
1022c1a20988Schristos enum
1023c1a20988Schristos {
1024c1a20988Schristos   GNU_PROPERTY_STACK_SIZE = 1,
1025c1a20988Schristos   GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
1026c1a20988Schristos   GNU_PROPERTY_LOPROC = 0xc0000000,
10274f645668Schristos   GNU_PROPERTY_X86_COMPAT_ISA_1_USED = 0xc0000000,
10284f645668Schristos   GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED = 0xc0000001,
10294f645668Schristos   GNU_PROPERTY_X86_UINT32_AND_LO = 0xc0000002,
10304f645668Schristos   GNU_PROPERTY_X86_UINT32_AND_HI = 0xc0007fff,
10314f645668Schristos   GNU_PROPERTY_X86_UINT32_OR_LO = 0xc0008000,
10324f645668Schristos   GNU_PROPERTY_X86_UINT32_OR_HI = 0xc000ffff,
10334f645668Schristos   GNU_PROPERTY_X86_UINT32_OR_AND_LO = 0xc0010000,
10344f645668Schristos   GNU_PROPERTY_X86_UINT32_OR_AND_HI = 0xc0017fff,
10354f645668Schristos   GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 0,
10364f645668Schristos   GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0,
10374f645668Schristos   GNU_PROPERTY_X86_FEATURE_1_AND = GNU_PROPERTY_X86_UINT32_AND_LO + 0,
10384f645668Schristos   GNU_PROPERTY_X86_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 2,
10394f645668Schristos   GNU_PROPERTY_X86_FEATURE_2_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 1,
10404f645668Schristos   GNU_PROPERTY_X86_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2,
10414f645668Schristos   GNU_PROPERTY_X86_FEATURE_2_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1,
1042c1a20988Schristos   GNU_PROPERTY_HIPROC = 0xdfffffff,
1043c1a20988Schristos   GNU_PROPERTY_LOUSER = 0xe0000000,
1044c1a20988Schristos   GNU_PROPERTY_HIUSER = 0xffffffff
1045c1a20988Schristos };
1046c1a20988Schristos 
10472a6b7db3Sskrll } // End namespace elfcpp.
10482a6b7db3Sskrll 
10492a6b7db3Sskrll // Include internal details after defining the types.
10502a6b7db3Sskrll #include "elfcpp_internal.h"
10512a6b7db3Sskrll 
10522a6b7db3Sskrll namespace elfcpp
10532a6b7db3Sskrll {
10542a6b7db3Sskrll 
10552a6b7db3Sskrll // The offset of the ELF file header in the ELF file.
10562a6b7db3Sskrll 
10572a6b7db3Sskrll const int file_header_offset = 0;
10582a6b7db3Sskrll 
10592a6b7db3Sskrll // ELF structure sizes.
10602a6b7db3Sskrll 
10612a6b7db3Sskrll template<int size>
10622a6b7db3Sskrll struct Elf_sizes
10632a6b7db3Sskrll {
10642a6b7db3Sskrll   // Size of ELF file header.
10652a6b7db3Sskrll   static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
10662a6b7db3Sskrll   // Size of ELF segment header.
10672a6b7db3Sskrll   static const int phdr_size = sizeof(internal::Phdr_data<size>);
10682a6b7db3Sskrll   // Size of ELF section header.
10692a6b7db3Sskrll   static const int shdr_size = sizeof(internal::Shdr_data<size>);
10709573673dSchristos   // Size of ELF compression header.
10719573673dSchristos   static const int chdr_size = sizeof(internal::Chdr_data<size>);
10722a6b7db3Sskrll   // Size of ELF symbol table entry.
10732a6b7db3Sskrll   static const int sym_size = sizeof(internal::Sym_data<size>);
10742a6b7db3Sskrll   // Sizes of ELF reloc entries.
10752a6b7db3Sskrll   static const int rel_size = sizeof(internal::Rel_data<size>);
10762a6b7db3Sskrll   static const int rela_size = sizeof(internal::Rela_data<size>);
10772a6b7db3Sskrll   // Size of ELF dynamic entry.
10782a6b7db3Sskrll   static const int dyn_size = sizeof(internal::Dyn_data<size>);
10792a6b7db3Sskrll   // Size of ELF version structures.
10802a6b7db3Sskrll   static const int verdef_size = sizeof(internal::Verdef_data);
10812a6b7db3Sskrll   static const int verdaux_size = sizeof(internal::Verdaux_data);
10822a6b7db3Sskrll   static const int verneed_size = sizeof(internal::Verneed_data);
10832a6b7db3Sskrll   static const int vernaux_size = sizeof(internal::Vernaux_data);
10842a6b7db3Sskrll };
10852a6b7db3Sskrll 
10862a6b7db3Sskrll // Accessor class for the ELF file header.
10872a6b7db3Sskrll 
10882a6b7db3Sskrll template<int size, bool big_endian>
10892a6b7db3Sskrll class Ehdr
10902a6b7db3Sskrll {
10912a6b7db3Sskrll  public:
10922a6b7db3Sskrll   Ehdr(const unsigned char* p)
10932a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
10942a6b7db3Sskrll   { }
10952a6b7db3Sskrll 
10962a6b7db3Sskrll   template<typename File>
10972a6b7db3Sskrll   Ehdr(File* file, typename File::Location loc)
10982a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
10992a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
11002a6b7db3Sskrll   { }
11012a6b7db3Sskrll 
11022a6b7db3Sskrll   const unsigned char*
11032a6b7db3Sskrll   get_e_ident() const
11042a6b7db3Sskrll   { return this->p_->e_ident; }
11052a6b7db3Sskrll 
11064f645668Schristos   unsigned char
11074f645668Schristos   get_ei_osabi() const
11084f645668Schristos   { return this->p_->e_ident[EI_OSABI]; }
11094f645668Schristos 
11104f645668Schristos   unsigned char
11114f645668Schristos   get_ei_abiversion() const
11124f645668Schristos   { return this->p_->e_ident[EI_ABIVERSION]; }
11134f645668Schristos 
11142a6b7db3Sskrll   Elf_Half
11152a6b7db3Sskrll   get_e_type() const
11162a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
11172a6b7db3Sskrll 
11182a6b7db3Sskrll   Elf_Half
11192a6b7db3Sskrll   get_e_machine() const
11202a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
11212a6b7db3Sskrll 
11222a6b7db3Sskrll   Elf_Word
11232a6b7db3Sskrll   get_e_version() const
11242a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
11252a6b7db3Sskrll 
11262a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
11272a6b7db3Sskrll   get_e_entry() const
11282a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
11292a6b7db3Sskrll 
11302a6b7db3Sskrll   typename Elf_types<size>::Elf_Off
11312a6b7db3Sskrll   get_e_phoff() const
11322a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
11332a6b7db3Sskrll 
11342a6b7db3Sskrll   typename Elf_types<size>::Elf_Off
11352a6b7db3Sskrll   get_e_shoff() const
11362a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
11372a6b7db3Sskrll 
11382a6b7db3Sskrll   Elf_Word
11392a6b7db3Sskrll   get_e_flags() const
11402a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
11412a6b7db3Sskrll 
11422a6b7db3Sskrll   Elf_Half
11432a6b7db3Sskrll   get_e_ehsize() const
11442a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
11452a6b7db3Sskrll 
11462a6b7db3Sskrll   Elf_Half
11472a6b7db3Sskrll   get_e_phentsize() const
11482a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
11492a6b7db3Sskrll 
11502a6b7db3Sskrll   Elf_Half
11512a6b7db3Sskrll   get_e_phnum() const
11522a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
11532a6b7db3Sskrll 
11542a6b7db3Sskrll   Elf_Half
11552a6b7db3Sskrll   get_e_shentsize() const
11562a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
11572a6b7db3Sskrll 
11582a6b7db3Sskrll   Elf_Half
11592a6b7db3Sskrll   get_e_shnum() const
11602a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
11612a6b7db3Sskrll 
11622a6b7db3Sskrll   Elf_Half
11632a6b7db3Sskrll   get_e_shstrndx() const
11642a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
11652a6b7db3Sskrll 
11662a6b7db3Sskrll  private:
11672a6b7db3Sskrll   const internal::Ehdr_data<size>* p_;
11682a6b7db3Sskrll };
11692a6b7db3Sskrll 
11702a6b7db3Sskrll // Write class for the ELF file header.
11712a6b7db3Sskrll 
11722a6b7db3Sskrll template<int size, bool big_endian>
11732a6b7db3Sskrll class Ehdr_write
11742a6b7db3Sskrll {
11752a6b7db3Sskrll  public:
11762a6b7db3Sskrll   Ehdr_write(unsigned char* p)
11772a6b7db3Sskrll     : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
11782a6b7db3Sskrll   { }
11792a6b7db3Sskrll 
11802a6b7db3Sskrll   void
11812a6b7db3Sskrll   put_e_ident(const unsigned char v[EI_NIDENT]) const
11822a6b7db3Sskrll   { memcpy(this->p_->e_ident, v, EI_NIDENT); }
11832a6b7db3Sskrll 
11842a6b7db3Sskrll   void
11852a6b7db3Sskrll   put_e_type(Elf_Half v)
11862a6b7db3Sskrll   { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
11872a6b7db3Sskrll 
11882a6b7db3Sskrll   void
11892a6b7db3Sskrll   put_e_machine(Elf_Half v)
11902a6b7db3Sskrll   { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
11912a6b7db3Sskrll 
11922a6b7db3Sskrll   void
11932a6b7db3Sskrll   put_e_version(Elf_Word v)
11942a6b7db3Sskrll   { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
11952a6b7db3Sskrll 
11962a6b7db3Sskrll   void
11972a6b7db3Sskrll   put_e_entry(typename Elf_types<size>::Elf_Addr v)
11982a6b7db3Sskrll   { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
11992a6b7db3Sskrll 
12002a6b7db3Sskrll   void
12012a6b7db3Sskrll   put_e_phoff(typename Elf_types<size>::Elf_Off v)
12022a6b7db3Sskrll   { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
12032a6b7db3Sskrll 
12042a6b7db3Sskrll   void
12052a6b7db3Sskrll   put_e_shoff(typename Elf_types<size>::Elf_Off v)
12062a6b7db3Sskrll   { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
12072a6b7db3Sskrll 
12082a6b7db3Sskrll   void
12092a6b7db3Sskrll   put_e_flags(Elf_Word v)
12102a6b7db3Sskrll   { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
12112a6b7db3Sskrll 
12122a6b7db3Sskrll   void
12132a6b7db3Sskrll   put_e_ehsize(Elf_Half v)
12142a6b7db3Sskrll   { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
12152a6b7db3Sskrll 
12162a6b7db3Sskrll   void
12172a6b7db3Sskrll   put_e_phentsize(Elf_Half v)
12182a6b7db3Sskrll   { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
12192a6b7db3Sskrll 
12202a6b7db3Sskrll   void
12212a6b7db3Sskrll   put_e_phnum(Elf_Half v)
12222a6b7db3Sskrll   { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
12232a6b7db3Sskrll 
12242a6b7db3Sskrll   void
12252a6b7db3Sskrll   put_e_shentsize(Elf_Half v)
12262a6b7db3Sskrll   { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
12272a6b7db3Sskrll 
12282a6b7db3Sskrll   void
12292a6b7db3Sskrll   put_e_shnum(Elf_Half v)
12302a6b7db3Sskrll   { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
12312a6b7db3Sskrll 
12322a6b7db3Sskrll   void
12332a6b7db3Sskrll   put_e_shstrndx(Elf_Half v)
12342a6b7db3Sskrll   { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
12352a6b7db3Sskrll 
12362a6b7db3Sskrll  private:
12372a6b7db3Sskrll   internal::Ehdr_data<size>* p_;
12382a6b7db3Sskrll };
12392a6b7db3Sskrll 
12402a6b7db3Sskrll // Accessor class for an ELF section header.
12412a6b7db3Sskrll 
12422a6b7db3Sskrll template<int size, bool big_endian>
12432a6b7db3Sskrll class Shdr
12442a6b7db3Sskrll {
12452a6b7db3Sskrll  public:
12462a6b7db3Sskrll   Shdr(const unsigned char* p)
12472a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
12482a6b7db3Sskrll   { }
12492a6b7db3Sskrll 
12502a6b7db3Sskrll   template<typename File>
12512a6b7db3Sskrll   Shdr(File* file, typename File::Location loc)
12522a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
12532a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
12542a6b7db3Sskrll   { }
12552a6b7db3Sskrll 
12562a6b7db3Sskrll   Elf_Word
12572a6b7db3Sskrll   get_sh_name() const
12582a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
12592a6b7db3Sskrll 
12602a6b7db3Sskrll   Elf_Word
12612a6b7db3Sskrll   get_sh_type() const
12622a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
12632a6b7db3Sskrll 
12642a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
12652a6b7db3Sskrll   get_sh_flags() const
12662a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
12672a6b7db3Sskrll 
12682a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
12692a6b7db3Sskrll   get_sh_addr() const
12702a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
12712a6b7db3Sskrll 
12722a6b7db3Sskrll   typename Elf_types<size>::Elf_Off
12732a6b7db3Sskrll   get_sh_offset() const
12742a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
12752a6b7db3Sskrll 
12762a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
12772a6b7db3Sskrll   get_sh_size() const
12782a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
12792a6b7db3Sskrll 
12802a6b7db3Sskrll   Elf_Word
12812a6b7db3Sskrll   get_sh_link() const
12822a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
12832a6b7db3Sskrll 
12842a6b7db3Sskrll   Elf_Word
12852a6b7db3Sskrll   get_sh_info() const
12862a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
12872a6b7db3Sskrll 
12882a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
12892a6b7db3Sskrll   get_sh_addralign() const
12902a6b7db3Sskrll   { return
12912a6b7db3Sskrll       Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
12922a6b7db3Sskrll 
12932a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
12942a6b7db3Sskrll   get_sh_entsize() const
12952a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
12962a6b7db3Sskrll 
12972a6b7db3Sskrll  private:
12982a6b7db3Sskrll   const internal::Shdr_data<size>* p_;
12992a6b7db3Sskrll };
13002a6b7db3Sskrll 
13012a6b7db3Sskrll // Write class for an ELF section header.
13022a6b7db3Sskrll 
13032a6b7db3Sskrll template<int size, bool big_endian>
13042a6b7db3Sskrll class Shdr_write
13052a6b7db3Sskrll {
13062a6b7db3Sskrll  public:
13072a6b7db3Sskrll   Shdr_write(unsigned char* p)
13082a6b7db3Sskrll     : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
13092a6b7db3Sskrll   { }
13102a6b7db3Sskrll 
13112a6b7db3Sskrll   void
13122a6b7db3Sskrll   put_sh_name(Elf_Word v)
13132a6b7db3Sskrll   { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
13142a6b7db3Sskrll 
13152a6b7db3Sskrll   void
13162a6b7db3Sskrll   put_sh_type(Elf_Word v)
13172a6b7db3Sskrll   { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
13182a6b7db3Sskrll 
13192a6b7db3Sskrll   void
13202a6b7db3Sskrll   put_sh_flags(typename Elf_types<size>::Elf_WXword v)
13212a6b7db3Sskrll   { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
13222a6b7db3Sskrll 
13232a6b7db3Sskrll   void
13242a6b7db3Sskrll   put_sh_addr(typename Elf_types<size>::Elf_Addr v)
13252a6b7db3Sskrll   { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
13262a6b7db3Sskrll 
13272a6b7db3Sskrll   void
13282a6b7db3Sskrll   put_sh_offset(typename Elf_types<size>::Elf_Off v)
13292a6b7db3Sskrll   { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
13302a6b7db3Sskrll 
13312a6b7db3Sskrll   void
13322a6b7db3Sskrll   put_sh_size(typename Elf_types<size>::Elf_WXword v)
13332a6b7db3Sskrll   { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
13342a6b7db3Sskrll 
13352a6b7db3Sskrll   void
13362a6b7db3Sskrll   put_sh_link(Elf_Word v)
13372a6b7db3Sskrll   { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
13382a6b7db3Sskrll 
13392a6b7db3Sskrll   void
13402a6b7db3Sskrll   put_sh_info(Elf_Word v)
13412a6b7db3Sskrll   { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
13422a6b7db3Sskrll 
13432a6b7db3Sskrll   void
13442a6b7db3Sskrll   put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
13452a6b7db3Sskrll   { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
13462a6b7db3Sskrll 
13472a6b7db3Sskrll   void
13482a6b7db3Sskrll   put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
13492a6b7db3Sskrll   { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
13502a6b7db3Sskrll 
13512a6b7db3Sskrll  private:
13522a6b7db3Sskrll   internal::Shdr_data<size>* p_;
13532a6b7db3Sskrll };
13542a6b7db3Sskrll 
13559573673dSchristos // Accessor class for an ELF compression header.
13569573673dSchristos 
13579573673dSchristos template<int size, bool big_endian>
13589573673dSchristos class Chdr
13599573673dSchristos {
13609573673dSchristos  public:
13619573673dSchristos   Chdr(const unsigned char* p)
13629573673dSchristos     : p_(reinterpret_cast<const internal::Chdr_data<size>*>(p))
13639573673dSchristos   { }
13649573673dSchristos 
13659573673dSchristos   template<typename File>
13669573673dSchristos   Chdr(File* file, typename File::Location loc)
13679573673dSchristos     : p_(reinterpret_cast<const internal::Chdr_data<size>*>(
13689573673dSchristos 	   file->view(loc.file_offset, loc.data_size).data()))
13699573673dSchristos   { }
13709573673dSchristos 
13719573673dSchristos   Elf_Word
13729573673dSchristos   get_ch_type() const
13739573673dSchristos   { return Convert<size, big_endian>::convert_host(this->p_->ch_type); }
13749573673dSchristos 
13759573673dSchristos   typename Elf_types<size>::Elf_WXword
13769573673dSchristos   get_ch_size() const
13779573673dSchristos   { return Convert<size, big_endian>::convert_host(this->p_->ch_size); }
13789573673dSchristos 
13799573673dSchristos   typename Elf_types<size>::Elf_WXword
13809573673dSchristos   get_ch_addralign() const
13819573673dSchristos   { return
13829573673dSchristos       Convert<size, big_endian>::convert_host(this->p_->ch_addralign); }
13839573673dSchristos 
13849573673dSchristos  private:
13859573673dSchristos   const internal::Chdr_data<size>* p_;
13869573673dSchristos };
13879573673dSchristos 
13889573673dSchristos // Write class for an ELF compression header.
13899573673dSchristos 
13909573673dSchristos template<int size, bool big_endian>
13919573673dSchristos class Chdr_write
13929573673dSchristos {
13939573673dSchristos  public:
13949573673dSchristos   Chdr_write(unsigned char* p)
13959573673dSchristos     : p_(reinterpret_cast<internal::Chdr_data<size>*>(p))
13969573673dSchristos   { }
13979573673dSchristos 
13989573673dSchristos   void
13999573673dSchristos   put_ch_type(typename Elf_types<size>::Elf_WXword v)
14009573673dSchristos   { this->p_->ch_type = Convert<size, big_endian>::convert_host(v); }
14019573673dSchristos 
14029573673dSchristos   void
14039573673dSchristos   put_ch_size(typename Elf_types<size>::Elf_WXword v)
14049573673dSchristos   { this->p_->ch_size = Convert<size, big_endian>::convert_host(v); }
14059573673dSchristos 
14069573673dSchristos   void
14079573673dSchristos   put_ch_addralign(typename Elf_types<size>::Elf_WXword v)
14089573673dSchristos   { this->p_->ch_addralign = Convert<size, big_endian>::convert_host(v); }
14099573673dSchristos 
1410fc4f4269Schristos   void
1411fc4f4269Schristos   put_ch_reserved(Elf_Word);
1412fc4f4269Schristos 
14139573673dSchristos  private:
14149573673dSchristos   internal::Chdr_data<size>* p_;
14159573673dSchristos };
14169573673dSchristos 
1417fc4f4269Schristos template<>
1418fc4f4269Schristos inline void
1419fc4f4269Schristos elfcpp::Chdr_write<64, true>::put_ch_reserved(Elf_Word v)
1420fc4f4269Schristos {
1421fc4f4269Schristos   this->p_->ch_reserved = v;
1422fc4f4269Schristos }
1423fc4f4269Schristos 
1424fc4f4269Schristos template<>
1425fc4f4269Schristos inline void
1426fc4f4269Schristos elfcpp::Chdr_write<64, false>::put_ch_reserved(Elf_Word v)
1427fc4f4269Schristos {
1428fc4f4269Schristos   this->p_->ch_reserved = v;
1429fc4f4269Schristos }
1430fc4f4269Schristos 
14312a6b7db3Sskrll // Accessor class for an ELF segment header.
14322a6b7db3Sskrll 
14332a6b7db3Sskrll template<int size, bool big_endian>
14342a6b7db3Sskrll class Phdr
14352a6b7db3Sskrll {
14362a6b7db3Sskrll  public:
14372a6b7db3Sskrll   Phdr(const unsigned char* p)
14382a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
14392a6b7db3Sskrll   { }
14402a6b7db3Sskrll 
14412a6b7db3Sskrll   template<typename File>
14422a6b7db3Sskrll   Phdr(File* file, typename File::Location loc)
14432a6b7db3Sskrll     : p_(reinterpret_cast<internal::Phdr_data<size>*>(
14442a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
14452a6b7db3Sskrll   { }
14462a6b7db3Sskrll 
14472a6b7db3Sskrll   Elf_Word
14482a6b7db3Sskrll   get_p_type() const
14492a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
14502a6b7db3Sskrll 
14512a6b7db3Sskrll   typename Elf_types<size>::Elf_Off
14522a6b7db3Sskrll   get_p_offset() const
14532a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
14542a6b7db3Sskrll 
14552a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
14562a6b7db3Sskrll   get_p_vaddr() const
14572a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
14582a6b7db3Sskrll 
14592a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
14602a6b7db3Sskrll   get_p_paddr() const
14612a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
14622a6b7db3Sskrll 
14632a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
14642a6b7db3Sskrll   get_p_filesz() const
14652a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
14662a6b7db3Sskrll 
14672a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
14682a6b7db3Sskrll   get_p_memsz() const
14692a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
14702a6b7db3Sskrll 
14712a6b7db3Sskrll   Elf_Word
14722a6b7db3Sskrll   get_p_flags() const
14732a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
14742a6b7db3Sskrll 
14752a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
14762a6b7db3Sskrll   get_p_align() const
14772a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
14782a6b7db3Sskrll 
14792a6b7db3Sskrll  private:
14802a6b7db3Sskrll   const internal::Phdr_data<size>* p_;
14812a6b7db3Sskrll };
14822a6b7db3Sskrll 
14832a6b7db3Sskrll // Write class for an ELF segment header.
14842a6b7db3Sskrll 
14852a6b7db3Sskrll template<int size, bool big_endian>
14862a6b7db3Sskrll class Phdr_write
14872a6b7db3Sskrll {
14882a6b7db3Sskrll  public:
14892a6b7db3Sskrll   Phdr_write(unsigned char* p)
14902a6b7db3Sskrll     : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
14912a6b7db3Sskrll   { }
14922a6b7db3Sskrll 
14932a6b7db3Sskrll   void
14942a6b7db3Sskrll   put_p_type(Elf_Word v)
14952a6b7db3Sskrll   { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
14962a6b7db3Sskrll 
14972a6b7db3Sskrll   void
14982a6b7db3Sskrll   put_p_offset(typename Elf_types<size>::Elf_Off v)
14992a6b7db3Sskrll   { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
15002a6b7db3Sskrll 
15012a6b7db3Sskrll   void
15022a6b7db3Sskrll   put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
15032a6b7db3Sskrll   { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
15042a6b7db3Sskrll 
15052a6b7db3Sskrll   void
15062a6b7db3Sskrll   put_p_paddr(typename Elf_types<size>::Elf_Addr v)
15072a6b7db3Sskrll   { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
15082a6b7db3Sskrll 
15092a6b7db3Sskrll   void
15102a6b7db3Sskrll   put_p_filesz(typename Elf_types<size>::Elf_WXword v)
15112a6b7db3Sskrll   { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
15122a6b7db3Sskrll 
15132a6b7db3Sskrll   void
15142a6b7db3Sskrll   put_p_memsz(typename Elf_types<size>::Elf_WXword v)
15152a6b7db3Sskrll   { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
15162a6b7db3Sskrll 
15172a6b7db3Sskrll   void
15182a6b7db3Sskrll   put_p_flags(Elf_Word v)
15192a6b7db3Sskrll   { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
15202a6b7db3Sskrll 
15212a6b7db3Sskrll   void
15222a6b7db3Sskrll   put_p_align(typename Elf_types<size>::Elf_WXword v)
15232a6b7db3Sskrll   { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
15242a6b7db3Sskrll 
15252a6b7db3Sskrll  private:
15262a6b7db3Sskrll   internal::Phdr_data<size>* p_;
15272a6b7db3Sskrll };
15282a6b7db3Sskrll 
15292a6b7db3Sskrll // Accessor class for an ELF symbol table entry.
15302a6b7db3Sskrll 
15312a6b7db3Sskrll template<int size, bool big_endian>
15322a6b7db3Sskrll class Sym
15332a6b7db3Sskrll {
15342a6b7db3Sskrll  public:
15352a6b7db3Sskrll   Sym(const unsigned char* p)
15362a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
15372a6b7db3Sskrll   { }
15382a6b7db3Sskrll 
15392a6b7db3Sskrll   template<typename File>
15402a6b7db3Sskrll   Sym(File* file, typename File::Location loc)
15412a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Sym_data<size>*>(
15422a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
15432a6b7db3Sskrll   { }
15442a6b7db3Sskrll 
15452a6b7db3Sskrll   Elf_Word
15462a6b7db3Sskrll   get_st_name() const
15472a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
15482a6b7db3Sskrll 
15492a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
15502a6b7db3Sskrll   get_st_value() const
15512a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
15522a6b7db3Sskrll 
15532a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
15542a6b7db3Sskrll   get_st_size() const
15552a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
15562a6b7db3Sskrll 
15572a6b7db3Sskrll   unsigned char
15582a6b7db3Sskrll   get_st_info() const
15592a6b7db3Sskrll   { return this->p_->st_info; }
15602a6b7db3Sskrll 
15612a6b7db3Sskrll   STB
15622a6b7db3Sskrll   get_st_bind() const
15632a6b7db3Sskrll   { return elf_st_bind(this->get_st_info()); }
15642a6b7db3Sskrll 
15652a6b7db3Sskrll   STT
15662a6b7db3Sskrll   get_st_type() const
15672a6b7db3Sskrll   { return elf_st_type(this->get_st_info()); }
15682a6b7db3Sskrll 
15692a6b7db3Sskrll   unsigned char
15702a6b7db3Sskrll   get_st_other() const
15712a6b7db3Sskrll   { return this->p_->st_other; }
15722a6b7db3Sskrll 
15732a6b7db3Sskrll   STV
15742a6b7db3Sskrll   get_st_visibility() const
15752a6b7db3Sskrll   { return elf_st_visibility(this->get_st_other()); }
15762a6b7db3Sskrll 
15772a6b7db3Sskrll   unsigned char
15782a6b7db3Sskrll   get_st_nonvis() const
15792a6b7db3Sskrll   { return elf_st_nonvis(this->get_st_other()); }
15802a6b7db3Sskrll 
15812a6b7db3Sskrll   Elf_Half
15822a6b7db3Sskrll   get_st_shndx() const
15832a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
15842a6b7db3Sskrll 
15852a6b7db3Sskrll  private:
15862a6b7db3Sskrll   const internal::Sym_data<size>* p_;
15872a6b7db3Sskrll };
15882a6b7db3Sskrll 
15892a6b7db3Sskrll // Writer class for an ELF symbol table entry.
15902a6b7db3Sskrll 
15912a6b7db3Sskrll template<int size, bool big_endian>
15922a6b7db3Sskrll class Sym_write
15932a6b7db3Sskrll {
15942a6b7db3Sskrll  public:
15952a6b7db3Sskrll   Sym_write(unsigned char* p)
15962a6b7db3Sskrll     : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
15972a6b7db3Sskrll   { }
15982a6b7db3Sskrll 
15992a6b7db3Sskrll   void
16002a6b7db3Sskrll   put_st_name(Elf_Word v)
16012a6b7db3Sskrll   { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
16022a6b7db3Sskrll 
16032a6b7db3Sskrll   void
16042a6b7db3Sskrll   put_st_value(typename Elf_types<size>::Elf_Addr v)
16052a6b7db3Sskrll   { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
16062a6b7db3Sskrll 
16072a6b7db3Sskrll   void
16082a6b7db3Sskrll   put_st_size(typename Elf_types<size>::Elf_WXword v)
16092a6b7db3Sskrll   { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
16102a6b7db3Sskrll 
16112a6b7db3Sskrll   void
16122a6b7db3Sskrll   put_st_info(unsigned char v)
16132a6b7db3Sskrll   { this->p_->st_info = v; }
16142a6b7db3Sskrll 
16152a6b7db3Sskrll   void
16162a6b7db3Sskrll   put_st_info(STB bind, STT type)
16172a6b7db3Sskrll   { this->p_->st_info = elf_st_info(bind, type); }
16182a6b7db3Sskrll 
16192a6b7db3Sskrll   void
16202a6b7db3Sskrll   put_st_other(unsigned char v)
16212a6b7db3Sskrll   { this->p_->st_other = v; }
16222a6b7db3Sskrll 
16232a6b7db3Sskrll   void
16242a6b7db3Sskrll   put_st_other(STV vis, unsigned char nonvis)
16252a6b7db3Sskrll   { this->p_->st_other = elf_st_other(vis, nonvis); }
16262a6b7db3Sskrll 
16272a6b7db3Sskrll   void
16282a6b7db3Sskrll   put_st_shndx(Elf_Half v)
16292a6b7db3Sskrll   { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
16302a6b7db3Sskrll 
16312a6b7db3Sskrll   Sym<size, big_endian>
16322a6b7db3Sskrll   sym()
16332a6b7db3Sskrll   { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
16342a6b7db3Sskrll 
16352a6b7db3Sskrll  private:
16362a6b7db3Sskrll   internal::Sym_data<size>* p_;
16372a6b7db3Sskrll };
16382a6b7db3Sskrll 
16392a6b7db3Sskrll // Accessor classes for an ELF REL relocation entry.
16402a6b7db3Sskrll 
16412a6b7db3Sskrll template<int size, bool big_endian>
16422a6b7db3Sskrll class Rel
16432a6b7db3Sskrll {
16442a6b7db3Sskrll  public:
16452a6b7db3Sskrll   Rel(const unsigned char* p)
16462a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
16472a6b7db3Sskrll   { }
16482a6b7db3Sskrll 
16492a6b7db3Sskrll   template<typename File>
16502a6b7db3Sskrll   Rel(File* file, typename File::Location loc)
16512a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Rel_data<size>*>(
16522a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
16532a6b7db3Sskrll   { }
16542a6b7db3Sskrll 
16552a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
16562a6b7db3Sskrll   get_r_offset() const
16572a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
16582a6b7db3Sskrll 
16592a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
16602a6b7db3Sskrll   get_r_info() const
16612a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
16622a6b7db3Sskrll 
16632a6b7db3Sskrll  private:
16642a6b7db3Sskrll   const internal::Rel_data<size>* p_;
16652a6b7db3Sskrll };
16662a6b7db3Sskrll 
16672a6b7db3Sskrll // Writer class for an ELF Rel relocation.
16682a6b7db3Sskrll 
16692a6b7db3Sskrll template<int size, bool big_endian>
16702a6b7db3Sskrll class Rel_write
16712a6b7db3Sskrll {
16722a6b7db3Sskrll  public:
16732a6b7db3Sskrll   Rel_write(unsigned char* p)
16742a6b7db3Sskrll     : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
16752a6b7db3Sskrll   { }
16762a6b7db3Sskrll 
16772a6b7db3Sskrll   void
16782a6b7db3Sskrll   put_r_offset(typename Elf_types<size>::Elf_Addr v)
16792a6b7db3Sskrll   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
16802a6b7db3Sskrll 
16812a6b7db3Sskrll   void
16822a6b7db3Sskrll   put_r_info(typename Elf_types<size>::Elf_WXword v)
16832a6b7db3Sskrll   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
16842a6b7db3Sskrll 
16852a6b7db3Sskrll  private:
16862a6b7db3Sskrll   internal::Rel_data<size>* p_;
16872a6b7db3Sskrll };
16882a6b7db3Sskrll 
16892a6b7db3Sskrll // Accessor class for an ELF Rela relocation.
16902a6b7db3Sskrll 
16912a6b7db3Sskrll template<int size, bool big_endian>
16922a6b7db3Sskrll class Rela
16932a6b7db3Sskrll {
16942a6b7db3Sskrll  public:
16952a6b7db3Sskrll   Rela(const unsigned char* p)
16962a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
16972a6b7db3Sskrll   { }
16982a6b7db3Sskrll 
16992a6b7db3Sskrll   template<typename File>
17002a6b7db3Sskrll   Rela(File* file, typename File::Location loc)
17012a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Rela_data<size>*>(
17022a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
17032a6b7db3Sskrll   { }
17042a6b7db3Sskrll 
17052a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
17062a6b7db3Sskrll   get_r_offset() const
17072a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
17082a6b7db3Sskrll 
17092a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
17102a6b7db3Sskrll   get_r_info() const
17112a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
17122a6b7db3Sskrll 
17132a6b7db3Sskrll   typename Elf_types<size>::Elf_Swxword
17142a6b7db3Sskrll   get_r_addend() const
17152a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
17162a6b7db3Sskrll 
17172a6b7db3Sskrll  private:
17182a6b7db3Sskrll   const internal::Rela_data<size>* p_;
17192a6b7db3Sskrll };
17202a6b7db3Sskrll 
17212a6b7db3Sskrll // Writer class for an ELF Rela relocation.
17222a6b7db3Sskrll 
17232a6b7db3Sskrll template<int size, bool big_endian>
17242a6b7db3Sskrll class Rela_write
17252a6b7db3Sskrll {
17262a6b7db3Sskrll  public:
17272a6b7db3Sskrll   Rela_write(unsigned char* p)
17282a6b7db3Sskrll     : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
17292a6b7db3Sskrll   { }
17302a6b7db3Sskrll 
17312a6b7db3Sskrll   void
17322a6b7db3Sskrll   put_r_offset(typename Elf_types<size>::Elf_Addr v)
17332a6b7db3Sskrll   { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
17342a6b7db3Sskrll 
17352a6b7db3Sskrll   void
17362a6b7db3Sskrll   put_r_info(typename Elf_types<size>::Elf_WXword v)
17372a6b7db3Sskrll   { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
17382a6b7db3Sskrll 
17392a6b7db3Sskrll   void
17402a6b7db3Sskrll   put_r_addend(typename Elf_types<size>::Elf_Swxword v)
17412a6b7db3Sskrll   { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
17422a6b7db3Sskrll 
17432a6b7db3Sskrll  private:
17442a6b7db3Sskrll   internal::Rela_data<size>* p_;
17452a6b7db3Sskrll };
17462a6b7db3Sskrll 
17478cbf5cb7Schristos // MIPS-64 has a non-standard relocation layout.
17488cbf5cb7Schristos 
17498cbf5cb7Schristos template<bool big_endian>
17508cbf5cb7Schristos class Mips64_rel
17518cbf5cb7Schristos {
17528cbf5cb7Schristos  public:
17538cbf5cb7Schristos   Mips64_rel(const unsigned char* p)
17548cbf5cb7Schristos     : p_(reinterpret_cast<const internal::Mips64_rel_data*>(p))
17558cbf5cb7Schristos   { }
17568cbf5cb7Schristos 
17578cbf5cb7Schristos   template<typename File>
17588cbf5cb7Schristos   Mips64_rel(File* file, typename File::Location loc)
17598cbf5cb7Schristos     : p_(reinterpret_cast<const internal::Mips64_rel_data*>(
17608cbf5cb7Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
17618cbf5cb7Schristos   { }
17628cbf5cb7Schristos 
17638cbf5cb7Schristos   typename Elf_types<64>::Elf_Addr
17648cbf5cb7Schristos   get_r_offset() const
17658cbf5cb7Schristos   { return Convert<64, big_endian>::convert_host(this->p_->r_offset); }
17668cbf5cb7Schristos 
17678cbf5cb7Schristos   Elf_Word
17688cbf5cb7Schristos   get_r_sym() const
17698cbf5cb7Schristos   { return Convert<32, big_endian>::convert_host(this->p_->r_sym); }
17708cbf5cb7Schristos 
17718cbf5cb7Schristos   unsigned char
17728cbf5cb7Schristos   get_r_ssym() const
17738cbf5cb7Schristos   { return this->p_->r_ssym; }
17748cbf5cb7Schristos 
17758cbf5cb7Schristos   unsigned char
17768cbf5cb7Schristos   get_r_type() const
17778cbf5cb7Schristos   { return this->p_->r_type; }
17788cbf5cb7Schristos 
17798cbf5cb7Schristos   unsigned char
17808cbf5cb7Schristos   get_r_type2() const
17818cbf5cb7Schristos   { return this->p_->r_type2; }
17828cbf5cb7Schristos 
17838cbf5cb7Schristos   unsigned char
17848cbf5cb7Schristos   get_r_type3() const
17858cbf5cb7Schristos   { return this->p_->r_type3; }
17868cbf5cb7Schristos 
17878cbf5cb7Schristos  private:
17888cbf5cb7Schristos   const internal::Mips64_rel_data* p_;
17898cbf5cb7Schristos };
17908cbf5cb7Schristos 
17918cbf5cb7Schristos template<bool big_endian>
17928cbf5cb7Schristos class Mips64_rel_write
17938cbf5cb7Schristos {
17948cbf5cb7Schristos  public:
17958cbf5cb7Schristos   Mips64_rel_write(unsigned char* p)
17968cbf5cb7Schristos     : p_(reinterpret_cast<internal::Mips64_rel_data*>(p))
17978cbf5cb7Schristos   { }
17988cbf5cb7Schristos 
17998cbf5cb7Schristos   void
18008cbf5cb7Schristos   put_r_offset(typename Elf_types<64>::Elf_Addr v)
18018cbf5cb7Schristos   { this->p_->r_offset = Convert<64, big_endian>::convert_host(v); }
18028cbf5cb7Schristos 
18038cbf5cb7Schristos   void
18048cbf5cb7Schristos   put_r_sym(Elf_Word v)
18058cbf5cb7Schristos   { this->p_->r_sym = Convert<32, big_endian>::convert_host(v); }
18068cbf5cb7Schristos 
18078cbf5cb7Schristos   void
18088cbf5cb7Schristos   put_r_ssym(unsigned char v)
18098cbf5cb7Schristos   { this->p_->r_ssym = v; }
18108cbf5cb7Schristos 
18118cbf5cb7Schristos   void
18128cbf5cb7Schristos   put_r_type(unsigned char v)
18138cbf5cb7Schristos   { this->p_->r_type = v; }
18148cbf5cb7Schristos 
18158cbf5cb7Schristos   void
18168cbf5cb7Schristos   put_r_type2(unsigned char v)
18178cbf5cb7Schristos   { this->p_->r_type2 = v; }
18188cbf5cb7Schristos 
18198cbf5cb7Schristos   void
18208cbf5cb7Schristos   put_r_type3(unsigned char v)
18218cbf5cb7Schristos   { this->p_->r_type3 = v; }
18228cbf5cb7Schristos 
18238cbf5cb7Schristos  private:
18248cbf5cb7Schristos   internal::Mips64_rel_data* p_;
18258cbf5cb7Schristos };
18268cbf5cb7Schristos 
18278cbf5cb7Schristos template<bool big_endian>
18288cbf5cb7Schristos class Mips64_rela
18298cbf5cb7Schristos {
18308cbf5cb7Schristos  public:
18318cbf5cb7Schristos   Mips64_rela(const unsigned char* p)
18328cbf5cb7Schristos     : p_(reinterpret_cast<const internal::Mips64_rela_data*>(p))
18338cbf5cb7Schristos   { }
18348cbf5cb7Schristos 
18358cbf5cb7Schristos   template<typename File>
18368cbf5cb7Schristos   Mips64_rela(File* file, typename File::Location loc)
18378cbf5cb7Schristos     : p_(reinterpret_cast<const internal::Mips64_rela_data*>(
18388cbf5cb7Schristos 	   file->view(loc.file_offset, loc.data_size).data()))
18398cbf5cb7Schristos   { }
18408cbf5cb7Schristos 
18418cbf5cb7Schristos   typename Elf_types<64>::Elf_Addr
18428cbf5cb7Schristos   get_r_offset() const
18438cbf5cb7Schristos   { return Convert<64, big_endian>::convert_host(this->p_->r_offset); }
18448cbf5cb7Schristos 
18458cbf5cb7Schristos   Elf_Word
18468cbf5cb7Schristos   get_r_sym() const
18478cbf5cb7Schristos   { return Convert<32, big_endian>::convert_host(this->p_->r_sym); }
18488cbf5cb7Schristos 
18498cbf5cb7Schristos   unsigned char
18508cbf5cb7Schristos   get_r_ssym() const
18518cbf5cb7Schristos   { return this->p_->r_ssym; }
18528cbf5cb7Schristos 
18538cbf5cb7Schristos   unsigned char
18548cbf5cb7Schristos   get_r_type() const
18558cbf5cb7Schristos   { return this->p_->r_type; }
18568cbf5cb7Schristos 
18578cbf5cb7Schristos   unsigned char
18588cbf5cb7Schristos   get_r_type2() const
18598cbf5cb7Schristos   { return this->p_->r_type2; }
18608cbf5cb7Schristos 
18618cbf5cb7Schristos   unsigned char
18628cbf5cb7Schristos   get_r_type3() const
18638cbf5cb7Schristos   { return this->p_->r_type3; }
18648cbf5cb7Schristos 
18658cbf5cb7Schristos   typename Elf_types<64>::Elf_Swxword
18668cbf5cb7Schristos   get_r_addend() const
18678cbf5cb7Schristos   { return Convert<64, big_endian>::convert_host(this->p_->r_addend); }
18688cbf5cb7Schristos 
18698cbf5cb7Schristos  private:
18708cbf5cb7Schristos   const internal::Mips64_rela_data* p_;
18718cbf5cb7Schristos };
18728cbf5cb7Schristos 
18738cbf5cb7Schristos template<bool big_endian>
18748cbf5cb7Schristos class Mips64_rela_write
18758cbf5cb7Schristos {
18768cbf5cb7Schristos  public:
18778cbf5cb7Schristos   Mips64_rela_write(unsigned char* p)
18788cbf5cb7Schristos     : p_(reinterpret_cast<internal::Mips64_rela_data*>(p))
18798cbf5cb7Schristos   { }
18808cbf5cb7Schristos 
18818cbf5cb7Schristos   void
18828cbf5cb7Schristos   put_r_offset(typename Elf_types<64>::Elf_Addr v)
18838cbf5cb7Schristos   { this->p_->r_offset = Convert<64, big_endian>::convert_host(v); }
18848cbf5cb7Schristos 
18858cbf5cb7Schristos   void
18868cbf5cb7Schristos   put_r_sym(Elf_Word v)
18878cbf5cb7Schristos   { this->p_->r_sym = Convert<32, big_endian>::convert_host(v); }
18888cbf5cb7Schristos 
18898cbf5cb7Schristos   void
18908cbf5cb7Schristos   put_r_ssym(unsigned char v)
18918cbf5cb7Schristos   { this->p_->r_ssym = v; }
18928cbf5cb7Schristos 
18938cbf5cb7Schristos   void
18948cbf5cb7Schristos   put_r_type(unsigned char v)
18958cbf5cb7Schristos   { this->p_->r_type = v; }
18968cbf5cb7Schristos 
18978cbf5cb7Schristos   void
18988cbf5cb7Schristos   put_r_type2(unsigned char v)
18998cbf5cb7Schristos   { this->p_->r_type2 = v; }
19008cbf5cb7Schristos 
19018cbf5cb7Schristos   void
19028cbf5cb7Schristos   put_r_type3(unsigned char v)
19038cbf5cb7Schristos   { this->p_->r_type3 = v; }
19048cbf5cb7Schristos 
19058cbf5cb7Schristos   void
19068cbf5cb7Schristos   put_r_addend(typename Elf_types<64>::Elf_Swxword v)
19078cbf5cb7Schristos   { this->p_->r_addend = Convert<64, big_endian>::convert_host(v); }
19088cbf5cb7Schristos 
19098cbf5cb7Schristos  private:
19108cbf5cb7Schristos   internal::Mips64_rela_data* p_;
19118cbf5cb7Schristos };
19128cbf5cb7Schristos 
19132a6b7db3Sskrll // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
19142a6b7db3Sskrll // PT_DYNAMIC segment.
19152a6b7db3Sskrll 
19162a6b7db3Sskrll template<int size, bool big_endian>
19172a6b7db3Sskrll class Dyn
19182a6b7db3Sskrll {
19192a6b7db3Sskrll  public:
19202a6b7db3Sskrll   Dyn(const unsigned char* p)
19212a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
19222a6b7db3Sskrll   { }
19232a6b7db3Sskrll 
19242a6b7db3Sskrll   template<typename File>
19252a6b7db3Sskrll   Dyn(File* file, typename File::Location loc)
19262a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
19272a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
19282a6b7db3Sskrll   { }
19292a6b7db3Sskrll 
19302a6b7db3Sskrll   typename Elf_types<size>::Elf_Swxword
19312a6b7db3Sskrll   get_d_tag() const
19322a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
19332a6b7db3Sskrll 
19342a6b7db3Sskrll   typename Elf_types<size>::Elf_WXword
19352a6b7db3Sskrll   get_d_val() const
19362a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
19372a6b7db3Sskrll 
19382a6b7db3Sskrll   typename Elf_types<size>::Elf_Addr
19392a6b7db3Sskrll   get_d_ptr() const
19402a6b7db3Sskrll   { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
19412a6b7db3Sskrll 
19422a6b7db3Sskrll  private:
19432a6b7db3Sskrll   const internal::Dyn_data<size>* p_;
19442a6b7db3Sskrll };
19452a6b7db3Sskrll 
19462a6b7db3Sskrll // Write class for an entry in the SHT_DYNAMIC section.
19472a6b7db3Sskrll 
19482a6b7db3Sskrll template<int size, bool big_endian>
19492a6b7db3Sskrll class Dyn_write
19502a6b7db3Sskrll {
19512a6b7db3Sskrll  public:
19522a6b7db3Sskrll   Dyn_write(unsigned char* p)
19532a6b7db3Sskrll     : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
19542a6b7db3Sskrll   { }
19552a6b7db3Sskrll 
19562a6b7db3Sskrll   void
19572a6b7db3Sskrll   put_d_tag(typename Elf_types<size>::Elf_Swxword v)
19582a6b7db3Sskrll   { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
19592a6b7db3Sskrll 
19602a6b7db3Sskrll   void
19612a6b7db3Sskrll   put_d_val(typename Elf_types<size>::Elf_WXword v)
19622a6b7db3Sskrll   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
19632a6b7db3Sskrll 
19642a6b7db3Sskrll   void
19652a6b7db3Sskrll   put_d_ptr(typename Elf_types<size>::Elf_Addr v)
19662a6b7db3Sskrll   { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
19672a6b7db3Sskrll 
19682a6b7db3Sskrll  private:
19692a6b7db3Sskrll   internal::Dyn_data<size>* p_;
19702a6b7db3Sskrll };
19712a6b7db3Sskrll 
19722a6b7db3Sskrll // Accessor classes for entries in the ELF SHT_GNU_verdef section.
19732a6b7db3Sskrll 
19742a6b7db3Sskrll template<int size, bool big_endian>
19752a6b7db3Sskrll class Verdef
19762a6b7db3Sskrll {
19772a6b7db3Sskrll  public:
19782a6b7db3Sskrll   Verdef(const unsigned char* p)
19792a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Verdef_data*>(p))
19802a6b7db3Sskrll   { }
19812a6b7db3Sskrll 
19822a6b7db3Sskrll   template<typename File>
19832a6b7db3Sskrll   Verdef(File* file, typename File::Location loc)
19842a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Verdef_data*>(
19852a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
19862a6b7db3Sskrll   { }
19872a6b7db3Sskrll 
19882a6b7db3Sskrll   Elf_Half
19892a6b7db3Sskrll   get_vd_version() const
19902a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
19912a6b7db3Sskrll 
19922a6b7db3Sskrll   Elf_Half
19932a6b7db3Sskrll   get_vd_flags() const
19942a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
19952a6b7db3Sskrll 
19962a6b7db3Sskrll   Elf_Half
19972a6b7db3Sskrll   get_vd_ndx() const
19982a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
19992a6b7db3Sskrll 
20002a6b7db3Sskrll   Elf_Half
20012a6b7db3Sskrll   get_vd_cnt() const
20022a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
20032a6b7db3Sskrll 
20042a6b7db3Sskrll   Elf_Word
20052a6b7db3Sskrll   get_vd_hash() const
20062a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
20072a6b7db3Sskrll 
20082a6b7db3Sskrll   Elf_Word
20092a6b7db3Sskrll   get_vd_aux() const
20102a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
20112a6b7db3Sskrll 
20122a6b7db3Sskrll   Elf_Word
20132a6b7db3Sskrll   get_vd_next() const
20142a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
20152a6b7db3Sskrll 
20162a6b7db3Sskrll  private:
20172a6b7db3Sskrll   const internal::Verdef_data* p_;
20182a6b7db3Sskrll };
20192a6b7db3Sskrll 
20202a6b7db3Sskrll template<int size, bool big_endian>
20212a6b7db3Sskrll class Verdef_write
20222a6b7db3Sskrll {
20232a6b7db3Sskrll  public:
20242a6b7db3Sskrll   Verdef_write(unsigned char* p)
20252a6b7db3Sskrll     : p_(reinterpret_cast<internal::Verdef_data*>(p))
20262a6b7db3Sskrll   { }
20272a6b7db3Sskrll 
20282a6b7db3Sskrll   void
20292a6b7db3Sskrll   set_vd_version(Elf_Half v)
20302a6b7db3Sskrll   { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
20312a6b7db3Sskrll 
20322a6b7db3Sskrll   void
20332a6b7db3Sskrll   set_vd_flags(Elf_Half v)
20342a6b7db3Sskrll   { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
20352a6b7db3Sskrll 
20362a6b7db3Sskrll   void
20372a6b7db3Sskrll   set_vd_ndx(Elf_Half v)
20382a6b7db3Sskrll   { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
20392a6b7db3Sskrll 
20402a6b7db3Sskrll   void
20412a6b7db3Sskrll   set_vd_cnt(Elf_Half v)
20422a6b7db3Sskrll   { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
20432a6b7db3Sskrll 
20442a6b7db3Sskrll   void
20452a6b7db3Sskrll   set_vd_hash(Elf_Word v)
20462a6b7db3Sskrll   { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
20472a6b7db3Sskrll 
20482a6b7db3Sskrll   void
20492a6b7db3Sskrll   set_vd_aux(Elf_Word v)
20502a6b7db3Sskrll   { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
20512a6b7db3Sskrll 
20522a6b7db3Sskrll   void
20532a6b7db3Sskrll   set_vd_next(Elf_Word v)
20542a6b7db3Sskrll   { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
20552a6b7db3Sskrll 
20562a6b7db3Sskrll  private:
20572a6b7db3Sskrll   internal::Verdef_data* p_;
20582a6b7db3Sskrll };
20592a6b7db3Sskrll 
20602a6b7db3Sskrll // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
20612a6b7db3Sskrll // section.
20622a6b7db3Sskrll 
20632a6b7db3Sskrll template<int size, bool big_endian>
20642a6b7db3Sskrll class Verdaux
20652a6b7db3Sskrll {
20662a6b7db3Sskrll  public:
20672a6b7db3Sskrll   Verdaux(const unsigned char* p)
20682a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
20692a6b7db3Sskrll   { }
20702a6b7db3Sskrll 
20712a6b7db3Sskrll   template<typename File>
20722a6b7db3Sskrll   Verdaux(File* file, typename File::Location loc)
20732a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Verdaux_data*>(
20742a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
20752a6b7db3Sskrll   { }
20762a6b7db3Sskrll 
20772a6b7db3Sskrll   Elf_Word
20782a6b7db3Sskrll   get_vda_name() const
20792a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
20802a6b7db3Sskrll 
20812a6b7db3Sskrll   Elf_Word
20822a6b7db3Sskrll   get_vda_next() const
20832a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
20842a6b7db3Sskrll 
20852a6b7db3Sskrll  private:
20862a6b7db3Sskrll   const internal::Verdaux_data* p_;
20872a6b7db3Sskrll };
20882a6b7db3Sskrll 
20892a6b7db3Sskrll template<int size, bool big_endian>
20902a6b7db3Sskrll class Verdaux_write
20912a6b7db3Sskrll {
20922a6b7db3Sskrll  public:
20932a6b7db3Sskrll   Verdaux_write(unsigned char* p)
20942a6b7db3Sskrll     : p_(reinterpret_cast<internal::Verdaux_data*>(p))
20952a6b7db3Sskrll   { }
20962a6b7db3Sskrll 
20972a6b7db3Sskrll   void
20982a6b7db3Sskrll   set_vda_name(Elf_Word v)
20992a6b7db3Sskrll   { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
21002a6b7db3Sskrll 
21012a6b7db3Sskrll   void
21022a6b7db3Sskrll   set_vda_next(Elf_Word v)
21032a6b7db3Sskrll   { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
21042a6b7db3Sskrll 
21052a6b7db3Sskrll  private:
21062a6b7db3Sskrll   internal::Verdaux_data* p_;
21072a6b7db3Sskrll };
21082a6b7db3Sskrll 
21092a6b7db3Sskrll // Accessor classes for entries in the ELF SHT_GNU_verneed section.
21102a6b7db3Sskrll 
21112a6b7db3Sskrll template<int size, bool big_endian>
21122a6b7db3Sskrll class Verneed
21132a6b7db3Sskrll {
21142a6b7db3Sskrll  public:
21152a6b7db3Sskrll   Verneed(const unsigned char* p)
21162a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Verneed_data*>(p))
21172a6b7db3Sskrll   { }
21182a6b7db3Sskrll 
21192a6b7db3Sskrll   template<typename File>
21202a6b7db3Sskrll   Verneed(File* file, typename File::Location loc)
21212a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Verneed_data*>(
21222a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
21232a6b7db3Sskrll   { }
21242a6b7db3Sskrll 
21252a6b7db3Sskrll   Elf_Half
21262a6b7db3Sskrll   get_vn_version() const
21272a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
21282a6b7db3Sskrll 
21292a6b7db3Sskrll   Elf_Half
21302a6b7db3Sskrll   get_vn_cnt() const
21312a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
21322a6b7db3Sskrll 
21332a6b7db3Sskrll   Elf_Word
21342a6b7db3Sskrll   get_vn_file() const
21352a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
21362a6b7db3Sskrll 
21372a6b7db3Sskrll   Elf_Word
21382a6b7db3Sskrll   get_vn_aux() const
21392a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
21402a6b7db3Sskrll 
21412a6b7db3Sskrll   Elf_Word
21422a6b7db3Sskrll   get_vn_next() const
21432a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
21442a6b7db3Sskrll 
21452a6b7db3Sskrll  private:
21462a6b7db3Sskrll   const internal::Verneed_data* p_;
21472a6b7db3Sskrll };
21482a6b7db3Sskrll 
21492a6b7db3Sskrll template<int size, bool big_endian>
21502a6b7db3Sskrll class Verneed_write
21512a6b7db3Sskrll {
21522a6b7db3Sskrll  public:
21532a6b7db3Sskrll   Verneed_write(unsigned char* p)
21542a6b7db3Sskrll     : p_(reinterpret_cast<internal::Verneed_data*>(p))
21552a6b7db3Sskrll   { }
21562a6b7db3Sskrll 
21572a6b7db3Sskrll   void
21582a6b7db3Sskrll   set_vn_version(Elf_Half v)
21592a6b7db3Sskrll   { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
21602a6b7db3Sskrll 
21612a6b7db3Sskrll   void
21622a6b7db3Sskrll   set_vn_cnt(Elf_Half v)
21632a6b7db3Sskrll   { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
21642a6b7db3Sskrll 
21652a6b7db3Sskrll   void
21662a6b7db3Sskrll   set_vn_file(Elf_Word v)
21672a6b7db3Sskrll   { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
21682a6b7db3Sskrll 
21692a6b7db3Sskrll   void
21702a6b7db3Sskrll   set_vn_aux(Elf_Word v)
21712a6b7db3Sskrll   { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
21722a6b7db3Sskrll 
21732a6b7db3Sskrll   void
21742a6b7db3Sskrll   set_vn_next(Elf_Word v)
21752a6b7db3Sskrll   { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
21762a6b7db3Sskrll 
21772a6b7db3Sskrll  private:
21782a6b7db3Sskrll   internal::Verneed_data* p_;
21792a6b7db3Sskrll };
21802a6b7db3Sskrll 
21812a6b7db3Sskrll // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
21822a6b7db3Sskrll // section.
21832a6b7db3Sskrll 
21842a6b7db3Sskrll template<int size, bool big_endian>
21852a6b7db3Sskrll class Vernaux
21862a6b7db3Sskrll {
21872a6b7db3Sskrll  public:
21882a6b7db3Sskrll   Vernaux(const unsigned char* p)
21892a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
21902a6b7db3Sskrll   { }
21912a6b7db3Sskrll 
21922a6b7db3Sskrll   template<typename File>
21932a6b7db3Sskrll   Vernaux(File* file, typename File::Location loc)
21942a6b7db3Sskrll     : p_(reinterpret_cast<const internal::Vernaux_data*>(
21952a6b7db3Sskrll 	   file->view(loc.file_offset, loc.data_size).data()))
21962a6b7db3Sskrll   { }
21972a6b7db3Sskrll 
21982a6b7db3Sskrll   Elf_Word
21992a6b7db3Sskrll   get_vna_hash() const
22002a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
22012a6b7db3Sskrll 
22022a6b7db3Sskrll   Elf_Half
22032a6b7db3Sskrll   get_vna_flags() const
22042a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
22052a6b7db3Sskrll 
22062a6b7db3Sskrll   Elf_Half
22072a6b7db3Sskrll   get_vna_other() const
22082a6b7db3Sskrll   { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
22092a6b7db3Sskrll 
22102a6b7db3Sskrll   Elf_Word
22112a6b7db3Sskrll   get_vna_name() const
22122a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
22132a6b7db3Sskrll 
22142a6b7db3Sskrll   Elf_Word
22152a6b7db3Sskrll   get_vna_next() const
22162a6b7db3Sskrll   { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
22172a6b7db3Sskrll 
22182a6b7db3Sskrll  private:
22192a6b7db3Sskrll   const internal::Vernaux_data* p_;
22202a6b7db3Sskrll };
22212a6b7db3Sskrll 
22222a6b7db3Sskrll template<int size, bool big_endian>
22232a6b7db3Sskrll class Vernaux_write
22242a6b7db3Sskrll {
22252a6b7db3Sskrll  public:
22262a6b7db3Sskrll   Vernaux_write(unsigned char* p)
22272a6b7db3Sskrll     : p_(reinterpret_cast<internal::Vernaux_data*>(p))
22282a6b7db3Sskrll   { }
22292a6b7db3Sskrll 
22302a6b7db3Sskrll   void
22312a6b7db3Sskrll   set_vna_hash(Elf_Word v)
22322a6b7db3Sskrll   { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
22332a6b7db3Sskrll 
22342a6b7db3Sskrll   void
22352a6b7db3Sskrll   set_vna_flags(Elf_Half v)
22362a6b7db3Sskrll   { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
22372a6b7db3Sskrll 
22382a6b7db3Sskrll   void
22392a6b7db3Sskrll   set_vna_other(Elf_Half v)
22402a6b7db3Sskrll   { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
22412a6b7db3Sskrll 
22422a6b7db3Sskrll   void
22432a6b7db3Sskrll   set_vna_name(Elf_Word v)
22442a6b7db3Sskrll   { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
22452a6b7db3Sskrll 
22462a6b7db3Sskrll   void
22472a6b7db3Sskrll   set_vna_next(Elf_Word v)
22482a6b7db3Sskrll   { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
22492a6b7db3Sskrll 
22502a6b7db3Sskrll  private:
22512a6b7db3Sskrll   internal::Vernaux_data* p_;
22522a6b7db3Sskrll };
22532a6b7db3Sskrll 
22542a6b7db3Sskrll } // End namespace elfcpp.
22552a6b7db3Sskrll 
22562a6b7db3Sskrll #endif // !defined(ELFPCP_H)
2257