include/elf
[deliverable/binutils-gdb.git] / elfcpp / elfcpp.h
index 3ae005ddc047ffa54d16a72f125d72952f326c4b..7abc9e3ac0a7603fc82ef9600edf4bb24eb41ce9 100644 (file)
@@ -1,11 +1,40 @@
 // elfcpp.h -- main header file for elfcpp    -*- C++ -*-
 
+// Copyright 2006, 2007, 2008, Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of elfcpp.
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public License
+// as published by the Free Software Foundation; either version 2, or
+// (at your option) any later version.
+
+// In addition to the permissions in the GNU Library General Public
+// License, the Free Software Foundation gives you unlimited
+// permission to link the compiled version of this file into
+// combinations with other programs, and to distribute those
+// combinations without any restriction coming from the use of this
+// file.  (The Library Public License restrictions do apply in other
+// respects; for example, they cover modification of the file, and
+/// distribution when not linked into a combined executable.)
+
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+
+// You should have received a copy of the GNU Library General Public
+// License along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+// 02110-1301, USA.
+
 // This is the external interface for elfcpp.
 
 #ifndef ELFCPP_H
 #define ELFCPP_H
 
-#include "elfcpp_config.h"
+#include "elfcpp_swap.h"
 
 #include <stdint.h>
 
@@ -286,7 +315,12 @@ enum
   SHN_ABS = 0xfff1,
   SHN_COMMON = 0xfff2,
   SHN_XINDEX = 0xffff,
-  SHN_HIRESERVE = 0xffff
+  SHN_HIRESERVE = 0xffff,
+
+  // Provide for initial and final section ordering in conjunction
+  // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
+  SHN_BEFORE = 0xff00,
+  SHN_AFTER = 0xff01,
 };
 
 // The valid values found in the Shdr sh_type field.
@@ -317,6 +351,12 @@ enum SHT
   SHT_LOUSER = 0x80000000,
   SHT_HIUSER = 0xffffffff,
   // The remaining values are not in the standard.
+  // Incremental build data.
+  SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700,
+  // Object attributes.
+  SHT_GNU_ATTRIBUTES = 0x6ffffff5,
+  // GNU style dynamic hash table.
+  SHT_GNU_HASH = 0x6ffffff6,
   // List of prelink dependencies.
   SHT_GNU_LIBLIST = 0x6ffffff7,
   // Versions defined by file.
@@ -328,6 +368,12 @@ enum SHT
   // Symbol versions,
   SHT_SUNW_versym = 0x6fffffff,
   SHT_GNU_versym = 0x6fffffff,
+
+  SHT_SPARC_GOTDATA = 0x70000000,
+
+  // Link editor is to sort the entries in this section based on the
+  // address specified in the associated symbol table entry.
+  SHT_ORDERED = 0x7fffffff,
 };
 
 // The valid bit flags found in the Shdr sh_flags field.
@@ -345,7 +391,19 @@ enum SHF
   SHF_GROUP = 0x200,
   SHF_TLS = 0x400,
   SHF_MASKOS = 0x0ff00000,
-  SHF_MASKPROC = 0xf0000000
+  SHF_MASKPROC = 0xf0000000,
+
+  // Indicates this section requires ordering in relation to
+  // other sections of the same type.  Ordered sections are
+  // combined within the section pointed to by the sh_link entry.
+  // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
+  // sorted section is to precede or follow, respectively, all
+  // other sections in the set being ordered.
+  SHF_ORDERED = 0x40000000,
+  // This section is excluded from input to the link-edit of an
+  // executable or shared object.  This flag is ignored if SHF_ALLOC
+  // is also set, or if relocations exist against the section.
+  SHF_EXCLUDE = 0x80000000,
 };
 
 // Bit flags which appear in the first 32-bit word of the section data
@@ -420,9 +478,14 @@ enum STT
   STT_COMMON = 5,
   STT_TLS = 6,
   STT_LOOS = 10,
+  STT_GNU_IFUNC = 10,
   STT_HIOS = 12,
   STT_LOPROC = 13,
-  STT_HIPROC = 15
+  STT_HIPROC = 15,
+
+  // The section type that must be used for register symbols on
+  // Sparc.  These symbols initialize a global register.
+  STT_SPARC_REGISTER = 13,
 };
 
 inline STB
