1 // gold.h -- general definitions for gold -*- C++ -*-
3 // Copyright 2006, 2007 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.
31 # define _(String) gettext (String)
33 # define N_(String) gettext_noop (String)
35 # define N_(String) (String)
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)
47 // Figure out how to get a hash set and a hash map.
49 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
51 #include <tr1/unordered_set>
52 #include <tr1/unordered_map>
54 // We need a template typedef here.
56 #define Unordered_set std::tr1::unordered_set
57 #define Unordered_map std::tr1::unordered_map
59 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
61 #include <ext/hash_map>
62 #include <ext/hash_set>
65 #define Unordered_set __gnu_cxx::hash_set
66 #define Unordered_map __gnu_cxx::hash_map
72 struct hash<std::string>
75 operator()(std::string s) const
76 { return __stl_hash_string(s.c_str()); }
83 operator()(T* p) const
84 { return reinterpret_cast<size_t>(p); }
91 // The fallback is to just use set and map.
96 #define Unordered_set std::set
97 #define Unordered_map std::map
102 extern "C" ssize_t pread(int, void*, size_t, off_t);
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.
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.
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.
122 #ifdef HAVE_MEMBER_TEMPLATE_SPECIFICATIONS
124 #define SELECT_SIZE_NAME(size) <size>
125 #define SELECT_SIZE(size)
126 #define SELECT_SIZE_ONLY(size)
128 #define ACCEPT_SIZE_ONLY
129 #define ACCEPT_SIZE_EXPLICIT(size)
131 #define SELECT_SIZE_ENDIAN_NAME(size, big_endian) <size, big_endian>
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
136 #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian)
138 #else // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
141 class Select_size { };
142 template<int size, bool big_endian>
143 class Select_size_endian { };
145 #define SELECT_SIZE_NAME(size)
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>
150 #define ACCEPT_SIZE_EXPLICIT(size) , Select_size<size>
152 #define SELECT_SIZE_ENDIAN_NAME(size, big_endian)
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>
159 #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian) \
160 , Select_size_endian<size, big_endian>
162 #endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
164 } // End namespace gold.
169 class General_options;
171 class Input_argument_list;
179 template<int size, bool big_endian>
180 struct Relocate_info;
182 // The name of the program as used in error messages.
183 extern const char* program_name;
185 // This function is called to exit the program. Status is true to
186 // exit success (0) and false to exit failure (1).
188 gold_exit(bool status) ATTRIBUTE_NORETURN;
190 // This function is called to emit an error message and then
191 // immediately exit with failure.
193 gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
195 // This function is called to issue an error. This will cause gold to
196 // eventually exit with failure.
198 gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1;
200 // This function is called to issue a warning.
202 gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
204 // This function is called to issue an error at the location of a
206 template<int size, bool big_endian>
208 gold_error_at_location(const Relocate_info<size, big_endian>*,
209 size_t, off_t, const char* format, ...)
212 // This function is called to issue a warning at the location of a
214 template<int size, bool big_endian>
216 gold_warning_at_location(const Relocate_info<size, big_endian>*,
217 size_t, off_t, const char* format, ...)
220 // This function is called to report an undefined symbol.
221 template<int size, bool big_endian>
223 gold_undefined_symbol(const Symbol*,
224 const Relocate_info<size, big_endian>*,
227 // This is function is called in some cases if we run out of memory.
229 gold_nomem() ATTRIBUTE_NORETURN;
231 // This macro and function are used in cases which can not arise if
232 // the code is written correctly.
234 #define gold_unreachable() \
235 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
237 extern void do_gold_unreachable(const char*, int, const char*)
242 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
244 // Print version information.
246 print_version(bool print_short);
248 // Get the version string.
250 get_version_string();
252 // Queue up the first set of tasks.
254 queue_initial_tasks(const General_options&,
262 // Queue up the middle set of tasks.
264 queue_middle_tasks(const General_options&,
265 const Input_objects*,
270 // Queue up the final set of tasks.
272 queue_final_tasks(const General_options&,
273 const Input_objects*,
279 } // End namespace gold.
281 #endif // !defined(GOLD_GOLD_H)