Implement -q/--emit-relocs.
[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 "parameters.h"
28
29 namespace gold
30 {
31
32 // Initialize the parameters from the options.
33
34 Parameters::Parameters(Errors* errors)
35 : errors_(errors), threads_(false), output_file_name_(NULL),
36 output_file_type_(OUTPUT_INVALID), emit_relocs_(false), sysroot_(),
37 strip_(STRIP_INVALID), allow_shlib_undefined_(false),
38 symbolic_(false), demangle_(false), detect_odr_violations_(false),
39 optimization_level_(0), export_dynamic_(false), debug_(0),
40 is_doing_static_link_valid_(false), doing_static_link_(false),
41 is_target_valid_(false), target_(NULL), size_(0), is_big_endian_(false),
42 max_page_size_(0), common_page_size_(0)
43 {
44 }
45
46 // Set fields from the command line options.
47
48 void
49 Parameters::set_from_options(const General_options* options)
50 {
51 this->threads_ = options->threads();
52 this->output_file_name_ = options->output_file_name();
53 this->emit_relocs_ = options->emit_relocs();
54 this->sysroot_ = options->sysroot();
55 this->allow_shlib_undefined_ = options->allow_shlib_undefined();
56 this->symbolic_ = options->Bsymbolic();
57 this->demangle_ = options->demangle();
58 this->detect_odr_violations_ = options->detect_odr_violations();
59 this->optimization_level_ = options->optimize();
60 this->export_dynamic_ = options->export_dynamic();
61 this->debug_ = options->debug();
62
63 if (options->shared())
64 this->output_file_type_ = OUTPUT_SHARED;
65 else if (options->relocatable())
66 this->output_file_type_ = OUTPUT_OBJECT;
67 else
68 this->output_file_type_ = OUTPUT_EXECUTABLE;
69
70 if (options->strip_all())
71 this->strip_ = STRIP_ALL;
72 else if (options->strip_debug())
73 this->strip_ = STRIP_DEBUG;
74 else if (options->strip_debug_gdb())
75 this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB;
76 else
77 this->strip_ = STRIP_NONE;
78
79 this->max_page_size_ = options->max_page_size();
80 this->common_page_size_ = options->common_page_size();
81
82 this->options_valid_ = true;
83 }
84
85 // Set whether we are doing a static link.
86
87 void
88 Parameters::set_doing_static_link(bool doing_static_link)
89 {
90 this->doing_static_link_ = doing_static_link;
91 this->is_doing_static_link_valid_ = true;
92 }
93
94 // Set the target.
95
96 void
97 Parameters::set_target(Target* target)
98 {
99 if (!this->is_target_valid_)
100 {
101 this->target_ = target;
102 this->size_ = target->get_size();
103 this->is_big_endian_ = target->is_big_endian();
104 this->is_target_valid_ = true;
105 }
106 else
107 gold_assert(target == this->target_);
108 }
109
110 // Our local version of the variable, which is not const.
111
112 static Parameters* static_parameters;
113
114 // The global variable.
115
116 const Parameters* parameters;
117
118 // Initialize the global variable.
119
120 void
121 initialize_parameters(Errors* errors)
122 {
123 parameters = static_parameters = new Parameters(errors);
124 }
125
126 // Set values from the options.
127
128 void
129 set_parameters_from_options(const General_options* options)
130 {
131 static_parameters->set_from_options(options);
132 }
133
134 // Set whether we are doing a static link.
135
136 void
137 set_parameters_doing_static_link(bool doing_static_link)
138 {
139 static_parameters->set_doing_static_link(doing_static_link);
140 }
141
142 // Set the target.
143
144 void
145 set_parameters_target(Target* target)
146 {
147 static_parameters->set_target(target);
148 }
149
150 } // End namespace gold.
This page took 0.033663 seconds and 5 git commands to generate.