daily update
[deliverable/binutils-gdb.git] / gold / parameters.cc
CommitLineData
7e1edb90
ILT
1// parameters.cc -- general parameters for a link using gold
2
6cb15b7f
ILT
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
7e1edb90
ILT
23#include "gold.h"
24
25#include "options.h"
96803768 26#include "target.h"
8851ecca 27#include "target-select.h"
7e1edb90
ILT
28
29namespace gold
30{
31
8851ecca
ILT
32void
33Parameters::set_errors(Errors* errors)
7e1edb90 34{
8851ecca
ILT
35 gold_assert(this->errors_ == NULL);
36 this->errors_ = errors;
3c2fafa5
ILT
37}
38
3c2fafa5 39void
8851ecca 40Parameters::set_options(const General_options* options)
3c2fafa5 41{
8851ecca
ILT
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();
7e1edb90
ILT
46}
47
b3b74ddc
ILT
48void
49Parameters::set_doing_static_link(bool doing_static_link)
50{
8851ecca 51 gold_assert(!this->doing_static_link_valid_);
b3b74ddc 52 this->doing_static_link_ = doing_static_link;
8851ecca 53 this->doing_static_link_valid_ = true;
b3b74ddc
ILT
54}
55
9025d29d 56void
8851ecca 57Parameters::set_target(const Target* target)
9025d29d 58{
8851ecca
ILT
59 if (!this->target_valid())
60 this->target_ = target;
9025d29d 61 else
96803768 62 gold_assert(target == this->target_);
9025d29d
ILT
63}
64
8851ecca
ILT
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.
9025d29d 70
8851ecca
ILT
71const Target&
72Parameters::default_target() const
73{
74 gold_assert(this->options_valid());
7cc619c3 75 if (this->options().oformat() != NULL)
8851ecca
ILT
76 {
77 const Target* target
7cc619c3 78 = select_target_by_name(this->options().oformat());
8851ecca
ILT
79 if (target != NULL)
80 return *target;
7e1edb90 81
8851ecca 82 gold_error(_("unrecognized output format %s"),
7cc619c3 83 this->options().oformat());
8851ecca 84 }
7e1edb90 85
8851ecca
ILT
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}
7e1edb90 94
8851ecca
ILT
95Parameters::Target_size_endianness
96Parameters::size_and_endianness() const
3c2fafa5 97{
8851ecca
ILT
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();
3c2fafa5
ILT
138}
139
3c2fafa5 140
8851ecca
ILT
141// Our local version of the variable, which is not const.
142
143static Parameters static_parameters;
144
145// The global variable.
9025d29d 146
8851ecca 147const Parameters* parameters = &static_parameters;
b3b74ddc
ILT
148
149void
8851ecca
ILT
150set_parameters_errors(Errors* errors)
151{ static_parameters.set_errors(errors); }
b3b74ddc 152
8851ecca
ILT
153void
154set_parameters_options(const General_options* options)
155{ static_parameters.set_options(options); }
b3b74ddc 156
9025d29d 157void
8851ecca
ILT
158set_parameters_target(const Target* target)
159{ static_parameters.set_target(target); }
160
161void
162set_parameters_doing_static_link(bool doing_static_link)
163{ static_parameters.set_doing_static_link(doing_static_link); }
7e1edb90
ILT
164
165} // End namespace gold.
This page took 0.056653 seconds and 4 git commands to generate.