Don't try to delete the output file if we don't know its name yet.
[external/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 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
56   // Whether to use threads.
57   bool
58   threads() const
59   {
60     gold_assert(this->options_valid_);
61     return this->threads_;
62   }
63
64   // Return the output file name.
65   const char*
66   output_file_name() const
67   {
68     gold_assert(this->options_valid_);
69     return this->output_file_name_;
70   }
71
72   // Whether we are generating a regular executable.
73   bool
74   output_is_executable() const
75   {
76     gold_assert(this->output_file_type_ != OUTPUT_INVALID);
77     return this->output_file_type_ == OUTPUT_EXECUTABLE;
78   }
79
80   // Whether we are generating a shared library.
81   bool
82   output_is_shared() const
83   {
84     gold_assert(this->output_file_type_ != OUTPUT_INVALID);
85     return this->output_file_type_ == OUTPUT_SHARED;
86   }
87
88   // Whether we are generating an object file.
89   bool
90   output_is_object() const
91   {
92     gold_assert(this->output_file_type_ != OUTPUT_INVALID);
93     return this->output_file_type_ == OUTPUT_OBJECT;
94   }
95
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
104   // The target system root directory.  This is NULL if there isn't
105   // one.
106   const std::string&
107   sysroot() const
108   {
109     gold_assert(this->options_valid_);
110     return this->sysroot_;
111   }
112
113   // Whether to strip all symbols.
114   bool
115   strip_all() const
116   {
117     gold_assert(this->strip_ != STRIP_INVALID);
118     return this->strip_ == STRIP_ALL;
119   }
120
121   // Whether to strip debugging information.
122   bool
123   strip_debug() const
124   {
125     gold_assert(this->strip_ != STRIP_INVALID);
126     return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG;
127   }
128
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
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
145   // Whether we are doing a symbolic link, in which all defined
146   // symbols are bound locally.
147   bool
148   symbolic() const
149   {
150     gold_assert(this->options_valid_);
151     return this->symbolic_;
152   }
153
154   // Whether we should demangle C++ symbols in our log messages.
155   bool
156   demangle() const
157   { return this->demangle_; }
158
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
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   }
182
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
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
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
219   // Set values recorded from options.
220   void
221   set_from_options(const General_options*);
222
223   // Set whether we are doing a static link.
224   void
225   set_doing_static_link(bool doing_static_link);
226
227   // Set the size and endianness.
228   void
229   set_size_and_endianness(int size, bool is_big_endian);
230
231  private:
232   // The types of output files.
233   enum Output_file_type
234     {
235       // Uninitialized.
236       OUTPUT_INVALID,
237       // Generating executable.
238       OUTPUT_EXECUTABLE,
239       // Generating shared library.
240       OUTPUT_SHARED,
241       // Generating object file.
242       OUTPUT_OBJECT
243     };
244
245   // Which symbols to strip.
246   enum Strip
247   {
248     // Uninitialize.
249     STRIP_INVALID,
250     // Don't strip any symbols.
251     STRIP_NONE,
252     // Strip all symbols.
253     STRIP_ALL,
254     // Strip debugging information.
255     STRIP_DEBUG,
256     // Strip debugging information that's not used by gdb (at least <= 6.7)
257     STRIP_DEBUG_UNUSED_BY_GDB
258   };
259
260   // A pointer to the error handling object.
261   Errors* errors_;
262
263   // Whether the fields set from the options are valid.
264   bool options_valid_;
265   // Whether to use threads.
266   bool threads_;
267   // The output file name.
268   const char* output_file_name_;
269   // The type of the output file.
270   Output_file_type output_file_type_;
271   // The target system root directory.
272   std::string sysroot_;
273   // Which symbols to strip.
274   Strip strip_;
275   // Whether to allow undefined references from shared libraries.
276   bool allow_shlib_undefined_;
277   // Whether we are doing a symbolic link.
278   bool symbolic_;
279   // Whether we should demangle C++ symbols in our log messages.
280   bool demangle_;
281   // Whether we try to detect One Definition Rule violations.
282   bool detect_odr_violations_;
283   // The optimization level.
284   int optimization_level_;
285   // Whether the -E/--export-dynamic flag is set.
286   bool export_dynamic_;
287   // The debug flags.
288   unsigned int debug_;
289
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_;
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_;
300 };
301
302 // This is a global variable.
303 extern const Parameters* parameters;
304
305 // Initialize the global variable.
306 extern void initialize_parameters(Errors*);
307
308 // Set the options.
309 extern void set_parameters_from_options(const General_options*);
310
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
314 // Set whether we are doing a static link.
315 extern void set_parameters_doing_static_link(bool doing_static_link);
316
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
324 } // End namespace gold.
325
326 #endif // !defined(GOLD_PARAMETERS_H)