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