1 // readsyms.h -- read input file symbols for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_READSYMS_H
24 #define GOLD_READSYMS_H
28 #include "workqueue.h"
30 #include "incremental.h"
41 // This Task is responsible for reading the symbols from an input
42 // file. This also includes reading the relocations so that we can
43 // check for any that require a PLT and/or a GOT. After the data has
44 // been read, this queues up another task to actually add the symbols
45 // to the symbol table. The tasks are separated because the file
46 // reading can occur in parallel but adding the symbols must be done
47 // in the order of the input files.
49 class Read_symbols
: public Task
52 // DIRPATH is the list of directories to search for libraries.
53 // INPUT is the file to read. INPUT_GROUP is not NULL if we are in
54 // the middle of an input group. THIS_BLOCKER is used to prevent
55 // the associated Add_symbols task from running before the previous
56 // one has completed; it will be NULL for the first task.
57 // NEXT_BLOCKER is used to block the next input file from adding
59 Read_symbols(Input_objects
* input_objects
, Symbol_table
* symtab
,
60 Layout
* layout
, Dirsearch
* dirpath
, int dirindex
,
61 Mapfile
* mapfile
, const Input_argument
* input_argument
,
62 Input_group
* input_group
, Archive_member
* member
,
63 Task_token
* this_blocker
, Task_token
* next_blocker
)
64 : input_objects_(input_objects
), symtab_(symtab
), layout_(layout
),
65 dirpath_(dirpath
), dirindex_(dirindex
), mapfile_(mapfile
),
66 input_argument_(input_argument
), input_group_(input_group
),
67 member_(member
), this_blocker_(this_blocker
),
68 next_blocker_(next_blocker
)
73 // If appropriate, issue a warning about skipping an incompatible
76 incompatible_warning(const Input_argument
*, const Input_file
*);
78 // Requeue a Read_symbols task to search for the next object with
81 requeue(Workqueue
*, Input_objects
*, Symbol_table
*, Layout
*, Dirsearch
*,
82 int dirindex
, Mapfile
*, const Input_argument
*, Input_group
*,
83 Task_token
* next_blocker
);
85 // The standard Task methods.
100 // Handle an archive group.
102 do_group(Workqueue
*);
104 // Handle --start-lib ... --end-lib
106 do_lib_group(Workqueue
*);
108 // Handle --whole-archive --start-lib ... --end-lib --no-whole-archive
110 do_whole_lib_group(Workqueue
*);
112 // Open and identify the file.
114 do_read_symbols(Workqueue
*);
116 Input_objects
* input_objects_
;
117 Symbol_table
* symtab_
;
122 const Input_argument
* input_argument_
;
123 Input_group
* input_group_
;
124 Archive_member
* member_
;
125 Task_token
* this_blocker_
;
126 Task_token
* next_blocker_
;
129 // This Task handles adding the symbols to the symbol table. These
130 // tasks must be run in the same order as the arguments appear on the
133 class Add_symbols
: public Task
136 // THIS_BLOCKER is used to prevent this task from running before the
137 // one for the previous input file. NEXT_BLOCKER is used to prevent
138 // the next task from running.
139 Add_symbols(Input_objects
* input_objects
, Symbol_table
* symtab
,
140 Layout
* layout
, Dirsearch
* dirpath
, int dirindex
,
141 Mapfile
* mapfile
, const Input_argument
* input_argument
,
142 Object
* object
, Incremental_library
* library
,
143 Read_symbols_data
* sd
, Task_token
* this_blocker
,
144 Task_token
* next_blocker
)
145 : input_objects_(input_objects
), symtab_(symtab
), layout_(layout
),
146 dirpath_(dirpath
), dirindex_(dirindex
), mapfile_(mapfile
),
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_
;
175 const Input_argument
* input_argument_
;
177 Incremental_library
* library_
;
178 Read_symbols_data
* sd_
;
179 Task_token
* this_blocker_
;
180 Task_token
* next_blocker_
;
183 // This Task is responsible for reading the symbols from an archive
184 // member that has changed since the last incremental link.
186 class Read_member
: public Task
189 // INPUT is the file to read. INPUT_GROUP is not NULL if we are in
190 // the middle of an input group. THIS_BLOCKER is used to prevent
191 // the associated Add_symbols task from running before the previous
192 // one has completed; it will be NULL for the first task.
193 // NEXT_BLOCKER is used to block the next input file from adding
195 Read_member(Input_objects
* input_objects
, Symbol_table
* symtab
,
196 Layout
* layout
, Mapfile
* mapfile
,
197 const Incremental_binary::Input_reader
* input_reader
,
198 Task_token
* this_blocker
, Task_token
* next_blocker
)
199 : input_objects_(input_objects
), symtab_(symtab
), layout_(layout
),
200 mapfile_(mapfile
), input_reader_(input_reader
),
201 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
206 // The standard Task methods.
220 return (std::string("Read_member ") + this->input_reader_
->filename());
224 Input_objects
* input_objects_
;
225 Symbol_table
* symtab_
;
228 const Incremental_binary::Input_reader
* input_reader_
;
229 Task_token
* this_blocker_
;
230 Task_token
* next_blocker_
;
233 // This Task is responsible for processing an input script file that has
234 // not changed since the last incremental link.
236 class Check_script
: public Task
239 Check_script(Layout
* layout
, Incremental_binary
* ibase
,
240 unsigned int input_file_index
,
241 const Incremental_binary::Input_reader
* input_reader
,
242 Task_token
* this_blocker
, Task_token
* next_blocker
)
243 : layout_(layout
), ibase_(ibase
), input_file_index_(input_file_index
),
244 input_reader_(input_reader
), this_blocker_(this_blocker
),
245 next_blocker_(next_blocker
)
247 this->filename_
= std::string(this->input_reader_
->filename());
252 // The standard Task methods.
266 return (std::string("Check_script ") + this->input_reader_
->filename());
270 std::string filename_
;
272 Incremental_binary
* ibase_
;
273 unsigned int input_file_index_
;
274 const Incremental_binary::Input_reader
* input_reader_
;
275 Task_token
* this_blocker_
;
276 Task_token
* next_blocker_
;
279 // This Task is responsible for processing an archive library that has
280 // not changed since the last incremental link.
282 class Check_library
: public Task
285 Check_library(Symbol_table
* symtab
, Layout
* layout
,
286 Incremental_binary
* ibase
,
287 unsigned int input_file_index
,
288 const Incremental_binary::Input_reader
* input_reader
,
289 Task_token
* this_blocker
, Task_token
* next_blocker
)
290 : layout_(layout
), symtab_(symtab
), ibase_(ibase
),
291 input_file_index_(input_file_index
), input_reader_(input_reader
),
292 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
297 // The standard Task methods.
311 return (std::string("Check_library ") + this->input_reader_
->filename());
316 Symbol_table
* symtab_
;
317 Incremental_binary
* ibase_
;
318 unsigned int input_file_index_
;
319 const Incremental_binary::Input_reader
* input_reader_
;
320 Task_token
* this_blocker_
;
321 Task_token
* next_blocker_
;
324 // This class is used to track the archives in a group.
329 typedef std::vector
<Archive
*> Archives
;
330 typedef Archives::const_iterator const_iterator
;
338 // Add an archive to the group.
340 add_archive(Archive
* arch
)
341 { this->archives_
.push_back(arch
); }
343 // Loop over the archives in the group.
347 { return this->archives_
.begin(); }
351 { return this->archives_
.end(); }
357 // This class starts the handling of a group. It exists only to pick
358 // up the number of undefined symbols at that point, so that we only
359 // run back through the group if we saw a new undefined symbol.
361 class Start_group
: public Task
364 Start_group(Symbol_table
* symtab
, Finish_group
* finish_group
,
365 Task_token
* this_blocker
, Task_token
* next_blocker
)
366 : symtab_(symtab
), finish_group_(finish_group
),
367 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
372 // The standard Task methods.
385 { return "Start_group"; }
388 Symbol_table
* symtab_
;
389 Finish_group
* finish_group_
;
390 Task_token
* this_blocker_
;
391 Task_token
* next_blocker_
;
394 // This class is used to finish up handling a group. It is just a
397 class Finish_group
: public Task
400 Finish_group(Input_objects
* input_objects
, Symbol_table
* symtab
,
401 Layout
* layout
, Mapfile
* mapfile
, Input_group
* input_group
,
402 Task_token
* next_blocker
)
403 : input_objects_(input_objects
), symtab_(symtab
),
404 layout_(layout
), mapfile_(mapfile
), input_group_(input_group
),
405 saw_undefined_(0), this_blocker_(NULL
), next_blocker_(next_blocker
)
410 // Set the number of undefined symbols when we start processing the
411 // group. This is called by the Start_group task.
413 set_saw_undefined(size_t saw_undefined
)
414 { this->saw_undefined_
= saw_undefined
; }
416 // Set the blocker to use for this task.
418 set_blocker(Task_token
* this_blocker
)
420 gold_assert(this->this_blocker_
== NULL
);
421 this->this_blocker_
= this_blocker
;
424 // The standard Task methods.
437 { return "Finish_group"; }
440 Input_objects
* input_objects_
;
441 Symbol_table
* symtab_
;
444 Input_group
* input_group_
;
445 size_t saw_undefined_
;
446 Task_token
* this_blocker_
;
447 Task_token
* next_blocker_
;
450 // This class is used to read a file which was not recognized as an
451 // object or archive. It tries to read it as a linker script, using
452 // the tokens to serialize with the calls to Add_symbols.
454 class Read_script
: public Task
457 Read_script(Symbol_table
* symtab
, Layout
* layout
, Dirsearch
* dirpath
,
458 int dirindex
, Input_objects
* input_objects
, Mapfile
* mapfile
,
459 Input_group
* input_group
, const Input_argument
* input_argument
,
460 Input_file
* input_file
, Task_token
* this_blocker
,
461 Task_token
* next_blocker
)
462 : symtab_(symtab
), layout_(layout
), dirpath_(dirpath
), dirindex_(dirindex
),
463 input_objects_(input_objects
), mapfile_(mapfile
),
464 input_group_(input_group
), input_argument_(input_argument
),
465 input_file_(input_file
), this_blocker_(this_blocker
),
466 next_blocker_(next_blocker
)
471 // The standard Task methods.
486 Symbol_table
* symtab_
;
490 Input_objects
* input_objects_
;
492 Input_group
* input_group_
;
493 const Input_argument
* input_argument_
;
494 Input_file
* input_file_
;
495 Task_token
* this_blocker_
;
496 Task_token
* next_blocker_
;
499 } // end namespace gold
501 #endif // !defined(GOLD_READSYMS_H)