X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=elfcpp%2Felfcpp_internal.h;h=36a6d6205f711db68c419f897fe586d185c2f1cf;hb=f16a9f57b50af64ccb9652d20cc934fc5e80cd20;hp=0d69baebfabb79dc6d5a245468daae30cf7ba62c;hpb=61ba1cf93601b0a0877a8ade94ba3c674a09f77e;p=deliverable%2Fbinutils-gdb.git diff --git a/elfcpp/elfcpp_internal.h b/elfcpp/elfcpp_internal.h index 0d69baebfa..36a6d6205f 100644 --- a/elfcpp/elfcpp_internal.h +++ b/elfcpp/elfcpp_internal.h @@ -1,12 +1,37 @@ // elfcpp_internal.h -- internals for elfcpp -*- C++ -*- +// Copyright (C) 2006-2020 Free Software Foundation, Inc. +// Written by Ian Lance Taylor . + +// 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 included by elfcpp.h, the external interface, but holds // information which we want to keep private. -#include "elfcpp_config.h" - -#include - #ifndef ELFCPP_INTERNAL_H #define ELFCPP_INTERNAL_H @@ -16,163 +41,6 @@ namespace elfcpp namespace internal { -#ifdef WORDS_BIG_ENDIAN -const bool host_big_endian = true; -#else -const bool host_big_endian = false; -#endif - -// Conversion routines between target and host. - -// Convert Elf_Half. - -template -Elf_Half -convert_half_host(Elf_Half v); - -template<> -inline Elf_Half -convert_half_host(Elf_Half v) -{ - return v; -} - -template<> -inline Elf_Half -convert_half_host(Elf_Half v) -{ - return bswap_16(v); -} - -template -inline Elf_Half -convert_half(Elf_Half v) -{ - return convert_half_host(v); -} - -// Convert Elf_Word. - -template -Elf_Word -convert_word_host(Elf_Word v); - -template<> -inline Elf_Word -convert_word_host(Elf_Word v) -{ - return v; -} - -template<> -inline Elf_Word -convert_word_host(Elf_Word v) -{ - return bswap_32(v); -} - -template -inline Elf_Word -convert_word(Elf_Word v) -{ - return convert_word_host(v); -} - -// Convert Elf_Xword. - -template -Elf_Xword -convert_xword_host(Elf_Xword v); - -template<> -inline Elf_Xword -convert_xword_host(Elf_Xword v) -{ - return v; -} - -template<> -inline Elf_Xword -convert_xword_host(Elf_Xword v) -{ - return bswap_64(v); -} - -template -inline Elf_Xword -convert_xword(Elf_Xword v) -{ - return convert_xword_host(v); -} - -// Convert Elf_addr. - -template -typename Elf_types::Elf_Addr -convert_addr_size(typename Elf_types::Elf_Addr); - -template<> -inline Elf_types<32>::Elf_Addr -convert_addr_size<32, true>(Elf_types<32>::Elf_Addr v) -{ - return v; -} - -template<> -inline Elf_types<64>::Elf_Addr -convert_addr_size<64, true>(Elf_types<64>::Elf_Addr v) -{ - return v; -} - -template<> -inline Elf_types<32>::Elf_Addr -convert_addr_size<32, false>(Elf_types<32>::Elf_Addr v) -{ - return bswap_32(v); -} - -template<> -inline Elf_types<64>::Elf_Addr -convert_addr_size<64, false>(Elf_types<64>::Elf_Addr v) -{ - return bswap_64(v); -} - -template -inline typename Elf_types::Elf_Addr -convert_addr(typename Elf_types::Elf_Addr v) -{ - return convert_addr_size(v); -} - -// Convert Elf_Off. - -template -inline typename Elf_types::Elf_Off -convert_off(typename Elf_types::Elf_Off v) -{ - return convert_addr_size(v); -} - -// Convert Elf_WXword. - -template -inline typename Elf_types::Elf_WXword -convert_wxword(typename Elf_types::Elf_WXword v) -{ - return convert_addr_size(v); -} - -// Convert ELF_Swxword. - -template -inline typename Elf_types::Elf_Swxword -convert_swxword(typename Elf_types::Elf_Swxword v) -{ - return convert_addr_size(v); -} - // The ELF file header. template @@ -194,7 +62,7 @@ struct Ehdr_data Elf_Half e_shstrndx; }; -// An Elf section header. +// An ELF section header. template struct Shdr_data @@ -211,6 +79,28 @@ struct Shdr_data typename Elf_types::Elf_WXword sh_entsize; }; +// An ELF compression header. + +template +struct Chdr_data; + +template<> +struct Chdr_data<32> +{ + Elf_Word ch_type; + Elf_Word ch_size; + Elf_Word ch_addralign; +}; + +template<> +struct Chdr_data<64> +{ + Elf_Word ch_type; + Elf_Word ch_reserved; + Elf_Xword ch_size; + Elf_Xword ch_addralign; +}; + // An ELF segment header. We use template specialization for the // 32-bit and 64-bit versions because the fields are in a different // order. @@ -273,7 +163,7 @@ struct Sym_data<64> Elf_Xword st_size; }; -// Elf relocation table entries. +// ELF relocation table entries. template struct Rel_data @@ -290,6 +180,104 @@ struct Rela_data typename Elf_types::Elf_Swxword r_addend; }; +// MIPS-64 has a non-standard layout for relocations. + +struct Mips64_rel_data +{ + Elf_types<64>::Elf_Addr r_offset; + Elf_Word r_sym; + unsigned char r_ssym; + unsigned char r_type3; + unsigned char r_type2; + unsigned char r_type; +}; + +struct Mips64_rela_data +{ + Elf_types<64>::Elf_Addr r_offset; + Elf_Word r_sym; + unsigned char r_ssym; + unsigned char r_type3; + unsigned char r_type2; + unsigned char r_type; + Elf_types<64>::Elf_Swxword r_addend; +}; + +// An entry in the ELF SHT_DYNAMIC section aka PT_DYNAMIC segment. + +template +struct Dyn_data +{ + typename Elf_types::Elf_Swxword d_tag; + typename Elf_types::Elf_WXword d_val; +}; + +// An entry in a SHT_GNU_verdef section. This structure is the same +// in 32-bit and 64-bit ELF files. + +struct Verdef_data +{ + // Version number of structure (VER_DEF_*). + Elf_Half vd_version; + // Bit flags (VER_FLG_*). + Elf_Half vd_flags; + // Version index. + Elf_Half vd_ndx; + // Number of auxiliary Verdaux entries. + Elf_Half vd_cnt; + // Hash of name. + Elf_Word vd_hash; + // Byte offset to first Verdaux entry. + Elf_Word vd_aux; + // Byte offset to next Verdef entry. + Elf_Word vd_next; +}; + +// An auxiliary entry in a SHT_GNU_verdef section. This structure is +// the same in 32-bit and 64-bit ELF files. + +struct Verdaux_data +{ + // Offset in string table of version name. + Elf_Word vda_name; + // Byte offset to next Verdaux entry. + Elf_Word vda_next; +}; + +// An entry in a SHT_GNU_verneed section. This structure is the same +// in 32-bit and 64-bit ELF files. + +struct Verneed_data +{ + // Version number of structure (VER_NEED_*). + Elf_Half vn_version; + // Number of auxiliary Vernaux entries. + Elf_Half vn_cnt; + // Offset in string table of library name. + Elf_Word vn_file; + // Byte offset to first Vernaux entry. + Elf_Word vn_aux; + // Byt eoffset to next Verneed entry. + Elf_Word vn_next; +}; + +// An auxiliary entry in a SHT_GNU_verneed section. This structure is +// the same in 32-bit and 64-bit ELF files. + +struct Vernaux_data +{ + // Hash of dependency name. + Elf_Word vna_hash; + // Bit flags (VER_FLG_*). + Elf_Half vna_flags; + // Version index used in SHT_GNU_versym entries. + Elf_Half vna_other; + // Offset in string table of version name. + Elf_Word vna_name; + // Byte offset to next Vernaux entry. + Elf_Word vna_next; +}; + } // End namespace internal. } // End namespace elfcpp.