Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // readsyms.h -- read input file symbols for gold -*- C++ -*- |
2 | ||
3 | #ifndef GOLD_READSYMS_H | |
4 | #define GOLD_READSYMS_H | |
5 | ||
ead1e424 ILT |
6 | #include <vector> |
7 | ||
bae7f79e ILT |
8 | #include "workqueue.h" |
9 | #include "object.h" | |
10 | ||
11 | namespace gold | |
12 | { | |
13 | ||
54dc6425 ILT |
14 | class Input_objects; |
15 | class Symbol_table; | |
ead1e424 ILT |
16 | class Input_group; |
17 | class Archive; | |
54dc6425 | 18 | |
bae7f79e ILT |
19 | // This Task is responsible for reading the symbols from an input |
20 | // file. This also includes reading the relocations so that we can | |
21 | // check for any that require a PLT and/or a GOT. After the data has | |
22 | // been read, this queues up another task to actually add the symbols | |
23 | // to the symbol table. The tasks are separated because the file | |
24 | // reading can occur in parallel but adding the symbols must be done | |
25 | // in the order of the input files. | |
26 | ||
27 | class Read_symbols : public Task | |
28 | { | |
29 | public: | |
30 | // DIRPATH is the list of directories to search for libraries. | |
ead1e424 ILT |
31 | // INPUT is the file to read. INPUT_GROUP is not NULL if we are in |
32 | // the middle of an input group. THIS_BLOCKER is used to prevent | |
33 | // the associated Add_symbols task from running before the previous | |
34 | // one has completed; it will be NULL for the first task. | |
35 | // NEXT_BLOCKER is used to block the next input file from adding | |
36 | // symbols. | |
54dc6425 | 37 | Read_symbols(const General_options& options, Input_objects* input_objects, |
12e14209 | 38 | Symbol_table* symtab, Layout* layout, const Dirsearch& dirpath, |
dbe717ef | 39 | const Input_argument* input_argument, Input_group* input_group, |
14bfc3f5 | 40 | Task_token* this_blocker, Task_token* next_blocker) |
a2fb1b05 | 41 | : options_(options), input_objects_(input_objects), symtab_(symtab), |
dbe717ef | 42 | layout_(layout), dirpath_(dirpath), input_argument_(input_argument), |
ead1e424 ILT |
43 | input_group_(input_group), this_blocker_(this_blocker), |
44 | next_blocker_(next_blocker) | |
bae7f79e ILT |
45 | { } |
46 | ||
47 | ~Read_symbols(); | |
48 | ||
49 | // The standard Task methods. | |
50 | ||
51 | Is_runnable_type | |
52 | is_runnable(Workqueue*); | |
53 | ||
54 | Task_locker* | |
55 | locks(Workqueue*); | |
56 | ||
57 | void | |
58 | run(Workqueue*); | |
59 | ||
60 | private: | |
ead1e424 ILT |
61 | // Handle an archive group. |
62 | void | |
63 | do_group(Workqueue*); | |
64 | ||
bae7f79e | 65 | const General_options& options_; |
54dc6425 | 66 | Input_objects* input_objects_; |
14bfc3f5 | 67 | Symbol_table* symtab_; |
12e14209 | 68 | Layout* layout_; |
bae7f79e | 69 | const Dirsearch& dirpath_; |
dbe717ef | 70 | const Input_argument* input_argument_; |
ead1e424 | 71 | Input_group* input_group_; |
bae7f79e ILT |
72 | Task_token* this_blocker_; |
73 | Task_token* next_blocker_; | |
74 | }; | |
75 | ||
76 | // This Task handles adding the symbols to the symbol table. These | |
77 | // tasks must be run in the same order as the arguments appear on the | |
78 | // command line. | |
79 | ||
80 | class Add_symbols : public Task | |
81 | { | |
82 | public: | |
83 | // THIS_BLOCKER is used to prevent this task from running before the | |
84 | // one for the previous input file. NEXT_BLOCKER is used to prevent | |
85 | // the next task from running. | |
7e1edb90 ILT |
86 | Add_symbols(Input_objects* input_objects, Symbol_table* symtab, |
87 | Layout* layout, Object* object, | |
f6ce93d6 ILT |
88 | Read_symbols_data* sd, Task_token* this_blocker, |
89 | Task_token* next_blocker) | |
7e1edb90 ILT |
90 | : input_objects_(input_objects), symtab_(symtab), layout_(layout), |
91 | object_(object), sd_(sd), this_blocker_(this_blocker), | |
ead1e424 | 92 | next_blocker_(next_blocker) |
bae7f79e ILT |
93 | { } |
94 | ||
95 | ~Add_symbols(); | |
96 | ||
97 | // The standard Task methods. | |
98 | ||
99 | Is_runnable_type | |
100 | is_runnable(Workqueue*); | |
101 | ||
102 | Task_locker* | |
103 | locks(Workqueue*); | |
104 | ||
105 | void | |
106 | run(Workqueue*); | |
107 | ||
108 | private: | |
a2fb1b05 ILT |
109 | class Add_symbols_locker; |
110 | ||
ead1e424 | 111 | Input_objects* input_objects_; |
14bfc3f5 | 112 | Symbol_table* symtab_; |
12e14209 | 113 | Layout* layout_; |
bae7f79e | 114 | Object* object_; |
12e14209 | 115 | Read_symbols_data* sd_; |
bae7f79e ILT |
116 | Task_token* this_blocker_; |
117 | Task_token* next_blocker_; | |
118 | }; | |
119 | ||
ead1e424 ILT |
120 | // This class is used to track the archives in a group. |
121 | ||
122 | class Input_group | |
123 | { | |
124 | public: | |
125 | typedef std::vector<Archive*> Archives; | |
126 | typedef Archives::const_iterator const_iterator; | |
127 | ||
128 | Input_group() | |
129 | : archives_() | |
130 | { } | |
131 | ||
132 | // Add an archive to the group. | |
133 | void | |
134 | add_archive(Archive* arch) | |
135 | { this->archives_.push_back(arch); } | |
136 | ||
137 | // Loop over the archives in the group. | |
138 | ||
139 | const_iterator | |
140 | begin() const | |
141 | { return this->archives_.begin(); } | |
142 | ||
143 | const_iterator | |
144 | end() const | |
145 | { return this->archives_.end(); } | |
146 | ||
147 | private: | |
148 | Archives archives_; | |
149 | }; | |
150 | ||
151 | // This class is used to finish up handling a group. It is just a | |
152 | // closure. | |
153 | ||
154 | class Finish_group : public Task | |
155 | { | |
156 | public: | |
7e1edb90 ILT |
157 | Finish_group(Input_objects* input_objects, Symbol_table* symtab, |
158 | Layout* layout, Input_group* input_group, | |
ead1e424 ILT |
159 | int saw_undefined, Task_token* this_blocker, |
160 | Task_token* next_blocker) | |
7e1edb90 | 161 | : input_objects_(input_objects), symtab_(symtab), |
f6ce93d6 ILT |
162 | layout_(layout), input_group_(input_group), |
163 | saw_undefined_(saw_undefined), this_blocker_(this_blocker), | |
164 | next_blocker_(next_blocker) | |
ead1e424 ILT |
165 | { } |
166 | ||
167 | ~Finish_group(); | |
168 | ||
169 | // The standard Task methods. | |
170 | ||
171 | Is_runnable_type | |
172 | is_runnable(Workqueue*); | |
173 | ||
174 | Task_locker* | |
175 | locks(Workqueue*); | |
176 | ||
177 | void | |
178 | run(Workqueue*); | |
179 | ||
180 | private: | |
181 | Input_objects* input_objects_; | |
182 | Symbol_table* symtab_; | |
183 | Layout* layout_; | |
184 | Input_group* input_group_; | |
185 | int saw_undefined_; | |
186 | Task_token* this_blocker_; | |
187 | Task_token* next_blocker_; | |
188 | }; | |
189 | ||
bae7f79e ILT |
190 | } // end namespace gold |
191 | ||
192 | #endif // !defined(GOLD_READSYMS_H) |