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