Re: nios2: Remove binutils support for Nios II target
[binutils-gdb.git] / gold / parameters.h
blobfeda2416d863856ab645d6d5bcf9f083406b0d90
1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
3 // Copyright (C) 2006-2024 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
26 namespace gold
29 class General_options;
30 class Errors;
31 class Timer;
32 class Target;
33 template<int size, bool big_endian>
34 class Sized_target;
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
43 // the commandline.
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
49 // dynamic library.
51 class Parameters
53 public:
54 Parameters();
56 // These should be called as soon as they are known.
57 void
58 set_errors(Errors* errors);
60 void
61 set_timer(Timer* timer);
63 void
64 set_options(const General_options* options);
66 void
67 set_target(Target* target);
69 void
70 set_doing_static_link(bool doing_static_link);
72 // Return the error object.
73 Errors*
74 errors() const
75 { return this->errors_; }
77 // Return the timer object.
78 Timer*
79 timer() const
80 { return this->timer_; }
82 // Whether the options are valid. This should not normally be
83 // called, but it is needed by gold_exit.
84 bool
85 options_valid() const
86 { return this->options_ != NULL; }
88 // Return the options object.
89 const General_options&
90 options() const
92 gold_assert(this->options_valid());
93 return *this->options_;
96 // Return whether the target field has been set.
97 bool
98 target_valid() const
99 { return this->target_ != NULL; }
101 // The target of the output file we are generating.
102 const Target&
103 target() const
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>*
113 sized_target() const
115 gold_assert(this->target_valid());
116 return static_cast<Sized_target<size, big_endian>*>(this->target_);
119 // Clear the target, for testing.
120 void
121 clear_target();
123 // Return true if TARGET is compatible with the current target.
124 bool
125 is_compatible_target(const Target*) const;
127 bool
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.
138 debug() const
140 // This can be called before the options are set up.
141 if (!this->options_valid())
142 return 0;
143 return debug_;
146 // Return the name of the entry symbol.
147 const char*
148 entry() const;
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.
164 bool
165 set_incremental_full();
167 // Return true if we need to prepare incremental linking information.
168 bool
169 incremental() const;
171 // Return true if we are doing a full incremental link.
172 bool
173 incremental_full() const;
175 // Return true if we are doing an incremental update.
176 bool
177 incremental_update() const;
179 private:
180 void
181 set_target_once(Target*);
183 void
184 check_target_endianness();
186 void
187 check_rodata_segment();
189 friend class Set_parameters_target_once;
191 Errors* errors_;
192 Timer* timer_;
193 const General_options* options_;
194 Target* target_;
195 bool doing_static_link_valid_;
196 bool doing_static_link_;
197 int debug_;
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.
208 extern void
209 set_parameters_errors(Errors* errors);
211 extern void
212 set_parameters_timer(Timer* timer);
214 extern void
215 set_parameters_options(const General_options* options);
217 extern void
218 set_parameters_target(Target* target);
220 extern void
221 set_parameters_doing_static_link(bool doing_static_link);
223 extern bool
224 set_parameters_incremental_full();
226 // Ensure that the target to be valid by using the default target if
227 // necessary.
229 extern void
230 parameters_force_valid_target();
232 // Clear the current target, for testing.
234 extern void
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.
240 inline bool
241 is_debugging_enabled(unsigned int type)
242 { return (parameters->debug() & type) != 0; }
244 } // End namespace gold.
246 #endif // !defined(GOLD_PARAMETERS_H)