]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/parameters.h
Compress all debug sections.
[thirdparty/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 // The target system root directory. This is NULL if there isn't
106 // one.
107 const std::string&
108 sysroot() const
109 {
110 gold_assert(this->options_valid_);
111 return this->sysroot_;
112 }
113
114 // Whether to strip all symbols.
115 bool
116 strip_all() const
117 {
118 gold_assert(this->strip_ != STRIP_INVALID);
119 return this->strip_ == STRIP_ALL;
120 }
121
122 // Whether to strip debugging information.
123 bool
124 strip_debug() const
125 {
126 gold_assert(this->strip_ != STRIP_INVALID);
127 return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG;
128 }
129
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
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
146 // Whether we are doing a symbolic link, in which all defined
147 // symbols are bound locally.
148 bool
149 symbolic() const
150 {
151 gold_assert(this->options_valid_);
152 return this->symbolic_;
153 }
154
155 // Whether we should demangle C++ symbols in our log messages.
156 bool
157 demangle() const
158 { return this->demangle_; }
159
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
168 // The general linker optimization level.
169 int
170 optimization_level() const
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 }
183
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
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
203 // The target of the output file we are generating.
204 Target*
205 target() const
206 {
207 gold_assert(this->is_target_valid_);
208 return this->target_;
209 }
210
211 // The size of the output file we are generating. This should
212 // return 32 or 64.
213 int
214 get_size() const
215 {
216 gold_assert(this->is_target_valid_);
217 return this->size_;
218 }
219
220 // Whether the output is big endian.
221 bool
222 is_big_endian() const
223 {
224 gold_assert(this->is_target_valid_);
225 return this->is_big_endian_;
226 }
227
228 // Set values recorded from options.
229 void
230 set_from_options(const General_options*);
231
232 // Set whether we are doing a static link.
233 void
234 set_doing_static_link(bool doing_static_link);
235
236 // Set the target.
237 void
238 set_target(Target* target);
239
240 private:
241 // The types of output files.
242 enum Output_file_type
243 {
244 // Uninitialized.
245 OUTPUT_INVALID,
246 // Generating executable.
247 OUTPUT_EXECUTABLE,
248 // Generating shared library.
249 OUTPUT_SHARED,
250 // Generating object file.
251 OUTPUT_OBJECT
252 };
253
254 // Which symbols to strip.
255 enum Strip
256 {
257 // Uninitialize.
258 STRIP_INVALID,
259 // Don't strip any symbols.
260 STRIP_NONE,
261 // Strip all symbols.
262 STRIP_ALL,
263 // Strip debugging information.
264 STRIP_DEBUG,
265 // Strip debugging information that's not used by gdb (at least <= 6.7)
266 STRIP_DEBUG_UNUSED_BY_GDB
267 };
268
269 // A pointer to the error handling object.
270 Errors* errors_;
271
272 // Whether the fields set from the options are valid.
273 bool options_valid_;
274 // Whether to use threads.
275 bool threads_;
276 // The output file name.
277 const char* output_file_name_;
278 // The type of the output file.
279 Output_file_type output_file_type_;
280 // The target system root directory.
281 std::string sysroot_;
282 // Which symbols to strip.
283 Strip strip_;
284 // Whether to allow undefined references from shared libraries.
285 bool allow_shlib_undefined_;
286 // Whether we are doing a symbolic link.
287 bool symbolic_;
288 // Whether we should demangle C++ symbols in our log messages.
289 bool demangle_;
290 // Whether we try to detect One Definition Rule violations.
291 bool detect_odr_violations_;
292 // The optimization level.
293 int optimization_level_;
294 // Whether the -E/--export-dynamic flag is set.
295 bool export_dynamic_;
296 // The debug flags.
297 unsigned int debug_;
298
299 // Whether the doing_static_link_ field is valid.
300 bool is_doing_static_link_valid_;
301 // Whether we are doing a static link.
302 bool doing_static_link_;
303 // Whether the target_ field is valid.
304 bool is_target_valid_;
305 // The target.
306 Target* target_;
307 // The size of the output file--32 or 64.
308 int size_;
309 // Whether the output file is big endian.
310 bool is_big_endian_;
311 };
312
313 // This is a global variable.
314 extern const Parameters* parameters;
315
316 // Initialize the global variable.
317 extern void initialize_parameters(Errors*);
318
319 // Set the options.
320 extern void set_parameters_from_options(const General_options*);
321
322 // Set the target recorded in the global parameters variable.
323 extern void set_parameters_target(Target* target);
324
325 // Set whether we are doing a static link.
326 extern void set_parameters_doing_static_link(bool doing_static_link);
327
328 // Return whether we are doing a particular debugging type. The
329 // argument is one of the flags from debug.h.
330
331 inline bool
332 is_debugging_enabled(unsigned int type)
333 { return (parameters->debug() & type) != 0; }
334
335 } // End namespace gold.
336
337 #endif // !defined(GOLD_PARAMETERS_H)