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.
30 #include <sys/types.h>
34 # define _(String) gettext (String)
36 # define N_(String) gettext_noop (String)
38 # define N_(String) (String)
41 # define gettext(Msgid) (Msgid)
42 # define dgettext(Domainname, Msgid) (Msgid)
43 # define dcgettext(Domainname, Msgid, Category) (Msgid)
44 # define textdomain(Domainname) while (0) /* nothing */
45 # define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
46 # define _(String) (String)
47 # define N_(String) (String)
50 // Figure out how to get a hash set and a hash map.
52 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
54 #include <tr1/unordered_set>
55 #include <tr1/unordered_map>
57 // We need a template typedef here.
59 #define Unordered_set std::tr1::unordered_set
60 #define Unordered_map std::tr1::unordered_map
62 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
64 #include <ext/hash_map>
65 #include <ext/hash_set>
68 #define Unordered_set __gnu_cxx::hash_set
69 #define Unordered_map __gnu_cxx::hash_map
75 struct hash
<std::string
>
78 operator()(std::string s
) const
79 { return __stl_hash_string(s
.c_str()); }
86 operator()(T
* p
) const
87 { return reinterpret_cast<size_t>(p
); }
94 // The fallback is to just use set and map.
99 #define Unordered_set std::set
100 #define Unordered_map std::map
105 extern "C" ssize_t
pread(int, void*, size_t, off_t
);
111 // General declarations.
113 class General_options
;
115 class Input_argument_list
;
124 template<int size
, bool big_endian
>
125 struct Relocate_info
;
127 // Some basic types. For these we use lower case initial letters.
129 // For an offset in an input or output file, use off_t. Note that
130 // this will often be a 64-bit type even for a 32-bit build.
132 // The size of a section if we are going to look at the contents.
133 typedef size_t section_size_type
;
135 // An offset within a section when we are looking at the contents.
136 typedef ptrdiff_t section_offset_type
;
138 // The name of the program as used in error messages.
139 extern const char* program_name
;
141 // This function is called to exit the program. Status is true to
142 // exit success (0) and false to exit failure (1).
144 gold_exit(bool status
) ATTRIBUTE_NORETURN
;
146 // This function is called to emit an error message and then
147 // immediately exit with failure.
149 gold_fatal(const char* format
, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1
;
151 // This function is called to issue an error. This will cause gold to
152 // eventually exit with failure.
154 gold_error(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
156 // This function is called to issue a warning.
158 gold_warning(const char* msg
, ...) ATTRIBUTE_PRINTF_1
;
160 // This function is called to issue an error at the location of a
162 template<int size
, bool big_endian
>
164 gold_error_at_location(const Relocate_info
<size
, big_endian
>*,
165 size_t, off_t
, const char* format
, ...)
168 // This function is called to issue a warning at the location of a
170 template<int size
, bool big_endian
>
172 gold_warning_at_location(const Relocate_info
<size
, big_endian
>*,
173 size_t, off_t
, const char* format
, ...)
176 // This function is called to report an undefined symbol.
177 template<int size
, bool big_endian
>
179 gold_undefined_symbol(const Symbol
*,
180 const Relocate_info
<size
, big_endian
>*,
183 // This is function is called in some cases if we run out of memory.
185 gold_nomem() ATTRIBUTE_NORETURN
;
187 // This macro and function are used in cases which can not arise if
188 // the code is written correctly.
190 #define gold_unreachable() \
191 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
193 extern void do_gold_unreachable(const char*, int, const char*)
198 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
200 // Print version information.
202 print_version(bool print_short
);
204 // Get the version string.
206 get_version_string();
208 // Convert numeric types without unnoticed loss of precision.
209 template<typename To
, typename From
>
211 convert_types(const From from
)
214 gold_assert(static_cast<From
>(to
) == from
);
218 // A common case of convert_types<>: convert to section_size_type.
219 template<typename From
>
220 inline section_size_type
221 convert_to_section_size_type(const From from
)
222 { return convert_types
<section_size_type
, From
>(from
); }
224 // Queue up the first set of tasks.
226 queue_initial_tasks(const General_options
&,
234 // Queue up the middle set of tasks.
236 queue_middle_tasks(const General_options
&,
238 const Input_objects
*,
243 // Queue up the final set of tasks.
245 queue_final_tasks(const General_options
&,
246 const Input_objects
*,
252 } // End namespace gold.
254 #endif // !defined(GOLD_GOLD_H)