gold/
[deliverable/binutils-gdb.git] / gold / readsyms.h
1 // readsyms.h -- read input file symbols for gold -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013
4 // Free Software Foundation, Inc.
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
24 #ifndef GOLD_READSYMS_H
25 #define GOLD_READSYMS_H
26
27 #include <vector>
28
29 #include "workqueue.h"
30 #include "object.h"
31 #include "incremental.h"
32
33 namespace gold
34 {
35
36 class Input_objects;
37 class Symbol_table;
38 class Input_group;
39 class Archive;
40 class Finish_group;
41
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.
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.
60 Read_symbols(Input_objects* input_objects, Symbol_table* symtab,
61 Layout* layout, Dirsearch* dirpath, int dirindex,
62 Mapfile* mapfile, const Input_argument* input_argument,
63 Input_group* input_group, Archive_member* member,
64 Task_token* this_blocker, Task_token* next_blocker)
65 : input_objects_(input_objects), symtab_(symtab), layout_(layout),
66 dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile),
67 input_argument_(input_argument), input_group_(input_group),
68 member_(member), this_blocker_(this_blocker),
69 next_blocker_(next_blocker)
70 { }
71
72 ~Read_symbols();
73
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
86 // The standard Task methods.
87
88 Task_token*
89 is_runnable();
90
91 void
92 locks(Task_locker*);
93
94 void
95 run(Workqueue*);
96
97 std::string
98 get_name() const;
99
100 private:
101 // Handle an archive group.
102 void
103 do_group(Workqueue*);
104
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
113 // Open and identify the file.
114 bool
115 do_read_symbols(Workqueue*);
116
117 Input_objects* input_objects_;
118 Symbol_table* symtab_;
119 Layout* layout_;
120 Dirsearch* dirpath_;
121 int dirindex_;
122 Mapfile* mapfile_;
123 const Input_argument* input_argument_;
124 Input_group* input_group_;
125 Archive_member* member_;
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.
140 Add_symbols(Input_objects* input_objects, Symbol_table* symtab,
141 Layout* layout, Dirsearch* /*dirpath*/, int /*dirindex*/,
142 Mapfile* /*mapfile*/, const Input_argument* input_argument,
143 Object* object, Incremental_library* library,
144 Read_symbols_data* sd, Task_token* this_blocker,
145 Task_token* next_blocker)
146 : input_objects_(input_objects), symtab_(symtab), layout_(layout),
147 input_argument_(input_argument), object_(object), library_(library),
148 sd_(sd), this_blocker_(this_blocker), next_blocker_(next_blocker)
149 { }
150
151 ~Add_symbols();
152
153 // The standard Task methods.
154
155 Task_token*
156 is_runnable();
157
158 void
159 locks(Task_locker*);
160
161 void
162 run(Workqueue*);
163
164 std::string
165 get_name() const
166 { return "Add_symbols " + this->object_->name(); }
167
168 private:
169 Input_objects* input_objects_;
170 Symbol_table* symtab_;
171 Layout* layout_;
172 const Input_argument* input_argument_;
173 Object* object_;
174 Incremental_library* library_;
175 Read_symbols_data* sd_;
176 Task_token* this_blocker_;
177 Task_token* next_blocker_;
178 };
179
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.
192 Read_member(Input_objects* /*input_objects*/, Symbol_table* /*symtab*/,
193 Layout* /*layout*/, Mapfile* /*mapfile*/,
194 const Incremental_binary::Input_reader* input_reader,
195 Task_token* this_blocker, Task_token* next_blocker)
196 : input_reader_(input_reader),
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:
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:
277 Check_library(Symbol_table* /*symtab*/, Layout* layout,
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)
282 : layout_(layout), ibase_(ibase),
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_;
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
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
327 ~Input_group();
328
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
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
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:
391 Finish_group(Input_objects* input_objects, Symbol_table* symtab,
392 Layout* layout, Mapfile* mapfile, Input_group* input_group,
393 Task_token* next_blocker)
394 : input_objects_(input_objects), symtab_(symtab),
395 layout_(layout), mapfile_(mapfile), input_group_(input_group),
396 saw_undefined_(0), this_blocker_(NULL), next_blocker_(next_blocker)
397 { }
398
399 ~Finish_group();
400
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
415 // The standard Task methods.
416
417 Task_token*
418 is_runnable();
419
420 void
421 locks(Task_locker*);
422
423 void
424 run(Workqueue*);
425
426 std::string
427 get_name() const
428 { return "Finish_group"; }
429
430 private:
431 Input_objects* input_objects_;
432 Symbol_table* symtab_;
433 Layout* layout_;
434 Mapfile* mapfile_;
435 Input_group* input_group_;
436 size_t saw_undefined_;
437 Task_token* this_blocker_;
438 Task_token* next_blocker_;
439 };
440
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:
448 Read_script(Symbol_table* symtab, Layout* layout, Dirsearch* dirpath,
449 int dirindex, Input_objects* input_objects, Mapfile* mapfile,
450 Input_group* input_group, const Input_argument* input_argument,
451 Input_file* input_file, Task_token* this_blocker,
452 Task_token* next_blocker)
453 : symtab_(symtab), layout_(layout), dirpath_(dirpath), dirindex_(dirindex),
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)
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:
477 Symbol_table* symtab_;
478 Layout* layout_;
479 Dirsearch* dirpath_;
480 int dirindex_;
481 Input_objects* input_objects_;
482 Mapfile* mapfile_;
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
490 } // end namespace gold
491
492 #endif // !defined(GOLD_READSYMS_H)
This page took 0.042317 seconds and 5 git commands to generate.