Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // readsyms.h -- read input file symbols for gold -*- C++ -*- |
2 | ||
43819297 RM |
3 | // Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013 |
4 | // Free Software Foundation, Inc. | |
6cb15b7f ILT |
5 | // Written by Ian Lance Taylor <iant@google.com>. |
6 | ||
7 | // This file is part of gold. | |
8 | ||
9 | // This program is free software; you can redistribute it and/or modify | |
10 | // it under the terms of the GNU General Public License as published by | |
11 | // the Free Software Foundation; either version 3 of the License, or | |
12 | // (at your option) any later version. | |
13 | ||
14 | // This program is distributed in the hope that it will be useful, | |
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | // GNU General Public License for more details. | |
18 | ||
19 | // You should have received a copy of the GNU General Public License | |
20 | // along with this program; if not, write to the Free Software | |
21 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
22 | // MA 02110-1301, USA. | |
23 | ||
bae7f79e ILT |
24 | #ifndef GOLD_READSYMS_H |
25 | #define GOLD_READSYMS_H | |
26 | ||
ead1e424 ILT |
27 | #include <vector> |
28 | ||
bae7f79e ILT |
29 | #include "workqueue.h" |
30 | #include "object.h" | |
cdc29364 | 31 | #include "incremental.h" |
bae7f79e ILT |
32 | |
33 | namespace gold | |
34 | { | |
35 | ||
54dc6425 ILT |
36 | class Input_objects; |
37 | class Symbol_table; | |
ead1e424 ILT |
38 | class Input_group; |
39 | class Archive; | |
114dfbe1 | 40 | class Finish_group; |
54dc6425 | 41 | |
bae7f79e ILT |
42 | // This Task is responsible for reading the symbols from an input |
43 | // file. This also includes reading the relocations so that we can | |
44 | // check for any that require a PLT and/or a GOT. After the data has | |
45 | // been read, this queues up another task to actually add the symbols | |
46 | // to the symbol table. The tasks are separated because the file | |
47 | // reading can occur in parallel but adding the symbols must be done | |
48 | // in the order of the input files. | |
49 | ||
50 | class Read_symbols : public Task | |
51 | { | |
52 | public: | |
53 | // DIRPATH is the list of directories to search for libraries. | |
ead1e424 ILT |
54 | // INPUT is the file to read. INPUT_GROUP is not NULL if we are in |
55 | // the middle of an input group. THIS_BLOCKER is used to prevent | |
56 | // the associated Add_symbols task from running before the previous | |
57 | // one has completed; it will be NULL for the first task. | |
58 | // NEXT_BLOCKER is used to block the next input file from adding | |
59 | // symbols. | |
f1ed28fb | 60 | Read_symbols(Input_objects* input_objects, Symbol_table* symtab, |
15f8229b ILT |
61 | Layout* layout, Dirsearch* dirpath, int dirindex, |
62 | Mapfile* mapfile, const Input_argument* input_argument, | |
b0193076 RÁE |
63 | Input_group* input_group, Archive_member* member, |
64 | Task_token* this_blocker, Task_token* next_blocker) | |
f1ed28fb | 65 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
15f8229b ILT |
66 | dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile), |
67 | input_argument_(input_argument), input_group_(input_group), | |
b0193076 RÁE |
68 | member_(member), this_blocker_(this_blocker), |
69 | next_blocker_(next_blocker) | |
bae7f79e ILT |
70 | { } |
71 | ||
72 | ~Read_symbols(); | |
73 | ||
15f8229b ILT |
74 | // If appropriate, issue a warning about skipping an incompatible |
75 | // object. | |
76 | static void | |
77 | incompatible_warning(const Input_argument*, const Input_file*); | |
78 | ||
79 | // Requeue a Read_symbols task to search for the next object with | |
80 | // the same name. | |
81 | static void | |
82 | requeue(Workqueue*, Input_objects*, Symbol_table*, Layout*, Dirsearch*, | |
83 | int dirindex, Mapfile*, const Input_argument*, Input_group*, | |
84 | Task_token* next_blocker); | |
85 | ||
bae7f79e ILT |
86 | // The standard Task methods. |
87 | ||
17a1d0a9 ILT |
88 | Task_token* |
89 | is_runnable(); | |
bae7f79e | 90 | |
17a1d0a9 ILT |
91 | void |
92 | locks(Task_locker*); | |
bae7f79e ILT |
93 | |
94 | void | |
95 | run(Workqueue*); | |
96 | ||
c7912668 ILT |
97 | std::string |
98 | get_name() const; | |
99 | ||
bae7f79e | 100 | private: |
ead1e424 ILT |
101 | // Handle an archive group. |
102 | void | |
103 | do_group(Workqueue*); | |
104 | ||
b0193076 RÁE |
105 | // Handle --start-lib ... --end-lib |
106 | bool | |
107 | do_lib_group(Workqueue*); | |
108 | ||
109 | // Handle --whole-archive --start-lib ... --end-lib --no-whole-archive | |
110 | bool | |
111 | do_whole_lib_group(Workqueue*); | |
112 | ||
ee6d2efe ILT |
113 | // Open and identify the file. |
114 | bool | |
115 | do_read_symbols(Workqueue*); | |
116 | ||
54dc6425 | 117 | Input_objects* input_objects_; |
14bfc3f5 | 118 | Symbol_table* symtab_; |
12e14209 | 119 | Layout* layout_; |
17a1d0a9 | 120 | Dirsearch* dirpath_; |
15f8229b | 121 | int dirindex_; |
7d9e3d98 | 122 | Mapfile* mapfile_; |
dbe717ef | 123 | const Input_argument* input_argument_; |
ead1e424 | 124 | Input_group* input_group_; |
b0193076 | 125 | Archive_member* member_; |
bae7f79e ILT |
126 | Task_token* this_blocker_; |
127 | Task_token* next_blocker_; | |
128 | }; | |
129 | ||
130 | // This Task handles adding the symbols to the symbol table. These | |
131 | // tasks must be run in the same order as the arguments appear on the | |
132 | // command line. | |
133 | ||
134 | class Add_symbols : public Task | |
135 | { | |
136 | public: | |
137 | // THIS_BLOCKER is used to prevent this task from running before the | |
138 | // one for the previous input file. NEXT_BLOCKER is used to prevent | |
139 | // the next task from running. | |
7e1edb90 | 140 | Add_symbols(Input_objects* input_objects, Symbol_table* symtab, |
43819297 RM |
141 | Layout* layout, Dirsearch* /*dirpath*/, int /*dirindex*/, |
142 | Mapfile* /*mapfile*/, const Input_argument* input_argument, | |
cdc29364 | 143 | Object* object, Incremental_library* library, |
f6ce93d6 ILT |
144 | Read_symbols_data* sd, Task_token* this_blocker, |
145 | Task_token* next_blocker) | |
7e1edb90 | 146 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
cdc29364 CC |
147 | input_argument_(input_argument), object_(object), library_(library), |
148 | sd_(sd), this_blocker_(this_blocker), next_blocker_(next_blocker) | |
bae7f79e ILT |
149 | { } |
150 | ||
151 | ~Add_symbols(); | |
152 | ||
153 | // The standard Task methods. | |
154 | ||
17a1d0a9 ILT |
155 | Task_token* |
156 | is_runnable(); | |
bae7f79e | 157 | |
17a1d0a9 ILT |
158 | void |
159 | locks(Task_locker*); | |
bae7f79e ILT |
160 | |
161 | void | |
162 | run(Workqueue*); | |
163 | ||
c7912668 ILT |
164 | std::string |
165 | get_name() const | |
166 | { return "Add_symbols " + this->object_->name(); } | |
167 | ||
bae7f79e | 168 | private: |
ead1e424 | 169 | Input_objects* input_objects_; |
14bfc3f5 | 170 | Symbol_table* symtab_; |
12e14209 | 171 | Layout* layout_; |
15f8229b | 172 | const Input_argument* input_argument_; |
bae7f79e | 173 | Object* object_; |
cdc29364 | 174 | Incremental_library* library_; |
12e14209 | 175 | Read_symbols_data* sd_; |
bae7f79e ILT |
176 | Task_token* this_blocker_; |
177 | Task_token* next_blocker_; | |
178 | }; | |
179 | ||
cdc29364 CC |
180 | // This Task is responsible for reading the symbols from an archive |
181 | // member that has changed since the last incremental link. | |
182 | ||
183 | class Read_member : public Task | |
184 | { | |
185 | public: | |
186 | // INPUT is the file to read. INPUT_GROUP is not NULL if we are in | |
187 | // the middle of an input group. THIS_BLOCKER is used to prevent | |
188 | // the associated Add_symbols task from running before the previous | |
189 | // one has completed; it will be NULL for the first task. | |
190 | // NEXT_BLOCKER is used to block the next input file from adding | |
191 | // symbols. | |
43819297 RM |
192 | Read_member(Input_objects* /*input_objects*/, Symbol_table* /*symtab*/, |
193 | Layout* /*layout*/, Mapfile* /*mapfile*/, | |
cdc29364 CC |
194 | const Incremental_binary::Input_reader* input_reader, |
195 | Task_token* this_blocker, Task_token* next_blocker) | |
43819297 | 196 | : input_reader_(input_reader), |
cdc29364 CC |
197 | this_blocker_(this_blocker), next_blocker_(next_blocker) |
198 | { } | |
199 | ||
200 | ~Read_member(); | |
201 | ||
202 | // The standard Task methods. | |
203 | ||
204 | Task_token* | |
205 | is_runnable(); | |
206 | ||
207 | void | |
208 | locks(Task_locker*); | |
209 | ||
210 | void | |
211 | run(Workqueue*); | |
212 | ||
213 | std::string | |
214 | get_name() const | |
215 | { | |
216 | return (std::string("Read_member ") + this->input_reader_->filename()); | |
217 | } | |
218 | ||
219 | private: | |
cdc29364 CC |
220 | const Incremental_binary::Input_reader* input_reader_; |
221 | Task_token* this_blocker_; | |
222 | Task_token* next_blocker_; | |
223 | }; | |
224 | ||
225 | // This Task is responsible for processing an input script file that has | |
226 | // not changed since the last incremental link. | |
227 | ||
228 | class Check_script : public Task | |
229 | { | |
230 | public: | |
231 | Check_script(Layout* layout, Incremental_binary* ibase, | |
232 | unsigned int input_file_index, | |
233 | const Incremental_binary::Input_reader* input_reader, | |
234 | Task_token* this_blocker, Task_token* next_blocker) | |
235 | : layout_(layout), ibase_(ibase), input_file_index_(input_file_index), | |
236 | input_reader_(input_reader), this_blocker_(this_blocker), | |
237 | next_blocker_(next_blocker) | |
238 | { | |
239 | this->filename_ = std::string(this->input_reader_->filename()); | |
240 | } | |
241 | ||
242 | ~Check_script(); | |
243 | ||
244 | // The standard Task methods. | |
245 | ||
246 | Task_token* | |
247 | is_runnable(); | |
248 | ||
249 | void | |
250 | locks(Task_locker*); | |
251 | ||
252 | void | |
253 | run(Workqueue*); | |
254 | ||
255 | std::string | |
256 | get_name() const | |
257 | { | |
258 | return (std::string("Check_script ") + this->input_reader_->filename()); | |
259 | } | |
260 | ||
261 | private: | |
262 | std::string filename_; | |
263 | Layout* layout_; | |
264 | Incremental_binary* ibase_; | |
265 | unsigned int input_file_index_; | |
266 | const Incremental_binary::Input_reader* input_reader_; | |
267 | Task_token* this_blocker_; | |
268 | Task_token* next_blocker_; | |
269 | }; | |
270 | ||
271 | // This Task is responsible for processing an archive library that has | |
272 | // not changed since the last incremental link. | |
273 | ||
274 | class Check_library : public Task | |
275 | { | |
276 | public: | |
43819297 | 277 | Check_library(Symbol_table* /*symtab*/, Layout* layout, |
cdc29364 CC |
278 | Incremental_binary* ibase, |
279 | unsigned int input_file_index, | |
280 | const Incremental_binary::Input_reader* input_reader, | |
281 | Task_token* this_blocker, Task_token* next_blocker) | |
43819297 | 282 | : layout_(layout), ibase_(ibase), |
cdc29364 CC |
283 | input_file_index_(input_file_index), input_reader_(input_reader), |
284 | this_blocker_(this_blocker), next_blocker_(next_blocker) | |
285 | { } | |
286 | ||
287 | ~Check_library(); | |
288 | ||
289 | // The standard Task methods. | |
290 | ||
291 | Task_token* | |
292 | is_runnable(); | |
293 | ||
294 | void | |
295 | locks(Task_locker*); | |
296 | ||
297 | void | |
298 | run(Workqueue*); | |
299 | ||
300 | std::string | |
301 | get_name() const | |
302 | { | |
303 | return (std::string("Check_library ") + this->input_reader_->filename()); | |
304 | } | |
305 | ||
306 | private: | |
307 | Layout* layout_; | |
cdc29364 CC |
308 | Incremental_binary* ibase_; |
309 | unsigned int input_file_index_; | |
310 | const Incremental_binary::Input_reader* input_reader_; | |
311 | Task_token* this_blocker_; | |
312 | Task_token* next_blocker_; | |
313 | }; | |
314 | ||
ead1e424 ILT |
315 | // This class is used to track the archives in a group. |
316 | ||
317 | class Input_group | |
318 | { | |
319 | public: | |
320 | typedef std::vector<Archive*> Archives; | |
321 | typedef Archives::const_iterator const_iterator; | |
322 | ||
323 | Input_group() | |
324 | : archives_() | |
325 | { } | |
326 | ||
0f3b89d8 ILT |
327 | ~Input_group(); |
328 | ||
ead1e424 ILT |
329 | // Add an archive to the group. |
330 | void | |
331 | add_archive(Archive* arch) | |
332 | { this->archives_.push_back(arch); } | |
333 | ||
334 | // Loop over the archives in the group. | |
335 | ||
336 | const_iterator | |
337 | begin() const | |
338 | { return this->archives_.begin(); } | |
339 | ||
340 | const_iterator | |
341 | end() const | |
342 | { return this->archives_.end(); } | |
343 | ||
344 | private: | |
345 | Archives archives_; | |
346 | }; | |
347 | ||
114dfbe1 ILT |
348 | // This class starts the handling of a group. It exists only to pick |
349 | // up the number of undefined symbols at that point, so that we only | |
350 | // run back through the group if we saw a new undefined symbol. | |
351 | ||
352 | class Start_group : public Task | |
353 | { | |
354 | public: | |
355 | Start_group(Symbol_table* symtab, Finish_group* finish_group, | |
356 | Task_token* this_blocker, Task_token* next_blocker) | |
357 | : symtab_(symtab), finish_group_(finish_group), | |
358 | this_blocker_(this_blocker), next_blocker_(next_blocker) | |
359 | { } | |
360 | ||
361 | ~Start_group(); | |
362 | ||
363 | // The standard Task methods. | |
364 | ||
365 | Task_token* | |
366 | is_runnable(); | |
367 | ||
368 | void | |
369 | locks(Task_locker*); | |
370 | ||
371 | void | |
372 | run(Workqueue*); | |
373 | ||
374 | std::string | |
375 | get_name() const | |
376 | { return "Start_group"; } | |
377 | ||
378 | private: | |
379 | Symbol_table* symtab_; | |
380 | Finish_group* finish_group_; | |
381 | Task_token* this_blocker_; | |
382 | Task_token* next_blocker_; | |
383 | }; | |
384 | ||
ead1e424 ILT |
385 | // This class is used to finish up handling a group. It is just a |
386 | // closure. | |
387 | ||
388 | class Finish_group : public Task | |
389 | { | |
390 | public: | |
7e1edb90 | 391 | Finish_group(Input_objects* input_objects, Symbol_table* symtab, |
7d9e3d98 | 392 | Layout* layout, Mapfile* mapfile, Input_group* input_group, |
ead1e424 | 393 | Task_token* next_blocker) |
7e1edb90 | 394 | : input_objects_(input_objects), symtab_(symtab), |
7d9e3d98 | 395 | layout_(layout), mapfile_(mapfile), input_group_(input_group), |
114dfbe1 | 396 | saw_undefined_(0), this_blocker_(NULL), next_blocker_(next_blocker) |
ead1e424 ILT |
397 | { } |
398 | ||
399 | ~Finish_group(); | |
400 | ||
114dfbe1 ILT |
401 | // Set the number of undefined symbols when we start processing the |
402 | // group. This is called by the Start_group task. | |
403 | void | |
404 | set_saw_undefined(size_t saw_undefined) | |
405 | { this->saw_undefined_ = saw_undefined; } | |
406 | ||
407 | // Set the blocker to use for this task. | |
408 | void | |
409 | set_blocker(Task_token* this_blocker) | |
410 | { | |
411 | gold_assert(this->this_blocker_ == NULL); | |
412 | this->this_blocker_ = this_blocker; | |
413 | } | |
414 | ||
ead1e424 ILT |
415 | // The standard Task methods. |
416 | ||
17a1d0a9 ILT |
417 | Task_token* |
418 | is_runnable(); | |
ead1e424 | 419 | |
17a1d0a9 ILT |
420 | void |
421 | locks(Task_locker*); | |
ead1e424 ILT |
422 | |
423 | void | |
424 | run(Workqueue*); | |
425 | ||
c7912668 ILT |
426 | std::string |
427 | get_name() const | |
428 | { return "Finish_group"; } | |
429 | ||
ead1e424 ILT |
430 | private: |
431 | Input_objects* input_objects_; | |
432 | Symbol_table* symtab_; | |
433 | Layout* layout_; | |
7d9e3d98 | 434 | Mapfile* mapfile_; |
ead1e424 | 435 | Input_group* input_group_; |
114dfbe1 | 436 | size_t saw_undefined_; |
ead1e424 ILT |
437 | Task_token* this_blocker_; |
438 | Task_token* next_blocker_; | |
439 | }; | |
440 | ||
da769d56 ILT |
441 | // This class is used to read a file which was not recognized as an |
442 | // object or archive. It tries to read it as a linker script, using | |
443 | // the tokens to serialize with the calls to Add_symbols. | |
444 | ||
445 | class Read_script : public Task | |
446 | { | |
447 | public: | |
f1ed28fb | 448 | Read_script(Symbol_table* symtab, Layout* layout, Dirsearch* dirpath, |
15f8229b | 449 | int dirindex, Input_objects* input_objects, Mapfile* mapfile, |
f1ed28fb | 450 | Input_group* input_group, const Input_argument* input_argument, |
da769d56 ILT |
451 | Input_file* input_file, Task_token* this_blocker, |
452 | Task_token* next_blocker) | |
15f8229b | 453 | : symtab_(symtab), layout_(layout), dirpath_(dirpath), dirindex_(dirindex), |
7d9e3d98 ILT |
454 | input_objects_(input_objects), mapfile_(mapfile), |
455 | input_group_(input_group), input_argument_(input_argument), | |
456 | input_file_(input_file), this_blocker_(this_blocker), | |
457 | next_blocker_(next_blocker) | |
da769d56 ILT |
458 | { } |
459 | ||
460 | ~Read_script(); | |
461 | ||
462 | // The standard Task methods. | |
463 | ||
464 | Task_token* | |
465 | is_runnable(); | |
466 | ||
467 | void | |
468 | locks(Task_locker*); | |
469 | ||
470 | void | |
471 | run(Workqueue*); | |
472 | ||
473 | std::string | |
474 | get_name() const; | |
475 | ||
476 | private: | |
da769d56 ILT |
477 | Symbol_table* symtab_; |
478 | Layout* layout_; | |
479 | Dirsearch* dirpath_; | |
15f8229b | 480 | int dirindex_; |
da769d56 | 481 | Input_objects* input_objects_; |
7d9e3d98 | 482 | Mapfile* mapfile_; |
da769d56 ILT |
483 | Input_group* input_group_; |
484 | const Input_argument* input_argument_; | |
485 | Input_file* input_file_; | |
486 | Task_token* this_blocker_; | |
487 | Task_token* next_blocker_; | |
488 | }; | |
489 | ||
bae7f79e ILT |
490 | } // end namespace gold |
491 | ||
492 | #endif // !defined(GOLD_READSYMS_H) |