1*a9fa9459Szrj // parameters.h -- general parameters for a link using gold -*- C++ -*-
2*a9fa9459Szrj
3*a9fa9459Szrj // Copyright (C) 2006-2016 Free Software Foundation, Inc.
4*a9fa9459Szrj // Written by Ian Lance Taylor <iant@google.com>.
5*a9fa9459Szrj
6*a9fa9459Szrj // This file is part of gold.
7*a9fa9459Szrj
8*a9fa9459Szrj // This program is free software; you can redistribute it and/or modify
9*a9fa9459Szrj // it under the terms of the GNU General Public License as published by
10*a9fa9459Szrj // the Free Software Foundation; either version 3 of the License, or
11*a9fa9459Szrj // (at your option) any later version.
12*a9fa9459Szrj
13*a9fa9459Szrj // This program is distributed in the hope that it will be useful,
14*a9fa9459Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
15*a9fa9459Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*a9fa9459Szrj // GNU General Public License for more details.
17*a9fa9459Szrj
18*a9fa9459Szrj // You should have received a copy of the GNU General Public License
19*a9fa9459Szrj // along with this program; if not, write to the Free Software
20*a9fa9459Szrj // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21*a9fa9459Szrj // MA 02110-1301, USA.
22*a9fa9459Szrj
23*a9fa9459Szrj #ifndef GOLD_PARAMETERS_H
24*a9fa9459Szrj #define GOLD_PARAMETERS_H
25*a9fa9459Szrj
26*a9fa9459Szrj namespace gold
27*a9fa9459Szrj {
28*a9fa9459Szrj
29*a9fa9459Szrj class General_options;
30*a9fa9459Szrj class Errors;
31*a9fa9459Szrj class Timer;
32*a9fa9459Szrj class Target;
33*a9fa9459Szrj template<int size, bool big_endian>
34*a9fa9459Szrj class Sized_target;
35*a9fa9459Szrj class Set_parameters_target_once;
36*a9fa9459Szrj
37*a9fa9459Szrj // Here we define the Parameters class which simply holds simple
38*a9fa9459Szrj // general parameters which apply to the entire link. We use a global
39*a9fa9459Szrj // variable for this. The parameters class holds three types of data:
40*a9fa9459Szrj // 1) An Errors struct. Any part of the code that wants to log an
41*a9fa9459Szrj // error can use parameters->errors().
42*a9fa9459Szrj // 2) A const General_options. These are the options as read on
43*a9fa9459Szrj // the commandline.
44*a9fa9459Szrj // 3) Target information, such as size and endian-ness. This is
45*a9fa9459Szrj // available as soon as we've decided on the Target (after
46*a9fa9459Szrj // parsing the first .o file).
47*a9fa9459Szrj // 4) Whether we're doing a static link or not. This is set
48*a9fa9459Szrj // after all inputs have been read and we know if any is a
49*a9fa9459Szrj // dynamic library.
50*a9fa9459Szrj
51*a9fa9459Szrj class Parameters
52*a9fa9459Szrj {
53*a9fa9459Szrj public:
54*a9fa9459Szrj Parameters();
55*a9fa9459Szrj
56*a9fa9459Szrj // These should be called as soon as they are known.
57*a9fa9459Szrj void
58*a9fa9459Szrj set_errors(Errors* errors);
59*a9fa9459Szrj
60*a9fa9459Szrj void
61*a9fa9459Szrj set_timer(Timer* timer);
62*a9fa9459Szrj
63*a9fa9459Szrj void
64*a9fa9459Szrj set_options(const General_options* options);
65*a9fa9459Szrj
66*a9fa9459Szrj void
67*a9fa9459Szrj set_target(Target* target);
68*a9fa9459Szrj
69*a9fa9459Szrj void
70*a9fa9459Szrj set_doing_static_link(bool doing_static_link);
71*a9fa9459Szrj
72*a9fa9459Szrj // Return the error object.
73*a9fa9459Szrj Errors*
errors()74*a9fa9459Szrj errors() const
75*a9fa9459Szrj { return this->errors_; }
76*a9fa9459Szrj
77*a9fa9459Szrj // Return the timer object.
78*a9fa9459Szrj Timer*
timer()79*a9fa9459Szrj timer() const
80*a9fa9459Szrj { return this->timer_; }
81*a9fa9459Szrj
82*a9fa9459Szrj // Whether the options are valid. This should not normally be
83*a9fa9459Szrj // called, but it is needed by gold_exit.
84*a9fa9459Szrj bool
options_valid()85*a9fa9459Szrj options_valid() const
86*a9fa9459Szrj { return this->options_ != NULL; }
87*a9fa9459Szrj
88*a9fa9459Szrj // Return the options object.
89*a9fa9459Szrj const General_options&
options()90*a9fa9459Szrj options() const
91*a9fa9459Szrj {
92*a9fa9459Szrj gold_assert(this->options_valid());
93*a9fa9459Szrj return *this->options_;
94*a9fa9459Szrj }
95*a9fa9459Szrj
96*a9fa9459Szrj // Return whether the target field has been set.
97*a9fa9459Szrj bool
target_valid()98*a9fa9459Szrj target_valid() const
99*a9fa9459Szrj { return this->target_ != NULL; }
100*a9fa9459Szrj
101*a9fa9459Szrj // The target of the output file we are generating.
102*a9fa9459Szrj const Target&
target()103*a9fa9459Szrj target() const
104*a9fa9459Szrj {
105*a9fa9459Szrj gold_assert(this->target_valid());
106*a9fa9459Szrj return *this->target_;
107*a9fa9459Szrj }
108*a9fa9459Szrj
109*a9fa9459Szrj // The Sized_target of the output file. The caller must request the
110*a9fa9459Szrj // right size and endianness.
111*a9fa9459Szrj template<int size, bool big_endian>
112*a9fa9459Szrj Sized_target<size, big_endian>*
sized_target()113*a9fa9459Szrj sized_target() const
114*a9fa9459Szrj {
115*a9fa9459Szrj gold_assert(this->target_valid());
116*a9fa9459Szrj return static_cast<Sized_target<size, big_endian>*>(this->target_);
117*a9fa9459Szrj }
118*a9fa9459Szrj
119*a9fa9459Szrj // Clear the target, for testing.
120*a9fa9459Szrj void
121*a9fa9459Szrj clear_target();
122*a9fa9459Szrj
123*a9fa9459Szrj // Return true if TARGET is compatible with the current target.
124*a9fa9459Szrj bool
125*a9fa9459Szrj is_compatible_target(const Target*) const;
126*a9fa9459Szrj
127*a9fa9459Szrj bool
doing_static_link()128*a9fa9459Szrj doing_static_link() const
129*a9fa9459Szrj {
130*a9fa9459Szrj gold_assert(this->doing_static_link_valid_);
131*a9fa9459Szrj return this->doing_static_link_;
132*a9fa9459Szrj }
133*a9fa9459Szrj
134*a9fa9459Szrj // This is just a copy of options().debug(). We make a copy so we
135*a9fa9459Szrj // don't have to #include options.h in order to inline
136*a9fa9459Szrj // is_debugging_enabled, below.
137*a9fa9459Szrj int
debug()138*a9fa9459Szrj debug() const
139*a9fa9459Szrj {
140*a9fa9459Szrj // This can be called before the options are set up.
141*a9fa9459Szrj if (!this->options_valid())
142*a9fa9459Szrj return 0;
143*a9fa9459Szrj return debug_;
144*a9fa9459Szrj }
145*a9fa9459Szrj
146*a9fa9459Szrj // Return the name of the entry symbol.
147*a9fa9459Szrj const char*
148*a9fa9459Szrj entry() const;
149*a9fa9459Szrj
150*a9fa9459Szrj // A convenience routine for combining size and endianness. It also
151*a9fa9459Szrj // checks the HAVE_TARGET_FOO configure options and dies if the
152*a9fa9459Szrj // current target's size/endianness is not supported according to
153*a9fa9459Szrj // HAVE_TARGET_FOO. Otherwise it returns this enum
154*a9fa9459Szrj enum Target_size_endianness
155*a9fa9459Szrj { TARGET_32_LITTLE, TARGET_32_BIG, TARGET_64_LITTLE, TARGET_64_BIG };
156*a9fa9459Szrj
157*a9fa9459Szrj Target_size_endianness
158*a9fa9459Szrj size_and_endianness() const;
159*a9fa9459Szrj
160*a9fa9459Szrj // Set the incremental linking mode to INCREMENTAL_FULL. Used when
161*a9fa9459Szrj // the linker determines that an incremental update is not possible.
162*a9fa9459Szrj // Returns false if the incremental mode was INCREMENTAL_UPDATE,
163*a9fa9459Szrj // indicating that the linker should exit if an update is not possible.
164*a9fa9459Szrj bool
165*a9fa9459Szrj set_incremental_full();
166*a9fa9459Szrj
167*a9fa9459Szrj // Return true if we need to prepare incremental linking information.
168*a9fa9459Szrj bool
169*a9fa9459Szrj incremental() const;
170*a9fa9459Szrj
171*a9fa9459Szrj // Return true if we are doing a full incremental link.
172*a9fa9459Szrj bool
173*a9fa9459Szrj incremental_full() const;
174*a9fa9459Szrj
175*a9fa9459Szrj // Return true if we are doing an incremental update.
176*a9fa9459Szrj bool
177*a9fa9459Szrj incremental_update() const;
178*a9fa9459Szrj
179*a9fa9459Szrj private:
180*a9fa9459Szrj void
181*a9fa9459Szrj set_target_once(Target*);
182*a9fa9459Szrj
183*a9fa9459Szrj void
184*a9fa9459Szrj check_target_endianness();
185*a9fa9459Szrj
186*a9fa9459Szrj void
187*a9fa9459Szrj check_rodata_segment();
188*a9fa9459Szrj
189*a9fa9459Szrj friend class Set_parameters_target_once;
190*a9fa9459Szrj
191*a9fa9459Szrj Errors* errors_;
192*a9fa9459Szrj Timer* timer_;
193*a9fa9459Szrj const General_options* options_;
194*a9fa9459Szrj Target* target_;
195*a9fa9459Szrj bool doing_static_link_valid_;
196*a9fa9459Szrj bool doing_static_link_;
197*a9fa9459Szrj int debug_;
198*a9fa9459Szrj int incremental_mode_;
199*a9fa9459Szrj Set_parameters_target_once* set_parameters_target_once_;
200*a9fa9459Szrj };
201*a9fa9459Szrj
202*a9fa9459Szrj // This is a global variable.
203*a9fa9459Szrj extern const Parameters* parameters;
204*a9fa9459Szrj
205*a9fa9459Szrj // We use free functions for these since they affect a global variable
206*a9fa9459Szrj // that is internal to parameters.cc.
207*a9fa9459Szrj
208*a9fa9459Szrj extern void
209*a9fa9459Szrj set_parameters_errors(Errors* errors);
210*a9fa9459Szrj
211*a9fa9459Szrj extern void
212*a9fa9459Szrj set_parameters_timer(Timer* timer);
213*a9fa9459Szrj
214*a9fa9459Szrj extern void
215*a9fa9459Szrj set_parameters_options(const General_options* options);
216*a9fa9459Szrj
217*a9fa9459Szrj extern void
218*a9fa9459Szrj set_parameters_target(Target* target);
219*a9fa9459Szrj
220*a9fa9459Szrj extern void
221*a9fa9459Szrj set_parameters_doing_static_link(bool doing_static_link);
222*a9fa9459Szrj
223*a9fa9459Szrj extern bool
224*a9fa9459Szrj set_parameters_incremental_full();
225*a9fa9459Szrj
226*a9fa9459Szrj // Ensure that the target to be valid by using the default target if
227*a9fa9459Szrj // necessary.
228*a9fa9459Szrj
229*a9fa9459Szrj extern void
230*a9fa9459Szrj parameters_force_valid_target();
231*a9fa9459Szrj
232*a9fa9459Szrj // Clear the current target, for testing.
233*a9fa9459Szrj
234*a9fa9459Szrj extern void
235*a9fa9459Szrj parameters_clear_target();
236*a9fa9459Szrj
237*a9fa9459Szrj // Return whether we are doing a particular debugging type. The
238*a9fa9459Szrj // argument is one of the flags from debug.h.
239*a9fa9459Szrj
240*a9fa9459Szrj inline bool
is_debugging_enabled(unsigned int type)241*a9fa9459Szrj is_debugging_enabled(unsigned int type)
242*a9fa9459Szrj { return (parameters->debug() & type) != 0; }
243*a9fa9459Szrj
244*a9fa9459Szrj } // End namespace gold.
245*a9fa9459Szrj
246*a9fa9459Szrj #endif // !defined(GOLD_PARAMETERS_H)
247