tls.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // tls.h -- Thread-Local Storage utility routines for gold -*- C++ -*-
  2. // Copyright (C) 2006-2015 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. #ifndef GOLD_TLS_H
  18. #define GOLD_TLS_H
  19. #include "elfcpp.h"
  20. #include "reloc.h"
  21. namespace gold
  22. {
  23. namespace tls
  24. {
  25. // This is used for relocations that can be converted to a different,
  26. // more efficient type of relocation.
  27. enum Tls_optimization
  28. {
  29. TLSOPT_NONE, // Can not convert this relocation to a more efficient one.
  30. TLSOPT_TO_LD, // Can convert General Dynamic to Local Dynamic.
  31. TLSOPT_TO_LE, // Can convert GD or LD to Local-Exec.
  32. TLSOPT_TO_IE, // Can convert GD or LD or LE to Initial-Exec.
  33. };
  34. // Check the range for a TLS relocation. This is inlined for efficiency.
  35. template<int size, bool big_endian>
  36. inline void
  37. check_range(const Relocate_info<size, big_endian>* relinfo,
  38. size_t relnum,
  39. typename elfcpp::Elf_types<size>::Elf_Addr rel_offset,
  40. section_size_type view_size, int off)
  41. {
  42. typename elfcpp::Elf_types<size>::Elf_Addr offset = rel_offset + off;
  43. // Elf_Addr is unsigned, so this also tests for signed offset < 0.
  44. if (offset > view_size)
  45. gold_error_at_location(relinfo, relnum, rel_offset,
  46. _("TLS relocation out of range"));
  47. }
  48. // Check the validity of a TLS relocation. This is like assert.
  49. template<int size, bool big_endian>
  50. inline void
  51. check_tls(const Relocate_info<size, big_endian>* relinfo,
  52. size_t relnum,
  53. typename elfcpp::Elf_types<size>::Elf_Addr rel_offset,
  54. bool valid)
  55. {
  56. if (!valid)
  57. gold_error_at_location(relinfo, relnum, rel_offset,
  58. _("TLS relocation against invalid instruction"));
  59. }
  60. } // End namespace tls.
  61. } // End namespace gold.
  62. #endif // !defined(GOLD_TLS_H)