PR 5646
[binutils.git] / gold / parameters.cc
blobe6b96825353c4a443bc72f858b760a4af08673f7
1 // parameters.cc -- general parameters for a link using gold
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #include "gold.h"
25 #include "options.h"
26 #include "target.h"
27 #include "parameters.h"
29 namespace gold
32 // Initialize the parameters from the options.
34 Parameters::Parameters(Errors* errors)
35 : errors_(errors), threads_(false), output_file_name_(NULL),
36 output_file_type_(OUTPUT_INVALID), 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)
45 // Set fields from the command line options.
47 void
48 Parameters::set_from_options(const General_options* options)
50 this->threads_ = options->threads();
51 this->output_file_name_ = options->output_file_name();
52 this->sysroot_ = options->sysroot();
53 this->allow_shlib_undefined_ = options->allow_shlib_undefined();
54 this->symbolic_ = options->symbolic();
55 this->demangle_ = options->demangle();
56 this->detect_odr_violations_ = options->detect_odr_violations();
57 this->optimization_level_ = options->optimization_level();
58 this->export_dynamic_ = options->export_dynamic();
59 this->debug_ = options->debug();
61 if (options->is_shared())
62 this->output_file_type_ = OUTPUT_SHARED;
63 else if (options->is_relocatable())
64 this->output_file_type_ = OUTPUT_OBJECT;
65 else
66 this->output_file_type_ = OUTPUT_EXECUTABLE;
68 if (options->strip_all())
69 this->strip_ = STRIP_ALL;
70 else if (options->strip_debug())
71 this->strip_ = STRIP_DEBUG;
72 else if (options->strip_debug_gdb())
73 this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB;
74 else
75 this->strip_ = STRIP_NONE;
77 this->options_valid_ = true;
80 // Set whether we are doing a static link.
82 void
83 Parameters::set_doing_static_link(bool doing_static_link)
85 this->doing_static_link_ = doing_static_link;
86 this->is_doing_static_link_valid_ = true;
89 // Set the target.
91 void
92 Parameters::set_target(Target* target)
94 if (!this->is_target_valid_)
96 this->target_ = target;
97 this->size_ = target->get_size();
98 this->is_big_endian_ = target->is_big_endian();
99 this->is_target_valid_ = true;
101 else
102 gold_assert(target == this->target_);
105 // Our local version of the variable, which is not const.
107 static Parameters* static_parameters;
109 // The global variable.
111 const Parameters* parameters;
113 // Initialize the global variable.
115 void
116 initialize_parameters(Errors* errors)
118 parameters = static_parameters = new Parameters(errors);
121 // Set values from the options.
123 void
124 set_parameters_from_options(const General_options* options)
126 static_parameters->set_from_options(options);
129 // Set whether we are doing a static link.
131 void
132 set_parameters_doing_static_link(bool doing_static_link)
134 static_parameters->set_doing_static_link(doing_static_link);
137 // Set the target.
139 void
140 set_parameters_target(Target* target)
142 static_parameters->set_target(target);
145 } // End namespace gold.