1 // gold.h -- general definitions for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009 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.
32 #include <sys/types.h>
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.
41 # define _LIBGETTEXT_H
44 // Always include <clocale> first to avoid conflicts with the macros
45 // used when ENABLE_NLS is not defined.
50 # define _(String) gettext (String)
52 # define N_(String) gettext_noop (String)
54 # define N_(String) (String)
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)
66 // Figure out how to get a hash set and a hash map.
68 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
70 #include <tr1/unordered_set>
71 #include <tr1/unordered_map>
73 // We need a template typedef here.
75 #define Unordered_set std::tr1::unordered_set
76 #define Unordered_map std::tr1::unordered_map
78 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
80 #include <ext/hash_map>
81 #include <ext/hash_set>
84 #define Unordered_set __gnu_cxx::hash_set
85 #define Unordered_map __gnu_cxx::hash_map
91 struct hash
<std::string
>
94 operator()(std::string s
) const
95 { return __stl_hash_string(s
.c_str()); }
102 operator()(T
* p
) const
103 { return reinterpret_cast<size_t>(p
); }
110 // The fallback is to just use set and map.
115 #define Unordered_set std::set
116 #define Unordered_map std::map
121 extern "C" ssize_t
pread(int, void*, size_t, off_t
);
124 #ifndef HAVE_FTRUNCATE
125 extern "C" int ftruncate(int, off_t
);
129 #define MREMAP_MAYMOVE 1
130 extern "C" void *mremap(void *, size_t, size_t, int, ...);
134 extern "C" int ffsll(long long);
140 // General declarations.
142 class General_options
;
144 class Input_argument_list
;
154 template<int size
, bool big_endian
>
155 struct Relocate_info
;
157 // Some basic types. For these we use lower case initial letters.
159 // For an offset in an input or output file, use off_t. Note that
160 // this will often be a 64-bit type even for a 32-bit build.
162 // The size of a section if we are going to look at the contents.
163 typedef size_t section_size_type
;
165 // An offset within a section when we are looking at the contents.
166 typedef ptrdiff_t section_offset_type
;
168 // The name of the program as used in error messages.
169 extern const char* program_name
;
171 // This function is called to exit the program. Status is true to
172 // exit success (0) and false to exit failure (1).
174 gold_exit(bool status
) ATTRIBUTE_NORETURN
;
176 // This function is called to emit an error message and then
177 // immediately exit with failure.
179 gold_fatal(const char* format
, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1
;
181 // This function is called to issue an error. This will cause gold to
182 // eventually exit with failure.
184 gold_error(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
186 // This function is called to issue a warning.
188 gold_warning(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
190 // This function is called to print an informational message.
192 gold_info(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
194 // Work around a bug in gcc 4.3.0. http://gcc.gnu.org/PR35546 . This
195 // can probably be removed after the bug has been fixed for a while.
196 #ifdef HAVE_TEMPLATE_ATTRIBUTES
197 #define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4
199 #define TEMPLATE_ATTRIBUTE_PRINTF_4
202 // This function is called to issue an error at the location of a
204 template<int size
, bool big_endian
>
206 gold_error_at_location(const Relocate_info
<size
, big_endian
>*,
207 size_t, off_t
, const char* format
, ...)
208 TEMPLATE_ATTRIBUTE_PRINTF_4
;
210 // This function is called to issue a warning at the location of a
212 template<int size
, bool big_endian
>
214 gold_warning_at_location(const Relocate_info
<size
, big_endian
>*,
215 size_t, off_t
, const char* format
, ...)
216 TEMPLATE_ATTRIBUTE_PRINTF_4
;
218 // This function is called to report an undefined symbol without
219 // a relocation (e.g., referenced by a dynamic object). SYM is
220 // the undefined symbol. The file name associated with the SYM
221 // is used to print a location for the undefined symbol.
223 gold_undefined_symbol(const Symbol
*);
225 // This function is called to report an undefined symbol resulting
226 // from a relocation. SYM is the undefined symbol. RELINFO is the
227 // general relocation info. RELNUM is the number of the reloc,
228 // and RELOFFSET is the reloc's offset.
229 template<int size
, bool big_endian
>
231 gold_undefined_symbol_at_location(const Symbol
*,
232 const Relocate_info
<size
, big_endian
>*,
235 // This is function is called in some cases if we run out of memory.
237 gold_nomem() ATTRIBUTE_NORETURN
;
239 // This macro and function are used in cases which can not arise if
240 // the code is written correctly.
242 #define gold_unreachable() \
243 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
245 extern void do_gold_unreachable(const char*, int, const char*)
250 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
252 // Print version information.
254 print_version(bool print_short
);
256 // Get the version string.
258 get_version_string();
260 // Convert numeric types without unnoticed loss of precision.
261 template<typename To
, typename From
>
263 convert_types(const From from
)
266 gold_assert(static_cast<From
>(to
) == from
);
270 // A common case of convert_types<>: convert to section_size_type.
271 template<typename From
>
272 inline section_size_type
273 convert_to_section_size_type(const From from
)
274 { return convert_types
<section_size_type
, From
>(from
); }
276 // Queue up the first set of tasks.
278 queue_initial_tasks(const General_options
&,
287 // Queue up the set of tasks to be done before
288 // the middle set of tasks. Only used when garbage
289 // collection is to be done.
291 queue_middle_gc_tasks(const General_options
&,
293 const Input_objects
*,
299 // Queue up the middle set of tasks.
301 queue_middle_tasks(const General_options
&,
303 const Input_objects
*,
309 // Queue up the final set of tasks.
311 queue_final_tasks(const General_options
&,
312 const Input_objects
*,
319 is_prefix_of(const char* prefix
, const char* str
)
321 return strncmp(prefix
, str
, strlen(prefix
)) == 0;
324 } // End namespace gold.
326 #endif // !defined(GOLD_GOLD_H)