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