Commit | Line | Data |
---|---|---|
7e1edb90 ILT |
1 | // parameters.h -- general parameters for a link using gold -*- C++ -*- |
2 | ||
6cb15b7f ILT |
3 | // Copyright 2006, 2007 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 | ||
7e1edb90 ILT |
23 | #ifndef GOLD_PARAMETERS_H |
24 | #define GOLD_PARAMETERS_H | |
25 | ||
26 | namespace gold | |
27 | { | |
28 | ||
29 | class General_options; | |
75f2446e | 30 | class Errors; |
7e1edb90 ILT |
31 | |
32 | // Here we define the Parameters class which simply holds simple | |
33 | // general parameters which apply to the entire link. We use a global | |
34 | // variable for this. This is in contrast to the General_options | |
35 | // class, which holds the complete state of position independent | |
36 | // command line options. The hope is that Parameters will stay fairly | |
37 | // simple, so that if this turns into a library it will be clear how | |
38 | // these parameters should be set. | |
39 | ||
40 | class Parameters | |
41 | { | |
42 | public: | |
3c2fafa5 | 43 | Parameters(Errors*); |
75f2446e ILT |
44 | |
45 | // Return the error object. | |
46 | Errors* | |
47 | errors() const | |
48 | { return this->errors_; } | |
49 | ||
c7912668 ILT |
50 | // Whether to use threads. |
51 | bool | |
52 | threads() const | |
53 | { | |
54 | gold_assert(this->options_valid_); | |
55 | return this->threads_; | |
56 | } | |
57 | ||
75f2446e ILT |
58 | // Return the output file name. |
59 | const char* | |
60 | output_file_name() const | |
3c2fafa5 ILT |
61 | { |
62 | gold_assert(this->options_valid_); | |
63 | return this->output_file_name_; | |
64 | } | |
7e1edb90 ILT |
65 | |
66 | // Whether we are generating a regular executable. | |
67 | bool | |
68 | output_is_executable() const | |
3c2fafa5 ILT |
69 | { |
70 | gold_assert(this->output_file_type_ != OUTPUT_INVALID); | |
71 | return this->output_file_type_ == OUTPUT_EXECUTABLE; | |
72 | } | |
7e1edb90 ILT |
73 | |
74 | // Whether we are generating a shared library. | |
75 | bool | |
76 | output_is_shared() const | |
3c2fafa5 ILT |
77 | { |
78 | gold_assert(this->output_file_type_ != OUTPUT_INVALID); | |
79 | return this->output_file_type_ == OUTPUT_SHARED; | |
80 | } | |
7e1edb90 ILT |
81 | |
82 | // Whether we are generating an object file. | |
83 | bool | |
84 | output_is_object() const | |
3c2fafa5 ILT |
85 | { |
86 | gold_assert(this->output_file_type_ != OUTPUT_INVALID); | |
87 | return this->output_file_type_ == OUTPUT_OBJECT; | |
88 | } | |
7e1edb90 | 89 | |
436ca963 ILT |
90 | // Whether we are generating position-independent output. |
91 | // This is the case when generating either a shared library | |
92 | // or a regular executable with the --pic-executable option. | |
93 | // FIXME: support --pic-executable | |
94 | bool | |
95 | output_is_position_independent() const | |
96 | { return output_is_shared(); } | |
97 | ||
ad2d6943 ILT |
98 | // The target system root directory. This is NULL if there isn't |
99 | // one. | |
100 | const std::string& | |
101 | sysroot() const | |
3c2fafa5 ILT |
102 | { |
103 | gold_assert(this->options_valid_); | |
104 | return this->sysroot_; | |
105 | } | |
ad2d6943 | 106 | |
9e2dcb77 ILT |
107 | // Whether to strip all symbols. |
108 | bool | |
109 | strip_all() const | |
3c2fafa5 ILT |
110 | { |
111 | gold_assert(this->strip_ != STRIP_INVALID); | |
112 | return this->strip_ == STRIP_ALL; | |
113 | } | |
9e2dcb77 ILT |
114 | |
115 | // Whether to strip debugging information. | |
116 | bool | |
117 | strip_debug() const | |
3c2fafa5 ILT |
118 | { |
119 | gold_assert(this->strip_ != STRIP_INVALID); | |
120 | return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG; | |
121 | } | |
9e2dcb77 | 122 | |
02d2ba74 ILT |
123 | // Whether to strip debugging information that's not used by gdb. |
124 | bool | |
125 | strip_debug_gdb() const | |
126 | { | |
127 | gold_assert(this->strip_ != STRIP_INVALID); | |
128 | return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB; | |
129 | } | |
130 | ||
e2827e5f ILT |
131 | // Whether to permit unresolved references from shared libraries. |
132 | bool | |
133 | allow_shlib_undefined() const | |
134 | { | |
135 | gold_assert(this->options_valid_); | |
136 | return this->allow_shlib_undefined_; | |
137 | } | |
138 | ||
51b08ebe ILT |
139 | // Whether we are doing a symbolic link, in which all defined |
140 | // symbols are bound locally. | |
141 | bool | |
142 | symbolic() const | |
3c2fafa5 ILT |
143 | { |
144 | gold_assert(this->options_valid_); | |
145 | return this->symbolic_; | |
146 | } | |
147 | ||
a2b1aa12 ILT |
148 | // Whether we should demangle C++ symbols in our log messages. |
149 | bool | |
150 | demangle() const | |
151 | { return this->demangle_; } | |
152 | ||
a55ce7fe ILT |
153 | // Whether we should try to detect violations of the One Definition Rule. |
154 | bool | |
155 | detect_odr_violations() const | |
156 | { | |
157 | gold_assert(this->options_valid_); | |
158 | return this->detect_odr_violations_; | |
159 | } | |
160 | ||
3c2fafa5 ILT |
161 | // The general linker optimization level. |
162 | int | |
163 | optimization_level() const | |
164 | { | |
165 | gold_assert(this->options_valid_); | |
166 | return this->optimization_level_; | |
167 | } | |
168 | ||
169 | // Whether the -E/--export-dynamic flag is set. | |
170 | bool | |
171 | export_dynamic() const | |
172 | { | |
173 | gold_assert(this->options_valid_); | |
174 | return this->export_dynamic_; | |
175 | } | |
51b08ebe | 176 | |
c7912668 ILT |
177 | // Return the debug flags. These are the flags for which we should |
178 | // report internal debugging information. | |
179 | unsigned int | |
180 | debug() const | |
181 | { | |
182 | gold_assert(this->options_valid_); | |
183 | return this->debug_; | |
184 | } | |
185 | ||
b3b74ddc ILT |
186 | // Whether we are doing a static link--a link in which none of the |
187 | // input files are shared libraries. This is only known after we | |
188 | // have seen all the input files. | |
189 | bool | |
190 | doing_static_link() const | |
191 | { | |
192 | gold_assert(this->is_doing_static_link_valid_); | |
193 | return this->doing_static_link_; | |
194 | } | |
195 | ||
9025d29d ILT |
196 | // The size of the output file we are generating. This should |
197 | // return 32 or 64. | |
198 | int | |
199 | get_size() const | |
200 | { | |
201 | gold_assert(this->is_size_and_endian_valid_); | |
202 | return this->size_; | |
203 | } | |
204 | ||
205 | // Whether the output is big endian. | |
206 | bool | |
207 | is_big_endian() const | |
208 | { | |
209 | gold_assert(this->is_size_and_endian_valid_); | |
210 | return this->is_big_endian_; | |
211 | } | |
212 | ||
3c2fafa5 ILT |
213 | // Set values recorded from options. |
214 | void | |
215 | set_from_options(const General_options*); | |
436ca963 | 216 | |
b3b74ddc ILT |
217 | // Set whether we are doing a static link. |
218 | void | |
219 | set_doing_static_link(bool doing_static_link); | |
220 | ||
9025d29d ILT |
221 | // Set the size and endianness. |
222 | void | |
223 | set_size_and_endianness(int size, bool is_big_endian); | |
224 | ||
7e1edb90 ILT |
225 | private: |
226 | // The types of output files. | |
227 | enum Output_file_type | |
228 | { | |
3c2fafa5 ILT |
229 | // Uninitialized. |
230 | OUTPUT_INVALID, | |
7e1edb90 ILT |
231 | // Generating executable. |
232 | OUTPUT_EXECUTABLE, | |
233 | // Generating shared library. | |
234 | OUTPUT_SHARED, | |
235 | // Generating object file. | |
236 | OUTPUT_OBJECT | |
237 | }; | |
238 | ||
9e2dcb77 ILT |
239 | // Which symbols to strip. |
240 | enum Strip | |
241 | { | |
3c2fafa5 ILT |
242 | // Uninitialize. |
243 | STRIP_INVALID, | |
9e2dcb77 ILT |
244 | // Don't strip any symbols. |
245 | STRIP_NONE, | |
246 | // Strip all symbols. | |
247 | STRIP_ALL, | |
248 | // Strip debugging information. | |
02d2ba74 ILT |
249 | STRIP_DEBUG, |
250 | // Strip debugging information that's not used by gdb (at least <= 6.7) | |
251 | STRIP_DEBUG_UNUSED_BY_GDB | |
9e2dcb77 ILT |
252 | }; |
253 | ||
75f2446e ILT |
254 | // A pointer to the error handling object. |
255 | Errors* errors_; | |
256 | ||
3c2fafa5 ILT |
257 | // Whether the fields set from the options are valid. |
258 | bool options_valid_; | |
c7912668 ILT |
259 | // Whether to use threads. |
260 | bool threads_; | |
75f2446e ILT |
261 | // The output file name. |
262 | const char* output_file_name_; | |
7e1edb90 ILT |
263 | // The type of the output file. |
264 | Output_file_type output_file_type_; | |
ad2d6943 ILT |
265 | // The target system root directory. |
266 | std::string sysroot_; | |
9e2dcb77 ILT |
267 | // Which symbols to strip. |
268 | Strip strip_; | |
e2827e5f ILT |
269 | // Whether to allow undefined references from shared libraries. |
270 | bool allow_shlib_undefined_; | |
51b08ebe ILT |
271 | // Whether we are doing a symbolic link. |
272 | bool symbolic_; | |
a2b1aa12 ILT |
273 | // Whether we should demangle C++ symbols in our log messages. |
274 | bool demangle_; | |
a55ce7fe ILT |
275 | // Whether we try to detect One Definition Rule violations. |
276 | bool detect_odr_violations_; | |
3c2fafa5 ILT |
277 | // The optimization level. |
278 | int optimization_level_; | |
279 | // Whether the -E/--export-dynamic flag is set. | |
280 | bool export_dynamic_; | |
c7912668 ILT |
281 | // The debug flags. |
282 | unsigned int debug_; | |
9e2dcb77 | 283 | |
b3b74ddc ILT |
284 | // Whether the doing_static_link_ field is valid. |
285 | bool is_doing_static_link_valid_; | |
286 | // Whether we are doing a static link. | |
287 | bool doing_static_link_; | |
9025d29d ILT |
288 | // Whether the size_ and is_big_endian_ fields are valid. |
289 | bool is_size_and_endian_valid_; | |
290 | // The size of the output file--32 or 64. | |
291 | int size_; | |
292 | // Whether the output file is big endian. | |
293 | bool is_big_endian_; | |
7e1edb90 ILT |
294 | }; |
295 | ||
296 | // This is a global variable. | |
297 | extern const Parameters* parameters; | |
298 | ||
299 | // Initialize the global variable. | |
3c2fafa5 ILT |
300 | extern void initialize_parameters(Errors*); |
301 | ||
302 | // Set the options. | |
303 | extern void set_parameters_from_options(const General_options*); | |
7e1edb90 | 304 | |
9025d29d ILT |
305 | // Set the size and endianness of the global parameters variable. |
306 | extern void set_parameters_size_and_endianness(int size, bool is_big_endian); | |
307 | ||
b3b74ddc ILT |
308 | // Set whether we are doing a static link. |
309 | extern void set_parameters_doing_static_link(bool doing_static_link); | |
310 | ||
c7912668 ILT |
311 | // Return whether we are doing a particular debugging type. The |
312 | // argument is one of the flags from debug.h. | |
313 | ||
314 | inline bool | |
315 | is_debugging_enabled(unsigned int type) | |
316 | { return (parameters->debug() & type) != 0; } | |
317 | ||
7e1edb90 ILT |
318 | } // End namespace gold. |
319 | ||
eb4dfdd4 | 320 | #endif // !defined(GOLD_PARAMETERS_H) |