Commit | Line | Data |
---|---|---|
7e1edb90 ILT |
1 | // parameters.h -- general parameters for a link using gold -*- C++ -*- |
2 | ||
114dfbe1 | 3 | // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <iant@google.com>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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. | |
22 | ||
7e1edb90 ILT |
23 | #ifndef GOLD_PARAMETERS_H |
24 | #define GOLD_PARAMETERS_H | |
25 | ||
26 | namespace gold | |
27 | { | |
28 | ||
29 | class General_options; | |
75f2446e | 30 | class Errors; |
96803768 | 31 | class Target; |
029ba973 ILT |
32 | template<int size, bool big_endian> |
33 | class Sized_target; | |
114dfbe1 | 34 | class Set_parameters_target_once; |
7e1edb90 ILT |
35 | |
36 | // Here we define the Parameters class which simply holds simple | |
37 | // general parameters which apply to the entire link. We use a global | |
8851ecca ILT |
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 | |
42 | // the commandline. | |
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 | |
48 | // dynamic library. | |
7e1edb90 ILT |
49 | |
50 | class Parameters | |
51 | { | |
52 | public: | |
114dfbe1 | 53 | Parameters(); |
8851ecca ILT |
54 | |
55 | // These should be called as soon as they are known. | |
56 | void | |
57 | set_errors(Errors* errors); | |
58 | ||
59 | void | |
60 | set_options(const General_options* options); | |
61 | ||
62 | void | |
029ba973 | 63 | set_target(Target* target); |
8851ecca ILT |
64 | |
65 | void | |
66 | set_doing_static_link(bool doing_static_link); | |
75f2446e ILT |
67 | |
68 | // Return the error object. | |
69 | Errors* | |
70 | errors() const | |
71 | { return this->errors_; } | |
72 | ||
2d684091 ILT |
73 | // Whether the options are valid. This should not normally be |
74 | // called, but it is needed by gold_exit. | |
75 | bool | |
76 | options_valid() const | |
8851ecca | 77 | { return this->options_ != NULL; } |
51b08ebe | 78 | |
8851ecca ILT |
79 | // Return the options object. |
80 | const General_options& | |
81 | options() const | |
b3b74ddc | 82 | { |
8851ecca ILT |
83 | gold_assert(this->options_valid()); |
84 | return *this->options_; | |
b3b74ddc ILT |
85 | } |
86 | ||
fbfba508 ILT |
87 | // Return whether the target field has been set. |
88 | bool | |
8851ecca ILT |
89 | target_valid() const |
90 | { return this->target_ != NULL; } | |
fbfba508 | 91 | |
96803768 | 92 | // The target of the output file we are generating. |
8851ecca | 93 | const Target& |
96803768 ILT |
94 | target() const |
95 | { | |
8851ecca ILT |
96 | gold_assert(this->target_valid()); |
97 | return *this->target_; | |
96803768 ILT |
98 | } |
99 | ||
029ba973 ILT |
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>* | |
104 | sized_target() const | |
105 | { | |
106 | gold_assert(this->target_valid()); | |
107 | return static_cast<Sized_target<size, big_endian>*>(this->target_); | |
108 | } | |
109 | ||
110 | // Clear the target, for testing. | |
111 | void | |
114dfbe1 | 112 | clear_target(); |
9025d29d | 113 | |
15f8229b ILT |
114 | // Return true if TARGET is compatible with the current target. |
115 | bool | |
116 | is_compatible_target(const Target*) const; | |
117 | ||
9025d29d | 118 | bool |
8851ecca | 119 | doing_static_link() const |
cd72c291 | 120 | { |
8851ecca ILT |
121 | gold_assert(this->doing_static_link_valid_); |
122 | return this->doing_static_link_; | |
cd72c291 ILT |
123 | } |
124 | ||
8851ecca ILT |
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. | |
128 | int | |
129 | debug() const | |
cd72c291 | 130 | { |
2285a610 ILT |
131 | // This can be called before the options are set up. |
132 | if (!this->options_valid()) | |
133 | return 0; | |
8851ecca | 134 | return debug_; |
cd72c291 ILT |
135 | } |
136 | ||
8851ecca ILT |
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 }; | |
436ca963 | 143 | |
8851ecca ILT |
144 | Target_size_endianness |
145 | size_and_endianness() const; | |
b3b74ddc | 146 | |
9025d29d | 147 | |
7e1edb90 | 148 | private: |
114dfbe1 ILT |
149 | void |
150 | set_target_once(Target*); | |
151 | ||
7296d933 DK |
152 | void |
153 | check_target_endianness(); | |
154 | ||
114dfbe1 ILT |
155 | friend class Set_parameters_target_once; |
156 | ||
75f2446e | 157 | Errors* errors_; |
8851ecca | 158 | const General_options* options_; |
029ba973 | 159 | Target* target_; |
8851ecca | 160 | bool doing_static_link_valid_; |
b3b74ddc | 161 | bool doing_static_link_; |
8851ecca | 162 | int debug_; |
114dfbe1 | 163 | Set_parameters_target_once* set_parameters_target_once_; |
7e1edb90 ILT |
164 | }; |
165 | ||
166 | // This is a global variable. | |
167 | extern const Parameters* parameters; | |
168 | ||
8851ecca ILT |
169 | // We use free functions for these since they affect a global variable |
170 | // that is internal to parameters.cc. | |
3c2fafa5 | 171 | |
8851ecca ILT |
172 | extern void |
173 | set_parameters_errors(Errors* errors); | |
7e1edb90 | 174 | |
8851ecca ILT |
175 | extern void |
176 | set_parameters_options(const General_options* options); | |
9025d29d | 177 | |
8851ecca | 178 | extern void |
029ba973 | 179 | set_parameters_target(Target* target); |
b3b74ddc | 180 | |
8851ecca ILT |
181 | extern void |
182 | set_parameters_doing_static_link(bool doing_static_link); | |
029ba973 ILT |
183 | |
184 | // Ensure that the target to be valid by using the default target if | |
185 | // necessary. | |
186 | ||
187 | extern void | |
188 | parameters_force_valid_target(); | |
189 | ||
190 | // Clear the current target, for testing. | |
191 | ||
192 | extern void | |
193 | parameters_clear_target(); | |
194 | ||
c7912668 ILT |
195 | // Return whether we are doing a particular debugging type. The |
196 | // argument is one of the flags from debug.h. | |
197 | ||
198 | inline bool | |
199 | is_debugging_enabled(unsigned int type) | |
200 | { return (parameters->debug() & type) != 0; } | |
201 | ||
7e1edb90 ILT |
202 | } // End namespace gold. |
203 | ||
eb4dfdd4 | 204 | #endif // !defined(GOLD_PARAMETERS_H) |