Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // readsyms.h -- read input file symbols for 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 | ||
bae7f79e ILT |
23 | #ifndef GOLD_READSYMS_H |
24 | #define GOLD_READSYMS_H | |
25 | ||
ead1e424 ILT |
26 | #include <vector> |
27 | ||
bae7f79e ILT |
28 | #include "workqueue.h" |
29 | #include "object.h" | |
30 | ||
31 | namespace gold | |
32 | { | |
33 | ||
54dc6425 ILT |
34 | class Input_objects; |
35 | class Symbol_table; | |
ead1e424 ILT |
36 | class Input_group; |
37 | class Archive; | |
114dfbe1 | 38 | class Finish_group; |
54dc6425 | 39 | |
bae7f79e ILT |
40 | // This Task is responsible for reading the symbols from an input |
41 | // file. This also includes reading the relocations so that we can | |
42 | // check for any that require a PLT and/or a GOT. After the data has | |
43 | // been read, this queues up another task to actually add the symbols | |
44 | // to the symbol table. The tasks are separated because the file | |
45 | // reading can occur in parallel but adding the symbols must be done | |
46 | // in the order of the input files. | |
47 | ||
48 | class Read_symbols : public Task | |
49 | { | |
50 | public: | |
51 | // DIRPATH is the list of directories to search for libraries. | |
ead1e424 ILT |
52 | // INPUT is the file to read. INPUT_GROUP is not NULL if we are in |
53 | // the middle of an input group. THIS_BLOCKER is used to prevent | |
54 | // the associated Add_symbols task from running before the previous | |
55 | // one has completed; it will be NULL for the first task. | |
56 | // NEXT_BLOCKER is used to block the next input file from adding | |
57 | // symbols. | |
f1ed28fb | 58 | Read_symbols(Input_objects* input_objects, Symbol_table* symtab, |
15f8229b ILT |
59 | Layout* layout, Dirsearch* dirpath, int dirindex, |
60 | Mapfile* mapfile, const Input_argument* input_argument, | |
7d9e3d98 ILT |
61 | Input_group* input_group, Task_token* this_blocker, |
62 | Task_token* next_blocker) | |
f1ed28fb | 63 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
15f8229b ILT |
64 | dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile), |
65 | input_argument_(input_argument), input_group_(input_group), | |
66 | this_blocker_(this_blocker), next_blocker_(next_blocker) | |
bae7f79e ILT |
67 | { } |
68 | ||
69 | ~Read_symbols(); | |
70 | ||
15f8229b ILT |
71 | // If appropriate, issue a warning about skipping an incompatible |
72 | // object. | |
73 | static void | |
74 | incompatible_warning(const Input_argument*, const Input_file*); | |
75 | ||
76 | // Requeue a Read_symbols task to search for the next object with | |
77 | // the same name. | |
78 | static void | |
79 | requeue(Workqueue*, Input_objects*, Symbol_table*, Layout*, Dirsearch*, | |
80 | int dirindex, Mapfile*, const Input_argument*, Input_group*, | |
81 | Task_token* next_blocker); | |
82 | ||
bae7f79e ILT |
83 | // The standard Task methods. |
84 | ||
17a1d0a9 ILT |
85 | Task_token* |
86 | is_runnable(); | |
bae7f79e | 87 | |
17a1d0a9 ILT |
88 | void |
89 | locks(Task_locker*); | |
bae7f79e ILT |
90 | |
91 | void | |
92 | run(Workqueue*); | |
93 | ||
c7912668 ILT |
94 | std::string |
95 | get_name() const; | |
96 | ||
bae7f79e | 97 | private: |
ead1e424 ILT |
98 | // Handle an archive group. |
99 | void | |
100 | do_group(Workqueue*); | |
101 | ||
ee6d2efe ILT |
102 | // Open and identify the file. |
103 | bool | |
104 | do_read_symbols(Workqueue*); | |
105 | ||
54dc6425 | 106 | Input_objects* input_objects_; |
14bfc3f5 | 107 | Symbol_table* symtab_; |
12e14209 | 108 | Layout* layout_; |
17a1d0a9 | 109 | Dirsearch* dirpath_; |
15f8229b | 110 | int dirindex_; |
7d9e3d98 | 111 | Mapfile* mapfile_; |
dbe717ef | 112 | const Input_argument* input_argument_; |
ead1e424 | 113 | Input_group* input_group_; |
bae7f79e ILT |
114 | Task_token* this_blocker_; |
115 | Task_token* next_blocker_; | |
116 | }; | |
117 | ||
118 | // This Task handles adding the symbols to the symbol table. These | |
119 | // tasks must be run in the same order as the arguments appear on the | |
120 | // command line. | |
121 | ||
122 | class Add_symbols : public Task | |
123 | { | |
124 | public: | |
125 | // THIS_BLOCKER is used to prevent this task from running before the | |
126 | // one for the previous input file. NEXT_BLOCKER is used to prevent | |
127 | // the next task from running. | |
7e1edb90 | 128 | Add_symbols(Input_objects* input_objects, Symbol_table* symtab, |
15f8229b ILT |
129 | Layout* layout, Dirsearch* dirpath, int dirindex, |
130 | Mapfile* mapfile, const Input_argument* input_argument, | |
131 | Input_group* input_group, Object* object, | |
f6ce93d6 ILT |
132 | Read_symbols_data* sd, Task_token* this_blocker, |
133 | Task_token* next_blocker) | |
7e1edb90 | 134 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
15f8229b ILT |
135 | dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile), |
136 | input_argument_(input_argument), input_group_(input_group), | |
7e1edb90 | 137 | object_(object), sd_(sd), this_blocker_(this_blocker), |
ead1e424 | 138 | next_blocker_(next_blocker) |
bae7f79e ILT |
139 | { } |
140 | ||
141 | ~Add_symbols(); | |
142 | ||
143 | // The standard Task methods. | |
144 | ||
17a1d0a9 ILT |
145 | Task_token* |
146 | is_runnable(); | |
bae7f79e | 147 | |
17a1d0a9 ILT |
148 | void |
149 | locks(Task_locker*); | |
bae7f79e ILT |
150 | |
151 | void | |
152 | run(Workqueue*); | |
153 | ||
c7912668 ILT |
154 | std::string |
155 | get_name() const | |
156 | { return "Add_symbols " + this->object_->name(); } | |
157 | ||
bae7f79e | 158 | private: |
ead1e424 | 159 | Input_objects* input_objects_; |
14bfc3f5 | 160 | Symbol_table* symtab_; |
12e14209 | 161 | Layout* layout_; |
15f8229b ILT |
162 | Dirsearch* dirpath_; |
163 | int dirindex_; | |
164 | Mapfile* mapfile_; | |
165 | const Input_argument* input_argument_; | |
166 | Input_group* input_group_; | |
bae7f79e | 167 | Object* object_; |
12e14209 | 168 | Read_symbols_data* sd_; |
bae7f79e ILT |
169 | Task_token* this_blocker_; |
170 | Task_token* next_blocker_; | |
171 | }; | |
172 | ||
ead1e424 ILT |
173 | // This class is used to track the archives in a group. |
174 | ||
175 | class Input_group | |
176 | { | |
177 | public: | |
178 | typedef std::vector<Archive*> Archives; | |
179 | typedef Archives::const_iterator const_iterator; | |
180 | ||
181 | Input_group() | |
182 | : archives_() | |
183 | { } | |
184 | ||
185 | // Add an archive to the group. | |
186 | void | |
187 | add_archive(Archive* arch) | |
188 | { this->archives_.push_back(arch); } | |
189 | ||
190 | // Loop over the archives in the group. | |
191 | ||
192 | const_iterator | |
193 | begin() const | |
194 | { return this->archives_.begin(); } | |
195 | ||
196 | const_iterator | |
197 | end() const | |
198 | { return this->archives_.end(); } | |
199 | ||
200 | private: | |
201 | Archives archives_; | |
202 | }; | |
203 | ||
114dfbe1 ILT |
204 | // This class starts the handling of a group. It exists only to pick |
205 | // up the number of undefined symbols at that point, so that we only | |
206 | // run back through the group if we saw a new undefined symbol. | |
207 | ||
208 | class Start_group : public Task | |
209 | { | |
210 | public: | |
211 | Start_group(Symbol_table* symtab, Finish_group* finish_group, | |
212 | Task_token* this_blocker, Task_token* next_blocker) | |
213 | : symtab_(symtab), finish_group_(finish_group), | |
214 | this_blocker_(this_blocker), next_blocker_(next_blocker) | |
215 | { } | |
216 | ||
217 | ~Start_group(); | |
218 | ||
219 | // The standard Task methods. | |
220 | ||
221 | Task_token* | |
222 | is_runnable(); | |
223 | ||
224 | void | |
225 | locks(Task_locker*); | |
226 | ||
227 | void | |
228 | run(Workqueue*); | |
229 | ||
230 | std::string | |
231 | get_name() const | |
232 | { return "Start_group"; } | |
233 | ||
234 | private: | |
235 | Symbol_table* symtab_; | |
236 | Finish_group* finish_group_; | |
237 | Task_token* this_blocker_; | |
238 | Task_token* next_blocker_; | |
239 | }; | |
240 | ||
ead1e424 ILT |
241 | // This class is used to finish up handling a group. It is just a |
242 | // closure. | |
243 | ||
244 | class Finish_group : public Task | |
245 | { | |
246 | public: | |
7e1edb90 | 247 | Finish_group(Input_objects* input_objects, Symbol_table* symtab, |
7d9e3d98 | 248 | Layout* layout, Mapfile* mapfile, Input_group* input_group, |
ead1e424 | 249 | Task_token* next_blocker) |
7e1edb90 | 250 | : input_objects_(input_objects), symtab_(symtab), |
7d9e3d98 | 251 | layout_(layout), mapfile_(mapfile), input_group_(input_group), |
114dfbe1 | 252 | saw_undefined_(0), this_blocker_(NULL), next_blocker_(next_blocker) |
ead1e424 ILT |
253 | { } |
254 | ||
255 | ~Finish_group(); | |
256 | ||
114dfbe1 ILT |
257 | // Set the number of undefined symbols when we start processing the |
258 | // group. This is called by the Start_group task. | |
259 | void | |
260 | set_saw_undefined(size_t saw_undefined) | |
261 | { this->saw_undefined_ = saw_undefined; } | |
262 | ||
263 | // Set the blocker to use for this task. | |
264 | void | |
265 | set_blocker(Task_token* this_blocker) | |
266 | { | |
267 | gold_assert(this->this_blocker_ == NULL); | |
268 | this->this_blocker_ = this_blocker; | |
269 | } | |
270 | ||
ead1e424 ILT |
271 | // The standard Task methods. |
272 | ||
17a1d0a9 ILT |
273 | Task_token* |
274 | is_runnable(); | |
ead1e424 | 275 | |
17a1d0a9 ILT |
276 | void |
277 | locks(Task_locker*); | |
ead1e424 ILT |
278 | |
279 | void | |
280 | run(Workqueue*); | |
281 | ||
c7912668 ILT |
282 | std::string |
283 | get_name() const | |
284 | { return "Finish_group"; } | |
285 | ||
ead1e424 ILT |
286 | private: |
287 | Input_objects* input_objects_; | |
288 | Symbol_table* symtab_; | |
289 | Layout* layout_; | |
7d9e3d98 | 290 | Mapfile* mapfile_; |
ead1e424 | 291 | Input_group* input_group_; |
114dfbe1 | 292 | size_t saw_undefined_; |
ead1e424 ILT |
293 | Task_token* this_blocker_; |
294 | Task_token* next_blocker_; | |
295 | }; | |
296 | ||
da769d56 ILT |
297 | // This class is used to read a file which was not recognized as an |
298 | // object or archive. It tries to read it as a linker script, using | |
299 | // the tokens to serialize with the calls to Add_symbols. | |
300 | ||
301 | class Read_script : public Task | |
302 | { | |
303 | public: | |
f1ed28fb | 304 | Read_script(Symbol_table* symtab, Layout* layout, Dirsearch* dirpath, |
15f8229b | 305 | int dirindex, Input_objects* input_objects, Mapfile* mapfile, |
f1ed28fb | 306 | Input_group* input_group, const Input_argument* input_argument, |
da769d56 ILT |
307 | Input_file* input_file, Task_token* this_blocker, |
308 | Task_token* next_blocker) | |
15f8229b | 309 | : symtab_(symtab), layout_(layout), dirpath_(dirpath), dirindex_(dirindex), |
7d9e3d98 ILT |
310 | input_objects_(input_objects), mapfile_(mapfile), |
311 | input_group_(input_group), input_argument_(input_argument), | |
312 | input_file_(input_file), this_blocker_(this_blocker), | |
313 | next_blocker_(next_blocker) | |
da769d56 ILT |
314 | { } |
315 | ||
316 | ~Read_script(); | |
317 | ||
318 | // The standard Task methods. | |
319 | ||
320 | Task_token* | |
321 | is_runnable(); | |
322 | ||
323 | void | |
324 | locks(Task_locker*); | |
325 | ||
326 | void | |
327 | run(Workqueue*); | |
328 | ||
329 | std::string | |
330 | get_name() const; | |
331 | ||
332 | private: | |
da769d56 ILT |
333 | Symbol_table* symtab_; |
334 | Layout* layout_; | |
335 | Dirsearch* dirpath_; | |
15f8229b | 336 | int dirindex_; |
da769d56 | 337 | Input_objects* input_objects_; |
7d9e3d98 | 338 | Mapfile* mapfile_; |
da769d56 ILT |
339 | Input_group* input_group_; |
340 | const Input_argument* input_argument_; | |
341 | Input_file* input_file_; | |
342 | Task_token* this_blocker_; | |
343 | Task_token* next_blocker_; | |
344 | }; | |
345 | ||
bae7f79e ILT |
346 | } // end namespace gold |
347 | ||
348 | #endif // !defined(GOLD_READSYMS_H) |