@@ -529,6 +592,221 @@ elf_r_info<64>(unsigned int s, unsigned int t)
   return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
 }
 
+// Dynamic tags found in the PT_DYNAMIC segment.
+
+enum DT
+{
+  DT_NULL = 0,
+  DT_NEEDED = 1,
+  DT_PLTRELSZ = 2,
+  DT_PLTGOT = 3,
+  DT_HASH = 4,
+  DT_STRTAB = 5,
+  DT_SYMTAB = 6,
+  DT_RELA = 7,
+  DT_RELASZ = 8,
+  DT_RELAENT = 9,
+  DT_STRSZ = 10,
+  DT_SYMENT = 11,
+  DT_INIT = 12,
+  DT_FINI = 13,
+  DT_SONAME = 14,
+  DT_RPATH = 15,
+  DT_SYMBOLIC = 16,
+  DT_REL = 17,
+  DT_RELSZ = 18,
+  DT_RELENT = 19,
+  DT_PLTREL = 20,
+  DT_DEBUG = 21,
+  DT_TEXTREL = 22,
+  DT_JMPREL = 23,
+  DT_BIND_NOW = 24,
+  DT_INIT_ARRAY = 25,
+  DT_FINI_ARRAY = 26,
+  DT_INIT_ARRAYSZ = 27,
+  DT_FINI_ARRAYSZ = 28,
+  DT_RUNPATH = 29,
+  DT_FLAGS = 30,
+  DT_ENCODING = 32,
+  DT_PREINIT_ARRAY = 33,
+  DT_PREINIT_ARRAYSZ = 33,
+  DT_LOOS = 0x6000000d,
+  DT_HIOS = 0x6ffff000,
+  DT_LOPROC = 0x70000000,
+  DT_HIPROC = 0x7fffffff,
+
+  // The remaining values are extensions used by GNU or Solaris.
+  DT_VALRNGLO = 0x6ffffd00,
+  DT_GNU_PRELINKED = 0x6ffffdf5,
+  DT_GNU_CONFLICTSZ = 0x6ffffdf6,
+  DT_GNU_LIBLISTSZ = 0x6ffffdf7,
+  DT_CHECKSUM = 0x6ffffdf8,
+  DT_PLTPADSZ = 0x6ffffdf9,
+  DT_MOVEENT = 0x6ffffdfa,
+  DT_MOVESZ = 0x6ffffdfb,
+  DT_FEATURE = 0x6ffffdfc,
+  DT_POSFLAG_1 = 0x6ffffdfd,
+  DT_SYMINSZ = 0x6ffffdfe,
+  DT_SYMINENT = 0x6ffffdff,
+  DT_VALRNGHI = 0x6ffffdff,
+
+  DT_ADDRRNGLO = 0x6ffffe00,
+  DT_GNU_HASH = 0x6ffffef5,
+  DT_TLSDESC_PLT = 0x6ffffef6,
+  DT_TLSDESC_GOT = 0x6ffffef7,
+  DT_GNU_CONFLICT = 0x6ffffef8,
+  DT_GNU_LIBLIST = 0x6ffffef9,
+  DT_CONFIG = 0x6ffffefa,
+  DT_DEPAUDIT = 0x6ffffefb,
+  DT_AUDIT = 0x6ffffefc,
+  DT_PLTPAD = 0x6ffffefd,
+  DT_MOVETAB = 0x6ffffefe,
+  DT_SYMINFO = 0x6ffffeff,
+  DT_ADDRRNGHI = 0x6ffffeff,
+
+  DT_RELACOUNT = 0x6ffffff9,
+  DT_RELCOUNT = 0x6ffffffa,
+  DT_FLAGS_1 = 0x6ffffffb,
+  DT_VERDEF = 0x6ffffffc,
+  DT_VERDEFNUM = 0x6ffffffd,
+  DT_VERNEED = 0x6ffffffe,
+  DT_VERNEEDNUM = 0x6fffffff,
+
+  DT_VERSYM = 0x6ffffff0,
+
+  // Specify the value of _GLOBAL_OFFSET_TABLE_.
+  DT_PPC_GOT = 0x70000000,
+
+  // Specify the start of the .glink section.
+  DT_PPC64_GLINK = 0x70000000,
+
+  // Specify the start and size of the .opd section.
+  DT_PPC64_OPD = 0x70000001,
+  DT_PPC64_OPDSZ = 0x70000002,
+
+  // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
+  // symbol table.  One dynamic entry exists for every STT_SPARC_REGISTER
+  // symbol in the symbol table.
+  DT_SPARC_REGISTER = 0x70000001,
+
+  DT_AUXILIARY = 0x7ffffffd,
+  DT_USED = 0x7ffffffe,
+  DT_FILTER = 0x7fffffff
+};
+
+// Flags found in the DT_FLAGS dynamic element.
+
+enum DF
+{
+  DF_ORIGIN = 0x1,
+  DF_SYMBOLIC = 0x2,
+  DF_TEXTREL = 0x4,
+  DF_BIND_NOW = 0x8,
+  DF_STATIC_TLS = 0x10
+};
+
+// Flags found in the DT_FLAGS_1 dynamic element.
+
+enum DF_1
+{
+  DF_1_NOW = 0x1,
+  DF_1_GLOBAL = 0x2,
+  DF_1_GROUP = 0x4,
+  DF_1_NODELETE = 0x8,
+  DF_1_LOADFLTR = 0x10,
+  DF_1_INITFIRST = 0x20,
+  DF_1_NOOPEN = 0x40,
+  DF_1_ORIGIN = 0x80,
+  DF_1_DIRECT = 0x100,
+  DF_1_TRANS = 0x200,
+  DF_1_INTERPOSE = 0x400,
+  DF_1_NODEFLIB = 0x800,
+  DF_1_NODUMP = 0x1000,
+  DF_1_CONLFAT = 0x2000,
+};
+
+// Version numbers which appear in the vd_version field of a Verdef
+// structure.
+
+const int VER_DEF_NONE = 0;
+const int VER_DEF_CURRENT = 1;
+
+// Version numbers which appear in the vn_version field of a Verneed
+// structure.
+
+const int VER_NEED_NONE = 0;
+const int VER_NEED_CURRENT = 1;
+
+// Bit flags which appear in vd_flags of Verdef and vna_flags of
+// Vernaux.
+
+const int VER_FLG_BASE = 0x1;
+const int VER_FLG_WEAK = 0x2;
+
+// Special constants found in the SHT_GNU_versym entries.
+
+const int VER_NDX_LOCAL = 0;
+const int VER_NDX_GLOBAL = 1;
+
+// A SHT_GNU_versym section holds 16-bit words.  This bit is set if
+// the symbol is hidden and can only be seen when referenced using an
+// explicit version number.  This is a GNU extension.
+
+const int VERSYM_HIDDEN = 0x8000;
+
+// This is the mask for the rest of the data in a word read from a
+// SHT_GNU_versym section.
+
+const int VERSYM_VERSION = 0x7fff;
+
+// Note descriptor type codes for notes in a non-core file with an
+// empty name.
+
+enum
+{
+  // A version string.
+  NT_VERSION = 1,
+  // An architecture string.
+  NT_ARCH = 2
+};
+
+// Note descriptor type codes for notes in a non-core file with the
+// name "GNU".
+
+enum
+{
+  // The minimum ABI level.  This is used by the dynamic linker to
+  // describe the minimal kernel version on which a shared library may
+  // be used.  Th value should be four words.  Word 0 is an OS
+  // descriptor (see below).  Word 1 is the major version of the ABI.
+  // Word 2 is the minor version.  Word 3 is the subminor version.
+  NT_GNU_ABI_TAG = 1,
+  // Hardware capabilities information.  Word 0 is the number of
+  // entries.  Word 1 is a bitmask of enabled entries.  The rest of
+  // the descriptor is a series of entries, where each entry is a
+  // single byte followed by a nul terminated string.  The byte gives
+  // the bit number to test if enabled in the bitmask.
+  NT_GNU_HWCAP = 2,
+  // The build ID as set by the linker's --build-id option.  The
+  // format of the descriptor depends on the build ID style.
+  NT_GNU_BUILD_ID = 3,
+  // The version of gold used to link.  Th descriptor is just a
+  // string.
+  NT_GNU_GOLD_VERSION = 4
+};
+
+// The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
+
+enum
+{
+  ELF_NOTE_OS_LINUX = 0,
+  ELF_NOTE_OS_GNU = 1,
+  ELF_NOTE_OS_SOLARIS2 = 2,
+  ELF_NOTE_OS_FREEBSD = 3,
+  ELF_NOTE_OS_NETBSD = 4,
+  ELF_NOTE_OS_SYLLABLE = 5
+};
+
 } // End namespace elfcpp.
 
 // Include internal details after defining the types.
