*** empty log message ***
[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
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());
7e1edb90
ILT
48}
49
b3b74ddc
ILT
50void
51Parameters::set_doing_static_link(bool doing_static_link)
52{
8851ecca 53 gold_assert(!this->doing_static_link_valid_);
b3b74ddc 54 this->doing_static_link_ = doing_static_link;
8851ecca 55 this->doing_static_link_valid_ = true;
b3b74ddc
ILT
56}
57
9025d29d 58void
8851ecca 59Parameters::set_target(const Target* target)
9025d29d 60{
8851ecca
ILT
61 if (!this->target_valid())
62 this->target_ = target;
9025d29d 63 else
96803768 64 gold_assert(target == this->target_);
9025d29d
ILT
65}
66
8851ecca
ILT
67// The x86_64 kernel build converts a binary file to an object file
68// using -r --format binary --oformat elf32-i386 foo.o. In order to
69// support that for gold we support determining the default target
70// choice from the output format. We recognize names that the GNU
71// linker uses.
9025d29d 72
8851ecca
ILT
73const Target&
74Parameters::default_target() const
75{
76 gold_assert(this->options_valid());
7dfac99f 77 if (this->options().user_set_oformat())
8851ecca
ILT
78 {
79 const Target* target
7cc619c3 80 = select_target_by_name(this->options().oformat());
8851ecca
ILT
81 if (target != NULL)
82 return *target;
7e1edb90 83
8851ecca 84 gold_error(_("unrecognized output format %s"),
7cc619c3 85 this->options().oformat());
8851ecca 86 }
7e1edb90 87
8851ecca
ILT
88 // The GOLD_DEFAULT_xx macros are defined by the configure script.
89 const Target* target = select_target(elfcpp::GOLD_DEFAULT_MACHINE,
90 GOLD_DEFAULT_SIZE,
91 GOLD_DEFAULT_BIG_ENDIAN,
92 0, 0);
93 gold_assert(target != NULL);
94 return *target;
95}
7e1edb90 96
8851ecca
ILT
97Parameters::Target_size_endianness
98Parameters::size_and_endianness() const
3c2fafa5 99{
8851ecca
ILT
100 if (this->target().get_size() == 32)
101 {
102 if (!this->target().is_big_endian())
103 {
104#ifdef HAVE_TARGET_32_LITTLE
105 return TARGET_32_LITTLE;
106#else
107 gold_unreachable();
108#endif
109 }
110 else
111 {
112#ifdef HAVE_TARGET_32_BIG
113 return TARGET_32_BIG;
114#else
115 gold_unreachable();
116#endif
117 }
118 }
119 else if (parameters->target().get_size() == 64)
120 {
121 if (!parameters->target().is_big_endian())
122 {
123#ifdef HAVE_TARGET_64_LITTLE
124 return TARGET_64_LITTLE;
125#else
126 gold_unreachable();
127#endif
128 }
129 else
130 {
131#ifdef HAVE_TARGET_64_BIG
132 return TARGET_64_BIG;
133#else
134 gold_unreachable();
135#endif
136 }
137 }
138 else
139 gold_unreachable();
3c2fafa5
ILT
140}
141
3c2fafa5 142
8851ecca
ILT
143// Our local version of the variable, which is not const.
144
145static Parameters static_parameters;
146
147// The global variable.
9025d29d 148
8851ecca 149const Parameters* parameters = &static_parameters;
b3b74ddc
ILT
150
151void
8851ecca
ILT
152set_parameters_errors(Errors* errors)
153{ static_parameters.set_errors(errors); }
b3b74ddc 154
8851ecca
ILT
155void
156set_parameters_options(const General_options* options)
157{ static_parameters.set_options(options); }
b3b74ddc 158
9025d29d 159void
8851ecca
ILT
160set_parameters_target(const Target* target)
161{ static_parameters.set_target(target); }
162
163void
164set_parameters_doing_static_link(bool doing_static_link)
165{ static_parameters.set_doing_static_link(doing_static_link); }
7e1edb90
ILT
166
167} // End namespace gold.
This page took 0.050789 seconds and 4 git commands to generate.