* mapfile.cc: New file.
[deliverable/binutils-gdb.git] / gold / gold.h
1 // gold.h -- general definitions for gold -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
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.
12
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.
17
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.
22
23 #ifndef GOLD_GOLD_H
24 #define GOLD_GOLD_H
25
26 #include "config.h"
27 #include "ansidecl.h"
28
29 #include <cstddef>
30 #include <sys/types.h>
31
32 #ifdef ENABLE_NLS
33 # include <libintl.h>
34 # define _(String) gettext (String)
35 # ifdef gettext_noop
36 # define N_(String) gettext_noop (String)
37 # else
38 # define N_(String) (String)
39 # endif
40 #else
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)
48 #endif
49
50 // Figure out how to get a hash set and a hash map.
51
52 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
53
54 #include <tr1/unordered_set>
55 #include <tr1/unordered_map>
56
57 // We need a template typedef here.
58
59 #define Unordered_set std::tr1::unordered_set
60 #define Unordered_map std::tr1::unordered_map
61
62 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
63
64 #include <ext/hash_map>
65 #include <ext/hash_set>
66 #include <string>
67
68 #define Unordered_set __gnu_cxx::hash_set
69 #define Unordered_map __gnu_cxx::hash_map
70
71 namespace __gnu_cxx
72 {
73
74 template<>
75 struct hash<std::string>
76 {
77 size_t
78 operator()(std::string s) const
79 { return __stl_hash_string(s.c_str()); }
80 };
81
82 template<typename T>
83 struct hash<T*>
84 {
85 size_t
86 operator()(T* p) const
87 { return reinterpret_cast<size_t>(p); }
88 };
89
90 }
91
92 #else
93
94 // The fallback is to just use set and map.
95
96 #include <set>
97 #include <map>
98
99 #define Unordered_set std::set
100 #define Unordered_map std::map
101
102 #endif
103
104 #ifndef HAVE_PREAD
105 extern "C" ssize_t pread(int, void*, size_t, off_t);
106 #endif
107
108 namespace gold
109 {
110
111 // General declarations.
112
113 class General_options;
114 class Command_line;
115 class Input_argument_list;
116 class Dirsearch;
117 class Input_objects;
118 class Mapfile;
119 class Symbol;
120 class Symbol_table;
121 class Layout;
122 class Task;
123 class Workqueue;
124 class Output_file;
125 template<int size, bool big_endian>
126 struct Relocate_info;
127
128 // Some basic types. For these we use lower case initial letters.
129
130 // For an offset in an input or output file, use off_t. Note that
131 // this will often be a 64-bit type even for a 32-bit build.
132
133 // The size of a section if we are going to look at the contents.
134 typedef size_t section_size_type;
135
136 // An offset within a section when we are looking at the contents.
137 typedef ptrdiff_t section_offset_type;
138
139 // The name of the program as used in error messages.
140 extern const char* program_name;
141
142 // This function is called to exit the program. Status is true to
143 // exit success (0) and false to exit failure (1).
144 extern void
145 gold_exit(bool status) ATTRIBUTE_NORETURN;
146
147 // This function is called to emit an error message and then
148 // immediately exit with failure.
149 extern void
150 gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
151
152 // This function is called to issue an error. This will cause gold to
153 // eventually exit with failure.
154 extern void
155 gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1;
156
157 // This function is called to issue a warning.
158 extern void
159 gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
160
161 // This function is called to print an informational message.
162 extern void
163 gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
164
165 // Work around a bug in gcc 4.3.0. http://gcc.gnu.org/PR35546 . This
166 // can probably be removed after the bug has been fixed for a while.
167 #ifdef HAVE_TEMPLATE_ATTRIBUTES
168 #define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4
169 #else
170 #define TEMPLATE_ATTRIBUTE_PRINTF_4
171 #endif
172
173 // This function is called to issue an error at the location of a
174 // reloc.
175 template<int size, bool big_endian>
176 extern void
177 gold_error_at_location(const Relocate_info<size, big_endian>*,
178 size_t, off_t, const char* format, ...)
179 TEMPLATE_ATTRIBUTE_PRINTF_4;
180
181 // This function is called to issue a warning at the location of a
182 // reloc.
183 template<int size, bool big_endian>
184 extern void
185 gold_warning_at_location(const Relocate_info<size, big_endian>*,
186 size_t, off_t, const char* format, ...)
187 TEMPLATE_ATTRIBUTE_PRINTF_4;
188
189 // This function is called to report an undefined symbol.
190 template<int size, bool big_endian>
191 extern void
192 gold_undefined_symbol(const Symbol*,
193 const Relocate_info<size, big_endian>*,
194 size_t, off_t);
195
196 // This is function is called in some cases if we run out of memory.
197 extern void
198 gold_nomem() ATTRIBUTE_NORETURN;
199
200 // This macro and function are used in cases which can not arise if
201 // the code is written correctly.
202
203 #define gold_unreachable() \
204 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
205
206 extern void do_gold_unreachable(const char*, int, const char*)
207 ATTRIBUTE_NORETURN;
208
209 // Assertion check.
210
211 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
212
213 // Print version information.
214 extern void
215 print_version(bool print_short);
216
217 // Get the version string.
218 extern const char*
219 get_version_string();
220
221 // Convert numeric types without unnoticed loss of precision.
222 template<typename To, typename From>
223 inline To
224 convert_types(const From from)
225 {
226 To to = from;
227 gold_assert(static_cast<From>(to) == from);
228 return to;
229 }
230
231 // A common case of convert_types<>: convert to section_size_type.
232 template<typename From>
233 inline section_size_type
234 convert_to_section_size_type(const From from)
235 { return convert_types<section_size_type, From>(from); }
236
237 // Queue up the first set of tasks.
238 extern void
239 queue_initial_tasks(const General_options&,
240 Dirsearch&,
241 const Command_line&,
242 Workqueue*,
243 Input_objects*,
244 Symbol_table*,
245 Layout*,
246 Mapfile*);
247
248 // Queue up the middle set of tasks.
249 extern void
250 queue_middle_tasks(const General_options&,
251 const Task*,
252 const Input_objects*,
253 Symbol_table*,
254 Layout*,
255 Workqueue*,
256 Mapfile*);
257
258 // Queue up the final set of tasks.
259 extern void
260 queue_final_tasks(const General_options&,
261 const Input_objects*,
262 const Symbol_table*,
263 Layout*,
264 Workqueue*,
265 Output_file* of);
266
267 } // End namespace gold.
268
269 #endif // !defined(GOLD_GOLD_H)
This page took 0.035406 seconds and 5 git commands to generate.