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 <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 | ||
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. | |
54dc6425 | 57 | Read_symbols(const General_options& options, Input_objects* input_objects, |
17a1d0a9 | 58 | Symbol_table* symtab, Layout* layout, Dirsearch* dirpath, |
7d9e3d98 ILT |
59 | Mapfile* mapfile, const Input_argument* input_argument, |
60 | Input_group* input_group, Task_token* this_blocker, | |
61 | Task_token* next_blocker) | |
a2fb1b05 | 62 | : options_(options), input_objects_(input_objects), symtab_(symtab), |
7d9e3d98 ILT |
63 | layout_(layout), dirpath_(dirpath), 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 | ||
70 | // The standard Task methods. | |
71 | ||
17a1d0a9 ILT |
72 | Task_token* |
73 | is_runnable(); | |
bae7f79e | 74 | |
17a1d0a9 ILT |
75 | void |
76 | locks(Task_locker*); | |
bae7f79e ILT |
77 | |
78 | void | |
79 | run(Workqueue*); | |
80 | ||
c7912668 ILT |
81 | std::string |
82 | get_name() const; | |
83 | ||
bae7f79e | 84 | private: |
ead1e424 ILT |
85 | // Handle an archive group. |
86 | void | |
87 | do_group(Workqueue*); | |
88 | ||
ee6d2efe ILT |
89 | // Open and identify the file. |
90 | bool | |
91 | do_read_symbols(Workqueue*); | |
92 | ||
bae7f79e | 93 | const General_options& options_; |
54dc6425 | 94 | Input_objects* input_objects_; |
14bfc3f5 | 95 | Symbol_table* symtab_; |
12e14209 | 96 | Layout* layout_; |
17a1d0a9 | 97 | Dirsearch* dirpath_; |
7d9e3d98 | 98 | Mapfile* mapfile_; |
dbe717ef | 99 | const Input_argument* input_argument_; |
ead1e424 | 100 | Input_group* input_group_; |
bae7f79e ILT |
101 | Task_token* this_blocker_; |
102 | Task_token* next_blocker_; | |
103 | }; | |
104 | ||
105 | // This Task handles adding the symbols to the symbol table. These | |
106 | // tasks must be run in the same order as the arguments appear on the | |
107 | // command line. | |
108 | ||
109 | class Add_symbols : public Task | |
110 | { | |
111 | public: | |
112 | // THIS_BLOCKER is used to prevent this task from running before the | |
113 | // one for the previous input file. NEXT_BLOCKER is used to prevent | |
114 | // the next task from running. | |
7e1edb90 ILT |
115 | Add_symbols(Input_objects* input_objects, Symbol_table* symtab, |
116 | Layout* layout, Object* object, | |
f6ce93d6 ILT |
117 | Read_symbols_data* sd, Task_token* this_blocker, |
118 | Task_token* next_blocker) | |
7e1edb90 ILT |
119 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
120 | object_(object), sd_(sd), this_blocker_(this_blocker), | |
ead1e424 | 121 | next_blocker_(next_blocker) |
bae7f79e ILT |
122 | { } |
123 | ||
124 | ~Add_symbols(); | |
125 | ||
126 | // The standard Task methods. | |
127 | ||
17a1d0a9 ILT |
128 | Task_token* |
129 | is_runnable(); | |
bae7f79e | 130 | |
17a1d0a9 ILT |
131 | void |
132 | locks(Task_locker*); | |
bae7f79e ILT |
133 | |
134 | void | |
135 | run(Workqueue*); | |
136 | ||
c7912668 ILT |
137 | std::string |
138 | get_name() const | |
139 | { return "Add_symbols " + this->object_->name(); } | |
140 | ||
bae7f79e | 141 | private: |
ead1e424 | 142 | Input_objects* input_objects_; |
14bfc3f5 | 143 | Symbol_table* symtab_; |
12e14209 | 144 | Layout* layout_; |
bae7f79e | 145 | Object* object_; |
12e14209 | 146 | Read_symbols_data* sd_; |
bae7f79e ILT |
147 | Task_token* this_blocker_; |
148 | Task_token* next_blocker_; | |
149 | }; | |
150 | ||
ead1e424 ILT |
151 | // This class is used to track the archives in a group. |
152 | ||
153 | class Input_group | |
154 | { | |
155 | public: | |
156 | typedef std::vector<Archive*> Archives; | |
157 | typedef Archives::const_iterator const_iterator; | |
158 | ||
159 | Input_group() | |
160 | : archives_() | |
161 | { } | |
162 | ||
163 | // Add an archive to the group. | |
164 | void | |
165 | add_archive(Archive* arch) | |
166 | { this->archives_.push_back(arch); } | |
167 | ||
168 | // Loop over the archives in the group. | |
169 | ||
170 | const_iterator | |
171 | begin() const | |
172 | { return this->archives_.begin(); } | |
173 | ||
174 | const_iterator | |
175 | end() const | |
176 | { return this->archives_.end(); } | |
177 | ||
178 | private: | |
179 | Archives archives_; | |
180 | }; | |
181 | ||
182 | // This class is used to finish up handling a group. It is just a | |
183 | // closure. | |
184 | ||
185 | class Finish_group : public Task | |
186 | { | |
187 | public: | |
7e1edb90 | 188 | Finish_group(Input_objects* input_objects, Symbol_table* symtab, |
7d9e3d98 | 189 | Layout* layout, Mapfile* mapfile, Input_group* input_group, |
ead1e424 ILT |
190 | int saw_undefined, Task_token* this_blocker, |
191 | Task_token* next_blocker) | |
7e1edb90 | 192 | : input_objects_(input_objects), symtab_(symtab), |
7d9e3d98 | 193 | layout_(layout), mapfile_(mapfile), input_group_(input_group), |
f6ce93d6 ILT |
194 | saw_undefined_(saw_undefined), this_blocker_(this_blocker), |
195 | next_blocker_(next_blocker) | |
ead1e424 ILT |
196 | { } |
197 | ||
198 | ~Finish_group(); | |
199 | ||
200 | // The standard Task methods. | |
201 | ||
17a1d0a9 ILT |
202 | Task_token* |
203 | is_runnable(); | |
ead1e424 | 204 | |
17a1d0a9 ILT |
205 | void |
206 | locks(Task_locker*); | |
ead1e424 ILT |
207 | |
208 | void | |
209 | run(Workqueue*); | |
210 | ||
c7912668 ILT |
211 | std::string |
212 | get_name() const | |
213 | { return "Finish_group"; } | |
214 | ||
ead1e424 ILT |
215 | private: |
216 | Input_objects* input_objects_; | |
217 | Symbol_table* symtab_; | |
218 | Layout* layout_; | |
7d9e3d98 | 219 | Mapfile* mapfile_; |
ead1e424 ILT |
220 | Input_group* input_group_; |
221 | int saw_undefined_; | |
222 | Task_token* this_blocker_; | |
223 | Task_token* next_blocker_; | |
224 | }; | |
225 | ||
da769d56 ILT |
226 | // This class is used to read a file which was not recognized as an |
227 | // object or archive. It tries to read it as a linker script, using | |
228 | // the tokens to serialize with the calls to Add_symbols. | |
229 | ||
230 | class Read_script : public Task | |
231 | { | |
232 | public: | |
233 | Read_script(const General_options& options, Symbol_table* symtab, | |
234 | Layout* layout, Dirsearch* dirpath, Input_objects* input_objects, | |
7d9e3d98 ILT |
235 | Mapfile* mapfile, Input_group* input_group, |
236 | const Input_argument* input_argument, | |
da769d56 ILT |
237 | Input_file* input_file, Task_token* this_blocker, |
238 | Task_token* next_blocker) | |
239 | : options_(options), symtab_(symtab), layout_(layout), dirpath_(dirpath), | |
7d9e3d98 ILT |
240 | input_objects_(input_objects), mapfile_(mapfile), |
241 | input_group_(input_group), input_argument_(input_argument), | |
242 | input_file_(input_file), this_blocker_(this_blocker), | |
243 | next_blocker_(next_blocker) | |
da769d56 ILT |
244 | { } |
245 | ||
246 | ~Read_script(); | |
247 | ||
248 | // The standard Task methods. | |
249 | ||
250 | Task_token* | |
251 | is_runnable(); | |
252 | ||
253 | void | |
254 | locks(Task_locker*); | |
255 | ||
256 | void | |
257 | run(Workqueue*); | |
258 | ||
259 | std::string | |
260 | get_name() const; | |
261 | ||
262 | private: | |
263 | const General_options& options_; | |
264 | Symbol_table* symtab_; | |
265 | Layout* layout_; | |
266 | Dirsearch* dirpath_; | |
267 | Input_objects* input_objects_; | |
7d9e3d98 | 268 | Mapfile* mapfile_; |
da769d56 ILT |
269 | Input_group* input_group_; |
270 | const Input_argument* input_argument_; | |
271 | Input_file* input_file_; | |
272 | Task_token* this_blocker_; | |
273 | Task_token* next_blocker_; | |
274 | }; | |
275 | ||
bae7f79e ILT |
276 | } // end namespace gold |
277 | ||
278 | #endif // !defined(GOLD_READSYMS_H) |