1 // readsyms.h -- read input file symbols for gold -*- C++ -*-
3 // Copyright (C) 2006-2020 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 input_argument_(input_argument
), object_(object
), library_(library
),
147 sd_(sd
), this_blocker_(this_blocker
), next_blocker_(next_blocker
)
152 // The standard Task methods.
165 { return "Add_symbols " + this->object_
->name(); }
168 Input_objects
* input_objects_
;
169 Symbol_table
* symtab_
;
171 const Input_argument
* input_argument_
;
173 Incremental_library
* library_
;
174 Read_symbols_data
* sd_
;
175 Task_token
* this_blocker_
;
176 Task_token
* next_blocker_
;
179 // This Task is responsible for reading the symbols from an archive
180 // member that has changed since the last incremental link.
182 class Read_member
: public Task
185 // INPUT is the file to read. INPUT_GROUP is not NULL if we are in
186 // the middle of an input group. THIS_BLOCKER is used to prevent
187 // the associated Add_symbols task from running before the previous
188 // one has completed; it will be NULL for the first task.
189 // NEXT_BLOCKER is used to block the next input file from adding
191 Read_member(Input_objects
* /*input_objects*/, Symbol_table
* /*symtab*/,
192 Layout
* /*layout*/, Mapfile
* /*mapfile*/,
193 const Incremental_binary::Input_reader
* input_reader
,
194 Task_token
* this_blocker
, Task_token
* next_blocker
)
195 : input_reader_(input_reader
),
196 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
201 // The standard Task methods.
215 return (std::string("Read_member ") + this->input_reader_
->filename());
219 const Incremental_binary::Input_reader
* input_reader_
;
220 Task_token
* this_blocker_
;
221 Task_token
* next_blocker_
;
224 // This Task is responsible for processing an input script file that has
225 // not changed since the last incremental link.
227 class Check_script
: public Task
230 Check_script(Layout
* layout
, Incremental_binary
* ibase
,
231 unsigned int input_file_index
,
232 const Incremental_binary::Input_reader
* input_reader
,
233 Task_token
* this_blocker
, Task_token
* next_blocker
)
234 : layout_(layout
), ibase_(ibase
), input_file_index_(input_file_index
),
235 input_reader_(input_reader
), this_blocker_(this_blocker
),
236 next_blocker_(next_blocker
)
238 this->filename_
= std::string(this->input_reader_
->filename());
243 // The standard Task methods.
257 return (std::string("Check_script ") + this->input_reader_
->filename());
261 std::string filename_
;
263 Incremental_binary
* ibase_
;
264 unsigned int input_file_index_
;
265 const Incremental_binary::Input_reader
* input_reader_
;
266 Task_token
* this_blocker_
;
267 Task_token
* next_blocker_
;
270 // This Task is responsible for processing an archive library that has
271 // not changed since the last incremental link.
273 class Check_library
: public Task
276 Check_library(Symbol_table
* /*symtab*/, Layout
* layout
,
277 Incremental_binary
* ibase
,
278 unsigned int input_file_index
,
279 const Incremental_binary::Input_reader
* input_reader
,
280 Task_token
* this_blocker
, Task_token
* next_blocker
)
281 : layout_(layout
), ibase_(ibase
),
282 input_file_index_(input_file_index
), input_reader_(input_reader
),
283 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
288 // The standard Task methods.
302 return (std::string("Check_library ") + this->input_reader_
->filename());
307 Incremental_binary
* ibase_
;
308 unsigned int input_file_index_
;
309 const Incremental_binary::Input_reader
* input_reader_
;
310 Task_token
* this_blocker_
;
311 Task_token
* next_blocker_
;
314 // This class is used to track the archives in a group.
319 typedef std::vector
<Archive
*> Archives
;
320 typedef Archives::const_iterator const_iterator
;
328 // Add an archive to the group.
330 add_archive(Archive
* arch
)
331 { this->archives_
.push_back(arch
); }
333 // Loop over the archives in the group.
337 { return this->archives_
.begin(); }
341 { return this->archives_
.end(); }
347 // This class starts the handling of a group. It exists only to pick
348 // up the number of undefined symbols at that point, so that we only
349 // run back through the group if we saw a new undefined symbol.
351 class Start_group
: public Task
354 Start_group(Symbol_table
* symtab
, Finish_group
* finish_group
,
355 Task_token
* this_blocker
, Task_token
* next_blocker
)
356 : symtab_(symtab
), finish_group_(finish_group
),
357 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
362 // The standard Task methods.
375 { return "Start_group"; }
378 Symbol_table
* symtab_
;
379 Finish_group
* finish_group_
;
380 Task_token
* this_blocker_
;
381 Task_token
* next_blocker_
;
384 // This class is used to finish up handling a group. It is just a
387 class Finish_group
: public Task
390 Finish_group(Input_objects
* input_objects
, Symbol_table
* symtab
,
391 Layout
* layout
, Mapfile
* mapfile
, Input_group
* input_group
,
392 Task_token
* next_blocker
)
393 : input_objects_(input_objects
), symtab_(symtab
),
394 layout_(layout
), mapfile_(mapfile
), input_group_(input_group
),
395 saw_undefined_(0), this_blocker_(NULL
), next_blocker_(next_blocker
)
400 // Set the number of undefined symbols when we start processing the
401 // group. This is called by the Start_group task.
403 set_saw_undefined(size_t saw_undefined
)
404 { this->saw_undefined_
= saw_undefined
; }
406 // Set the blocker to use for this task.
408 set_blocker(Task_token
* this_blocker
)
410 gold_assert(this->this_blocker_
== NULL
);
411 this->this_blocker_
= this_blocker
;
414 // The standard Task methods.
427 { return "Finish_group"; }
430 Input_objects
* input_objects_
;
431 Symbol_table
* symtab_
;
434 Input_group
* input_group_
;
435 size_t saw_undefined_
;
436 Task_token
* this_blocker_
;
437 Task_token
* next_blocker_
;
440 // This class is used to read a file which was not recognized as an
441 // object or archive. It tries to read it as a linker script, using
442 // the tokens to serialize with the calls to Add_symbols.
444 class Read_script
: public Task
447 Read_script(Symbol_table
* symtab
, Layout
* layout
, Dirsearch
* dirpath
,
448 int dirindex
, Input_objects
* input_objects
, Mapfile
* mapfile
,
449 Input_group
* input_group
, const Input_argument
* input_argument
,
450 Input_file
* input_file
, Task_token
* this_blocker
,
451 Task_token
* next_blocker
)
452 : symtab_(symtab
), layout_(layout
), dirpath_(dirpath
), dirindex_(dirindex
),
453 input_objects_(input_objects
), mapfile_(mapfile
),
454 input_group_(input_group
), input_argument_(input_argument
),
455 input_file_(input_file
), this_blocker_(this_blocker
),
456 next_blocker_(next_blocker
)
461 // The standard Task methods.
476 Symbol_table
* symtab_
;
480 Input_objects
* input_objects_
;
482 Input_group
* input_group_
;
483 const Input_argument
* input_argument_
;
484 Input_file
* input_file_
;
485 Task_token
* this_blocker_
;
486 Task_token
* next_blocker_
;
489 } // end namespace gold
491 #endif // !defined(GOLD_READSYMS_H)