Implement -q/--emit-relocs.
[deliverable/binutils-gdb.git] / gold / parameters.h
1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
2
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
23 #ifndef GOLD_PARAMETERS_H
24 #define GOLD_PARAMETERS_H
25
26 namespace gold
27 {
28
29 class General_options;
30 class Errors;
31 class Target;
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:
44 Parameters(Errors*);
45
46 // Return the error object.
47 Errors*
48 errors() const
49 { return this->errors_; }
50
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
57 // Whether to use threads.
58 bool
59 threads() const
60 {
61 gold_assert(this->options_valid_);
62 return this->threads_;
63 }
64
65 // Return the output file name.
66 const char*
67 output_file_name() const
68 {
69 gold_assert(this->options_valid_);
70 return this->output_file_name_;
71 }
72
73 // Whether we are generating a regular executable.
74 bool
75 output_is_executable() const
76 {
77 gold_assert(this->output_file_type_ != OUTPUT_INVALID);
78 return this->output_file_type_ == OUTPUT_EXECUTABLE;
79 }
80
81 // Whether we are generating a shared library.
82 bool
83 output_is_shared() const
84 {
85 gold_assert(this->output_file_type_ != OUTPUT_INVALID);
86 return this->output_file_type_ == OUTPUT_SHARED;
87 }
88
89 // Whether we are generating an object file.
90 bool
91 output_is_object() const
92 {
93 gold_assert(this->output_file_type_ != OUTPUT_INVALID);
94 return this->output_file_type_ == OUTPUT_OBJECT;
95 }
96
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
105 // Whether to emit relocations in the output.
106 bool
107 emit_relocs() const
108 { return this->emit_relocs_; }
109
110 // The target system root directory. This is NULL if there isn't
111 // one.
112 const std::string&
113 sysroot() const
114 {
115 gold_assert(this->options_valid_);
116 return this->sysroot_;
117 }
118
119 // Whether to strip all symbols.
120 bool
121 strip_all() const
122 {
123 gold_assert(this->strip_ != STRIP_INVALID);
124 return this->strip_ == STRIP_ALL;
125 }
126
127 // Whether to strip debugging information.
128 bool
129 strip_debug() const
130 {
131 gold_assert(this->strip_ != STRIP_INVALID);
132 return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG;
133 }
134
135 // Whether to strip debugging information that's not used by gdb.
136 bool
137 strip_debug_gdb() const
138 {
139 gold_assert(this->strip_ != STRIP_INVALID);
140 return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB;
141 }
142
143 // Whether to permit unresolved references from shared libraries.
144 bool
145 allow_shlib_undefined() const
146 {
147 gold_assert(this->options_valid_);
148 return this->allow_shlib_undefined_;
149 }
150
151 // Whether we are doing a symbolic link, in which all defined
152 // symbols are bound locally.
153 bool
154 Bsymbolic() const
155 {
156 gold_assert(this->options_valid_);
157 return this->symbolic_;
158 }
159
160 // Whether we should demangle C++ symbols in our log messages.
161 bool
162 demangle() const
163 { return this->demangle_; }
164
165 // Whether we should try to detect violations of the One Definition Rule.
166 bool
167 detect_odr_violations() const
168 {
169 gold_assert(this->options_valid_);
170 return this->detect_odr_violations_;
171 }
172
173 // The general linker optimization level (-O).
174 int
175 optimize() const
176 {
177 gold_assert(this->options_valid_);
178 return this->optimization_level_;
179 }
180
181 // Whether the -E/--export-dynamic flag is set.
182 bool
183 export_dynamic() const
184 {
185 gold_assert(this->options_valid_);
186 return this->export_dynamic_;
187 }
188
189 // Return the debug flags. These are the flags for which we should
190 // report internal debugging information.
191 unsigned int
192 debug() const
193 {
194 gold_assert(this->options_valid_);
195 return this->debug_;
196 }
197
198 // Whether we are doing a static link--a link in which none of the
199 // input files are shared libraries. This is only known after we
200 // have seen all the input files.
201 bool
202 doing_static_link() const
203 {
204 gold_assert(this->is_doing_static_link_valid_);
205 return this->doing_static_link_;
206 }
207
208 // Return whether the target field has been set.
209 bool
210 is_target_valid() const
211 { return this->is_target_valid_; }
212
213 // The target of the output file we are generating.
214 Target*
215 target() const
216 {
217 gold_assert(this->is_target_valid_);
218 return this->target_;
219 }
220
221 // The size of the output file we are generating. This should
222 // return 32 or 64.
223 int
224 get_size() const
225 {
226 gold_assert(this->is_target_valid_);
227 return this->size_;
228 }
229
230 // Whether the output is big endian.
231 bool
232 is_big_endian() const
233 {
234 gold_assert(this->is_target_valid_);
235 return this->is_big_endian_;
236 }
237
238 // The maximum page size
239 uint64_t
240 max_page_size() const
241 {
242 gold_assert(this->is_target_valid_);
243 return this->max_page_size_;
244 }
245
246 // The common page size
247 uint64_t
248 common_page_size() const
249 {
250 gold_assert(this->is_target_valid_);
251 return this->common_page_size_;
252 }
253
254 // Set values recorded from options.
255 void
256 set_from_options(const General_options*);
257
258 // Set whether we are doing a static link.
259 void
260 set_doing_static_link(bool doing_static_link);
261
262 // Set the target.
263 void
264 set_target(Target* target);
265
266 private:
267 // The types of output files.
268 enum Output_file_type
269 {
270 // Uninitialized.
271 OUTPUT_INVALID,
272 // Generating executable.
273 OUTPUT_EXECUTABLE,
274 // Generating shared library.
275 OUTPUT_SHARED,
276 // Generating object file.
277 OUTPUT_OBJECT
278 };
279
280 // Which symbols to strip.
281 enum Strip
282 {
283 // Uninitialize.
284 STRIP_INVALID,
285 // Don't strip any symbols.
286 STRIP_NONE,
287 // Strip all symbols.
288 STRIP_ALL,
289 // Strip debugging information.
290 STRIP_DEBUG,
291 // Strip debugging information that's not used by gdb (at least <= 6.7)
292 STRIP_DEBUG_UNUSED_BY_GDB
293 };
294
295 // A pointer to the error handling object.
296 Errors* errors_;
297
298 // Whether the fields set from the options are valid.
299 bool options_valid_;
300 // Whether to use threads.
301 bool threads_;
302 // The output file name.
303 const char* output_file_name_;
304 // The type of the output file.
305 Output_file_type output_file_type_;
306 // Whether to emit relocations (-q/--emit-relocs).
307 bool emit_relocs_;
308 // The target system root directory.
309 std::string sysroot_;
310 // Which symbols to strip.
311 Strip strip_;
312 // Whether to allow undefined references from shared libraries.
313 bool allow_shlib_undefined_;
314 // Whether we are doing a symbolic link.
315 bool symbolic_;
316 // Whether we should demangle C++ symbols in our log messages.
317 bool demangle_;
318 // Whether we try to detect One Definition Rule violations.
319 bool detect_odr_violations_;
320 // The optimization level.
321 int optimization_level_;
322 // Whether the -E/--export-dynamic flag is set.
323 bool export_dynamic_;
324 // The debug flags.
325 unsigned int debug_;
326
327 // Whether the doing_static_link_ field is valid.
328 bool is_doing_static_link_valid_;
329 // Whether we are doing a static link.
330 bool doing_static_link_;
331 // Whether the target_ field is valid.
332 bool is_target_valid_;
333 // The target.
334 Target* target_;
335 // The size of the output file--32 or 64.
336 int size_;
337 // Whether the output file is big endian.
338 bool is_big_endian_;
339 // The maximum page size and common page size
340 int max_page_size_;
341 int common_page_size_;
342 };
343
344 // This is a global variable.
345 extern const Parameters* parameters;
346
347 // Initialize the global variable.
348 extern void initialize_parameters(Errors*);
349
350 // Set the options.
351 extern void set_parameters_from_options(const General_options*);
352
353 // Set the target recorded in the global parameters variable.
354 extern void set_parameters_target(Target* target);
355
356 // Set whether we are doing a static link.
357 extern void set_parameters_doing_static_link(bool doing_static_link);
358
359 // Return whether we are doing a particular debugging type. The
360 // argument is one of the flags from debug.h.
361
362 inline bool
363 is_debugging_enabled(unsigned int type)
364 { return (parameters->debug() & type) != 0; }
365
366 } // End namespace gold.
367
368 #endif // !defined(GOLD_PARAMETERS_H)
This page took 0.037328 seconds and 5 git commands to generate.