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