From Craig Silverstein: Have Parameters point to General_options.
[deliverable/binutils-gdb.git] / gold / parameters.cc
1 // parameters.cc -- general parameters for a link using gold
2
3 // Copyright 2006, 2007 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 "options.h"
26 #include "target.h"
27 #include "target-select.h"
28
29 namespace gold
30 {
31
32 void
33 Parameters::set_errors(Errors* errors)
34 {
35 gold_assert(this->errors_ == NULL);
36 this->errors_ = errors;
37 }
38
39 void
40 Parameters::set_options(const General_options* options)
41 {
42 gold_assert(!this->options_valid());
43 this->options_ = options;
44 // For speed, we make our own copy of the debug variable.
45 this->debug_ = this->options().debug();
46 }
47
48 void
49 Parameters::set_doing_static_link(bool doing_static_link)
50 {
51 gold_assert(!this->doing_static_link_valid_);
52 this->doing_static_link_ = doing_static_link;
53 this->doing_static_link_valid_ = true;
54 }
55
56 void
57 Parameters::set_target(const Target* target)
58 {
59 if (!this->target_valid())
60 this->target_ = target;
61 else
62 gold_assert(target == this->target_);
63 }
64
65 // The x86_64 kernel build converts a binary file to an object file
66 // using -r --format binary --oformat elf32-i386 foo.o. In order to
67 // support that for gold we support determining the default target
68 // choice from the output format. We recognize names that the GNU
69 // linker uses.
70
71 const Target&
72 Parameters::default_target() const
73 {
74 gold_assert(this->options_valid());
75 if (this->options().oformat_string() != NULL)
76 {
77 const Target* target
78 = select_target_by_name(this->options().oformat_string());
79 if (target != NULL)
80 return *target;
81
82 gold_error(_("unrecognized output format %s"),
83 this->options().oformat_string());
84 }
85
86 // The GOLD_DEFAULT_xx macros are defined by the configure script.
87 const Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
88 GOLD_DEFAULT_SIZE,
89 GOLD_DEFAULT_BIG_ENDIAN,
90 0, 0);
91 gold_assert(target != NULL);
92 return *target;
93 }
94
95 Parameters::Target_size_endianness
96 Parameters::size_and_endianness() const
97 {
98 if (this->target().get_size() == 32)
99 {
100 if (!this->target().is_big_endian())
101 {
102 #ifdef HAVE_TARGET_32_LITTLE
103 return TARGET_32_LITTLE;
104 #else
105 gold_unreachable();
106 #endif
107 }
108 else
109 {
110 #ifdef HAVE_TARGET_32_BIG
111 return TARGET_32_BIG;
112 #else
113 gold_unreachable();
114 #endif
115 }
116 }
117 else if (parameters->target().get_size() == 64)
118 {
119 if (!parameters->target().is_big_endian())
120 {
121 #ifdef HAVE_TARGET_64_LITTLE
122 return TARGET_64_LITTLE;
123 #else
124 gold_unreachable();
125 #endif
126 }
127 else
128 {
129 #ifdef HAVE_TARGET_64_BIG
130 return TARGET_64_BIG;
131 #else
132 gold_unreachable();
133 #endif
134 }
135 }
136 else
137 gold_unreachable();
138 }
139
140
141 // Our local version of the variable, which is not const.
142
143 static Parameters static_parameters;
144
145 // The global variable.
146
147 const Parameters* parameters = &static_parameters;
148
149 void
150 set_parameters_errors(Errors* errors)
151 { static_parameters.set_errors(errors); }
152
153 void
154 set_parameters_options(const General_options* options)
155 { static_parameters.set_options(options); }
156
157 void
158 set_parameters_target(const Target* target)
159 { static_parameters.set_target(target); }
160
161 void
162 set_parameters_doing_static_link(bool doing_static_link)
163 { static_parameters.set_doing_static_link(doing_static_link); }
164
165 } // End namespace gold.
This page took 0.034128 seconds and 5 git commands to generate.