PR binutils/10924
[deliverable/binutils-gdb.git] / gold / parameters.cc
CommitLineData
7e1edb90
ILT
1// parameters.cc -- general parameters for a link using gold
2
91d6fa6a 3// Copyright 2006, 2007, 2008, 2009 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
8851ecca 33void
91d6fa6a 34Parameters::set_errors(Errors* errs)
7e1edb90 35{
8851ecca 36 gold_assert(this->errors_ == NULL);
91d6fa6a 37 this->errors_ = errs;
3c2fafa5
ILT
38}
39
3c2fafa5 40void
91d6fa6a 41Parameters::set_options(const General_options* opts)
3c2fafa5 42{
8851ecca 43 gold_assert(!this->options_valid());
91d6fa6a 44 this->options_ = opts;
ee1fe73e
ILT
45 // For speed, we convert the options() debug var from a string to an
46 // enum (from debug.h).
47 this->debug_ = debug_string_to_enum(this->options().debug());
2285a610 48 // If --verbose is set, it acts as "--debug=files".
91d6fa6a 49 if (opts->verbose())
2285a610 50 this->debug_ |= DEBUG_FILES;
7e1edb90
ILT
51}
52
b3b74ddc 53void
91d6fa6a 54Parameters::set_doing_static_link(bool doing_staticlink)
b3b74ddc 55{
8851ecca 56 gold_assert(!this->doing_static_link_valid_);
91d6fa6a 57 this->doing_static_link_ = doing_staticlink;
8851ecca 58 this->doing_static_link_valid_ = true;
b3b74ddc
ILT
59}
60
9025d29d 61void
91d6fa6a 62Parameters::set_target(Target* targ)
9025d29d 63{
8851ecca 64 if (!this->target_valid())
91d6fa6a 65 this->target_ = targ;
9025d29d 66 else
91d6fa6a 67 gold_assert(targ == this->target_);
9025d29d
ILT
68}
69
15f8229b
ILT
70// Return whether TARGET is compatible with the target we are using.
71
72bool
91d6fa6a 73Parameters::is_compatible_target(const Target* targ) const
15f8229b
ILT
74{
75 if (this->target_ == NULL)
76 return true;
91d6fa6a 77 return targ == this->target_;
15f8229b
ILT
78}
79
8851ecca
ILT
80Parameters::Target_size_endianness
81Parameters::size_and_endianness() const
3c2fafa5 82{
8851ecca
ILT
83 if (this->target().get_size() == 32)
84 {
85 if (!this->target().is_big_endian())
86 {
87#ifdef HAVE_TARGET_32_LITTLE
88 return TARGET_32_LITTLE;
89#else
90 gold_unreachable();
91#endif
92 }
93 else
94 {
95#ifdef HAVE_TARGET_32_BIG
96 return TARGET_32_BIG;
97#else
98 gold_unreachable();
99#endif
100 }
101 }
102 else if (parameters->target().get_size() == 64)
103 {
104 if (!parameters->target().is_big_endian())
105 {
106#ifdef HAVE_TARGET_64_LITTLE
107 return TARGET_64_LITTLE;
108#else
109 gold_unreachable();
110#endif
111 }
112 else
113 {
114#ifdef HAVE_TARGET_64_BIG
115 return TARGET_64_BIG;
116#else
117 gold_unreachable();
118#endif
119 }
120 }
121 else
122 gold_unreachable();
3c2fafa5
ILT
123}
124
3c2fafa5 125
8851ecca
ILT
126// Our local version of the variable, which is not const.
127
128static Parameters static_parameters;
129
130// The global variable.
9025d29d 131
8851ecca 132const Parameters* parameters = &static_parameters;
b3b74ddc
ILT
133
134void
8851ecca
ILT
135set_parameters_errors(Errors* errors)
136{ static_parameters.set_errors(errors); }
b3b74ddc 137
8851ecca
ILT
138void
139set_parameters_options(const General_options* options)
140{ static_parameters.set_options(options); }
b3b74ddc 141
9025d29d 142void
029ba973 143set_parameters_target(Target* target)
8851ecca
ILT
144{ static_parameters.set_target(target); }
145
146void
147set_parameters_doing_static_link(bool doing_static_link)
148{ static_parameters.set_doing_static_link(doing_static_link); }
7e1edb90 149
029ba973
ILT
150// Force the target to be valid by using the default. Use the
151// --oformat option is set; this supports the x86_64 kernel build,
152// which converts a binary file to an object file using -r --format
153// binary --oformat elf32-i386 foo.o. Otherwise use the configured
154// default.
155
156void
157parameters_force_valid_target()
158{
159 if (parameters->target_valid())
160 return;
161
162 gold_assert(parameters->options_valid());
163 if (parameters->options().user_set_oformat())
164 {
165 Target* target = select_target_by_name(parameters->options().oformat());
166 if (target != NULL)
167 {
168 set_parameters_target(target);
169 return;
170 }
171
172 gold_error(_("unrecognized output format %s"),
173 parameters->options().oformat());
174 }
175
176 // The GOLD_DEFAULT_xx macros are defined by the configure script.
177 Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
178 GOLD_DEFAULT_SIZE,
179 GOLD_DEFAULT_BIG_ENDIAN,
180 elfcpp::GOLD_DEFAULT_OSABI,
181 0);
182 gold_assert(target != NULL);
183 set_parameters_target(target);
184}
185
186// Clear the current target, for testing.
187
188void
189parameters_clear_target()
190{
191 static_parameters.clear_target();
192}
193
7e1edb90 194} // End namespace gold.
This page took 0.183083 seconds and 4 git commands to generate.