Updated Swedish translation for the binutils subdirectory
[binutils-gdb.git] / gold / readsyms.h
blob8d6b48b6fcbedcd135471b6433805e2f003753ea
1 // readsyms.h -- read input file symbols for gold -*- C++ -*-
3 // Copyright (C) 2006-2023 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
26 #include <vector>
28 #include "workqueue.h"
29 #include "object.h"
30 #include "incremental.h"
32 namespace gold
35 class Input_objects;
36 class Symbol_table;
37 class Input_group;
38 class Archive;
39 class Finish_group;
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
51 public:
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
58 // symbols.
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)
69 { }
71 ~Read_symbols();
73 // If appropriate, issue a warning about skipping an incompatible
74 // object.
75 static void
76 incompatible_warning(const Input_argument*, const Input_file*);
78 // Requeue a Read_symbols task to search for the next object with
79 // the same name.
80 static void
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.
87 Task_token*
88 is_runnable();
90 void
91 locks(Task_locker*);
93 void
94 run(Workqueue*);
96 std::string
97 get_name() const;
99 private:
100 // Handle an archive group.
101 void
102 do_group(Workqueue*);
104 // Handle --start-lib ... --end-lib
105 bool
106 do_lib_group(Workqueue*);
108 // Handle --whole-archive --start-lib ... --end-lib --no-whole-archive
109 bool
110 do_whole_lib_group(Workqueue*);
112 // Open and identify the file.
113 bool
114 do_read_symbols(Workqueue*);
116 Input_objects* input_objects_;
117 Symbol_table* symtab_;
118 Layout* layout_;
119 Dirsearch* dirpath_;
120 int dirindex_;
121 Mapfile* mapfile_;
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
131 // command line.
133 class Add_symbols : public Task
135 public:
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)
150 ~Add_symbols();
152 // The standard Task methods.
154 Task_token*
155 is_runnable();
157 void
158 locks(Task_locker*);
160 void
161 run(Workqueue*);
163 std::string
164 get_name() const
165 { return "Add_symbols " + this->object_->name(); }
167 private:
168 Input_objects* input_objects_;
169 Symbol_table* symtab_;
170 Layout* layout_;
171 const Input_argument* input_argument_;
172 Object* object_;
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
184 public:
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
190 // symbols.
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)
199 ~Read_member();
201 // The standard Task methods.
203 Task_token*
204 is_runnable();
206 void
207 locks(Task_locker*);
209 void
210 run(Workqueue*);
212 std::string
213 get_name() const
215 return (std::string("Read_member ") + this->input_reader_->filename());
218 private:
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
229 public:
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());
241 ~Check_script();
243 // The standard Task methods.
245 Task_token*
246 is_runnable();
248 void
249 locks(Task_locker*);
251 void
252 run(Workqueue*);
254 std::string
255 get_name() const
257 return (std::string("Check_script ") + this->input_reader_->filename());
260 private:
261 std::string filename_;
262 Layout* layout_;
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
275 public:
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)
286 ~Check_library();
288 // The standard Task methods.
290 Task_token*
291 is_runnable();
293 void
294 locks(Task_locker*);
296 void
297 run(Workqueue*);
299 std::string
300 get_name() const
302 return (std::string("Check_library ") + this->input_reader_->filename());
305 private:
306 Layout* layout_;
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.
316 class Input_group
318 public:
319 typedef std::vector<Archive*> Archives;
320 typedef Archives::const_iterator const_iterator;
322 Input_group()
323 : archives_()
326 ~Input_group();
328 // Add an archive to the group.
329 void
330 add_archive(Archive* arch)
331 { this->archives_.push_back(arch); }
333 // Loop over the archives in the group.
335 const_iterator
336 begin() const
337 { return this->archives_.begin(); }
339 const_iterator
340 end() const
341 { return this->archives_.end(); }
343 private:
344 Archives archives_;
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
353 public:
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)
360 ~Start_group();
362 // The standard Task methods.
364 Task_token*
365 is_runnable();
367 void
368 locks(Task_locker*);
370 void
371 run(Workqueue*);
373 std::string
374 get_name() const
375 { return "Start_group"; }
377 private:
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
385 // closure.
387 class Finish_group : public Task
389 public:
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)
398 ~Finish_group();
400 // Set the number of undefined symbols when we start processing the
401 // group. This is called by the Start_group task.
402 void
403 set_saw_undefined(size_t saw_undefined)
404 { this->saw_undefined_ = saw_undefined; }
406 // Set the blocker to use for this task.
407 void
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.
416 Task_token*
417 is_runnable();
419 void
420 locks(Task_locker*);
422 void
423 run(Workqueue*);
425 std::string
426 get_name() const
427 { return "Finish_group"; }
429 private:
430 Input_objects* input_objects_;
431 Symbol_table* symtab_;
432 Layout* layout_;
433 Mapfile* mapfile_;
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
446 public:
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)
459 ~Read_script();
461 // The standard Task methods.
463 Task_token*
464 is_runnable();
466 void
467 locks(Task_locker*);
469 void
470 run(Workqueue*);
472 std::string
473 get_name() const;
475 private:
476 Symbol_table* symtab_;
477 Layout* layout_;
478 Dirsearch* dirpath_;
479 int dirindex_;
480 Input_objects* input_objects_;
481 Mapfile* mapfile_;
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)