1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008 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
;
32 template<int size
, bool big_endian
>
35 // Here we define the Parameters class which simply holds simple
36 // general parameters which apply to the entire link. We use a global
37 // variable for this. The parameters class holds three types of data:
38 // 1) An Errors struct. Any part of the code that wants to log an
39 // error can use parameters->errors().
40 // 2) A const General_options. These are the options as read on
42 // 3) Target information, such as size and endian-ness. This is
43 // available as soon as we've decided on the Target (after
44 // parsing the first .o file).
45 // 4) Whether we're doing a static link or not. This is set
46 // after all inputs have been read and we know if any is a
53 : errors_(NULL
), options_(NULL
), target_(NULL
),
54 doing_static_link_valid_(false), doing_static_link_(false),
58 // These should be called as soon as they are known.
60 set_errors(Errors
* errors
);
63 set_options(const General_options
* options
);
66 set_target(Target
* target
);
69 set_doing_static_link(bool doing_static_link
);
71 // Return the error object.
74 { return this->errors_
; }
76 // Whether the options are valid. This should not normally be
77 // called, but it is needed by gold_exit.
80 { return this->options_
!= NULL
; }
82 // Return the options object.
83 const General_options
&
86 gold_assert(this->options_valid());
87 return *this->options_
;
90 // Return whether the target field has been set.
93 { return this->target_
!= NULL
; }
95 // The target of the output file we are generating.
99 gold_assert(this->target_valid());
100 return *this->target_
;
103 // The Sized_target of the output file. The caller must request the
104 // right size and endianness.
105 template<int size
, bool big_endian
>
106 Sized_target
<size
, big_endian
>*
109 gold_assert(this->target_valid());
110 return static_cast<Sized_target
<size
, big_endian
>*>(this->target_
);
113 // Clear the target, for testing.
116 { this->target_
= NULL
; }
118 // Return true if TARGET is compatible with the current target.
120 is_compatible_target(const Target
*) const;
123 doing_static_link() const
125 gold_assert(this->doing_static_link_valid_
);
126 return this->doing_static_link_
;
129 // This is just a copy of options().debug(). We make a copy so we
130 // don't have to #include options.h in order to inline
131 // is_debugging_enabled, below.
135 // This can be called before the options are set up.
136 if (!this->options_valid())
141 // A convenience routine for combining size and endianness. It also
142 // checks the HAVE_TARGET_FOO configure options and dies if the
143 // current target's size/endianness is not supported according to
144 // HAVE_TARGET_FOO. Otherwise it returns this enum
145 enum Target_size_endianness
146 { TARGET_32_LITTLE
, TARGET_32_BIG
, TARGET_64_LITTLE
, TARGET_64_BIG
};
148 Target_size_endianness
149 size_and_endianness() const;
154 const General_options
* options_
;
156 bool doing_static_link_valid_
;
157 bool doing_static_link_
;
161 // This is a global variable.
162 extern const Parameters
* parameters
;
164 // We use free functions for these since they affect a global variable
165 // that is internal to parameters.cc.
168 set_parameters_errors(Errors
* errors
);
171 set_parameters_options(const General_options
* options
);
174 set_parameters_target(Target
* target
);
177 set_parameters_doing_static_link(bool doing_static_link
);
179 // Ensure that the target to be valid by using the default target if
183 parameters_force_valid_target();
185 // Clear the current target, for testing.
188 parameters_clear_target();
190 // Return whether we are doing a particular debugging type. The
191 // argument is one of the flags from debug.h.
194 is_debugging_enabled(unsigned int type
)
195 { return (parameters
->debug() & type
) != 0; }
197 } // End namespace gold.
199 #endif // !defined(GOLD_PARAMETERS_H)