]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/readsyms.h
Correct locking if a file could not be opened.
[thirdparty/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 private:
81 // Handle an archive group.
82 void
83 do_group(Workqueue*);
84
85 // Open and identify the file.
86 bool
87 do_read_symbols(Workqueue*);
88
89 const General_options& options_;
90 Input_objects* input_objects_;
91 Symbol_table* symtab_;
92 Layout* layout_;
93 const Dirsearch& dirpath_;
94 const Input_argument* input_argument_;
95 Input_group* input_group_;
96 Task_token* this_blocker_;
97 Task_token* next_blocker_;
98 };
99
100 // This Task handles adding the symbols to the symbol table. These
101 // tasks must be run in the same order as the arguments appear on the
102 // command line.
103
104 class Add_symbols : public Task
105 {
106 public:
107 // THIS_BLOCKER is used to prevent this task from running before the
108 // one for the previous input file. NEXT_BLOCKER is used to prevent
109 // the next task from running.
110 Add_symbols(Input_objects* input_objects, Symbol_table* symtab,
111 Layout* layout, Object* object,
112 Read_symbols_data* sd, Task_token* this_blocker,
113 Task_token* next_blocker)
114 : input_objects_(input_objects), symtab_(symtab), layout_(layout),
115 object_(object), sd_(sd), this_blocker_(this_blocker),
116 next_blocker_(next_blocker)
117 { }
118
119 ~Add_symbols();
120
121 // The standard Task methods.
122
123 Is_runnable_type
124 is_runnable(Workqueue*);
125
126 Task_locker*
127 locks(Workqueue*);
128
129 void
130 run(Workqueue*);
131
132 private:
133 class Add_symbols_locker;
134
135 Input_objects* input_objects_;
136 Symbol_table* symtab_;
137 Layout* layout_;
138 Object* object_;
139 Read_symbols_data* sd_;
140 Task_token* this_blocker_;
141 Task_token* next_blocker_;
142 };
143
144 // This class is used to track the archives in a group.
145
146 class Input_group
147 {
148 public:
149 typedef std::vector<Archive*> Archives;
150 typedef Archives::const_iterator const_iterator;
151
152 Input_group()
153 : archives_()
154 { }
155
156 // Add an archive to the group.
157 void
158 add_archive(Archive* arch)
159 { this->archives_.push_back(arch); }
160
161 // Loop over the archives in the group.
162
163 const_iterator
164 begin() const
165 { return this->archives_.begin(); }
166
167 const_iterator
168 end() const
169 { return this->archives_.end(); }
170
171 private:
172 Archives archives_;
173 };
174
175 // This class is used to finish up handling a group. It is just a
176 // closure.
177
178 class Finish_group : public Task
179 {
180 public:
181 Finish_group(Input_objects* input_objects, Symbol_table* symtab,
182 Layout* layout, Input_group* input_group,
183 int saw_undefined, Task_token* this_blocker,
184 Task_token* next_blocker)
185 : input_objects_(input_objects), symtab_(symtab),
186 layout_(layout), input_group_(input_group),
187 saw_undefined_(saw_undefined), this_blocker_(this_blocker),
188 next_blocker_(next_blocker)
189 { }
190
191 ~Finish_group();
192
193 // The standard Task methods.
194
195 Is_runnable_type
196 is_runnable(Workqueue*);
197
198 Task_locker*
199 locks(Workqueue*);
200
201 void
202 run(Workqueue*);
203
204 private:
205 Input_objects* input_objects_;
206 Symbol_table* symtab_;
207 Layout* layout_;
208 Input_group* input_group_;
209 int saw_undefined_;
210 Task_token* this_blocker_;
211 Task_token* next_blocker_;
212 };
213
214 } // end namespace gold
215
216 #endif // !defined(GOLD_READSYMS_H)