]>
Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // readsyms.h -- read input file symbols for gold -*- C++ -*- |
2 | ||
ebdbb458 | 3 | // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <[email protected]>. |
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 | ||
31 | namespace gold | |
32 | { | |
33 | ||
54dc6425 ILT |
34 | class Input_objects; |
35 | class Symbol_table; | |
ead1e424 ILT |
36 | class Input_group; |
37 | class Archive; | |
54dc6425 | 38 | |
bae7f79e ILT |
39 | // This Task is responsible for reading the symbols from an input |
40 | // file. This also includes reading the relocations so that we can | |
41 | // check for any that require a PLT and/or a GOT. After the data has | |
42 | // been read, this queues up another task to actually add the symbols | |
43 | // to the symbol table. The tasks are separated because the file | |
44 | // reading can occur in parallel but adding the symbols must be done | |
45 | // in the order of the input files. | |
46 | ||
47 | class Read_symbols : public Task | |
48 | { | |
49 | public: | |
50 | // DIRPATH is the list of directories to search for libraries. | |
ead1e424 ILT |
51 | // INPUT is the file to read. INPUT_GROUP is not NULL if we are in |
52 | // the middle of an input group. THIS_BLOCKER is used to prevent | |
53 | // the associated Add_symbols task from running before the previous | |
54 | // one has completed; it will be NULL for the first task. | |
55 | // NEXT_BLOCKER is used to block the next input file from adding | |
56 | // symbols. | |
f1ed28fb | 57 | Read_symbols(Input_objects* input_objects, Symbol_table* symtab, |
15f8229b ILT |
58 | Layout* layout, Dirsearch* dirpath, int dirindex, |
59 | Mapfile* mapfile, const Input_argument* input_argument, | |
7d9e3d98 ILT |
60 | Input_group* input_group, Task_token* this_blocker, |
61 | Task_token* next_blocker) | |
f1ed28fb | 62 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
15f8229b ILT |
63 | dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile), |
64 | input_argument_(input_argument), input_group_(input_group), | |
65 | this_blocker_(this_blocker), next_blocker_(next_blocker) | |
bae7f79e ILT |
66 | { } |
67 | ||
68 | ~Read_symbols(); | |
69 | ||
15f8229b ILT |
70 | // If appropriate, issue a warning about skipping an incompatible |
71 | // object. | |
72 | static void | |
73 | incompatible_warning(const Input_argument*, const Input_file*); | |
74 | ||
75 | // Requeue a Read_symbols task to search for the next object with | |
76 | // the same name. | |
77 | static void | |
78 | requeue(Workqueue*, Input_objects*, Symbol_table*, Layout*, Dirsearch*, | |
79 | int dirindex, Mapfile*, const Input_argument*, Input_group*, | |
80 | Task_token* next_blocker); | |
81 | ||
bae7f79e ILT |
82 | // The standard Task methods. |
83 | ||
17a1d0a9 ILT |
84 | Task_token* |
85 | is_runnable(); | |
bae7f79e | 86 | |
17a1d0a9 ILT |
87 | void |
88 | locks(Task_locker*); | |
bae7f79e ILT |
89 | |
90 | void | |
91 | run(Workqueue*); | |
92 | ||
c7912668 ILT |
93 | std::string |
94 | get_name() const; | |
95 | ||
bae7f79e | 96 | private: |
ead1e424 ILT |
97 | // Handle an archive group. |
98 | void | |
99 | do_group(Workqueue*); | |
100 | ||
ee6d2efe ILT |
101 | // Open and identify the file. |
102 | bool | |
103 | do_read_symbols(Workqueue*); | |
104 | ||
54dc6425 | 105 | Input_objects* input_objects_; |
14bfc3f5 | 106 | Symbol_table* symtab_; |
12e14209 | 107 | Layout* layout_; |
17a1d0a9 | 108 | Dirsearch* dirpath_; |
15f8229b | 109 | int dirindex_; |
7d9e3d98 | 110 | Mapfile* mapfile_; |
dbe717ef | 111 | const Input_argument* input_argument_; |
ead1e424 | 112 | Input_group* input_group_; |
bae7f79e ILT |
113 | Task_token* this_blocker_; |
114 | Task_token* next_blocker_; | |
115 | }; | |
116 | ||
117 | // This Task handles adding the symbols to the symbol table. These | |
118 | // tasks must be run in the same order as the arguments appear on the | |
119 | // command line. | |
120 | ||
121 | class Add_symbols : public Task | |
122 | { | |
123 | public: | |
124 | // THIS_BLOCKER is used to prevent this task from running before the | |
125 | // one for the previous input file. NEXT_BLOCKER is used to prevent | |
126 | // the next task from running. | |
7e1edb90 | 127 | Add_symbols(Input_objects* input_objects, Symbol_table* symtab, |
15f8229b ILT |
128 | Layout* layout, Dirsearch* dirpath, int dirindex, |
129 | Mapfile* mapfile, const Input_argument* input_argument, | |
130 | Input_group* input_group, Object* object, | |
f6ce93d6 ILT |
131 | Read_symbols_data* sd, Task_token* this_blocker, |
132 | Task_token* next_blocker) | |
7e1edb90 | 133 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
15f8229b ILT |
134 | dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile), |
135 | input_argument_(input_argument), input_group_(input_group), | |
7e1edb90 | 136 | object_(object), sd_(sd), this_blocker_(this_blocker), |
ead1e424 | 137 | next_blocker_(next_blocker) |
bae7f79e ILT |
138 | { } |
139 | ||
140 | ~Add_symbols(); | |
141 | ||
142 | // The standard Task methods. | |
143 | ||
17a1d0a9 ILT |
144 | Task_token* |
145 | is_runnable(); | |
bae7f79e | 146 | |
17a1d0a9 ILT |
147 | void |
148 | locks(Task_locker*); | |
bae7f79e ILT |
149 | |
150 | void | |
151 | run(Workqueue*); | |
152 | ||
c7912668 ILT |
153 | std::string |
154 | get_name() const | |
155 | { return "Add_symbols " + this->object_->name(); } | |
156 | ||
bae7f79e | 157 | private: |
ead1e424 | 158 | Input_objects* input_objects_; |
14bfc3f5 | 159 | Symbol_table* symtab_; |
12e14209 | 160 | Layout* layout_; |
15f8229b ILT |
161 | Dirsearch* dirpath_; |
162 | int dirindex_; | |
163 | Mapfile* mapfile_; | |
164 | const Input_argument* input_argument_; | |
165 | Input_group* input_group_; | |
bae7f79e | 166 | Object* object_; |
12e14209 | 167 | Read_symbols_data* sd_; |
bae7f79e ILT |
168 | Task_token* this_blocker_; |
169 | Task_token* next_blocker_; | |
170 | }; | |
171 | ||
ead1e424 ILT |
172 | // This class is used to track the archives in a group. |
173 | ||
174 | class Input_group | |
175 | { | |
176 | public: | |
177 | typedef std::vector<Archive*> Archives; | |
178 | typedef Archives::const_iterator const_iterator; | |
179 | ||
180 | Input_group() | |
181 | : archives_() | |
182 | { } | |
183 | ||
184 | // Add an archive to the group. | |
185 | void | |
186 | add_archive(Archive* arch) | |
187 | { this->archives_.push_back(arch); } | |
188 | ||
189 | // Loop over the archives in the group. | |
190 | ||
191 | const_iterator | |
192 | begin() const | |
193 | { return this->archives_.begin(); } | |
194 | ||
195 | const_iterator | |
196 | end() const | |
197 | { return this->archives_.end(); } | |
198 | ||
199 | private: | |
200 | Archives archives_; | |
201 | }; | |
202 | ||
203 | // This class is used to finish up handling a group. It is just a | |
204 | // closure. | |
205 | ||
206 | class Finish_group : public Task | |
207 | { | |
208 | public: | |
7e1edb90 | 209 | Finish_group(Input_objects* input_objects, Symbol_table* symtab, |
7d9e3d98 | 210 | Layout* layout, Mapfile* mapfile, Input_group* input_group, |
ead1e424 ILT |
211 | int saw_undefined, Task_token* this_blocker, |
212 | Task_token* next_blocker) | |
7e1edb90 | 213 | : input_objects_(input_objects), symtab_(symtab), |
7d9e3d98 | 214 | layout_(layout), mapfile_(mapfile), input_group_(input_group), |
f6ce93d6 ILT |
215 | saw_undefined_(saw_undefined), this_blocker_(this_blocker), |
216 | next_blocker_(next_blocker) | |
ead1e424 ILT |
217 | { } |
218 | ||
219 | ~Finish_group(); | |
220 | ||
221 | // The standard Task methods. | |
222 | ||
17a1d0a9 ILT |
223 | Task_token* |
224 | is_runnable(); | |
ead1e424 | 225 | |
17a1d0a9 ILT |
226 | void |
227 | locks(Task_locker*); | |
ead1e424 ILT |
228 | |
229 | void | |
230 | run(Workqueue*); | |
231 | ||
c7912668 ILT |
232 | std::string |
233 | get_name() const | |
234 | { return "Finish_group"; } | |
235 | ||
ead1e424 ILT |
236 | private: |
237 | Input_objects* input_objects_; | |
238 | Symbol_table* symtab_; | |
239 | Layout* layout_; | |
7d9e3d98 | 240 | Mapfile* mapfile_; |
ead1e424 ILT |
241 | Input_group* input_group_; |
242 | int saw_undefined_; | |
243 | Task_token* this_blocker_; | |
244 | Task_token* next_blocker_; | |
245 | }; | |
246 | ||
da769d56 ILT |
247 | // This class is used to read a file which was not recognized as an |
248 | // object or archive. It tries to read it as a linker script, using | |
249 | // the tokens to serialize with the calls to Add_symbols. | |
250 | ||
251 | class Read_script : public Task | |
252 | { | |
253 | public: | |
f1ed28fb | 254 | Read_script(Symbol_table* symtab, Layout* layout, Dirsearch* dirpath, |
15f8229b | 255 | int dirindex, Input_objects* input_objects, Mapfile* mapfile, |
f1ed28fb | 256 | Input_group* input_group, const Input_argument* input_argument, |
da769d56 ILT |
257 | Input_file* input_file, Task_token* this_blocker, |
258 | Task_token* next_blocker) | |
15f8229b | 259 | : symtab_(symtab), layout_(layout), dirpath_(dirpath), dirindex_(dirindex), |
7d9e3d98 ILT |
260 | input_objects_(input_objects), mapfile_(mapfile), |
261 | input_group_(input_group), input_argument_(input_argument), | |
262 | input_file_(input_file), this_blocker_(this_blocker), | |
263 | next_blocker_(next_blocker) | |
da769d56 ILT |
264 | { } |
265 | ||
266 | ~Read_script(); | |
267 | ||
268 | // The standard Task methods. | |
269 | ||
270 | Task_token* | |
271 | is_runnable(); | |
272 | ||
273 | void | |
274 | locks(Task_locker*); | |
275 | ||
276 | void | |
277 | run(Workqueue*); | |
278 | ||
279 | std::string | |
280 | get_name() const; | |
281 | ||
282 | private: | |
da769d56 ILT |
283 | Symbol_table* symtab_; |
284 | Layout* layout_; | |
285 | Dirsearch* dirpath_; | |
15f8229b | 286 | int dirindex_; |
da769d56 | 287 | Input_objects* input_objects_; |
7d9e3d98 | 288 | Mapfile* mapfile_; |
da769d56 ILT |
289 | Input_group* input_group_; |
290 | const Input_argument* input_argument_; | |
291 | Input_file* input_file_; | |
292 | Task_token* this_blocker_; | |
293 | Task_token* next_blocker_; | |
294 | }; | |
295 | ||
bae7f79e ILT |
296 | } // end namespace gold |
297 | ||
298 | #endif // !defined(GOLD_READSYMS_H) |