1 // readsyms.h -- read input file symbols for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013
4 // Free Software Foundation, Inc.
5 // Written by Ian Lance Taylor <iant@google.com>.
7 // This file is part of gold.
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.
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.
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.
24 #ifndef GOLD_READSYMS_H
25 #define GOLD_READSYMS_H
29 #include "workqueue.h"
31 #include "incremental.h"
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.
50 class Read_symbols : public Task
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
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)
74 // If appropriate, issue a warning about skipping an incompatible
77 incompatible_warning(const Input_argument*, const Input_file*);
79 // Requeue a Read_symbols task to search for the next object with
82 requeue(Workqueue*, Input_objects*, Symbol_table*, Layout*, Dirsearch*,
83 int dirindex, Mapfile*, const Input_argument*, Input_group*,
84 Task_token* next_blocker);
86 // The standard Task methods.
101 // Handle an archive group.
103 do_group(Workqueue*);
105 // Handle --start-lib ... --end-lib
107 do_lib_group(Workqueue*);
109 // Handle --whole-archive --start-lib ... --end-lib --no-whole-archive
111 do_whole_lib_group(Workqueue*);
113 // Open and identify the file.
115 do_read_symbols(Workqueue*);
117 Input_objects* input_objects_;
118 Symbol_table* symtab_;
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_;
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
134 class Add_symbols : public Task
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)
153 // The standard Task methods.
166 { return "Add_symbols " + this->object_->name(); }
169 Input_objects* input_objects_;
170 Symbol_table* symtab_;
172 const Input_argument* input_argument_;
174 Incremental_library* library_;
175 Read_symbols_data* sd_;
176 Task_token* this_blocker_;
177 Task_token* next_blocker_;
180 // This Task is responsible for reading the symbols from an archive
181 // member that has changed since the last incremental link.
183 class Read_member : public Task
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
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)
202 // The standard Task methods.
216 return (std::string("Read_member ") + this->input_reader_->filename());
220 const Incremental_binary::Input_reader* input_reader_;
221 Task_token* this_blocker_;
222 Task_token* next_blocker_;
225 // This Task is responsible for processing an input script file that has
226 // not changed since the last incremental link.
228 class Check_script : public Task
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)
239 this->filename_ = std::string(this->input_reader_->filename());
244 // The standard Task methods.
258 return (std::string("Check_script ") + this->input_reader_->filename());
262 std::string filename_;
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_;
271 // This Task is responsible for processing an archive library that has
272 // not changed since the last incremental link.
274 class Check_library : public Task
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)
289 // The standard Task methods.
303 return (std::string("Check_library ") + this->input_reader_->filename());
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_;
315 // This class is used to track the archives in a group.
320 typedef std::vector<Archive*> Archives;
321 typedef Archives::const_iterator const_iterator;
329 // Add an archive to the group.
331 add_archive(Archive* arch)
332 { this->archives_.push_back(arch); }
334 // Loop over the archives in the group.
338 { return this->archives_.begin(); }
342 { return this->archives_.end(); }
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.
352 class Start_group : public Task
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)
363 // The standard Task methods.
376 { return "Start_group"; }
379 Symbol_table* symtab_;
380 Finish_group* finish_group_;
381 Task_token* this_blocker_;
382 Task_token* next_blocker_;
385 // This class is used to finish up handling a group. It is just a
388 class Finish_group : public Task
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)
401 // Set the number of undefined symbols when we start processing the
402 // group. This is called by the Start_group task.
404 set_saw_undefined(size_t saw_undefined)
405 { this->saw_undefined_ = saw_undefined; }
407 // Set the blocker to use for this task.
409 set_blocker(Task_token* this_blocker)
411 gold_assert(this->this_blocker_ == NULL);
412 this->this_blocker_ = this_blocker;
415 // The standard Task methods.
428 { return "Finish_group"; }
431 Input_objects* input_objects_;
432 Symbol_table* symtab_;
435 Input_group* input_group_;
436 size_t saw_undefined_;
437 Task_token* this_blocker_;
438 Task_token* next_blocker_;
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.
445 class Read_script : public Task
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)
462 // The standard Task methods.
477 Symbol_table* symtab_;
481 Input_objects* input_objects_;
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_;
490 } // end namespace gold
492 #endif // !defined(GOLD_READSYMS_H)