Commit | Line | Data |
---|---|---|
af6359d5 ILT |
1 | // tls.h -- Thread-Local Storage utility routines for gold -*- C++ -*- |
2 | ||
3 | // Copyright 2006, 2007 Free Software Foundation, Inc. | |
4 | // Written by Ian Lance Taylor <iant@google.com>. | |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
23 | #ifndef GOLD_TLS_H | |
24 | #define GOLD_TLS_H | |
25 | ||
26 | #include "elfcpp.h" | |
27 | #include "reloc.h" | |
28 | ||
29 | namespace gold | |
30 | { | |
31 | ||
32 | namespace tls | |
33 | { | |
34 | ||
35 | // This is used for relocations that can be converted to a different, | |
36 | // more efficient type of relocation. | |
37 | ||
38 | enum Tls_optimization | |
39 | { | |
40 | TLSOPT_NONE, // Can not convert this relocation to a more efficient one. | |
41 | TLSOPT_TO_LD, // Can convert General Dynamic to Local Dynamic. | |
42 | TLSOPT_TO_LE, // Can convert GD or LD to Local-Exec. | |
43 | TLSOPT_TO_IE, // Can convert GD or LD or LE to Initial-Exec. | |
44 | }; | |
45 | ||
46 | // Check the range for a TLS relocation. This is inlined for efficiency. | |
47 | ||
48 | template<int size, bool big_endian> | |
49 | inline void | |
50 | check_range(const Relocate_info<size, big_endian>* relinfo, | |
51 | size_t relnum, | |
52 | typename elfcpp::Elf_types<size>::Elf_Addr rel_offset, | |
53 | off_t view_size, off_t off) | |
54 | { | |
55 | off_t offset = rel_offset + off; | |
56 | if (offset < 0 || offset > view_size) | |
57 | { | |
58 | fprintf(stderr, _("%s: %s: TLS relocation out of range\n"), | |
59 | program_name, | |
60 | relinfo->location(relnum, rel_offset).c_str()); | |
61 | gold_exit(false); | |
62 | } | |
63 | } | |
64 | ||
65 | // Check the validity of a TLS relocation. This is like assert. | |
66 | ||
67 | template<int size, bool big_endian> | |
68 | inline void | |
69 | check_tls(const Relocate_info<size, big_endian>* relinfo, | |
70 | size_t relnum, | |
71 | typename elfcpp::Elf_types<size>::Elf_Addr rel_offset, | |
72 | bool valid) | |
73 | { | |
74 | if (!valid) | |
75 | { | |
76 | fprintf(stderr, | |
77 | _("%s: %s: TLS relocation against invalid instruction\n"), | |
78 | program_name, | |
79 | relinfo->location(relnum, rel_offset).c_str()); | |
80 | gold_exit(false); | |
81 | } | |
82 | } | |
83 | ||
84 | ||
85 | } // End namespace tls. | |
86 | ||
87 | } // End namespace gold. | |
88 | ||
89 | #endif // !defined(GOLD_TLS_H) |