*** empty log message ***
[deliverable/binutils-gdb.git] / gold / readsyms.h
CommitLineData
bae7f79e
ILT
1// readsyms.h -- read input file symbols for gold -*- C++ -*-
2
0f3b89d8 3// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
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.
12
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.
17
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.
22
bae7f79e
ILT
23#ifndef GOLD_READSYMS_H
24#define GOLD_READSYMS_H
25
ead1e424
ILT
26#include <vector>
27
bae7f79e
ILT
28#include "workqueue.h"
29#include "object.h"
30
31namespace gold
32{
33
54dc6425
ILT
34class Input_objects;
35class Symbol_table;
ead1e424
ILT
36class Input_group;
37class Archive;
114dfbe1 38class Finish_group;
54dc6425 39
bae7f79e
ILT
40// This Task is responsible for reading the symbols from an input
41// file. This also includes reading the relocations so that we can
42// check for any that require a PLT and/or a GOT. After the data has
43// been read, this queues up another task to actually add the symbols
44// to the symbol table. The tasks are separated because the file
45// reading can occur in parallel but adding the symbols must be done
46// in the order of the input files.
47
48class Read_symbols : public Task
49{
50 public:
51 // DIRPATH is the list of directories to search for libraries.
ead1e424
ILT
52 // INPUT is the file to read. INPUT_GROUP is not NULL if we are in
53 // the middle of an input group. THIS_BLOCKER is used to prevent
54 // the associated Add_symbols task from running before the previous
55 // one has completed; it will be NULL for the first task.
56 // NEXT_BLOCKER is used to block the next input file from adding
57 // symbols.
f1ed28fb 58 Read_symbols(Input_objects* input_objects, Symbol_table* symtab,
15f8229b
ILT
59 Layout* layout, Dirsearch* dirpath, int dirindex,
60 Mapfile* mapfile, const Input_argument* input_argument,
b0193076
RÁE
61 Input_group* input_group, Archive_member* member,
62 Task_token* this_blocker, Task_token* next_blocker)
f1ed28fb 63 : input_objects_(input_objects), symtab_(symtab), layout_(layout),
15f8229b
ILT
64 dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile),
65 input_argument_(input_argument), input_group_(input_group),
b0193076
RÁE
66 member_(member), this_blocker_(this_blocker),
67 next_blocker_(next_blocker)
bae7f79e
ILT
68 { }
69
70 ~Read_symbols();
71
15f8229b
ILT
72 // If appropriate, issue a warning about skipping an incompatible
73 // object.
74 static void
75 incompatible_warning(const Input_argument*, const Input_file*);
76
77 // Requeue a Read_symbols task to search for the next object with
78 // the same name.
79 static void
80 requeue(Workqueue*, Input_objects*, Symbol_table*, Layout*, Dirsearch*,
81 int dirindex, Mapfile*, const Input_argument*, Input_group*,
82 Task_token* next_blocker);
83
bae7f79e
ILT
84 // The standard Task methods.
85
17a1d0a9
ILT
86 Task_token*
87 is_runnable();
bae7f79e 88
17a1d0a9
ILT
89 void
90 locks(Task_locker*);
bae7f79e
ILT
91
92 void
93 run(Workqueue*);
94
c7912668
ILT
95 std::string
96 get_name() const;
97
bae7f79e 98 private:
ead1e424
ILT
99 // Handle an archive group.
100 void
101 do_group(Workqueue*);
102
b0193076
RÁE
103 // Handle --start-lib ... --end-lib
104 bool
105 do_lib_group(Workqueue*);
106
107 // Handle --whole-archive --start-lib ... --end-lib --no-whole-archive
108 bool
109 do_whole_lib_group(Workqueue*);
110
ee6d2efe
ILT
111 // Open and identify the file.
112 bool
113 do_read_symbols(Workqueue*);
114
54dc6425 115 Input_objects* input_objects_;
14bfc3f5 116 Symbol_table* symtab_;
12e14209 117 Layout* layout_;
17a1d0a9 118 Dirsearch* dirpath_;
15f8229b 119 int dirindex_;
7d9e3d98 120 Mapfile* mapfile_;
dbe717ef 121 const Input_argument* input_argument_;
ead1e424 122 Input_group* input_group_;
b0193076 123 Archive_member* member_;
bae7f79e
ILT
124 Task_token* this_blocker_;
125 Task_token* next_blocker_;
126};
127
128// This Task handles adding the symbols to the symbol table. These
129// tasks must be run in the same order as the arguments appear on the
130// command line.
131
132class Add_symbols : public Task
133{
134 public:
135 // THIS_BLOCKER is used to prevent this task from running before the
136 // one for the previous input file. NEXT_BLOCKER is used to prevent
137 // the next task from running.
7e1edb90 138 Add_symbols(Input_objects* input_objects, Symbol_table* symtab,
15f8229b
ILT
139 Layout* layout, Dirsearch* dirpath, int dirindex,
140 Mapfile* mapfile, const Input_argument* input_argument,
b672b057 141 Object* object,
f6ce93d6
ILT
142 Read_symbols_data* sd, Task_token* this_blocker,
143 Task_token* next_blocker)
7e1edb90 144 : input_objects_(input_objects), symtab_(symtab), layout_(layout),
15f8229b 145 dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile),
b672b057 146 input_argument_(input_argument),
7e1edb90 147 object_(object), sd_(sd), this_blocker_(this_blocker),
ead1e424 148 next_blocker_(next_blocker)
bae7f79e
ILT
149 { }
150
151 ~Add_symbols();
152
153 // The standard Task methods.
154
17a1d0a9
ILT
155 Task_token*
156 is_runnable();
bae7f79e 157
17a1d0a9
ILT
158 void
159 locks(Task_locker*);
bae7f79e
ILT
160
161 void
162 run(Workqueue*);
163
c7912668
ILT
164 std::string
165 get_name() const
166 { return "Add_symbols " + this->object_->name(); }
167
bae7f79e 168private:
ead1e424 169 Input_objects* input_objects_;
14bfc3f5 170 Symbol_table* symtab_;
12e14209 171 Layout* layout_;
15f8229b
ILT
172 Dirsearch* dirpath_;
173 int dirindex_;
174 Mapfile* mapfile_;
175 const Input_argument* input_argument_;
bae7f79e 176 Object* object_;
12e14209 177 Read_symbols_data* sd_;
bae7f79e
ILT
178 Task_token* this_blocker_;
179 Task_token* next_blocker_;
180};
181
ead1e424
ILT
182// This class is used to track the archives in a group.
183
184class Input_group
185{
186 public:
187 typedef std::vector<Archive*> Archives;
188 typedef Archives::const_iterator const_iterator;
189
190 Input_group()
191 : archives_()
192 { }
193
0f3b89d8
ILT
194 ~Input_group();
195
ead1e424
ILT
196 // Add an archive to the group.
197 void
198 add_archive(Archive* arch)
199 { this->archives_.push_back(arch); }
200
201 // Loop over the archives in the group.
202
203 const_iterator
204 begin() const
205 { return this->archives_.begin(); }
206
207 const_iterator
208 end() const
209 { return this->archives_.end(); }
210
211 private:
212 Archives archives_;
213};
214
114dfbe1
ILT
215// This class starts the handling of a group. It exists only to pick
216// up the number of undefined symbols at that point, so that we only
217// run back through the group if we saw a new undefined symbol.
218
219class Start_group : public Task
220{
221 public:
222 Start_group(Symbol_table* symtab, Finish_group* finish_group,
223 Task_token* this_blocker, Task_token* next_blocker)
224 : symtab_(symtab), finish_group_(finish_group),
225 this_blocker_(this_blocker), next_blocker_(next_blocker)
226 { }
227
228 ~Start_group();
229
230 // The standard Task methods.
231
232 Task_token*
233 is_runnable();
234
235 void
236 locks(Task_locker*);
237
238 void
239 run(Workqueue*);
240
241 std::string
242 get_name() const
243 { return "Start_group"; }
244
245 private:
246 Symbol_table* symtab_;
247 Finish_group* finish_group_;
248 Task_token* this_blocker_;
249 Task_token* next_blocker_;
250};
251
ead1e424
ILT
252// This class is used to finish up handling a group. It is just a
253// closure.
254
255class Finish_group : public Task
256{
257 public:
7e1edb90 258 Finish_group(Input_objects* input_objects, Symbol_table* symtab,
7d9e3d98 259 Layout* layout, Mapfile* mapfile, Input_group* input_group,
ead1e424 260 Task_token* next_blocker)
7e1edb90 261 : input_objects_(input_objects), symtab_(symtab),
7d9e3d98 262 layout_(layout), mapfile_(mapfile), input_group_(input_group),
114dfbe1 263 saw_undefined_(0), this_blocker_(NULL), next_blocker_(next_blocker)
ead1e424
ILT
264 { }
265
266 ~Finish_group();
267
114dfbe1
ILT
268 // Set the number of undefined symbols when we start processing the
269 // group. This is called by the Start_group task.
270 void
271 set_saw_undefined(size_t saw_undefined)
272 { this->saw_undefined_ = saw_undefined; }
273
274 // Set the blocker to use for this task.
275 void
276 set_blocker(Task_token* this_blocker)
277 {
278 gold_assert(this->this_blocker_ == NULL);
279 this->this_blocker_ = this_blocker;
280 }
281
ead1e424
ILT
282 // The standard Task methods.
283
17a1d0a9
ILT
284 Task_token*
285 is_runnable();
ead1e424 286
17a1d0a9
ILT
287 void
288 locks(Task_locker*);
ead1e424
ILT
289
290 void
291 run(Workqueue*);
292
c7912668
ILT
293 std::string
294 get_name() const
295 { return "Finish_group"; }
296
ead1e424
ILT
297 private:
298 Input_objects* input_objects_;
299 Symbol_table* symtab_;
300 Layout* layout_;
7d9e3d98 301 Mapfile* mapfile_;
ead1e424 302 Input_group* input_group_;
114dfbe1 303 size_t saw_undefined_;
ead1e424
ILT
304 Task_token* this_blocker_;
305 Task_token* next_blocker_;
306};
307
da769d56
ILT
308// This class is used to read a file which was not recognized as an
309// object or archive. It tries to read it as a linker script, using
310// the tokens to serialize with the calls to Add_symbols.
311
312class Read_script : public Task
313{
314 public:
f1ed28fb 315 Read_script(Symbol_table* symtab, Layout* layout, Dirsearch* dirpath,
15f8229b 316 int dirindex, Input_objects* input_objects, Mapfile* mapfile,
f1ed28fb 317 Input_group* input_group, const Input_argument* input_argument,
da769d56
ILT
318 Input_file* input_file, Task_token* this_blocker,
319 Task_token* next_blocker)
15f8229b 320 : symtab_(symtab), layout_(layout), dirpath_(dirpath), dirindex_(dirindex),
7d9e3d98
ILT
321 input_objects_(input_objects), mapfile_(mapfile),
322 input_group_(input_group), input_argument_(input_argument),
323 input_file_(input_file), this_blocker_(this_blocker),
324 next_blocker_(next_blocker)
da769d56
ILT
325 { }
326
327 ~Read_script();
328
329 // The standard Task methods.
330
331 Task_token*
332 is_runnable();
333
334 void
335 locks(Task_locker*);
336
337 void
338 run(Workqueue*);
339
340 std::string
341 get_name() const;
342
343 private:
da769d56
ILT
344 Symbol_table* symtab_;
345 Layout* layout_;
346 Dirsearch* dirpath_;
15f8229b 347 int dirindex_;
da769d56 348 Input_objects* input_objects_;
7d9e3d98 349 Mapfile* mapfile_;
da769d56
ILT
350 Input_group* input_group_;
351 const Input_argument* input_argument_;
352 Input_file* input_file_;
353 Task_token* this_blocker_;
354 Task_token* next_blocker_;
355};
356
bae7f79e
ILT
357} // end namespace gold
358
359#endif // !defined(GOLD_READSYMS_H)
This page took 0.236766 seconds and 4 git commands to generate.