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