1*fae548d3Szrj // reloc-types.h -- ELF relocation templates for gold -*- C++ -*- 2*fae548d3Szrj 3*fae548d3Szrj // Copyright (C) 2006-2020 Free Software Foundation, Inc. 4*fae548d3Szrj // Written by Ian Lance Taylor <iant@google.com>. 5*fae548d3Szrj 6*fae548d3Szrj // This file is part of gold. 7*fae548d3Szrj 8*fae548d3Szrj // This program is free software; you can redistribute it and/or modify 9*fae548d3Szrj // it under the terms of the GNU General Public License as published by 10*fae548d3Szrj // the Free Software Foundation; either version 3 of the License, or 11*fae548d3Szrj // (at your option) any later version. 12*fae548d3Szrj 13*fae548d3Szrj // This program is distributed in the hope that it will be useful, 14*fae548d3Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 15*fae548d3Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*fae548d3Szrj // GNU General Public License for more details. 17*fae548d3Szrj 18*fae548d3Szrj // You should have received a copy of the GNU General Public License 19*fae548d3Szrj // along with this program; if not, write to the Free Software 20*fae548d3Szrj // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 21*fae548d3Szrj // MA 02110-1301, USA. 22*fae548d3Szrj 23*fae548d3Szrj // This header files defines a few convenient templated types for use 24*fae548d3Szrj // when handling ELF relocations. 25*fae548d3Szrj 26*fae548d3Szrj #ifndef GOLD_RELOC_TYPES_H 27*fae548d3Szrj #define GOLD_RELOC_TYPES_H 28*fae548d3Szrj 29*fae548d3Szrj #include "elfcpp.h" 30*fae548d3Szrj 31*fae548d3Szrj namespace gold 32*fae548d3Szrj { 33*fae548d3Szrj 34*fae548d3Szrj // Pick the ELF relocation accessor class and the size based on 35*fae548d3Szrj // SH_TYPE, which is either elfcpp::SHT_REL or elfcpp::SHT_RELA. 36*fae548d3Szrj 37*fae548d3Szrj template<int sh_type, int size, bool big_endian> 38*fae548d3Szrj struct Reloc_types; 39*fae548d3Szrj 40*fae548d3Szrj template<int size, bool big_endian> 41*fae548d3Szrj struct Reloc_types<elfcpp::SHT_REL, size, big_endian> 42*fae548d3Szrj { 43*fae548d3Szrj typedef typename elfcpp::Rel<size, big_endian> Reloc; 44*fae548d3Szrj typedef typename elfcpp::Rel_write<size, big_endian> Reloc_write; 45*fae548d3Szrj static const int reloc_size = elfcpp::Elf_sizes<size>::rel_size; 46*fae548d3Szrj 47*fae548d3Szrj static inline typename elfcpp::Elf_types<size>::Elf_Swxword 48*fae548d3Szrj get_reloc_addend(const Reloc*) 49*fae548d3Szrj { gold_unreachable(); } 50*fae548d3Szrj 51*fae548d3Szrj static inline typename elfcpp::Elf_types<size>::Elf_Swxword 52*fae548d3Szrj get_reloc_addend_noerror(const Reloc*) 53*fae548d3Szrj { return 0; } 54*fae548d3Szrj 55*fae548d3Szrj static inline void 56*fae548d3Szrj set_reloc_addend(Reloc_write*, 57*fae548d3Szrj typename elfcpp::Elf_types<size>::Elf_Swxword) 58*fae548d3Szrj { gold_unreachable(); } 59*fae548d3Szrj }; 60*fae548d3Szrj 61*fae548d3Szrj template<int size, bool big_endian> 62*fae548d3Szrj struct Reloc_types<elfcpp::SHT_RELA, size, big_endian> 63*fae548d3Szrj { 64*fae548d3Szrj typedef typename elfcpp::Rela<size, big_endian> Reloc; 65*fae548d3Szrj typedef typename elfcpp::Rela_write<size, big_endian> Reloc_write; 66*fae548d3Szrj static const int reloc_size = elfcpp::Elf_sizes<size>::rela_size; 67*fae548d3Szrj 68*fae548d3Szrj static inline typename elfcpp::Elf_types<size>::Elf_Swxword 69*fae548d3Szrj get_reloc_addend(const Reloc* p) 70*fae548d3Szrj { return p->get_r_addend(); } 71*fae548d3Szrj 72*fae548d3Szrj static inline typename elfcpp::Elf_types<size>::Elf_Swxword 73*fae548d3Szrj get_reloc_addend_noerror(const Reloc* p) 74*fae548d3Szrj { return p->get_r_addend(); } 75*fae548d3Szrj 76*fae548d3Szrj static inline void 77*fae548d3Szrj set_reloc_addend(Reloc_write* p, 78*fae548d3Szrj typename elfcpp::Elf_types<size>::Elf_Swxword val) 79*fae548d3Szrj { p->put_r_addend(val); } 80*fae548d3Szrj }; 81*fae548d3Szrj 82*fae548d3Szrj }; // End namespace gold. 83*fae548d3Szrj 84*fae548d3Szrj #endif // !defined(GOLD_RELOC_TYPE_SH) 85