]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/parameters.cc
* readsyms.cc (Read_symbols::incompatible_warning): New function.
[thirdparty/binutils-gdb.git] / gold / parameters.cc
CommitLineData
7e1edb90
ILT
1// parameters.cc -- general parameters for a link using gold
2
ebdbb458 3// Copyright 2006, 2007, 2008 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
ILT
33void
34Parameters::set_errors(Errors* errors)
7e1edb90 35{
8851ecca
ILT
36 gold_assert(this->errors_ == NULL);
37 this->errors_ = errors;
3c2fafa5
ILT
38}
39
3c2fafa5 40void
8851ecca 41Parameters::set_options(const General_options* options)
3c2fafa5 42{
8851ecca
ILT
43 gold_assert(!this->options_valid());
44 this->options_ = options;
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
ILT
48 // If --verbose is set, it acts as "--debug=files".
49 if (options->verbose())
50 this->debug_ |= DEBUG_FILES;
7e1edb90
ILT
51}
52
b3b74ddc
ILT
53void
54Parameters::set_doing_static_link(bool doing_static_link)
55{
8851ecca 56 gold_assert(!this->doing_static_link_valid_);
b3b74ddc 57 this->doing_static_link_ = doing_static_link;
8851ecca 58 this->doing_static_link_valid_ = true;
b3b74ddc
ILT
59}
60
9025d29d 61void
8851ecca 62Parameters::set_target(const Target* target)
9025d29d 63{
8851ecca
ILT
64 if (!this->target_valid())
65 this->target_ = target;
9025d29d 66 else
96803768 67 gold_assert(target == this->target_);
9025d29d
ILT
68}
69
8851ecca
ILT
70// The x86_64 kernel build converts a binary file to an object file
71// using -r --format binary --oformat elf32-i386 foo.o. In order to
72// support that for gold we support determining the default target
73// choice from the output format. We recognize names that the GNU
74// linker uses.
9025d29d 75
8851ecca
ILT
76const Target&
77Parameters::default_target() const
78{
79 gold_assert(this->options_valid());
7dfac99f 80 if (this->options().user_set_oformat())
8851ecca
ILT
81 {
82 const Target* target
7cc619c3 83 = select_target_by_name(this->options().oformat());
8851ecca
ILT
84 if (target != NULL)
85 return *target;
7e1edb90 86
8851ecca 87 gold_error(_("unrecognized output format %s"),
7cc619c3 88 this->options().oformat());
8851ecca 89 }
7e1edb90 90
8851ecca
ILT
91 // The GOLD_DEFAULT_xx macros are defined by the configure script.
92 const Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
93 GOLD_DEFAULT_SIZE,
94 GOLD_DEFAULT_BIG_ENDIAN,
95 0, 0);
96 gold_assert(target != NULL);
97 return *target;
98}
7e1edb90 99
15f8229b
ILT
100// Return whether TARGET is compatible with the target we are using.
101
102bool
103Parameters::is_compatible_target(const Target* target) const
104{
105 if (this->target_ == NULL)
106 return true;
107 return target == this->target_;
108}
109
8851ecca
ILT
110Parameters::Target_size_endianness
111Parameters::size_and_endianness() const
3c2fafa5 112{
8851ecca
ILT
113 if (this->target().get_size() == 32)
114 {
115 if (!this->target().is_big_endian())
116 {
117#ifdef HAVE_TARGET_32_LITTLE
118 return TARGET_32_LITTLE;
119#else
120 gold_unreachable();
121#endif
122 }
123 else
124 {
125#ifdef HAVE_TARGET_32_BIG
126 return TARGET_32_BIG;
127#else
128 gold_unreachable();
129#endif
130 }
131 }
132 else if (parameters->target().get_size() == 64)
133 {
134 if (!parameters->target().is_big_endian())
135 {
136#ifdef HAVE_TARGET_64_LITTLE
137 return TARGET_64_LITTLE;
138#else
139 gold_unreachable();
140#endif
141 }
142 else
143 {
144#ifdef HAVE_TARGET_64_BIG
145 return TARGET_64_BIG;
146#else
147 gold_unreachable();
148#endif
149 }
150 }
151 else
152 gold_unreachable();
3c2fafa5
ILT
153}
154
3c2fafa5 155
8851ecca
ILT
156// Our local version of the variable, which is not const.
157
158static Parameters static_parameters;
159
160// The global variable.
9025d29d 161
8851ecca 162const Parameters* parameters = &static_parameters;
b3b74ddc
ILT
163
164void
8851ecca
ILT
165set_parameters_errors(Errors* errors)
166{ static_parameters.set_errors(errors); }
b3b74ddc 167
8851ecca
ILT
168void
169set_parameters_options(const General_options* options)
170{ static_parameters.set_options(options); }
b3b74ddc 171
9025d29d 172void
8851ecca
ILT
173set_parameters_target(const Target* target)
174{ static_parameters.set_target(target); }
175
176void
177set_parameters_doing_static_link(bool doing_static_link)
178{ static_parameters.set_doing_static_link(doing_static_link); }
7e1edb90
ILT
179
180} // End namespace gold.