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