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
);
108 // General declarations.
110 class General_options
;
112 class Input_argument_list
;
121 template<int size
, bool big_endian
>
122 struct Relocate_info
;
124 // Some basic types. For these we use lower case initial letters.
126 // For an offset in an input or output file, use off_t. Note that
127 // this will often be a 64-bit type even for a 32-bit build.
129 // The size of a section if we are going to look at the contents.
130 typedef size_t section_size_type
;
132 // An offset within a section when we are looking at the contents.
133 typedef ptrdiff_t section_offset_type
;
135 // The name of the program as used in error messages.
136 extern const char* program_name
;
138 // This function is called to exit the program. Status is true to
139 // exit success (0) and false to exit failure (1).
141 gold_exit(bool status
) ATTRIBUTE_NORETURN
;
143 // This function is called to emit an error message and then
144 // immediately exit with failure.
146 gold_fatal(const char* format
, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1
;
148 // This function is called to issue an error. This will cause gold to
149 // eventually exit with failure.
151 gold_error(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
153 // This function is called to issue a warning.
155 gold_warning(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
157 // This function is called to issue an error at the location of a
159 template<int size
, bool big_endian
>
161 gold_error_at_location(const Relocate_info
<size
, big_endian
>*,
162 size_t, off_t
, const char* format
, ...)
165 // This function is called to issue a warning at the location of a
167 template<int size
, bool big_endian
>
169 gold_warning_at_location(const Relocate_info
<size
, big_endian
>*,
170 size_t, off_t
, const char* format
, ...)
173 // This function is called to report an undefined symbol.
174 template<int size
, bool big_endian
>
176 gold_undefined_symbol(const Symbol
*,
177 const Relocate_info
<size
, big_endian
>*,
180 // This is function is called in some cases if we run out of memory.
182 gold_nomem() ATTRIBUTE_NORETURN
;
184 // This macro and function are used in cases which can not arise if
185 // the code is written correctly.
187 #define gold_unreachable() \
188 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
190 extern void do_gold_unreachable(const char*, int, const char*)
195 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
197 // Print version information.
199 print_version(bool print_short
);
201 // Get the version string.
203 get_version_string();
205 // Convert numeric types without unnoticed loss of precision.
206 template<typename To
, typename From
>
208 convert_types(const From from
)
211 gold_assert(static_cast<From
>(to
) == from
);
215 // A common case of convert_types<>: convert to section_size_type.
216 template<typename From
>
217 inline section_size_type
218 convert_to_section_size_type(const From from
)
219 { return convert_types
<section_size_type
, From
>(from
); }
221 // Queue up the first set of tasks.
223 queue_initial_tasks(const General_options
&,
231 // Queue up the middle set of tasks.
233 queue_middle_tasks(const General_options
&,
235 const Input_objects
*,
240 // Queue up the final set of tasks.
242 queue_final_tasks(const General_options
&,
243 const Input_objects
*,
249 } // End namespace gold.
251 #endif // !defined(GOLD_GOLD_H)