@@ -557,26 +835,15 @@ struct Elf_sizes
   // Sizes of ELF reloc entries.
   static const int rel_size = sizeof(internal::Rel_data<size>);
   static const int rela_size = sizeof(internal::Rela_data<size>);
+  // Size of ELF dynamic entry.
+  static const int dyn_size = sizeof(internal::Dyn_data<size>);
+  // Size of ELF version structures.
+  static const int verdef_size = sizeof(internal::Verdef_data);
+  static const int verdaux_size = sizeof(internal::Verdaux_data);
+  static const int verneed_size = sizeof(internal::Verneed_data);
+  static const int vernaux_size = sizeof(internal::Vernaux_data);
 };
 
-// Given the address of an Elf_Word, return the value.
-
-template<bool big_endian>
-inline Elf_Word
-read_elf_word(const Elf_Word* p)
-{
-  return internal::convert_word<big_endian>(*p);
-}
-
-// Store an Elf_Word into an address.
-
-template<bool big_endian>
-inline void
-write_elf_word(Elf_Word* p, Elf_Word v)
-{
-  *p = internal::convert_word<big_endian>(v);
-}
-
 // Accessor class for the ELF file header.
 
 template<int size, bool big_endian>
@@ -587,61 +854,67 @@ class Ehdr
     : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
   { }
 
