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