Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // gold.h -- general definitions for gold -*- C++ -*- |
2 | ||
3 | #ifndef GOLD_GOLD_H | |
6724bacc | 4 | #define GOLD_GOLD_H |
bae7f79e ILT |
5 | |
6 | #include "config.h" | |
7 | #include "ansidecl.h" | |
8 | ||
9 | #ifdef ENABLE_NLS | |
10 | # include <libintl.h> | |
11 | # define _(String) gettext (String) | |
12 | # ifdef gettext_noop | |
13 | # define N_(String) gettext_noop (String) | |
14 | # else | |
15 | # define N_(String) (String) | |
16 | # endif | |
17 | #else | |
18 | # define gettext(Msgid) (Msgid) | |
19 | # define dgettext(Domainname, Msgid) (Msgid) | |
20 | # define dcgettext(Domainname, Msgid, Category) (Msgid) | |
21 | # define textdomain(Domainname) while (0) /* nothing */ | |
22 | # define bindtextdomain(Domainname, Dirname) while (0) /* nothing */ | |
23 | # define _(String) (String) | |
24 | # define N_(String) (String) | |
25 | #endif | |
26 | ||
54dc6425 ILT |
27 | // Figure out how to get a hash set and a hash map. |
28 | ||
d288e464 | 29 | #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP) |
bae7f79e ILT |
30 | |
31 | #include <tr1/unordered_set> | |
32 | #include <tr1/unordered_map> | |
33 | ||
34 | // We need a template typedef here. | |
35 | ||
36 | #define Unordered_set std::tr1::unordered_set | |
37 | #define Unordered_map std::tr1::unordered_map | |
38 | ||
d288e464 | 39 | #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET) |
54dc6425 ILT |
40 | |
41 | #include <ext/hash_map> | |
42 | #include <ext/hash_set> | |
274e99f9 | 43 | #include <string> |
54dc6425 ILT |
44 | |
45 | #define Unordered_set __gnu_cxx::hash_set | |
46 | #define Unordered_map __gnu_cxx::hash_map | |
47 | ||
274e99f9 ILT |
48 | namespace __gnu_cxx |
49 | { | |
50 | ||
51 | template<> | |
52 | struct hash<std::string> | |
53 | { | |
54 | size_t | |
55 | operator()(std::string s) const | |
56 | { return __stl_hash_string(s.c_str()); } | |
57 | }; | |
58 | ||
59 | template<typename T> | |
60 | struct hash<T*> | |
61 | { | |
62 | size_t | |
63 | operator()(T* p) const | |
64 | { return reinterpret_cast<size_t>(p); } | |
65 | }; | |
66 | ||
67 | } | |
68 | ||
54dc6425 ILT |
69 | #else |
70 | ||
71 | // The fallback is to just use set and map. | |
72 | ||
73 | #include <set> | |
74 | #include <map> | |
75 | ||
76 | #define Unordered_set std::set | |
77 | #define Unordered_map std::map | |
78 | ||
79 | #endif | |
80 | ||
5482377d ILT |
81 | namespace gold |
82 | { | |
83 | // This is a hack to work around a problem with older versions of g++. | |
84 | // The problem is that they don't support calling a member template by | |
85 | // specifying the template parameters. It works to pass in an | |
86 | // argument for argument dependent lookup. | |
87 | ||
88 | // To use this, the member template method declaration should put | |
89 | // ACCEPT_SIZE or ACCEPT_SIZE_ENDIAN after the last parameter. If the | |
90 | // method takes no parameters, use ACCEPT_SIZE_ONLY or | |
91 | // ACCEPT_SIZE_ENDIAN_ONLY. | |
92 | ||
93 | // When calling the method, instead of using fn<size>, use fn | |
94 | // SELECT_SIZE_NAME or SELECT_SIZE_ENDIAN_NAME. And after the last | |
95 | // argument, put SELECT_SIZE(size) or SELECT_SIZE_ENDIAN(size, | |
96 | // big_endian). If there is only one argment, use the _ONLY variants. | |
97 | ||
98 | #ifdef HAVE_MEMBER_TEMPLATE_SPECIFICATIONS | |
99 | ||
593f47df | 100 | #define SELECT_SIZE_NAME(size) <size> |
5482377d ILT |
101 | #define SELECT_SIZE(size) |
102 | #define SELECT_SIZE_ONLY(size) | |
103 | #define ACCEPT_SIZE | |
104 | #define ACCEPT_SIZE_ONLY | |
91da9340 | 105 | #define ACCEPT_SIZE_EXPLICIT(size) |
5482377d | 106 | |
593f47df | 107 | #define SELECT_SIZE_ENDIAN_NAME(size, big_endian) <size, big_endian> |
5482377d ILT |
108 | #define SELECT_SIZE_ENDIAN(size, big_endian) |
109 | #define SELECT_SIZE_ENDIAN_ONLY(size, big_endian) | |
110 | #define ACCEPT_SIZE_ENDIAN | |
111 | #define ACCEPT_SIZE_ENDIAN_ONLY | |
91da9340 | 112 | #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian) |
5482377d ILT |
113 | |
114 | #else // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS) | |
115 | ||
116 | template<int size> | |
117 | class Select_size { }; | |
118 | template<int size, bool big_endian> | |
119 | class Select_size_endian { }; | |
120 | ||
593f47df | 121 | #define SELECT_SIZE_NAME(size) |
5482377d ILT |
122 | #define SELECT_SIZE(size) , Select_size<size>() |
123 | #define SELECT_SIZE_ONLY(size) Select_size<size>() | |
124 | #define ACCEPT_SIZE , Select_size<size> | |
125 | #define ACCEPT_SIZE_ONLY Select_size<size> | |
91da9340 | 126 | #define ACCEPT_SIZE_EXPLICIT(size) , Select_size<size> |
5482377d | 127 | |
593f47df | 128 | #define SELECT_SIZE_ENDIAN_NAME(size, big_endian) |
5482377d ILT |
129 | #define SELECT_SIZE_ENDIAN(size, big_endian) \ |
130 | , Select_size_endian<size, big_endian>() | |
131 | #define SELECT_SIZE_ENDIAN_ONLY(size, big_endian) \ | |
132 | Select_size_endian<size, big_endian>() | |
133 | #define ACCEPT_SIZE_ENDIAN , Select_size_endian<size, big_endian> | |
134 | #define ACCEPT_SIZE_ENDIAN_ONLY Select_size_endian<size, big_endian> | |
91da9340 ILT |
135 | #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian) \ |
136 | , Select_size_endian<size, big_endian> | |
5482377d ILT |
137 | |
138 | #endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS) | |
139 | ||
140 | } // End namespace gold. | |
141 | ||
bae7f79e ILT |
142 | namespace gold |
143 | { | |
144 | ||
61ba1cf9 | 145 | class General_options; |
5a6f7e2d | 146 | class Command_line; |
92e059d8 ILT |
147 | class Input_argument_list; |
148 | class Dirsearch; | |
61ba1cf9 ILT |
149 | class Input_objects; |
150 | class Symbol_table; | |
151 | class Layout; | |
152 | class Workqueue; | |
153 | class Output_file; | |
154 | ||
bae7f79e ILT |
155 | // The name of the program as used in error messages. |
156 | extern const char* program_name; | |
157 | ||
158 | // This function is called to exit the program. Status is true to | |
159 | // exit success (0) and false to exit failure (1). | |
160 | extern void | |
161 | gold_exit(bool status) ATTRIBUTE_NORETURN; | |
162 | ||
163 | // This function is called to emit an unexpected error message and a | |
164 | // newline, and then exit with failure. If PERRNO is true, it reports | |
165 | // the error in errno. | |
166 | extern void | |
167 | gold_fatal(const char* msg, bool perrno) ATTRIBUTE_NORETURN; | |
168 | ||
169 | // This is function is called in some cases if we run out of memory. | |
170 | extern void | |
171 | gold_nomem() ATTRIBUTE_NORETURN; | |
172 | ||
a3ad94ed ILT |
173 | // This macro and function are used in cases which can not arise if |
174 | // the code is written correctly. | |
175 | ||
176 | #define gold_unreachable() \ | |
177 | (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__)) | |
178 | ||
179 | extern void do_gold_unreachable(const char*, int, const char*) | |
180 | ATTRIBUTE_NORETURN; | |
181 | ||
182 | // Assertion check. | |
183 | ||
184 | #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0)) | |
bae7f79e | 185 | |
92e059d8 ILT |
186 | // Queue up the first set of tasks. |
187 | extern void | |
188 | queue_initial_tasks(const General_options&, | |
189 | const Dirsearch&, | |
5a6f7e2d | 190 | const Command_line&, |
92e059d8 ILT |
191 | Workqueue*, |
192 | Input_objects*, | |
193 | Symbol_table*, | |
194 | Layout*); | |
195 | ||
196 | // Queue up the middle set of tasks. | |
197 | extern void | |
198 | queue_middle_tasks(const General_options&, | |
199 | const Input_objects*, | |
200 | Symbol_table*, | |
201 | Layout*, | |
202 | Workqueue*); | |
203 | ||
204 | // Queue up the final set of tasks. | |
61ba1cf9 ILT |
205 | extern void |
206 | queue_final_tasks(const General_options&, | |
207 | const Input_objects*, | |
208 | const Symbol_table*, | |
209 | const Layout*, | |
210 | Workqueue*, | |
211 | Output_file* of); | |
212 | ||
bae7f79e ILT |
213 | } // End namespace gold. |
214 | ||
215 | #endif // !defined(GOLD_GOLD_H) |