1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
3 // Copyright (C) 2006-2020 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 #ifndef GOLD_PARAMETERS_H
24 #define GOLD_PARAMETERS_H
29 class General_options
;
33 template<int size
, bool big_endian
>
35 class Set_parameters_target_once
;
37 // Here we define the Parameters class which simply holds simple
38 // general parameters which apply to the entire link. We use a global
39 // variable for this. The parameters class holds three types of data:
40 // 1) An Errors struct. Any part of the code that wants to log an
41 // error can use parameters->errors().
42 // 2) A const General_options. These are the options as read on
44 // 3) Target information, such as size and endian-ness. This is
45 // available as soon as we've decided on the Target (after
46 // parsing the first .o file).
47 // 4) Whether we're doing a static link or not. This is set
48 // after all inputs have been read and we know if any is a
56 // These should be called as soon as they are known.
58 set_errors(Errors
* errors
);
61 set_timer(Timer
* timer
);
64 set_options(const General_options
* options
);
67 set_target(Target
* target
);
70 set_doing_static_link(bool doing_static_link
);
72 // Return the error object.
75 { return this->errors_
; }
77 // Return the timer object.
80 { return this->timer_
; }
82 // Whether the options are valid. This should not normally be
83 // called, but it is needed by gold_exit.
86 { return this->options_
!= NULL
; }
88 // Return the options object.
89 const General_options
&
92 gold_assert(this->options_valid());
93 return *this->options_
;
96 // Return whether the target field has been set.
99 { return this->target_
!= NULL
; }
101 // The target of the output file we are generating.
105 gold_assert(this->target_valid());
106 return *this->target_
;
109 // The Sized_target of the output file. The caller must request the
110 // right size and endianness.
111 template<int size
, bool big_endian
>
112 Sized_target
<size
, big_endian
>*
115 gold_assert(this->target_valid());
116 return static_cast<Sized_target
<size
, big_endian
>*>(this->target_
);
119 // Clear the target, for testing.
123 // Return true if TARGET is compatible with the current target.
125 is_compatible_target(const Target
*) const;
128 doing_static_link() const
130 gold_assert(this->doing_static_link_valid_
);
131 return this->doing_static_link_
;
134 // This is just a copy of options().debug(). We make a copy so we
135 // don't have to #include options.h in order to inline
136 // is_debugging_enabled, below.
140 // This can be called before the options are set up.
141 if (!this->options_valid())
146 // Return the name of the entry symbol.
150 // A convenience routine for combining size and endianness. It also
151 // checks the HAVE_TARGET_FOO configure options and dies if the
152 // current target's size/endianness is not supported according to
153 // HAVE_TARGET_FOO. Otherwise it returns this enum
154 enum Target_size_endianness
155 { TARGET_32_LITTLE
, TARGET_32_BIG
, TARGET_64_LITTLE
, TARGET_64_BIG
};
157 Target_size_endianness
158 size_and_endianness() const;
160 // Set the incremental linking mode to INCREMENTAL_FULL. Used when
161 // the linker determines that an incremental update is not possible.
162 // Returns false if the incremental mode was INCREMENTAL_UPDATE,
163 // indicating that the linker should exit if an update is not possible.
165 set_incremental_full();
167 // Return true if we need to prepare incremental linking information.
171 // Return true if we are doing a full incremental link.
173 incremental_full() const;
175 // Return true if we are doing an incremental update.
177 incremental_update() const;
181 set_target_once(Target
*);
184 check_target_endianness();
187 check_rodata_segment();
189 friend class Set_parameters_target_once
;
193 const General_options
* options_
;
195 bool doing_static_link_valid_
;
196 bool doing_static_link_
;
198 int incremental_mode_
;
199 Set_parameters_target_once
* set_parameters_target_once_
;
202 // This is a global variable.
203 extern const Parameters
* parameters
;
205 // We use free functions for these since they affect a global variable
206 // that is internal to parameters.cc.
209 set_parameters_errors(Errors
* errors
);
212 set_parameters_timer(Timer
* timer
);
215 set_parameters_options(const General_options
* options
);
218 set_parameters_target(Target
* target
);
221 set_parameters_doing_static_link(bool doing_static_link
);
224 set_parameters_incremental_full();
226 // Ensure that the target to be valid by using the default target if
230 parameters_force_valid_target();
232 // Clear the current target, for testing.
235 parameters_clear_target();
237 // Return whether we are doing a particular debugging type. The
238 // argument is one of the flags from debug.h.
241 is_debugging_enabled(unsigned int type
)
242 { return (parameters
->debug() & type
) != 0; }
244 } // End namespace gold.
246 #endif // !defined(GOLD_PARAMETERS_H)