* libtool.m4: Update to libtool 2.2.6.
[binutils.git] / gold / gold.h
blob63df9942ffdbbd8ed51a21787b8005fb9e618945
1 // gold.h -- general definitions for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_GOLD_H
24 #define GOLD_GOLD_H
26 #include "config.h"
27 #include "ansidecl.h"
29 #include <cstddef>
30 #include <sys/types.h>
32 #ifndef ENABLE_NLS
33 // The Solaris version of locale.h always includes libintl.h. If we
34 // have been configured with --disable-nls then ENABLE_NLS will not
35 // be defined and the dummy definitions of bindtextdomain (et al)
36 // below will conflict with the defintions in libintl.h. So we
37 // define these values to prevent the bogus inclusion of libintl.h.
38 # define _LIBINTL_H
39 # define _LIBGETTEXT_H
40 #endif
42 // Always include <clocale> first to avoid conflicts with the macros
43 // used when ENABLE_NLS is not defined.
44 #include <clocale>
46 #ifdef ENABLE_NLS
47 # include <libintl.h>
48 # define _(String) gettext (String)
49 # ifdef gettext_noop
50 # define N_(String) gettext_noop (String)
51 # else
52 # define N_(String) (String)
53 # endif
54 #else
55 # define gettext(Msgid) (Msgid)
56 # define dgettext(Domainname, Msgid) (Msgid)
57 # define dcgettext(Domainname, Msgid, Category) (Msgid)
58 # define textdomain(Domainname) while (0) /* nothing */
59 # define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
60 # define _(String) (String)
61 # define N_(String) (String)
62 #endif
64 // Figure out how to get a hash set and a hash map.
66 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
68 #include <tr1/unordered_set>
69 #include <tr1/unordered_map>
71 // We need a template typedef here.
73 #define Unordered_set std::tr1::unordered_set
74 #define Unordered_map std::tr1::unordered_map
76 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
78 #include <ext/hash_map>
79 #include <ext/hash_set>
80 #include <string>
82 #define Unordered_set __gnu_cxx::hash_set
83 #define Unordered_map __gnu_cxx::hash_map
85 namespace __gnu_cxx
88 template<>
89 struct hash<std::string>
91 size_t
92 operator()(std::string s) const
93 { return __stl_hash_string(s.c_str()); }
96 template<typename T>
97 struct hash<T*>
99 size_t
100 operator()(T* p) const
101 { return reinterpret_cast<size_t>(p); }
106 #else
108 // The fallback is to just use set and map.
110 #include <set>
111 #include <map>
113 #define Unordered_set std::set
114 #define Unordered_map std::map
116 #endif
118 #ifndef HAVE_PREAD
119 extern "C" ssize_t pread(int, void*, size_t, off_t);
120 #endif
122 namespace gold
125 // General declarations.
127 class General_options;
128 class Command_line;
129 class Input_argument_list;
130 class Dirsearch;
131 class Input_objects;
132 class Mapfile;
133 class Symbol;
134 class Symbol_table;
135 class Layout;
136 class Task;
137 class Workqueue;
138 class Output_file;
139 template<int size, bool big_endian>
140 struct Relocate_info;
142 // Some basic types. For these we use lower case initial letters.
144 // For an offset in an input or output file, use off_t. Note that
145 // this will often be a 64-bit type even for a 32-bit build.
147 // The size of a section if we are going to look at the contents.
148 typedef size_t section_size_type;
150 // An offset within a section when we are looking at the contents.
151 typedef ptrdiff_t section_offset_type;
153 // The name of the program as used in error messages.
154 extern const char* program_name;
156 // This function is called to exit the program. Status is true to
157 // exit success (0) and false to exit failure (1).
158 extern void
159 gold_exit(bool status) ATTRIBUTE_NORETURN;
161 // This function is called to emit an error message and then
162 // immediately exit with failure.
163 extern void
164 gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
166 // This function is called to issue an error. This will cause gold to
167 // eventually exit with failure.
168 extern void
169 gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1;
171 // This function is called to issue a warning.
172 extern void
173 gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
175 // This function is called to print an informational message.
176 extern void
177 gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
179 // Work around a bug in gcc 4.3.0. http://gcc.gnu.org/PR35546 . This
180 // can probably be removed after the bug has been fixed for a while.
181 #ifdef HAVE_TEMPLATE_ATTRIBUTES
182 #define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4
183 #else
184 #define TEMPLATE_ATTRIBUTE_PRINTF_4
185 #endif
187 // This function is called to issue an error at the location of a
188 // reloc.
189 template<int size, bool big_endian>
190 extern void
191 gold_error_at_location(const Relocate_info<size, big_endian>*,
192 size_t, off_t, const char* format, ...)
193 TEMPLATE_ATTRIBUTE_PRINTF_4;
195 // This function is called to issue a warning at the location of a
196 // reloc.
197 template<int size, bool big_endian>
198 extern void
199 gold_warning_at_location(const Relocate_info<size, big_endian>*,
200 size_t, off_t, const char* format, ...)
201 TEMPLATE_ATTRIBUTE_PRINTF_4;
203 // This function is called to report an undefined symbol.
204 template<int size, bool big_endian>
205 extern void
206 gold_undefined_symbol(const Symbol*,
207 const Relocate_info<size, big_endian>*,
208 size_t, off_t);
210 // This is function is called in some cases if we run out of memory.
211 extern void
212 gold_nomem() ATTRIBUTE_NORETURN;
214 // This macro and function are used in cases which can not arise if
215 // the code is written correctly.
217 #define gold_unreachable() \
218 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
220 extern void do_gold_unreachable(const char*, int, const char*)
221 ATTRIBUTE_NORETURN;
223 // Assertion check.
225 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
227 // Print version information.
228 extern void
229 print_version(bool print_short);
231 // Get the version string.
232 extern const char*
233 get_version_string();
235 // Convert numeric types without unnoticed loss of precision.
236 template<typename To, typename From>
237 inline To
238 convert_types(const From from)
240 To to = from;
241 gold_assert(static_cast<From>(to) == from);
242 return to;
245 // A common case of convert_types<>: convert to section_size_type.
246 template<typename From>
247 inline section_size_type
248 convert_to_section_size_type(const From from)
249 { return convert_types<section_size_type, From>(from); }
251 // Queue up the first set of tasks.
252 extern void
253 queue_initial_tasks(const General_options&,
254 Dirsearch&,
255 const Command_line&,
256 Workqueue*,
257 Input_objects*,
258 Symbol_table*,
259 Layout*,
260 Mapfile*);
262 // Queue up the middle set of tasks.
263 extern void
264 queue_middle_tasks(const General_options&,
265 const Task*,
266 const Input_objects*,
267 Symbol_table*,
268 Layout*,
269 Workqueue*,
270 Mapfile*);
272 // Queue up the final set of tasks.
273 extern void
274 queue_final_tasks(const General_options&,
275 const Input_objects*,
276 const Symbol_table*,
277 Layout*,
278 Workqueue*,
279 Output_file* of);
281 } // End namespace gold.
283 #endif // !defined(GOLD_GOLD_H)