*** empty log message ***
[deliverable/binutils-gdb.git] / gold / parameters.h
CommitLineData
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
26namespace gold
27{
28
29class General_options;
75f2446e 30class Errors;
96803768 31class 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
41class 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
7019cd25
ILT
105 // Whether to emit relocations in the output.
106 bool
107 emit_relocs() const
108 { return this->emit_relocs_; }
109
ad2d6943
ILT
110 // The target system root directory. This is NULL if there isn't
111 // one.
112 const std::string&
113 sysroot() const
3c2fafa5
ILT
114 {
115 gold_assert(this->options_valid_);
116 return this->sysroot_;
117 }
ad2d6943 118
9e2dcb77
ILT
119 // Whether to strip all symbols.
120 bool
121 strip_all() const
3c2fafa5
ILT
122 {
123 gold_assert(this->strip_ != STRIP_INVALID);
124 return this->strip_ == STRIP_ALL;
125 }
9e2dcb77
ILT
126
127 // Whether to strip debugging information.
128 bool
129 strip_debug() const
3c2fafa5
ILT
130 {
131 gold_assert(this->strip_ != STRIP_INVALID);
132 return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG;
133 }
9e2dcb77 134
02d2ba74
ILT
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
e2827e5f
ILT
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
51b08ebe
ILT
151 // Whether we are doing a symbolic link, in which all defined
152 // symbols are bound locally.
153 bool
45aa233b 154 Bsymbolic() const
3c2fafa5
ILT
155 {
156 gold_assert(this->options_valid_);
157 return this->symbolic_;
158 }
159
a2b1aa12
ILT
160 // Whether we should demangle C++ symbols in our log messages.
161 bool
162 demangle() const
163 { return this->demangle_; }
164
a55ce7fe
ILT
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
45aa233b 173 // The general linker optimization level (-O).
3c2fafa5 174 int
45aa233b 175 optimize() const
3c2fafa5
ILT
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 }
51b08ebe 188
c7912668
ILT
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
b3b74ddc
ILT
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
fbfba508
ILT
208 // Return whether the target field has been set.
209 bool
210 is_target_valid() const
211 { return this->is_target_valid_; }
212
96803768
ILT
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
9025d29d
ILT
221 // The size of the output file we are generating. This should
222 // return 32 or 64.
223 int
224 get_size() const
225 {
96803768 226 gold_assert(this->is_target_valid_);
9025d29d
ILT
227 return this->size_;
228 }
229
230 // Whether the output is big endian.
231 bool
232 is_big_endian() const
233 {
96803768 234 gold_assert(this->is_target_valid_);
9025d29d
ILT
235 return this->is_big_endian_;
236 }
237
cd72c291
ILT
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
3c2fafa5
ILT
254 // Set values recorded from options.
255 void
256 set_from_options(const General_options*);
436ca963 257
b3b74ddc
ILT
258 // Set whether we are doing a static link.
259 void
260 set_doing_static_link(bool doing_static_link);
261
96803768 262 // Set the target.
9025d29d 263 void
96803768 264 set_target(Target* target);
9025d29d 265
7e1edb90
ILT
266 private:
267 // The types of output files.
268 enum Output_file_type
269 {
3c2fafa5
ILT
270 // Uninitialized.
271 OUTPUT_INVALID,
7e1edb90
ILT
272 // Generating executable.
273 OUTPUT_EXECUTABLE,
274 // Generating shared library.
275 OUTPUT_SHARED,
276 // Generating object file.
277 OUTPUT_OBJECT
278 };
279
9e2dcb77
ILT
280 // Which symbols to strip.
281 enum Strip
282 {
3c2fafa5
ILT
283 // Uninitialize.
284 STRIP_INVALID,
9e2dcb77
ILT
285 // Don't strip any symbols.
286 STRIP_NONE,
287 // Strip all symbols.
288 STRIP_ALL,
289 // Strip debugging information.
02d2ba74
ILT
290 STRIP_DEBUG,
291 // Strip debugging information that's not used by gdb (at least <= 6.7)
292 STRIP_DEBUG_UNUSED_BY_GDB
9e2dcb77
ILT
293 };
294
75f2446e
ILT
295 // A pointer to the error handling object.
296 Errors* errors_;
297
3c2fafa5
ILT
298 // Whether the fields set from the options are valid.
299 bool options_valid_;
c7912668
ILT
300 // Whether to use threads.
301 bool threads_;
75f2446e
ILT
302 // The output file name.
303 const char* output_file_name_;
7e1edb90
ILT
304 // The type of the output file.
305 Output_file_type output_file_type_;
7019cd25
ILT
306 // Whether to emit relocations (-q/--emit-relocs).
307 bool emit_relocs_;
ad2d6943
ILT
308 // The target system root directory.
309 std::string sysroot_;
9e2dcb77
ILT
310 // Which symbols to strip.
311 Strip strip_;
e2827e5f
ILT
312 // Whether to allow undefined references from shared libraries.
313 bool allow_shlib_undefined_;
51b08ebe
ILT
314 // Whether we are doing a symbolic link.
315 bool symbolic_;
a2b1aa12
ILT
316 // Whether we should demangle C++ symbols in our log messages.
317 bool demangle_;
a55ce7fe
ILT
318 // Whether we try to detect One Definition Rule violations.
319 bool detect_odr_violations_;
3c2fafa5
ILT
320 // The optimization level.
321 int optimization_level_;
322 // Whether the -E/--export-dynamic flag is set.
323 bool export_dynamic_;
c7912668
ILT
324 // The debug flags.
325 unsigned int debug_;
9e2dcb77 326
b3b74ddc
ILT
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_;
96803768
ILT
331 // Whether the target_ field is valid.
332 bool is_target_valid_;
333 // The target.
334 Target* target_;
9025d29d
ILT
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_;
cd72c291
ILT
339 // The maximum page size and common page size
340 int max_page_size_;
341 int common_page_size_;
7e1edb90
ILT
342};
343
344// This is a global variable.
345extern const Parameters* parameters;
346
347// Initialize the global variable.
3c2fafa5
ILT
348extern void initialize_parameters(Errors*);
349
350// Set the options.
351extern void set_parameters_from_options(const General_options*);
7e1edb90 352
96803768
ILT
353// Set the target recorded in the global parameters variable.
354extern void set_parameters_target(Target* target);
9025d29d 355
b3b74ddc
ILT
356// Set whether we are doing a static link.
357extern void set_parameters_doing_static_link(bool doing_static_link);
358
c7912668
ILT
359// Return whether we are doing a particular debugging type. The
360// argument is one of the flags from debug.h.
361
362inline bool
363is_debugging_enabled(unsigned int type)
364{ return (parameters->debug() & type) != 0; }
365
7e1edb90
ILT
366} // End namespace gold.
367
eb4dfdd4 368#endif // !defined(GOLD_PARAMETERS_H)
This page took 0.061913 seconds and 4 git commands to generate.