reloc-types.h 2.7 KB

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