* elf-m10300.c (mn10300_elf_relax_section): Extend previous fix to cover forward...
[binutils-gdb.git] / gold / readsyms.h
1 // readsyms.h -- read input file symbols for gold -*- C++ -*-
2
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
23 #ifndef GOLD_READSYMS_H
24 #define GOLD_READSYMS_H
25
26 #include <vector>
27
28 #include "workqueue.h"
29 #include "object.h"
30
31 namespace gold
32 {
33
34 class Input_objects;
35 class Symbol_table;
36 class Input_group;
37 class Archive;
38
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.
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.
57 Read_symbols(const General_options& options, Input_objects* input_objects,
58 Symbol_table* symtab, Layout* layout, const Dirsearch& dirpath,
59 const Input_argument* input_argument, Input_group* input_group,
60 Task_token* this_blocker, Task_token* next_blocker)
61 : options_(options), input_objects_(input_objects), symtab_(symtab),
62 layout_(layout), dirpath_(dirpath), input_argument_(input_argument),
63 input_group_(input_group), this_blocker_(this_blocker),
64 next_blocker_(next_blocker)
65 { }
66
67 ~Read_symbols();
68
69 // The standard Task methods.
70
71 Is_runnable_type
72 is_runnable(Workqueue*);
73
74 Task_locker*
75 locks(Workqueue*);
76
77 void
78 run(Workqueue*);
79
80 std::string
81 get_name() const;
82
83 private:
84 // Handle an archive group.
85 void
86 do_group(Workqueue*);
87
88 // Open and identify the file.
89 bool
90 do_read_symbols(Workqueue*);
91
92 const General_options& options_;
93 Input_objects* input_objects_;
94 Symbol_table* symtab_;
95 Layout* layout_;
96 const Dirsearch& dirpath_;
97 const Input_argument* input_argument_;
98 Input_group* input_group_;
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.
113 Add_symbols(Input_objects* input_objects, Symbol_table* symtab,
114 Layout* layout, Object* object,
115 Read_symbols_data* sd, Task_token* this_blocker,
116 Task_token* next_blocker)
117 : input_objects_(input_objects), symtab_(symtab), layout_(layout),
118 object_(object), sd_(sd), this_blocker_(this_blocker),
119 next_blocker_(next_blocker)
120 { }
121
122 ~Add_symbols();
123
124 // The standard Task methods.
125
126 Is_runnable_type
127 is_runnable(Workqueue*);
128
129 Task_locker*
130 locks(Workqueue*);
131
132 void
133 run(Workqueue*);
134
135 std::string
136 get_name() const
137 { return "Add_symbols " + this->object_->name(); }
138
139 private:
140 class Add_symbols_locker;
141
142 Input_objects* input_objects_;
143 Symbol_table* symtab_;
144 Layout* layout_;
145 Object* object_;
146 Read_symbols_data* sd_;
147 Task_token* this_blocker_;
148 Task_token* next_blocker_;
149 };
150
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:
188 Finish_group(Input_objects* input_objects, Symbol_table* symtab,
189 Layout* layout, Input_group* input_group,
190 int saw_undefined, Task_token* this_blocker,
191 Task_token* next_blocker)
192 : input_objects_(input_objects), symtab_(symtab),
193 layout_(layout), input_group_(input_group),
194 saw_undefined_(saw_undefined), this_blocker_(this_blocker),
195 next_blocker_(next_blocker)
196 { }
197
198 ~Finish_group();
199
200 // The standard Task methods.
201
202 Is_runnable_type
203 is_runnable(Workqueue*);
204
205 Task_locker*
206 locks(Workqueue*);
207
208 void
209 run(Workqueue*);
210
211 std::string
212 get_name() const
213 { return "Finish_group"; }
214
215 private:
216 Input_objects* input_objects_;
217 Symbol_table* symtab_;
218 Layout* layout_;
219 Input_group* input_group_;
220 int saw_undefined_;
221 Task_token* this_blocker_;
222 Task_token* next_blocker_;
223 };
224
225 } // end namespace gold
226
227 #endif // !defined(GOLD_READSYMS_H)