Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // gold.h -- general definitions for gold -*- C++ -*- |
2 | ||
6d03d481 | 3 | // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
6cb15b7f ILT |
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 | ||
bae7f79e | 23 | #ifndef GOLD_GOLD_H |
6724bacc | 24 | #define GOLD_GOLD_H |
bae7f79e ILT |
25 | |
26 | #include "config.h" | |
27 | #include "ansidecl.h" | |
28 | ||
cbb93e63 | 29 | #include <cstddef> |
e0ebcf42 ILT |
30 | #include <cstring> |
31 | #include <stdint.h> | |
cbb93e63 ILT |
32 | #include <sys/types.h> |
33 | ||
801647d1 ILT |
34 | #ifndef ENABLE_NLS |
35 | // The Solaris version of locale.h always includes libintl.h. If we | |
36 | // have been configured with --disable-nls then ENABLE_NLS will not | |
37 | // be defined and the dummy definitions of bindtextdomain (et al) | |
38 | // below will conflict with the defintions in libintl.h. So we | |
39 | // define these values to prevent the bogus inclusion of libintl.h. | |
40 | # define _LIBINTL_H | |
41 | # define _LIBGETTEXT_H | |
42 | #endif | |
43 | ||
44 | // Always include <clocale> first to avoid conflicts with the macros | |
45 | // used when ENABLE_NLS is not defined. | |
46 | #include <clocale> | |
47 | ||
bae7f79e ILT |
48 | #ifdef ENABLE_NLS |
49 | # include <libintl.h> | |
50 | # define _(String) gettext (String) | |
51 | # ifdef gettext_noop | |
52 | # define N_(String) gettext_noop (String) | |
53 | # else | |
54 | # define N_(String) (String) | |
55 | # endif | |
56 | #else | |
57 | # define gettext(Msgid) (Msgid) | |
58 | # define dgettext(Domainname, Msgid) (Msgid) | |
59 | # define dcgettext(Domainname, Msgid, Category) (Msgid) | |
60 | # define textdomain(Domainname) while (0) /* nothing */ | |
61 | # define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ | |
62 | # define _(String) (String) | |
63 | # define N_(String) (String) | |
64 | #endif | |
65 | ||
54dc6425 ILT |
66 | // Figure out how to get a hash set and a hash map. |
67 | ||
40fde488 CD |
68 | #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP) \ |
69 | && defined(HAVE_TR1_UNORDERED_MAP_REHASH) | |
bae7f79e ILT |
70 | |
71 | #include <tr1/unordered_set> | |
72 | #include <tr1/unordered_map> | |
73 | ||
74 | // We need a template typedef here. | |
75 | ||
76 | #define Unordered_set std::tr1::unordered_set | |
77 | #define Unordered_map std::tr1::unordered_map | |
78 | ||
e55bde5e ILT |
79 | #define reserve_unordered_map(map, n) ((map)->rehash(n)) |
80 | ||
d288e464 | 81 | #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET) |
54dc6425 ILT |
82 | |
83 | #include <ext/hash_map> | |
84 | #include <ext/hash_set> | |
274e99f9 | 85 | #include <string> |
54dc6425 ILT |
86 | |
87 | #define Unordered_set __gnu_cxx::hash_set | |
88 | #define Unordered_map __gnu_cxx::hash_map | |
89 | ||
274e99f9 ILT |
90 | namespace __gnu_cxx |
91 | { | |
92 | ||
93 | template<> | |
94 | struct hash<std::string> | |
95 | { | |
96 | size_t | |
97 | operator()(std::string s) const | |
98 | { return __stl_hash_string(s.c_str()); } | |
99 | }; | |
100 | ||
101 | template<typename T> | |
102 | struct hash<T*> | |
103 | { | |
104 | size_t | |
105 | operator()(T* p) const | |
106 | { return reinterpret_cast<size_t>(p); } | |
107 | }; | |
108 | ||
109 | } | |
110 | ||
e55bde5e ILT |
111 | #define reserve_unordered_map(map, n) ((map)->resize(n)) |
112 | ||
54dc6425 ILT |
113 | #else |
114 | ||
115 | // The fallback is to just use set and map. | |
116 | ||
117 | #include <set> | |
118 | #include <map> | |
119 | ||
120 | #define Unordered_set std::set | |
121 | #define Unordered_map std::map | |
122 | ||
e55bde5e ILT |
123 | #define reserve_unordered_map(map, n) |
124 | ||
54dc6425 ILT |
125 | #endif |
126 | ||
82dcae9d ILT |
127 | #ifndef HAVE_PREAD |
128 | extern "C" ssize_t pread(int, void*, size_t, off_t); | |
129 | #endif | |
130 | ||
9201d894 ILT |
131 | #ifndef HAVE_FTRUNCATE |
132 | extern "C" int ftruncate(int, off_t); | |
133 | #endif | |
134 | ||
2f35ab9b ILT |
135 | #ifndef HAVE_MREMAP |
136 | #define MREMAP_MAYMOVE 1 | |
fd03461a ILT |
137 | extern "C" void *mremap(void *, size_t, size_t, int, ...); |
138 | #endif | |
139 | ||
140 | #ifndef HAVE_FFSLL | |
141 | extern "C" int ffsll(long long); | |
2f35ab9b ILT |
142 | #endif |
143 | ||
5482377d ILT |
144 | namespace gold |
145 | { | |
5482377d | 146 | |
8383303e | 147 | // General declarations. |
bae7f79e | 148 | |
61ba1cf9 | 149 | class General_options; |
5a6f7e2d | 150 | class Command_line; |
92e059d8 ILT |
151 | class Input_argument_list; |
152 | class Dirsearch; | |
61ba1cf9 | 153 | class Input_objects; |
7d9e3d98 | 154 | class Mapfile; |
75f2446e | 155 | class Symbol; |
61ba1cf9 ILT |
156 | class Symbol_table; |
157 | class Layout; | |
17a1d0a9 | 158 | class Task; |
61ba1cf9 ILT |
159 | class Workqueue; |
160 | class Output_file; | |
75f2446e ILT |
161 | template<int size, bool big_endian> |
162 | struct Relocate_info; | |
61ba1cf9 | 163 | |
8383303e ILT |
164 | // Some basic types. For these we use lower case initial letters. |
165 | ||
166 | // For an offset in an input or output file, use off_t. Note that | |
167 | // this will often be a 64-bit type even for a 32-bit build. | |
168 | ||
169 | // The size of a section if we are going to look at the contents. | |
170 | typedef size_t section_size_type; | |
171 | ||
172 | // An offset within a section when we are looking at the contents. | |
173 | typedef ptrdiff_t section_offset_type; | |
174 | ||
bae7f79e ILT |
175 | // The name of the program as used in error messages. |
176 | extern const char* program_name; | |
177 | ||
178 | // This function is called to exit the program. Status is true to | |
179 | // exit success (0) and false to exit failure (1). | |
180 | extern void | |
181 | gold_exit(bool status) ATTRIBUTE_NORETURN; | |
182 | ||
75f2446e ILT |
183 | // This function is called to emit an error message and then |
184 | // immediately exit with failure. | |
185 | extern void | |
186 | gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1; | |
187 | ||
188 | // This function is called to issue an error. This will cause gold to | |
189 | // eventually exit with failure. | |
190 | extern void | |
191 | gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1; | |
192 | ||
193 | // This function is called to issue a warning. | |
194 | extern void | |
195 | gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1; | |
196 | ||
c5818ff1 CC |
197 | // This function is called to print an informational message. |
198 | extern void | |
199 | gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1; | |
200 | ||
04bf7072 ILT |
201 | // Work around a bug in gcc 4.3.0. http://gcc.gnu.org/PR35546 . This |
202 | // can probably be removed after the bug has been fixed for a while. | |
203 | #ifdef HAVE_TEMPLATE_ATTRIBUTES | |
204 | #define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4 | |
205 | #else | |
206 | #define TEMPLATE_ATTRIBUTE_PRINTF_4 | |
207 | #endif | |
208 | ||
75f2446e ILT |
209 | // This function is called to issue an error at the location of a |
210 | // reloc. | |
211 | template<int size, bool big_endian> | |
212 | extern void | |
213 | gold_error_at_location(const Relocate_info<size, big_endian>*, | |
214 | size_t, off_t, const char* format, ...) | |
04bf7072 | 215 | TEMPLATE_ATTRIBUTE_PRINTF_4; |
75f2446e ILT |
216 | |
217 | // This function is called to issue a warning at the location of a | |
218 | // reloc. | |
219 | template<int size, bool big_endian> | |
220 | extern void | |
221 | gold_warning_at_location(const Relocate_info<size, big_endian>*, | |
222 | size_t, off_t, const char* format, ...) | |
04bf7072 | 223 | TEMPLATE_ATTRIBUTE_PRINTF_4; |
75f2446e | 224 | |
f073bbf7 CD |
225 | // This function is called to report an undefined symbol without |
226 | // a relocation (e.g., referenced by a dynamic object). SYM is | |
227 | // the undefined symbol. The file name associated with the SYM | |
228 | // is used to print a location for the undefined symbol. | |
229 | extern void | |
230 | gold_undefined_symbol(const Symbol*); | |
231 | ||
232 | // This function is called to report an undefined symbol resulting | |
233 | // from a relocation. SYM is the undefined symbol. RELINFO is the | |
234 | // general relocation info. RELNUM is the number of the reloc, | |
235 | // and RELOFFSET is the reloc's offset. | |
75f2446e | 236 | template<int size, bool big_endian> |
bae7f79e | 237 | extern void |
f073bbf7 CD |
238 | gold_undefined_symbol_at_location(const Symbol*, |
239 | const Relocate_info<size, big_endian>*, | |
240 | size_t, off_t); | |
bae7f79e ILT |
241 | |
242 | // This is function is called in some cases if we run out of memory. | |
243 | extern void | |
244 | gold_nomem() ATTRIBUTE_NORETURN; | |
245 | ||
a3ad94ed ILT |
246 | // This macro and function are used in cases which can not arise if |
247 | // the code is written correctly. | |
248 | ||
249 | #define gold_unreachable() \ | |
250 | (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__)) | |
251 | ||
252 | extern void do_gold_unreachable(const char*, int, const char*) | |
253 | ATTRIBUTE_NORETURN; | |
254 | ||
255 | // Assertion check. | |
256 | ||
257 | #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0)) | |
bae7f79e | 258 | |
8486ee48 ILT |
259 | // Print version information. |
260 | extern void | |
261 | print_version(bool print_short); | |
262 | ||
4f211c8b ILT |
263 | // Get the version string. |
264 | extern const char* | |
265 | get_version_string(); | |
266 | ||
8383303e ILT |
267 | // Convert numeric types without unnoticed loss of precision. |
268 | template<typename To, typename From> | |
269 | inline To | |
270 | convert_types(const From from) | |
271 | { | |
272 | To to = from; | |
9bb53bf8 | 273 | gold_assert(static_cast<From>(to) == from); |
8383303e ILT |
274 | return to; |
275 | } | |
276 | ||
277 | // A common case of convert_types<>: convert to section_size_type. | |
278 | template<typename From> | |
279 | inline section_size_type | |
280 | convert_to_section_size_type(const From from) | |
281 | { return convert_types<section_size_type, From>(from); } | |
282 | ||
92e059d8 ILT |
283 | // Queue up the first set of tasks. |
284 | extern void | |
285 | queue_initial_tasks(const General_options&, | |
17a1d0a9 | 286 | Dirsearch&, |
5a6f7e2d | 287 | const Command_line&, |
92e059d8 ILT |
288 | Workqueue*, |
289 | Input_objects*, | |
290 | Symbol_table*, | |
7d9e3d98 ILT |
291 | Layout*, |
292 | Mapfile*); | |
92e059d8 | 293 | |
6d03d481 ST |
294 | // Queue up the set of tasks to be done before |
295 | // the middle set of tasks. Only used when garbage | |
296 | // collection is to be done. | |
297 | extern void | |
298 | queue_middle_gc_tasks(const General_options&, | |
299 | const Task*, | |
300 | const Input_objects*, | |
301 | Symbol_table*, | |
302 | Layout*, | |
303 | Workqueue*, | |
304 | Mapfile*); | |
305 | ||
92e059d8 ILT |
306 | // Queue up the middle set of tasks. |
307 | extern void | |
308 | queue_middle_tasks(const General_options&, | |
17a1d0a9 | 309 | const Task*, |
92e059d8 ILT |
310 | const Input_objects*, |
311 | Symbol_table*, | |
312 | Layout*, | |
7d9e3d98 ILT |
313 | Workqueue*, |
314 | Mapfile*); | |
92e059d8 ILT |
315 | |
316 | // Queue up the final set of tasks. | |
61ba1cf9 ILT |
317 | extern void |
318 | queue_final_tasks(const General_options&, | |
319 | const Input_objects*, | |
320 | const Symbol_table*, | |
27bc2bce | 321 | Layout*, |
61ba1cf9 ILT |
322 | Workqueue*, |
323 | Output_file* of); | |
324 | ||
6d03d481 ST |
325 | inline bool |
326 | is_prefix_of(const char* prefix, const char* str) | |
327 | { | |
328 | return strncmp(prefix, str, strlen(prefix)) == 0; | |
329 | } | |
330 | ||
bae7f79e ILT |
331 | } // End namespace gold. |
332 | ||
333 | #endif // !defined(GOLD_GOLD_H) |