* gold.h: Include <cstring> and <stdint.h>.
[deliverable/binutils-gdb.git] / gold / gold.h
1 // gold.h -- general definitions for gold -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008, 2009 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_GOLD_H
24 #define GOLD_GOLD_H
25
26 #include "config.h"
27 #include "ansidecl.h"
28
29 #include <cstddef>
30 #include <cstring>
31 #include <stdint.h>
32 #include <sys/types.h>
33
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
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
66 // Figure out how to get a hash set and a hash map.
67
68 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
69
70 #include <tr1/unordered_set>
71 #include <tr1/unordered_map>
72
73 // We need a template typedef here.
74
75 #define Unordered_set std::tr1::unordered_set
76 #define Unordered_map std::tr1::unordered_map
77
78 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
79
80 #include <ext/hash_map>
81 #include <ext/hash_set>
82 #include <string>
83
84 #define Unordered_set __gnu_cxx::hash_set
85 #define Unordered_map __gnu_cxx::hash_map
86
87 namespace __gnu_cxx
88 {
89
90 template<>
91 struct hash<std::string>
92 {
93 size_t
94 operator()(std::string s) const
95 { return __stl_hash_string(s.c_str()); }
96 };
97
98 template<typename T>
99 struct hash<T*>
100 {
101 size_t
102 operator()(T* p) const
103 { return reinterpret_cast<size_t>(p); }
104 };
105
106 }
107
108 #else
109
110 // The fallback is to just use set and map.
111
112 #include <set>
113 #include <map>
114
115 #define Unordered_set std::set
116 #define Unordered_map std::map
117
118 #endif
119
120 #ifndef HAVE_PREAD
121 extern "C" ssize_t pread(int, void*, size_t, off_t);
122 #endif
123
124 namespace gold
125 {
126
127 // General declarations.
128
129 class General_options;
130 class Command_line;
131 class Input_argument_list;
132 class Dirsearch;
133 class Input_objects;
134 class Mapfile;
135 class Symbol;
136 class Symbol_table;
137 class Layout;
138 class Task;
139 class Workqueue;
140 class Output_file;
141 template<int size, bool big_endian>
142 struct Relocate_info;
143
144 // Some basic types. For these we use lower case initial letters.
145
146 // For an offset in an input or output file, use off_t. Note that
147 // this will often be a 64-bit type even for a 32-bit build.
148
149 // The size of a section if we are going to look at the contents.
150 typedef size_t section_size_type;
151
152 // An offset within a section when we are looking at the contents.
153 typedef ptrdiff_t section_offset_type;
154
155 // The name of the program as used in error messages.
156 extern const char* program_name;
157
158 // This function is called to exit the program. Status is true to
159 // exit success (0) and false to exit failure (1).
160 extern void
161 gold_exit(bool status) ATTRIBUTE_NORETURN;
162
163 // This function is called to emit an error message and then
164 // immediately exit with failure.
165 extern void
166 gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
167
168 // This function is called to issue an error. This will cause gold to
169 // eventually exit with failure.
170 extern void
171 gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1;
172
173 // This function is called to issue a warning.
174 extern void
175 gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
176
177 // This function is called to print an informational message.
178 extern void
179 gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
180
181 // Work around a bug in gcc 4.3.0. http://gcc.gnu.org/PR35546 . This
182 // can probably be removed after the bug has been fixed for a while.
183 #ifdef HAVE_TEMPLATE_ATTRIBUTES
184 #define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4
185 #else
186 #define TEMPLATE_ATTRIBUTE_PRINTF_4
187 #endif
188
189 // This function is called to issue an error at the location of a
190 // reloc.
191 template<int size, bool big_endian>
192 extern void
193 gold_error_at_location(const Relocate_info<size, big_endian>*,
194 size_t, off_t, const char* format, ...)
195 TEMPLATE_ATTRIBUTE_PRINTF_4;
196
197 // This function is called to issue a warning at the location of a
198 // reloc.
199 template<int size, bool big_endian>
200 extern void
201 gold_warning_at_location(const Relocate_info<size, big_endian>*,
202 size_t, off_t, const char* format, ...)
203 TEMPLATE_ATTRIBUTE_PRINTF_4;
204
205 // This function is called to report an undefined symbol.
206 template<int size, bool big_endian>
207 extern void
208 gold_undefined_symbol(const Symbol*,
209 const Relocate_info<size, big_endian>*,
210 size_t, off_t);
211
212 // This is function is called in some cases if we run out of memory.
213 extern void
214 gold_nomem() ATTRIBUTE_NORETURN;
215
216 // This macro and function are used in cases which can not arise if
217 // the code is written correctly.
218
219 #define gold_unreachable() \
220 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
221
222 extern void do_gold_unreachable(const char*, int, const char*)
223 ATTRIBUTE_NORETURN;
224
225 // Assertion check.
226
227 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
228
229 // Print version information.
230 extern void
231 print_version(bool print_short);
232
233 // Get the version string.
234 extern const char*
235 get_version_string();
236
237 // Convert numeric types without unnoticed loss of precision.
238 template<typename To, typename From>
239 inline To
240 convert_types(const From from)
241 {
242 To to = from;
243 gold_assert(static_cast<From>(to) == from);
244 return to;
245 }
246
247 // A common case of convert_types<>: convert to section_size_type.
248 template<typename From>
249 inline section_size_type
250 convert_to_section_size_type(const From from)
251 { return convert_types<section_size_type, From>(from); }
252
253 // Queue up the first set of tasks.
254 extern void
255 queue_initial_tasks(const General_options&,
256 Dirsearch&,
257 const Command_line&,
258 Workqueue*,
259 Input_objects*,
260 Symbol_table*,
261 Layout*,
262 Mapfile*);
263
264 // Queue up the set of tasks to be done before
265 // the middle set of tasks. Only used when garbage
266 // collection is to be done.
267 extern void
268 queue_middle_gc_tasks(const General_options&,
269 const Task*,
270 const Input_objects*,
271 Symbol_table*,
272 Layout*,
273 Workqueue*,
274 Mapfile*);
275
276 // Queue up the middle set of tasks.
277 extern void
278 queue_middle_tasks(const General_options&,
279 const Task*,
280 const Input_objects*,
281 Symbol_table*,
282 Layout*,
283 Workqueue*,
284 Mapfile*);
285
286 // Queue up the final set of tasks.
287 extern void
288 queue_final_tasks(const General_options&,
289 const Input_objects*,
290 const Symbol_table*,
291 Layout*,
292 Workqueue*,
293 Output_file* of);
294
295 inline bool
296 is_prefix_of(const char* prefix, const char* str)
297 {
298 return strncmp(prefix, str, strlen(prefix)) == 0;
299 }
300
301 } // End namespace gold.
302
303 #endif // !defined(GOLD_GOLD_H)
This page took 0.0389 seconds and 5 git commands to generate.