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