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