* archive.cc (Library_base::should_include_member): Pull in object
[deliverable/binutils-gdb.git] / gold / parameters.h
1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008, 2009, 2010 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 template<int size, bool big_endian>
33 class Sized_target;
34 class Set_parameters_target_once;
35
36 // Here we define the Parameters class which simply holds simple
37 // general parameters which apply to the entire link. We use a global
38 // variable for this. The parameters class holds three types of data:
39 // 1) An Errors struct. Any part of the code that wants to log an
40 // error can use parameters->errors().
41 // 2) A const General_options. These are the options as read on
42 // the commandline.
43 // 3) Target information, such as size and endian-ness. This is
44 // available as soon as we've decided on the Target (after
45 // parsing the first .o file).
46 // 4) Whether we're doing a static link or not. This is set
47 // after all inputs have been read and we know if any is a
48 // dynamic library.
49
50 class Parameters
51 {
52 public:
53 Parameters();
54
55 // These should be called as soon as they are known.
56 void
57 set_errors(Errors* errors);
58
59 void
60 set_options(const General_options* options);
61
62 void
63 set_target(Target* target);
64
65 void
66 set_doing_static_link(bool doing_static_link);
67
68 // Return the error object.
69 Errors*
70 errors() const
71 { return this->errors_; }
72
73 // Whether the options are valid. This should not normally be
74 // called, but it is needed by gold_exit.
75 bool
76 options_valid() const
77 { return this->options_ != NULL; }
78
79 // Return the options object.
80 const General_options&
81 options() const
82 {
83 gold_assert(this->options_valid());
84 return *this->options_;
85 }
86
87 // Return whether the target field has been set.
88 bool
89 target_valid() const
90 { return this->target_ != NULL; }
91
92 // The target of the output file we are generating.
93 const Target&
94 target() const
95 {
96 gold_assert(this->target_valid());
97 return *this->target_;
98 }
99
100 // The Sized_target of the output file. The caller must request the
101 // right size and endianness.
102 template<int size, bool big_endian>
103 Sized_target<size, big_endian>*
104 sized_target() const
105 {
106 gold_assert(this->target_valid());
107 return static_cast<Sized_target<size, big_endian>*>(this->target_);
108 }
109
110 // Clear the target, for testing.
111 void
112 clear_target();
113
114 // Return true if TARGET is compatible with the current target.
115 bool
116 is_compatible_target(const Target*) const;
117
118 bool
119 doing_static_link() const
120 {
121 gold_assert(this->doing_static_link_valid_);
122 return this->doing_static_link_;
123 }
124
125 // This is just a copy of options().debug(). We make a copy so we
126 // don't have to #include options.h in order to inline
127 // is_debugging_enabled, below.
128 int
129 debug() const
130 {
131 // This can be called before the options are set up.
132 if (!this->options_valid())
133 return 0;
134 return debug_;
135 }
136
137 // Return the name of the entry symbol.
138 const char*
139 entry() const;
140
141 // A convenience routine for combining size and endianness. It also
142 // checks the HAVE_TARGET_FOO configure options and dies if the
143 // current target's size/endianness is not supported according to
144 // HAVE_TARGET_FOO. Otherwise it returns this enum
145 enum Target_size_endianness
146 { TARGET_32_LITTLE, TARGET_32_BIG, TARGET_64_LITTLE, TARGET_64_BIG };
147
148 Target_size_endianness
149 size_and_endianness() const;
150
151 // Set the incremental linking mode to INCREMENTAL_FULL. Used when
152 // the linker determines that an incremental update is not possible.
153 // Returns false if the incremental mode was INCREMENTAL_UPDATE,
154 // indicating that the linker should exit if an update is not possible.
155 bool
156 set_incremental_full();
157
158 // Return true if we need to prepare incremental linking information.
159 bool
160 incremental() const;
161
162 // Return true if we are doing an incremental update.
163 bool
164 incremental_update() const;
165
166 private:
167 void
168 set_target_once(Target*);
169
170 void
171 check_target_endianness();
172
173 friend class Set_parameters_target_once;
174
175 Errors* errors_;
176 const General_options* options_;
177 Target* target_;
178 bool doing_static_link_valid_;
179 bool doing_static_link_;
180 int debug_;
181 int incremental_mode_;
182 Set_parameters_target_once* set_parameters_target_once_;
183 };
184
185 // This is a global variable.
186 extern const Parameters* parameters;
187
188 // We use free functions for these since they affect a global variable
189 // that is internal to parameters.cc.
190
191 extern void
192 set_parameters_errors(Errors* errors);
193
194 extern void
195 set_parameters_options(const General_options* options);
196
197 extern void
198 set_parameters_target(Target* target);
199
200 extern void
201 set_parameters_doing_static_link(bool doing_static_link);
202
203 extern bool
204 set_parameters_incremental_full();
205
206 // Ensure that the target to be valid by using the default target if
207 // necessary.
208
209 extern void
210 parameters_force_valid_target();
211
212 // Clear the current target, for testing.
213
214 extern void
215 parameters_clear_target();
216
217 // Return whether we are doing a particular debugging type. The
218 // argument is one of the flags from debug.h.
219
220 inline bool
221 is_debugging_enabled(unsigned int type)
222 { return (parameters->debug() & type) != 0; }
223
224 } // End namespace gold.
225
226 #endif // !defined(GOLD_PARAMETERS_H)
This page took 0.036803 seconds and 5 git commands to generate.