+  template<typename File>
+  Ehdr(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
   const unsigned char*
   get_e_ident() const
   { return this->p_->e_ident; }
 
   Elf_Half
   get_e_type() const
-  { return internal::convert_half<big_endian>(this->p_->e_type); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
 
   Elf_Half
   get_e_machine() const
-  { return internal::convert_half<big_endian>(this->p_->e_machine); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
 
   Elf_Word
   get_e_version() const
-  { return internal::convert_word<big_endian>(this->p_->e_version); }
+  { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
 
   typename Elf_types<size>::Elf_Addr
   get_e_entry() const
-  { return internal::convert_addr<size, big_endian>(this->p_->e_entry); }
+  { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
 
   typename Elf_types<size>::Elf_Off
   get_e_phoff() const
-  { return internal::convert_off<size, big_endian>(this->p_->e_phoff); }
+  { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
 
   typename Elf_types<size>::Elf_Off
   get_e_shoff() const
-  { return internal::convert_off<size, big_endian>(this->p_->e_shoff); }
+  { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
 
   Elf_Word
   get_e_flags() const
-  { return internal::convert_word<big_endian>(this->p_->e_flags); }
+  { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
 
   Elf_Half
   get_e_ehsize() const
-  { return internal::convert_half<big_endian>(this->p_->e_ehsize); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
 
   Elf_Half
   get_e_phentsize() const
-  { return internal::convert_half<big_endian>(this->p_->e_phentsize); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
 
   Elf_Half
   get_e_phnum() const
-  { return internal::convert_half<big_endian>(this->p_->e_phnum); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
 
   Elf_Half
   get_e_shentsize() const
-  { return internal::convert_half<big_endian>(this->p_->e_shentsize); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
 
   Elf_Half
   get_e_shnum() const
-  { return internal::convert_half<big_endian>(this->p_->e_shnum); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
 
   Elf_Half
   get_e_shstrndx() const
-  { return internal::convert_half<big_endian>(this->p_->e_shstrndx); }
+  { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
 
  private:
   const internal::Ehdr_data<size>* p_;
@@ -663,55 +936,55 @@ class Ehdr_write
 
   void
   put_e_type(Elf_Half v)
-  { this->p_->e_type = internal::convert_half<big_endian>(v); }
-  
+  { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
+
   void
   put_e_machine(Elf_Half v)
-  { this->p_->e_machine = internal::convert_half<big_endian>(v); }
+  { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
 
   void
   put_e_version(Elf_Word v)
-  { this->p_->e_version = internal::convert_word<big_endian>(v); }
+  { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_e_entry(typename Elf_types<size>::Elf_Addr v)
-  { this->p_->e_entry = internal::convert_addr<size, big_endian>(v); }
+  { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_e_phoff(typename Elf_types<size>::Elf_Off v)
-  { this->p_->e_phoff = internal::convert_off<size, big_endian>(v); }
+  { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_e_shoff(typename Elf_types<size>::Elf_Off v)
-  { this->p_->e_shoff = internal::convert_off<size, big_endian>(v); }
+  { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_e_flags(Elf_Word v)
-  { this->p_->e_flags = internal::convert_word<big_endian>(v); }
+  { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_e_ehsize(Elf_Half v)
-  { this->p_->e_ehsize = internal::convert_half<big_endian>(v); }
+  { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
 
   void
   put_e_phentsize(Elf_Half v)
-  { this->p_->e_phentsize = internal::convert_half<big_endian>(v); }
+  { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
 
   void
   put_e_phnum(Elf_Half v)
-  { this->p_->e_phnum = internal::convert_half<big_endian>(v); }
+  { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
 
   void
   put_e_shentsize(Elf_Half v)
-  { this->p_->e_shentsize = internal::convert_half<big_endian>(v); }
+  { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
 
   void
   put_e_shnum(Elf_Half v)
-  { this->p_->e_shnum = internal::convert_half<big_endian>(v); }
+  { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
 
   void
   put_e_shstrndx(Elf_Half v)
-  { this->p_->e_shstrndx = internal::convert_half<big_endian>(v); }
+  { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
 
  private:
   internal::Ehdr_data<size>* p_;
@@ -727,46 +1000,52 @@ class Shdr
     : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
   { }
 
+  template<typename File>
+  Shdr(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
   Elf_Word
   get_sh_name() const
-  { return internal::convert_word<big_endian>(this->p_->sh_name); }
+  { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
 
   Elf_Word
   get_sh_type() const
-  { return internal::convert_word<big_endian>(this->p_->sh_type); }
+  { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_flags() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->sh_flags); }
+  { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
 
   typename Elf_types<size>::Elf_Addr
   get_sh_addr() const
-  { return internal::convert_addr<size, big_endian>(this->p_->sh_addr); }
+  { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
 
   typename Elf_types<size>::Elf_Off
   get_sh_offset() const
-  { return internal::convert_off<size, big_endian>(this->p_->sh_offset); }
+  { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_size() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->sh_size); }
+  { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
 
   Elf_Word
   get_sh_link() const
-  { return internal::convert_word<big_endian>(this->p_->sh_link); }
+  { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
 
   Elf_Word
   get_sh_info() const
-  { return internal::convert_word<big_endian>(this->p_->sh_info); }
+  { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_addralign() const
   { return
-      internal::convert_wxword<size, big_endian>(this->p_->sh_addralign); }
+      Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_entsize() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->sh_entsize); }
+  { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
 
  private:
   const internal::Shdr_data<size>* p_;
@@ -784,43 +1063,43 @@ class Shdr_write
 
   void
   put_sh_name(Elf_Word v)
-  { this->p_->sh_name = internal::convert_word<big_endian>(v); }
+  { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_sh_type(Elf_Word v)
-  { this->p_->sh_type = internal::convert_word<big_endian>(v); }
+  { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_sh_flags(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->sh_flags = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_sh_addr(typename Elf_types<size>::Elf_Addr v)
-  { this->p_->sh_addr = internal::convert_addr<size, big_endian>(v); }
+  { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_sh_offset(typename Elf_types<size>::Elf_Off v)
-  { this->p_->sh_offset = internal::convert_off<size, big_endian>(v); }
+  { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_sh_size(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->sh_size = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_sh_link(Elf_Word v)
-  { this->p_->sh_link = internal::convert_word<big_endian>(v); }
+  { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_sh_info(Elf_Word v)
-  { this->p_->sh_info = internal::convert_word<big_endian>(v); }
+  { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->sh_addralign = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->sh_entsize = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
 
  private:
   internal::Shdr_data<size>* p_;
@@ -836,37 +1115,43 @@ class Phdr
     : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
   { }
 
+  template<typename File>
+  Phdr(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<internal::Phdr_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
   Elf_Word
   get_p_type() const
-  { return internal::convert_word<big_endian>(this->p_->p_type); }
+  { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
 
   typename Elf_types<size>::Elf_Off
   get_p_offset() const
-  { return internal::convert_off<size, big_endian>(this->p_->p_offset); }
+  { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
 
   typename Elf_types<size>::Elf_Addr
   get_p_vaddr() const
-  { return internal::convert_addr<size, big_endian>(this->p_->p_vaddr); }
+  { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
 
   typename Elf_types<size>::Elf_Addr
   get_p_paddr() const
-  { return internal::convert_addr<size, big_endian>(this->p_->p_paddr); }
+  { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
 
   typename Elf_types<size>::Elf_WXword
   get_p_filesz() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->p_filesz); }
+  { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
 
   typename Elf_types<size>::Elf_WXword
   get_p_memsz() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->p_memsz); }
+  { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
 
   Elf_Word
   get_p_flags() const
-  { return internal::convert_word<big_endian>(this->p_->p_flags); }
+  { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
 
   typename Elf_types<size>::Elf_WXword
   get_p_align() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->p_align); }
+  { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
 
  private:
   const internal::Phdr_data<size>* p_;
@@ -884,35 +1169,35 @@ class Phdr_write
 
   void
   put_p_type(Elf_Word v)
-  { this->p_->p_type = internal::convert_word<big_endian>(v); }
+  { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_p_offset(typename Elf_types<size>::Elf_Off v)
-  { this->p_->p_offset = internal::convert_off<size, big_endian>(v); }
+  { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
-  { this->p_->p_vaddr = internal::convert_addr<size, big_endian>(v); }
+  { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_p_paddr(typename Elf_types<size>::Elf_Addr v)
-  { this->p_->p_paddr = internal::convert_addr<size, big_endian>(v); }
+  { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_p_filesz(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->p_filesz = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_p_memsz(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->p_memsz = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_p_flags(Elf_Word v)
-  { this->p_->p_flags = internal::convert_word<big_endian>(v); }
+  { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_p_align(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->p_align = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
 
  private:
   internal::Phdr_data<size>* p_;
@@ -928,17 +1213,23 @@ class Sym
     : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
   { }
 
+  template<typename File>
+  Sym(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Sym_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
   Elf_Word
   get_st_name() const
-  { return internal::convert_word<big_endian>(this->p_->st_name); }
+  { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
 
   typename Elf_types<size>::Elf_Addr
   get_st_value() const
-  { return internal::convert_addr<size, big_endian>(this->p_->st_value); }
+  { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
 
   typename Elf_types<size>::Elf_WXword
   get_st_size() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->st_size); }
+  { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
 
   unsigned char
   get_st_info() const
@@ -966,7 +1257,7 @@ class Sym
 
   Elf_Half
   get_st_shndx() const
-  { return internal::convert_half<big_endian>(this->p_->st_shndx); }
+  { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
 
  private:
   const internal::Sym_data<size>* p_;
@@ -984,15 +1275,15 @@ class Sym_write
 
   void
   put_st_name(Elf_Word v)
-  { this->p_->st_name = internal::convert_word<big_endian>(v); }
+  { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
 
   void
   put_st_value(typename Elf_types<size>::Elf_Addr v)
-  { this->p_->st_value = internal::convert_addr<size, big_endian>(v); }
+  { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_st_size(typename Elf_types<size>::Elf_WXword v)
-  { this->p_->st_size = internal::convert_wxword<size, big_endian>(v); }
+  { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
 
   void
   put_st_info(unsigned char v)
@@ -1012,7 +1303,7 @@ class Sym_write
 
   void
   put_st_shndx(Elf_Half v)
-  { this->p_->st_shndx = internal::convert_half<big_endian>(v); }
+  { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
 
   Sym<size, big_endian>
   sym()
@@ -1022,7 +1313,7 @@ class Sym_write
   internal::Sym_data<size>* p_;
 };
 
-// Accessor classes for Elf relocation table entries.
+// Accessor classes for an ELF REL relocation entry.
 
 template<int size, bool big_endian>
 class Rel
@@ -1032,18 +1323,48 @@ class Rel
     : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
   { }
 
+  template<typename File>
+  Rel(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Rel_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
   typename Elf_types<size>::Elf_Addr
   get_r_offset() const
-  { return internal::convert_addr<size, big_endian>(this->p_->r_offset); }
+  { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
 
   typename Elf_types<size>::Elf_WXword
   get_r_info() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->r_info); }
+  { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
 
  private:
   const internal::Rel_data<size>* p_;
 };
 
+// Writer class for an ELF Rel relocation.
+
+template<int size, bool big_endian>
+class Rel_write
+{
+ public:
+  Rel_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
+  { }
+
+  void
+  put_r_offset(typename Elf_types<size>::Elf_Addr v)
+  { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_r_info(typename Elf_types<size>::Elf_WXword v)
+  { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
+
+ private:
+  internal::Rel_data<size>* p_;
+};
+
+// Accessor class for an ELF Rela relocation.
+
 template<int size, bool big_endian>
 class Rela
 {
@@ -1052,22 +1373,395 @@ class Rela
     : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
   { }
 
+  template<typename File>
+  Rela(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Rela_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
   typename Elf_types<size>::Elf_Addr
   get_r_offset() const
-  { return internal::convert_addr<size, big_endian>(this->p_->r_offset); }
+  { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
 
   typename Elf_types<size>::Elf_WXword
   get_r_info() const
-  { return internal::convert_wxword<size, big_endian>(this->p_->r_info); }
+  { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
 
   typename Elf_types<size>::Elf_Swxword
   get_r_addend() const
-  { return internal::convert_swxword<size, big_endian>(this->p_->r_addend); }
+  { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
 
  private:
   const internal::Rela_data<size>* p_;
 };
 
+// Writer class for an ELF Rela relocation.
+
+template<int size, bool big_endian>
+class Rela_write
+{
+ public:
+  Rela_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
+  { }
+
+  void
+  put_r_offset(typename Elf_types<size>::Elf_Addr v)
+  { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_r_info(typename Elf_types<size>::Elf_WXword v)
+  { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_r_addend(typename Elf_types<size>::Elf_Swxword v)
+  { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
+
+ private:
+  internal::Rela_data<size>* p_;
+};
+
+// Accessor classes for entries in the ELF SHT_DYNAMIC section aka
+// PT_DYNAMIC segment.
+
+template<int size, bool big_endian>
+class Dyn
+{
+ public:
+  Dyn(const unsigned char* p)
+    : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
+  { }
+
+  template<typename File>
+  Dyn(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
+  typename Elf_types<size>::Elf_Swxword
+  get_d_tag() const
+  { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
+
+  typename Elf_types<size>::Elf_WXword
+  get_d_val() const
+  { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
+
+  typename Elf_types<size>::Elf_Addr
+  get_d_ptr() const
+  { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
+
+ private:
+  const internal::Dyn_data<size>* p_;
+};
+
+// Write class for an entry in the SHT_DYNAMIC section.
+
+template<int size, bool big_endian>
+class Dyn_write
+{
+ public:
+  Dyn_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
+  { }
+
+  void
+  put_d_tag(typename Elf_types<size>::Elf_Swxword v)
+  { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_d_val(typename Elf_types<size>::Elf_WXword v)
+  { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_d_ptr(typename Elf_types<size>::Elf_Addr v)
+  { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
+
+ private:
+  internal::Dyn_data<size>* p_;
+};
+
+// Accessor classes for entries in the ELF SHT_GNU_verdef section.
+
+template<int size, bool big_endian>
+class Verdef
+{
+ public:
+  Verdef(const unsigned char* p)
+    : p_(reinterpret_cast<const internal::Verdef_data*>(p))
+  { }
+
+  template<typename File>
+  Verdef(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Verdef_data*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
+  Elf_Half
+  get_vd_version() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
+
+  Elf_Half
+  get_vd_flags() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
+
+  Elf_Half
+  get_vd_ndx() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
+
+  Elf_Half
+  get_vd_cnt() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
+
+  Elf_Word
+  get_vd_hash() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
+
+  Elf_Word
+  get_vd_aux() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
+
+  Elf_Word
+  get_vd_next() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
+
+ private:
+  const internal::Verdef_data* p_;
+};
+
+template<int size, bool big_endian>
+class Verdef_write
+{
+ public:
+  Verdef_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Verdef_data*>(p))
+  { }
+
+  void
+  set_vd_version(Elf_Half v)
+  { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vd_flags(Elf_Half v)
+  { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vd_ndx(Elf_Half v)
+  { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vd_cnt(Elf_Half v)
+  { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vd_hash(Elf_Word v)
+  { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vd_aux(Elf_Word v)
+  { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vd_next(Elf_Word v)
+  { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
+
+ private:
+  internal::Verdef_data* p_;
+};
+
+// Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
+// section.
+
+template<int size, bool big_endian>
+class Verdaux
+{
+ public:
+  Verdaux(const unsigned char* p)
+    : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
+  { }
+
+  template<typename File>
+  Verdaux(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Verdaux_data*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
+  Elf_Word
+  get_vda_name() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
+
+  Elf_Word
+  get_vda_next() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
+
+ private:
+  const internal::Verdaux_data* p_;
+};
+
+template<int size, bool big_endian>
+class Verdaux_write
+{
+ public:
+  Verdaux_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Verdaux_data*>(p))
+  { }
+
+  void
+  set_vda_name(Elf_Word v)
+  { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vda_next(Elf_Word v)
+  { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
+
+ private:
+  internal::Verdaux_data* p_;
+};
+
+// Accessor classes for entries in the ELF SHT_GNU_verneed section.
+
+template<int size, bool big_endian>
+class Verneed
+{
+ public:
+  Verneed(const unsigned char* p)
+    : p_(reinterpret_cast<const internal::Verneed_data*>(p))
+  { }
+
+  template<typename File>
+  Verneed(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Verneed_data*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
+  Elf_Half
+  get_vn_version() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
+
+  Elf_Half
+  get_vn_cnt() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
+
+  Elf_Word
+  get_vn_file() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
+
+  Elf_Word
+  get_vn_aux() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
+
+  Elf_Word
+  get_vn_next() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
+
+ private:
+  const internal::Verneed_data* p_;
+};
+
+template<int size, bool big_endian>
+class Verneed_write
+{
+ public:
+  Verneed_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Verneed_data*>(p))
+  { }
+
+  void
+  set_vn_version(Elf_Half v)
+  { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vn_cnt(Elf_Half v)
+  { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vn_file(Elf_Word v)
+  { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vn_aux(Elf_Word v)
+  { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vn_next(Elf_Word v)
+  { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
+
+ private:
+  internal::Verneed_data* p_;
+};
+
+// Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
+// section.
+
+template<int size, bool big_endian>
+class Vernaux
+{
+ public:
+  Vernaux(const unsigned char* p)
+    : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
+  { }
+
+  template<typename File>
+  Vernaux(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Vernaux_data*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
+  Elf_Word
+  get_vna_hash() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
+
+  Elf_Half
+  get_vna_flags() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
+
+  Elf_Half
+  get_vna_other() const
+  { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
+
+  Elf_Word
+  get_vna_name() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
+
+  Elf_Word
+  get_vna_next() const
+  { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
+
+ private:
+  const internal::Vernaux_data* p_;
+};
+
+template<int size, bool big_endian>
+class Vernaux_write
+{
+ public:
+  Vernaux_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Vernaux_data*>(p))
+  { }
+
+  void
+  set_vna_hash(Elf_Word v)
+  { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vna_flags(Elf_Half v)
+  { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vna_other(Elf_Half v)
+  { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
+
+  void
+  set_vna_name(Elf_Word v)
+  { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
+
+  void
+  set_vna_next(Elf_Word v)
+  { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
+
+ private:
+  internal::Vernaux_data* p_;
+};
+
 } // End namespace elfcpp.
 
 #endif // !defined(ELFPCP_H)
This page took 0.038125 seconds and 4 git commands to generate.