Regenerate gold/Makefile.in.
[deliverable/binutils-gdb.git] / gold / parameters.cc
CommitLineData
7e1edb90
ILT
1// parameters.cc -- general parameters for a link using gold
2
4b95cf5c 3// Copyright (C) 2006-2014 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#include "gold.h"
24
ee1fe73e 25#include "debug.h"
7e1edb90 26#include "options.h"
96803768 27#include "target.h"
8851ecca 28#include "target-select.h"
7e1edb90
ILT
29
30namespace gold
31{
32
114dfbe1
ILT
33// Our local version of the variable, which is not const.
34
35static Parameters static_parameters;
36
37// The global variable.
38
39const Parameters* parameters = &static_parameters;
40
41// A helper class to set the target once.
42
43class Set_parameters_target_once : public Once
44{
45 public:
46 Set_parameters_target_once(Parameters* parameters)
47 : parameters_(parameters)
48 { }
49
50 protected:
51 void
52 do_run_once(void* arg)
53 { this->parameters_->set_target_once(static_cast<Target*>(arg)); }
54
55 private:
56 Parameters* parameters_;
57};
58
59// We only need one Set_parameters_target_once.
60
61static
62Set_parameters_target_once set_parameters_target_once(&static_parameters);
63
64// Class Parameters.
65
66Parameters::Parameters()
b490c0bb 67 : errors_(NULL), timer_(NULL), options_(NULL), target_(NULL),
114dfbe1 68 doing_static_link_valid_(false), doing_static_link_(false),
8c21d9d3 69 debug_(0), incremental_mode_(General_options::INCREMENTAL_OFF),
114dfbe1
ILT
70 set_parameters_target_once_(&set_parameters_target_once)
71 {
72 }
73
8851ecca 74void
2ea97941 75Parameters::set_errors(Errors* errors)
7e1edb90 76{
8851ecca 77 gold_assert(this->errors_ == NULL);
2ea97941 78 this->errors_ = errors;
3c2fafa5
ILT
79}
80
b490c0bb
CC
81void
82Parameters::set_timer(Timer* timer)
83{
84 gold_assert(this->timer_ == NULL);
85 this->timer_ = timer;
86}
87
3c2fafa5 88void
2ea97941 89Parameters::set_options(const General_options* options)
3c2fafa5 90{
8851ecca 91 gold_assert(!this->options_valid());
2ea97941 92 this->options_ = options;
ee1fe73e
ILT
93 // For speed, we convert the options() debug var from a string to an
94 // enum (from debug.h).
95 this->debug_ = debug_string_to_enum(this->options().debug());
8c21d9d3
CC
96 // Set incremental_mode_ based on the value of the --incremental option.
97 // We copy the mode into parameters because it can change based on inputs.
98 this->incremental_mode_ = this->options().incremental_mode();
2285a610 99 // If --verbose is set, it acts as "--debug=files".
2ea97941 100 if (options->verbose())
2285a610 101 this->debug_ |= DEBUG_FILES;
7296d933
DK
102 if (this->target_valid())
103 this->check_target_endianness();
7e1edb90
ILT
104}
105
b3b74ddc 106void
2ea97941 107Parameters::set_doing_static_link(bool doing_static_link)
b3b74ddc 108{
8851ecca 109 gold_assert(!this->doing_static_link_valid_);
2ea97941 110 this->doing_static_link_ = doing_static_link;
8851ecca 111 this->doing_static_link_valid_ = true;
b3b74ddc
ILT
112}
113
9025d29d 114void
2ea97941 115Parameters::set_target(Target* target)
9025d29d 116{
114dfbe1
ILT
117 this->set_parameters_target_once_->run_once(static_cast<void*>(target));
118 gold_assert(target == this->target_);
119}
120
121// This is called at most once.
122
123void
124Parameters::set_target_once(Target* target)
125{
126 gold_assert(this->target_ == NULL);
127 this->target_ = target;
7296d933 128 if (this->options_valid())
a3ed37d8
RM
129 {
130 this->check_target_endianness();
131 this->check_rodata_segment();
132 }
114dfbe1
ILT
133}
134
135// Clear the target, for testing.
136
137void
138Parameters::clear_target()
139{
140 this->target_ = NULL;
141 // We need a new Set_parameters_target_once so that we can set the
142 // target again.
143 this->set_parameters_target_once_ = new Set_parameters_target_once(this);
9025d29d
ILT
144}
145
15f8229b
ILT
146// Return whether TARGET is compatible with the target we are using.
147
148bool
2ea97941 149Parameters::is_compatible_target(const Target* target) const
15f8229b
ILT
150{
151 if (this->target_ == NULL)
152 return true;
2ea97941 153 return target == this->target_;
15f8229b
ILT
154}
155
8851ecca
ILT
156Parameters::Target_size_endianness
157Parameters::size_and_endianness() const
3c2fafa5 158{
8851ecca
ILT
159 if (this->target().get_size() == 32)
160 {
161 if (!this->target().is_big_endian())
162 {
163#ifdef HAVE_TARGET_32_LITTLE
164 return TARGET_32_LITTLE;
165#else
166 gold_unreachable();
167#endif
168 }
169 else
170 {
171#ifdef HAVE_TARGET_32_BIG
172 return TARGET_32_BIG;
173#else
174 gold_unreachable();
175#endif
176 }
177 }
178 else if (parameters->target().get_size() == 64)
179 {
180 if (!parameters->target().is_big_endian())
181 {
182#ifdef HAVE_TARGET_64_LITTLE
183 return TARGET_64_LITTLE;
184#else
185 gold_unreachable();
186#endif
187 }
188 else
189 {
190#ifdef HAVE_TARGET_64_BIG
191 return TARGET_64_BIG;
192#else
193 gold_unreachable();
194#endif
195 }
196 }
197 else
198 gold_unreachable();
3c2fafa5
ILT
199}
200
7296d933
DK
201// If output endianness is specified in command line, check that it does
202// not conflict with the target.
203
204void
205Parameters::check_target_endianness()
206{
207 General_options::Endianness endianness = this->options().endianness();
208 if (endianness != General_options::ENDIANNESS_NOT_SET)
209 {
210 bool big_endian;
211 if (endianness == General_options::ENDIANNESS_BIG)
212 big_endian = true;
213 else
214 {
215 gold_assert(endianness == General_options::ENDIANNESS_LITTLE);
216 big_endian = false;;
217 }
2e702c99 218
7296d933
DK
219 if (this->target().is_big_endian() != big_endian)
220 gold_error(_("input file does not match -EB/EL option"));
221 }
222}
223
a3ed37d8
RM
224void
225Parameters::check_rodata_segment()
226{
227 if (this->options().user_set_Trodata_segment()
228 && !this->options().rosegment()
229 && !this->target().isolate_execinstr())
230 gold_error(_("-Trodata-segment is meaningless without --rosegment"));
231}
232
a10ae760
ILT
233// Return the name of the entry symbol.
234
235const char*
236Parameters::entry() const
237{
238 const char* ret = this->options().entry();
239 if (ret == NULL)
a67858e0 240 ret = parameters->target().entry_symbol_name();
a10ae760
ILT
241 return ret;
242}
243
8c21d9d3
CC
244// Set the incremental linking mode to INCREMENTAL_FULL. Used when
245// the linker determines that an incremental update is not possible.
246// Returns false if the incremental mode was INCREMENTAL_UPDATE,
247// indicating that the linker should exit if an update is not possible.
248
249bool
250Parameters::set_incremental_full()
251{
252 gold_assert(this->incremental_mode_ != General_options::INCREMENTAL_OFF);
253 if (this->incremental_mode_ == General_options::INCREMENTAL_UPDATE)
254 return false;
255 this->incremental_mode_ = General_options::INCREMENTAL_FULL;
256 return true;
257}
258
259// Return true if we need to prepare incremental linking information.
260
261bool
262Parameters::incremental() const
263{
264 return this->incremental_mode_ != General_options::INCREMENTAL_OFF;
265}
266
9fbd3822
CC
267// Return true if we are doing a full incremental link.
268
269bool
270Parameters::incremental_full() const
271{
272 return this->incremental_mode_ == General_options::INCREMENTAL_FULL;
273}
274
8c21d9d3
CC
275// Return true if we are doing an incremental update.
276
277bool
278Parameters::incremental_update() const
279{
280 return (this->incremental_mode_ == General_options::INCREMENTAL_UPDATE
281 || this->incremental_mode_ == General_options::INCREMENTAL_AUTO);
282}
283
b3b74ddc 284void
8851ecca
ILT
285set_parameters_errors(Errors* errors)
286{ static_parameters.set_errors(errors); }
b3b74ddc 287
b490c0bb
CC
288void
289set_parameters_timer(Timer* timer)
290{ static_parameters.set_timer(timer); }
291
8851ecca
ILT
292void
293set_parameters_options(const General_options* options)
294{ static_parameters.set_options(options); }
b3b74ddc 295
9025d29d 296void
029ba973 297set_parameters_target(Target* target)
0d31c79d
DK
298{
299 static_parameters.set_target(target);
300 target->select_as_default_target();
301}
8851ecca
ILT
302
303void
304set_parameters_doing_static_link(bool doing_static_link)
305{ static_parameters.set_doing_static_link(doing_static_link); }
7e1edb90 306
8c21d9d3
CC
307// Set the incremental linking mode to INCREMENTAL_FULL. Used when
308// the linker determines that an incremental update is not possible.
309// Returns false if the incremental mode was INCREMENTAL_UPDATE,
310// indicating that the linker should exit if an update is not possible.
311bool
312set_parameters_incremental_full()
313{ return static_parameters.set_incremental_full(); }
314
029ba973
ILT
315// Force the target to be valid by using the default. Use the
316// --oformat option is set; this supports the x86_64 kernel build,
317// which converts a binary file to an object file using -r --format
318// binary --oformat elf32-i386 foo.o. Otherwise use the configured
319// default.
320
321void
322parameters_force_valid_target()
323{
324 if (parameters->target_valid())
325 return;
326
327 gold_assert(parameters->options_valid());
328 if (parameters->options().user_set_oformat())
329 {
03ef7571
ILT
330 const char* bfd_name = parameters->options().oformat();
331 Target* target = select_target_by_bfd_name(bfd_name);
029ba973
ILT
332 if (target != NULL)
333 {
334 set_parameters_target(target);
335 return;
336 }
337
03ef7571
ILT
338 gold_error(_("unrecognized output format %s"), bfd_name);
339 }
340
341 if (parameters->options().user_set_m())
342 {
343 const char* emulation = parameters->options().m();
344 Target* target = select_target_by_emulation(emulation);
345 if (target != NULL)
346 {
347 set_parameters_target(target);
348 return;
349 }
350
351 gold_error(_("unrecognized emulation %s"), emulation);
029ba973
ILT
352 }
353
354 // The GOLD_DEFAULT_xx macros are defined by the configure script.
7296d933
DK
355 bool is_big_endian;
356 General_options::Endianness endianness = parameters->options().endianness();
357 if (endianness == General_options::ENDIANNESS_BIG)
358 is_big_endian = true;
359 else if (endianness == General_options::ENDIANNESS_LITTLE)
360 is_big_endian = false;
361 else
362 is_big_endian = GOLD_DEFAULT_BIG_ENDIAN;
363
2e702c99
RM
364 Target* target = select_target(NULL, 0,
365 elfcpp::GOLD_DEFAULT_MACHINE,
029ba973 366 GOLD_DEFAULT_SIZE,
7296d933 367 is_big_endian,
029ba973
ILT
368 elfcpp::GOLD_DEFAULT_OSABI,
369 0);
f1ddb600
ILT
370
371 if (target == NULL)
372 {
373 gold_assert(is_big_endian != GOLD_DEFAULT_BIG_ENDIAN);
374 gold_fatal(_("no supported target for -EB/-EL option"));
375 }
376
029ba973
ILT
377 set_parameters_target(target);
378}
379
380// Clear the current target, for testing.
381
382void
383parameters_clear_target()
384{
385 static_parameters.clear_target();
386}
387
7e1edb90 388} // End namespace gold.
This page took 0.328114 seconds and 4 git commands to generate.