]>
Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // gold.h -- general definitions for gold -*- C++ -*- |
2 | ||
6cb15b7f ILT |
3 | // Copyright 2006, 2007 Free Software Foundation, Inc. |
4 | // Written by Ian Lance Taylor <[email protected]>. | |
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 | ||
bae7f79e | 23 | #ifndef GOLD_GOLD_H |
6724bacc | 24 | #define GOLD_GOLD_H |
bae7f79e ILT |
25 | |
26 | #include "config.h" | |
27 | #include "ansidecl.h" | |
28 | ||
29 | #ifdef ENABLE_NLS | |
30 | # include <libintl.h> | |
31 | # define _(String) gettext (String) | |
32 | # ifdef gettext_noop | |
33 | # define N_(String) gettext_noop (String) | |
34 | # else | |
35 | # define N_(String) (String) | |
36 | # endif | |
37 | #else | |
38 | # define gettext(Msgid) (Msgid) | |
39 | # define dgettext(Domainname, Msgid) (Msgid) | |
40 | # define dcgettext(Domainname, Msgid, Category) (Msgid) | |
41 | # define textdomain(Domainname) while (0) /* nothing */ | |
42 | # define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ | |
43 | # define _(String) (String) | |
44 | # define N_(String) (String) | |
45 | #endif | |
46 | ||
54dc6425 ILT |
47 | // Figure out how to get a hash set and a hash map. |
48 | ||
d288e464 | 49 | #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP) |
bae7f79e ILT |
50 | |
51 | #include <tr1/unordered_set> | |
52 | #include <tr1/unordered_map> | |
53 | ||
54 | // We need a template typedef here. | |
55 | ||
56 | #define Unordered_set std::tr1::unordered_set | |
57 | #define Unordered_map std::tr1::unordered_map | |
58 | ||
d288e464 | 59 | #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET) |
54dc6425 ILT |
60 | |
61 | #include <ext/hash_map> | |
62 | #include <ext/hash_set> | |
274e99f9 | 63 | #include <string> |
54dc6425 ILT |
64 | |
65 | #define Unordered_set __gnu_cxx::hash_set | |
66 | #define Unordered_map __gnu_cxx::hash_map | |
67 | ||
274e99f9 ILT |
68 | namespace __gnu_cxx |
69 | { | |
70 | ||
71 | template<> | |
72 | struct hash<std::string> | |
73 | { | |
74 | size_t | |
75 | operator()(std::string s) const | |
76 | { return __stl_hash_string(s.c_str()); } | |
77 | }; | |
78 | ||
79 | template<typename T> | |
80 | struct hash<T*> | |
81 | { | |
82 | size_t | |
83 | operator()(T* p) const | |
84 | { return reinterpret_cast<size_t>(p); } | |
85 | }; | |
86 | ||
87 | } | |
88 | ||
54dc6425 ILT |
89 | #else |
90 | ||
91 | // The fallback is to just use set and map. | |
92 | ||
93 | #include <set> | |
94 | #include <map> | |
95 | ||
96 | #define Unordered_set std::set | |
97 | #define Unordered_map std::map | |
98 | ||
99 | #endif | |
100 | ||
82dcae9d ILT |
101 | #ifndef HAVE_PREAD |
102 | extern "C" ssize_t pread(int, void*, size_t, off_t); | |
103 | #endif | |
104 | ||
5482377d ILT |
105 | namespace gold |
106 | { | |
107 | // This is a hack to work around a problem with older versions of g++. | |
108 | // The problem is that they don't support calling a member template by | |
109 | // specifying the template parameters. It works to pass in an | |
110 | // argument for argument dependent lookup. | |
111 | ||
112 | // To use this, the member template method declaration should put | |
113 | // ACCEPT_SIZE or ACCEPT_SIZE_ENDIAN after the last parameter. If the | |
114 | // method takes no parameters, use ACCEPT_SIZE_ONLY or | |
115 | // ACCEPT_SIZE_ENDIAN_ONLY. | |
116 | ||
117 | // When calling the method, instead of using fn<size>, use fn | |
118 | // SELECT_SIZE_NAME or SELECT_SIZE_ENDIAN_NAME. And after the last | |
119 | // argument, put SELECT_SIZE(size) or SELECT_SIZE_ENDIAN(size, | |
120 | // big_endian). If there is only one argment, use the _ONLY variants. | |
121 | ||
122 | #ifdef HAVE_MEMBER_TEMPLATE_SPECIFICATIONS | |
123 | ||
593f47df | 124 | #define SELECT_SIZE_NAME(size) <size> |
5482377d ILT |
125 | #define SELECT_SIZE(size) |
126 | #define SELECT_SIZE_ONLY(size) | |
127 | #define ACCEPT_SIZE | |
128 | #define ACCEPT_SIZE_ONLY | |
91da9340 | 129 | #define ACCEPT_SIZE_EXPLICIT(size) |
5482377d | 130 | |
593f47df | 131 | #define SELECT_SIZE_ENDIAN_NAME(size, big_endian) <size, big_endian> |
5482377d ILT |
132 | #define SELECT_SIZE_ENDIAN(size, big_endian) |
133 | #define SELECT_SIZE_ENDIAN_ONLY(size, big_endian) | |
134 | #define ACCEPT_SIZE_ENDIAN | |
135 | #define ACCEPT_SIZE_ENDIAN_ONLY | |
91da9340 | 136 | #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian) |
5482377d ILT |
137 | |
138 | #else // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS) | |
139 | ||
140 | template<int size> | |
141 | class Select_size { }; | |
142 | template<int size, bool big_endian> | |
143 | class Select_size_endian { }; | |
144 | ||
593f47df | 145 | #define SELECT_SIZE_NAME(size) |
5482377d ILT |
146 | #define SELECT_SIZE(size) , Select_size<size>() |
147 | #define SELECT_SIZE_ONLY(size) Select_size<size>() | |
148 | #define ACCEPT_SIZE , Select_size<size> | |
149 | #define ACCEPT_SIZE_ONLY Select_size<size> | |
91da9340 | 150 | #define ACCEPT_SIZE_EXPLICIT(size) , Select_size<size> |
5482377d | 151 | |
593f47df | 152 | #define SELECT_SIZE_ENDIAN_NAME(size, big_endian) |
5482377d ILT |
153 | #define SELECT_SIZE_ENDIAN(size, big_endian) \ |
154 | , Select_size_endian<size, big_endian>() | |
155 | #define SELECT_SIZE_ENDIAN_ONLY(size, big_endian) \ | |
156 | Select_size_endian<size, big_endian>() | |
157 | #define ACCEPT_SIZE_ENDIAN , Select_size_endian<size, big_endian> | |
158 | #define ACCEPT_SIZE_ENDIAN_ONLY Select_size_endian<size, big_endian> | |
91da9340 ILT |
159 | #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian) \ |
160 | , Select_size_endian<size, big_endian> | |
5482377d ILT |
161 | |
162 | #endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS) | |
163 | ||
8383303e | 164 | // General declarations. |
bae7f79e | 165 | |
61ba1cf9 | 166 | class General_options; |
5a6f7e2d | 167 | class Command_line; |
92e059d8 ILT |
168 | class Input_argument_list; |
169 | class Dirsearch; | |
61ba1cf9 | 170 | class Input_objects; |
75f2446e | 171 | class Symbol; |
61ba1cf9 ILT |
172 | class Symbol_table; |
173 | class Layout; | |
17a1d0a9 | 174 | class Task; |
61ba1cf9 ILT |
175 | class Workqueue; |
176 | class Output_file; | |
75f2446e ILT |
177 | template<int size, bool big_endian> |
178 | struct Relocate_info; | |
61ba1cf9 | 179 | |
8383303e ILT |
180 | // Some basic types. For these we use lower case initial letters. |
181 | ||
182 | // For an offset in an input or output file, use off_t. Note that | |
183 | // this will often be a 64-bit type even for a 32-bit build. | |
184 | ||
185 | // The size of a section if we are going to look at the contents. | |
186 | typedef size_t section_size_type; | |
187 | ||
188 | // An offset within a section when we are looking at the contents. | |
189 | typedef ptrdiff_t section_offset_type; | |
190 | ||
bae7f79e ILT |
191 | // The name of the program as used in error messages. |
192 | extern const char* program_name; | |
193 | ||
194 | // This function is called to exit the program. Status is true to | |
195 | // exit success (0) and false to exit failure (1). | |
196 | extern void | |
197 | gold_exit(bool status) ATTRIBUTE_NORETURN; | |
198 | ||
75f2446e ILT |
199 | // This function is called to emit an error message and then |
200 | // immediately exit with failure. | |
201 | extern void | |
202 | gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1; | |
203 | ||
204 | // This function is called to issue an error. This will cause gold to | |
205 | // eventually exit with failure. | |
206 | extern void | |
207 | gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1; | |
208 | ||
209 | // This function is called to issue a warning. | |
210 | extern void | |
211 | gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1; | |
212 | ||
213 | // This function is called to issue an error at the location of a | |
214 | // reloc. | |
215 | template<int size, bool big_endian> | |
216 | extern void | |
217 | gold_error_at_location(const Relocate_info<size, big_endian>*, | |
218 | size_t, off_t, const char* format, ...) | |
219 | ATTRIBUTE_PRINTF_4; | |
220 | ||
221 | // This function is called to issue a warning at the location of a | |
222 | // reloc. | |
223 | template<int size, bool big_endian> | |
224 | extern void | |
225 | gold_warning_at_location(const Relocate_info<size, big_endian>*, | |
226 | size_t, off_t, const char* format, ...) | |
227 | ATTRIBUTE_PRINTF_4; | |
228 | ||
229 | // This function is called to report an undefined symbol. | |
230 | template<int size, bool big_endian> | |
bae7f79e | 231 | extern void |
75f2446e ILT |
232 | gold_undefined_symbol(const Symbol*, |
233 | const Relocate_info<size, big_endian>*, | |
234 | size_t, off_t); | |
bae7f79e ILT |
235 | |
236 | // This is function is called in some cases if we run out of memory. | |
237 | extern void | |
238 | gold_nomem() ATTRIBUTE_NORETURN; | |
239 | ||
a3ad94ed ILT |
240 | // This macro and function are used in cases which can not arise if |
241 | // the code is written correctly. | |
242 | ||
243 | #define gold_unreachable() \ | |
244 | (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__)) | |
245 | ||
246 | extern void do_gold_unreachable(const char*, int, const char*) | |
247 | ATTRIBUTE_NORETURN; | |
248 | ||
249 | // Assertion check. | |
250 | ||
251 | #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0)) | |
bae7f79e | 252 | |
8486ee48 ILT |
253 | // Print version information. |
254 | extern void | |
255 | print_version(bool print_short); | |
256 | ||
4f211c8b ILT |
257 | // Get the version string. |
258 | extern const char* | |
259 | get_version_string(); | |
260 | ||
8383303e ILT |
261 | // Convert numeric types without unnoticed loss of precision. |
262 | template<typename To, typename From> | |
263 | inline To | |
264 | convert_types(const From from) | |
265 | { | |
266 | To to = from; | |
9bb53bf8 | 267 | gold_assert(static_cast<From>(to) == from); |
8383303e ILT |
268 | return to; |
269 | } | |
270 | ||
271 | // A common case of convert_types<>: convert to section_size_type. | |
272 | template<typename From> | |
273 | inline section_size_type | |
274 | convert_to_section_size_type(const From from) | |
275 | { return convert_types<section_size_type, From>(from); } | |
276 | ||
92e059d8 ILT |
277 | // Queue up the first set of tasks. |
278 | extern void | |
279 | queue_initial_tasks(const General_options&, | |
17a1d0a9 | 280 | Dirsearch&, |
5a6f7e2d | 281 | const Command_line&, |
92e059d8 ILT |
282 | Workqueue*, |
283 | Input_objects*, | |
284 | Symbol_table*, | |
285 | Layout*); | |
286 | ||
287 | // Queue up the middle set of tasks. | |
288 | extern void | |
289 | queue_middle_tasks(const General_options&, | |
17a1d0a9 | 290 | const Task*, |
92e059d8 ILT |
291 | const Input_objects*, |
292 | Symbol_table*, | |
293 | Layout*, | |
294 | Workqueue*); | |
295 | ||
296 | // Queue up the final set of tasks. | |
61ba1cf9 ILT |
297 | extern void |
298 | queue_final_tasks(const General_options&, | |
299 | const Input_objects*, | |
300 | const Symbol_table*, | |
27bc2bce | 301 | Layout*, |
61ba1cf9 ILT |
302 | Workqueue*, |
303 | Output_file* of); | |
304 | ||
bae7f79e ILT |
305 | } // End namespace gold. |
306 | ||
307 | #endif // !defined(GOLD_GOLD_H) |