From Craig Silverstein: Rework debug info code a bit, add option for
[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   // Return the output file name.
51   const char*
52   output_file_name() const
53   {
54     gold_assert(this->options_valid_);
55     return this->output_file_name_;
56   }
57
58   // Whether we are generating a regular executable.
59   bool
60   output_is_executable() const
61   {
62     gold_assert(this->output_file_type_ != OUTPUT_INVALID);
63     return this->output_file_type_ == OUTPUT_EXECUTABLE;
64   }
65
66   // Whether we are generating a shared library.
67   bool
68   output_is_shared() const
69   {
70     gold_assert(this->output_file_type_ != OUTPUT_INVALID);
71     return this->output_file_type_ == OUTPUT_SHARED;
72   }
73
74   // Whether we are generating an object file.
75   bool
76   output_is_object() const
77   {
78     gold_assert(this->output_file_type_ != OUTPUT_INVALID);
79     return this->output_file_type_ == OUTPUT_OBJECT;
80   }
81
82   // Whether we are generating position-independent output.
83   // This is the case when generating either a shared library
84   // or a regular executable with the --pic-executable option.
85   // FIXME: support --pic-executable
86   bool
87   output_is_position_independent() const
88   { return output_is_shared(); }
89
90   // The target system root directory.  This is NULL if there isn't
91   // one.
92   const std::string&
93   sysroot() const
94   {
95     gold_assert(this->options_valid_);
96     return this->sysroot_;
97   }
98
99   // Whether to strip all symbols.
100   bool
101   strip_all() const
102   {
103     gold_assert(this->strip_ != STRIP_INVALID);
104     return this->strip_ == STRIP_ALL;
105   }
106
107   // Whether to strip debugging information.
108   bool
109   strip_debug() const
110   {
111     gold_assert(this->strip_ != STRIP_INVALID);
112     return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG;
113   }
114
115   // Whether we are doing a symbolic link, in which all defined
116   // symbols are bound locally.
117   bool
118   symbolic() const
119   {
120     gold_assert(this->options_valid_);
121     return this->symbolic_;
122   }
123
124   // Whether we should try to detect violations of the One Definition Rule.
125   bool
126   detect_odr_violations() const
127   {
128     gold_assert(this->options_valid_);
129     return this->detect_odr_violations_;
130   }
131
132   // The general linker optimization level.
133   int
134   optimization_level() const
135   {
136     gold_assert(this->options_valid_);
137     return this->optimization_level_;
138   }
139
140   // Whether the -E/--export-dynamic flag is set.
141   bool
142   export_dynamic() const
143   {
144     gold_assert(this->options_valid_);
145     return this->export_dynamic_;
146   }
147
148   // Whether we are doing a static link--a link in which none of the
149   // input files are shared libraries.  This is only known after we
150   // have seen all the input files.
151   bool
152   doing_static_link() const
153   {
154     gold_assert(this->is_doing_static_link_valid_);
155     return this->doing_static_link_;
156   }
157
158   // The size of the output file we are generating.  This should
159   // return 32 or 64.
160   int
161   get_size() const
162   {
163     gold_assert(this->is_size_and_endian_valid_);
164     return this->size_;
165   }
166
167   // Whether the output is big endian.
168   bool
169   is_big_endian() const
170   {
171     gold_assert(this->is_size_and_endian_valid_);
172     return this->is_big_endian_;
173   }
174
175   // Set values recorded from options.
176   void
177   set_from_options(const General_options*);
178
179   // Set whether we are doing a static link.
180   void
181   set_doing_static_link(bool doing_static_link);
182
183   // Set the size and endianness.
184   void
185   set_size_and_endianness(int size, bool is_big_endian);
186
187  private:
188   // The types of output files.
189   enum Output_file_type
190     {
191       // Uninitialized.
192       OUTPUT_INVALID,
193       // Generating executable.
194       OUTPUT_EXECUTABLE,
195       // Generating shared library.
196       OUTPUT_SHARED,
197       // Generating object file.
198       OUTPUT_OBJECT
199     };
200
201   // Which symbols to strip.
202   enum Strip
203   {
204     // Uninitialize.
205     STRIP_INVALID,
206     // Don't strip any symbols.
207     STRIP_NONE,
208     // Strip all symbols.
209     STRIP_ALL,
210     // Strip debugging information.
211     STRIP_DEBUG
212   };
213
214   // A pointer to the error handling object.
215   Errors* errors_;
216
217   // Whether the fields set from the options are valid.
218   bool options_valid_;
219   // The output file name.
220   const char* output_file_name_;
221   // The type of the output file.
222   Output_file_type output_file_type_;
223   // The target system root directory.
224   std::string sysroot_;
225   // Which symbols to strip.
226   Strip strip_;
227   // Whether we are doing a symbolic link.
228   bool symbolic_;
229   // Whether we try to detect One Definition Rule violations.
230   bool detect_odr_violations_;
231   // The optimization level.
232   int optimization_level_;
233   // Whether the -E/--export-dynamic flag is set.
234   bool export_dynamic_;
235
236   // Whether the doing_static_link_ field is valid.
237   bool is_doing_static_link_valid_;
238   // Whether we are doing a static link.
239   bool doing_static_link_;
240   // Whether the size_ and is_big_endian_ fields are valid.
241   bool is_size_and_endian_valid_;
242   // The size of the output file--32 or 64.
243   int size_;
244   // Whether the output file is big endian.
245   bool is_big_endian_;
246 };
247
248 // This is a global variable.
249 extern const Parameters* parameters;
250
251 // Initialize the global variable.
252 extern void initialize_parameters(Errors*);
253
254 // Set the options.
255 extern void set_parameters_from_options(const General_options*);
256
257 // Set the size and endianness of the global parameters variable.
258 extern void set_parameters_size_and_endianness(int size, bool is_big_endian);
259
260 // Set whether we are doing a static link.
261 extern void set_parameters_doing_static_link(bool doing_static_link);
262
263 } // End namespace gold.
264
265 #endif // !defined(GOLD_PARAMETERS_H)