1 // parameters.cc -- general parameters for a link using gold
3 // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
28 #include "target-select.h"
34 Parameters::set_errors(Errors* errs)
36 gold_assert(this->errors_ == NULL);
41 Parameters::set_options(const General_options* opts)
43 gold_assert(!this->options_valid());
44 this->options_ = opts;
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());
48 // If --verbose is set, it acts as "--debug=files".
50 this->debug_ |= DEBUG_FILES;
54 Parameters::set_doing_static_link(bool doing_staticlink)
56 gold_assert(!this->doing_static_link_valid_);
57 this->doing_static_link_ = doing_staticlink;
58 this->doing_static_link_valid_ = true;
62 Parameters::set_target(Target* targ)
64 if (!this->target_valid())
67 gold_assert(targ == this->target_);
70 // Return whether TARGET is compatible with the target we are using.
73 Parameters::is_compatible_target(const Target* targ) const
75 if (this->target_ == NULL)
77 return targ == this->target_;
80 Parameters::Target_size_endianness
81 Parameters::size_and_endianness() const
83 if (this->target().get_size() == 32)
85 if (!this->target().is_big_endian())
87 #ifdef HAVE_TARGET_32_LITTLE
88 return TARGET_32_LITTLE;
95 #ifdef HAVE_TARGET_32_BIG
102 else if (parameters->target().get_size() == 64)
104 if (!parameters->target().is_big_endian())
106 #ifdef HAVE_TARGET_64_LITTLE
107 return TARGET_64_LITTLE;
114 #ifdef HAVE_TARGET_64_BIG
115 return TARGET_64_BIG;
126 // Our local version of the variable, which is not const.
128 static Parameters static_parameters;
130 // The global variable.
132 const Parameters* parameters = &static_parameters;
135 set_parameters_errors(Errors* errors)
136 { static_parameters.set_errors(errors); }
139 set_parameters_options(const General_options* options)
140 { static_parameters.set_options(options); }
143 set_parameters_target(Target* target)
144 { static_parameters.set_target(target); }
147 set_parameters_doing_static_link(bool doing_static_link)
148 { static_parameters.set_doing_static_link(doing_static_link); }
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
157 parameters_force_valid_target()
159 if (parameters->target_valid())
162 gold_assert(parameters->options_valid());
163 if (parameters->options().user_set_oformat())
165 Target* target = select_target_by_name(parameters->options().oformat());
168 set_parameters_target(target);
172 gold_error(_("unrecognized output format %s"),
173 parameters->options().oformat());
176 // The GOLD_DEFAULT_xx macros are defined by the configure script.
177 Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
179 GOLD_DEFAULT_BIG_ENDIAN,
180 elfcpp::GOLD_DEFAULT_OSABI,
182 gold_assert(target != NULL);
183 set_parameters_target(target);
186 // Clear the current target, for testing.
189 parameters_clear_target()
191 static_parameters.clear_target();
194 } // End namespace gold.