1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010 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
>
34 class Set_parameters_target_once
;
36 // Here we define the Parameters class which simply holds simple
37 // general parameters which apply to the entire link. We use a global
38 // variable for this. The parameters class holds three types of data:
39 // 1) An Errors struct. Any part of the code that wants to log an
40 // error can use parameters->errors().
41 // 2) A const General_options. These are the options as read on
43 // 3) Target information, such as size and endian-ness. This is
44 // available as soon as we've decided on the Target (after
45 // parsing the first .o file).
46 // 4) Whether we're doing a static link or not. This is set
47 // after all inputs have been read and we know if any is a
55 // These should be called as soon as they are known.
57 set_errors(Errors
* errors
);
60 set_options(const General_options
* options
);
63 set_target(Target
* target
);
66 set_doing_static_link(bool doing_static_link
);
68 // Return the error object.
71 { return this->errors_
; }
73 // Whether the options are valid. This should not normally be
74 // called, but it is needed by gold_exit.
77 { return this->options_
!= NULL
; }
79 // Return the options object.
80 const General_options
&
83 gold_assert(this->options_valid());
84 return *this->options_
;
87 // Return whether the target field has been set.
90 { return this->target_
!= NULL
; }
92 // The target of the output file we are generating.
96 gold_assert(this->target_valid());
97 return *this->target_
;
100 // The Sized_target of the output file. The caller must request the
101 // right size and endianness.
102 template<int size
, bool big_endian
>
103 Sized_target
<size
, big_endian
>*
106 gold_assert(this->target_valid());
107 return static_cast<Sized_target
<size
, big_endian
>*>(this->target_
);
110 // Clear the target, for testing.
114 // Return true if TARGET is compatible with the current target.
116 is_compatible_target(const Target
*) const;
119 doing_static_link() const
121 gold_assert(this->doing_static_link_valid_
);
122 return this->doing_static_link_
;
125 // This is just a copy of options().debug(). We make a copy so we
126 // don't have to #include options.h in order to inline
127 // is_debugging_enabled, below.
131 // This can be called before the options are set up.
132 if (!this->options_valid())
137 // A convenience routine for combining size and endianness. It also
138 // checks the HAVE_TARGET_FOO configure options and dies if the
139 // current target's size/endianness is not supported according to
140 // HAVE_TARGET_FOO. Otherwise it returns this enum
141 enum Target_size_endianness
142 { TARGET_32_LITTLE
, TARGET_32_BIG
, TARGET_64_LITTLE
, TARGET_64_BIG
};
144 Target_size_endianness
145 size_and_endianness() const;
150 set_target_once(Target
*);
153 check_target_endianness();
155 friend class Set_parameters_target_once
;
158 const General_options
* options_
;
160 bool doing_static_link_valid_
;
161 bool doing_static_link_
;
163 Set_parameters_target_once
* set_parameters_target_once_
;
166 // This is a global variable.
167 extern const Parameters
* parameters
;
169 // We use free functions for these since they affect a global variable
170 // that is internal to parameters.cc.
173 set_parameters_errors(Errors
* errors
);
176 set_parameters_options(const General_options
* options
);
179 set_parameters_target(Target
* target
);
182 set_parameters_doing_static_link(bool doing_static_link
);
184 // Ensure that the target to be valid by using the default target if
188 parameters_force_valid_target();
190 // Clear the current target, for testing.
193 parameters_clear_target();
195 // Return whether we are doing a particular debugging type. The
196 // argument is one of the flags from debug.h.
199 is_debugging_enabled(unsigned int type
)
200 { return (parameters
->debug() & type
) != 0; }
202 } // End namespace gold.
204 #endif // !defined(GOLD_PARAMETERS_H)