* tui/tui-stack.c (tui_make_status_line): Display PC as ?? if unknown.
[deliverable/binutils-gdb.git] / gold / parameters.cc
1 // parameters.cc -- general parameters for a link using gold
2
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
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
23 #include "gold.h"
24
25 #include "debug.h"
26 #include "options.h"
27 #include "target.h"
28 #include "target-select.h"
29
30 namespace gold
31 {
32
33 void
34 Parameters::set_errors(Errors* errors)
35 {
36 gold_assert(this->errors_ == NULL);
37 this->errors_ = errors;
38 }
39
40 void
41 Parameters::set_options(const General_options* options)
42 {
43 gold_assert(!this->options_valid());
44 this->options_ = options;
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".
49 if (options->verbose())
50 this->debug_ |= DEBUG_FILES;
51 }
52
53 void
54 Parameters::set_doing_static_link(bool doing_static_link)
55 {
56 gold_assert(!this->doing_static_link_valid_);
57 this->doing_static_link_ = doing_static_link;
58 this->doing_static_link_valid_ = true;
59 }
60
61 void
62 Parameters::set_target(const Target* target)
63 {
64 if (!this->target_valid())
65 this->target_ = target;
66 else
67 gold_assert(target == this->target_);
68 }
69
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.
75
76 const Target&
77 Parameters::default_target() const
78 {
79 gold_assert(this->options_valid());
80 if (this->options().user_set_oformat())
81 {
82 const Target* target
83 = select_target_by_name(this->options().oformat());
84 if (target != NULL)
85 return *target;
86
87 gold_error(_("unrecognized output format %s"),
88 this->options().oformat());
89 }
90
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 elfcpp::GOLD_DEFAULT_OSABI,
96 0);
97 gold_assert(target != NULL);
98 return *target;
99 }
100
101 // Return whether TARGET is compatible with the target we are using.
102
103 bool
104 Parameters::is_compatible_target(const Target* target) const
105 {
106 if (this->target_ == NULL)
107 return true;
108 return target == this->target_;
109 }
110
111 Parameters::Target_size_endianness
112 Parameters::size_and_endianness() const
113 {
114 if (this->target().get_size() == 32)
115 {
116 if (!this->target().is_big_endian())
117 {
118 #ifdef HAVE_TARGET_32_LITTLE
119 return TARGET_32_LITTLE;
120 #else
121 gold_unreachable();
122 #endif
123 }
124 else
125 {
126 #ifdef HAVE_TARGET_32_BIG
127 return TARGET_32_BIG;
128 #else
129 gold_unreachable();
130 #endif
131 }
132 }
133 else if (parameters->target().get_size() == 64)
134 {
135 if (!parameters->target().is_big_endian())
136 {
137 #ifdef HAVE_TARGET_64_LITTLE
138 return TARGET_64_LITTLE;
139 #else
140 gold_unreachable();
141 #endif
142 }
143 else
144 {
145 #ifdef HAVE_TARGET_64_BIG
146 return TARGET_64_BIG;
147 #else
148 gold_unreachable();
149 #endif
150 }
151 }
152 else
153 gold_unreachable();
154 }
155
156
157 // Our local version of the variable, which is not const.
158
159 static Parameters static_parameters;
160
161 // The global variable.
162
163 const Parameters* parameters = &static_parameters;
164
165 void
166 set_parameters_errors(Errors* errors)
167 { static_parameters.set_errors(errors); }
168
169 void
170 set_parameters_options(const General_options* options)
171 { static_parameters.set_options(options); }
172
173 void
174 set_parameters_target(const Target* target)
175 { static_parameters.set_target(target); }
176
177 void
178 set_parameters_doing_static_link(bool doing_static_link)
179 { static_parameters.set_doing_static_link(doing_static_link); }
180
181 } // End namespace gold.
This page took 0.034437 seconds and 4 git commands to generate.