Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // object.h -- support for an object file for linking in 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_OBJECT_H |
24 | #define GOLD_OBJECT_H | |
25 | ||
92e059d8 | 26 | #include <string> |
a2fb1b05 | 27 | #include <vector> |
14bfc3f5 | 28 | |
bae7f79e | 29 | #include "elfcpp.h" |
645f8123 | 30 | #include "elfcpp_file.h" |
bae7f79e | 31 | #include "fileread.h" |
14bfc3f5 | 32 | #include "target.h" |
bae7f79e ILT |
33 | |
34 | namespace gold | |
35 | { | |
36 | ||
92e059d8 | 37 | class General_options; |
17a1d0a9 | 38 | class Task; |
a2fb1b05 | 39 | class Layout; |
61ba1cf9 ILT |
40 | class Output_section; |
41 | class Output_file; | |
d491d34e | 42 | class Output_symtab_xindex; |
f6ce93d6 | 43 | class Dynobj; |
4625f782 | 44 | class Object_merge_map; |
6a74a719 | 45 | class Relocatable_relocs; |
a2fb1b05 | 46 | |
b8e6aad9 ILT |
47 | template<typename Stringpool_char> |
48 | class Stringpool_template; | |
49 | ||
bae7f79e ILT |
50 | // Data to pass from read_symbols() to add_symbols(). |
51 | ||
52 | struct Read_symbols_data | |
53 | { | |
12e14209 ILT |
54 | // Section headers. |
55 | File_view* section_headers; | |
56 | // Section names. | |
57 | File_view* section_names; | |
58 | // Size of section name data in bytes. | |
8383303e | 59 | section_size_type section_names_size; |
bae7f79e ILT |
60 | // Symbol data. |
61 | File_view* symbols; | |
62 | // Size of symbol data in bytes. | |
8383303e | 63 | section_size_type symbols_size; |
730cdc88 ILT |
64 | // Offset of external symbols within symbol data. This structure |
65 | // sometimes contains only external symbols, in which case this will | |
66 | // be zero. Sometimes it contains all symbols. | |
8383303e | 67 | section_offset_type external_symbols_offset; |
bae7f79e ILT |
68 | // Symbol names. |
69 | File_view* symbol_names; | |
70 | // Size of symbol name data in bytes. | |
8383303e | 71 | section_size_type symbol_names_size; |
dbe717ef ILT |
72 | |
73 | // Version information. This is only used on dynamic objects. | |
74 | // Version symbol data (from SHT_GNU_versym section). | |
75 | File_view* versym; | |
8383303e | 76 | section_size_type versym_size; |
dbe717ef ILT |
77 | // Version definition data (from SHT_GNU_verdef section). |
78 | File_view* verdef; | |
8383303e | 79 | section_size_type verdef_size; |
dbe717ef ILT |
80 | unsigned int verdef_info; |
81 | // Needed version data (from SHT_GNU_verneed section). | |
82 | File_view* verneed; | |
8383303e | 83 | section_size_type verneed_size; |
dbe717ef | 84 | unsigned int verneed_info; |
bae7f79e ILT |
85 | }; |
86 | ||
f7e2ee48 ILT |
87 | // Information used to print error messages. |
88 | ||
89 | struct Symbol_location_info | |
90 | { | |
91 | std::string source_file; | |
92 | std::string enclosing_symbol_name; | |
93 | int line_number; | |
94 | }; | |
95 | ||
92e059d8 ILT |
96 | // Data about a single relocation section. This is read in |
97 | // read_relocs and processed in scan_relocs. | |
98 | ||
99 | struct Section_relocs | |
100 | { | |
101 | // Index of reloc section. | |
102 | unsigned int reloc_shndx; | |
103 | // Index of section that relocs apply to. | |
104 | unsigned int data_shndx; | |
105 | // Contents of reloc section. | |
106 | File_view* contents; | |
107 | // Reloc section type. | |
108 | unsigned int sh_type; | |
109 | // Number of reloc entries. | |
110 | size_t reloc_count; | |
730cdc88 ILT |
111 | // Output section. |
112 | Output_section* output_section; | |
113 | // Whether this section has special handling for offsets. | |
114 | bool needs_special_offset_handling; | |
7019cd25 ILT |
115 | // Whether the data section is allocated (has the SHF_ALLOC flag set). |
116 | bool is_data_section_allocated; | |
92e059d8 ILT |
117 | }; |
118 | ||
119 | // Relocations in an object file. This is read in read_relocs and | |
120 | // processed in scan_relocs. | |
121 | ||
122 | struct Read_relocs_data | |
123 | { | |
124 | typedef std::vector<Section_relocs> Relocs_list; | |
125 | // The relocations. | |
126 | Relocs_list relocs; | |
127 | // The local symbols. | |
128 | File_view* local_symbols; | |
129 | }; | |
130 | ||
d491d34e ILT |
131 | // The Xindex class manages section indexes for objects with more than |
132 | // 0xff00 sections. | |
133 | ||
134 | class Xindex | |
135 | { | |
136 | public: | |
137 | Xindex(int large_shndx_offset) | |
138 | : large_shndx_offset_(large_shndx_offset), symtab_xindex_() | |
139 | { } | |
140 | ||
141 | // Initialize the symtab_xindex_ array, given the object and the | |
142 | // section index of the symbol table to use. | |
143 | template<int size, bool big_endian> | |
144 | void | |
145 | initialize_symtab_xindex(Object*, unsigned int symtab_shndx); | |
146 | ||
147 | // Read in the symtab_xindex_ array, given its section index. | |
148 | // PSHDRS may optionally point to the section headers. | |
149 | template<int size, bool big_endian> | |
150 | void | |
151 | read_symtab_xindex(Object*, unsigned int xindex_shndx, | |
152 | const unsigned char* pshdrs); | |
153 | ||
154 | // Symbol SYMNDX in OBJECT has a section of SHN_XINDEX; return the | |
155 | // real section index. | |
156 | unsigned int | |
157 | sym_xindex_to_shndx(Object* object, unsigned int symndx); | |
158 | ||
159 | private: | |
160 | // The type of the array giving the real section index for symbols | |
161 | // whose st_shndx field holds SHN_XINDEX. | |
162 | typedef std::vector<unsigned int> Symtab_xindex; | |
163 | ||
164 | // Adjust a section index if necessary. This should only be called | |
165 | // for ordinary section indexes. | |
166 | unsigned int | |
167 | adjust_shndx(unsigned int shndx) | |
168 | { | |
169 | if (shndx >= elfcpp::SHN_LORESERVE) | |
170 | shndx += this->large_shndx_offset_; | |
171 | return shndx; | |
172 | } | |
173 | ||
174 | // Adjust to apply to large section indexes. | |
175 | int large_shndx_offset_; | |
176 | // The data from the SHT_SYMTAB_SHNDX section. | |
177 | Symtab_xindex symtab_xindex_; | |
178 | }; | |
179 | ||
f6ce93d6 ILT |
180 | // Object is an abstract base class which represents either a 32-bit |
181 | // or a 64-bit input object. This can be a regular object file | |
182 | // (ET_REL) or a shared object (ET_DYN). | |
bae7f79e ILT |
183 | |
184 | class Object | |
185 | { | |
186 | public: | |
187 | // NAME is the name of the object as we would report it to the user | |
188 | // (e.g., libfoo.a(bar.o) if this is in an archive. INPUT_FILE is | |
189 | // used to read the file. OFFSET is the offset within the input | |
190 | // file--0 for a .o or .so file, something else for a .a file. | |
14bfc3f5 ILT |
191 | Object(const std::string& name, Input_file* input_file, bool is_dynamic, |
192 | off_t offset = 0) | |
dbe717ef | 193 | : name_(name), input_file_(input_file), offset_(offset), shnum_(-1U), |
d491d34e | 194 | is_dynamic_(is_dynamic), target_(NULL), xindex_(NULL) |
cb295612 | 195 | { input_file->file().add_object(); } |
bae7f79e ILT |
196 | |
197 | virtual ~Object() | |
cb295612 | 198 | { this->input_file_->file().remove_object(); } |
bae7f79e | 199 | |
14bfc3f5 | 200 | // Return the name of the object as we would report it to the tuser. |
bae7f79e ILT |
201 | const std::string& |
202 | name() const | |
203 | { return this->name_; } | |
204 | ||
cec9d2f3 ILT |
205 | // Get the offset into the file. |
206 | off_t | |
207 | offset() const | |
208 | { return this->offset_; } | |
209 | ||
14bfc3f5 ILT |
210 | // Return whether this is a dynamic object. |
211 | bool | |
212 | is_dynamic() const | |
213 | { return this->is_dynamic_; } | |
214 | ||
14bfc3f5 ILT |
215 | // Return the target structure associated with this object. |
216 | Target* | |
a2fb1b05 | 217 | target() const |
14bfc3f5 ILT |
218 | { return this->target_; } |
219 | ||
a2fb1b05 ILT |
220 | // Lock the underlying file. |
221 | void | |
17a1d0a9 ILT |
222 | lock(const Task* t) |
223 | { this->input_file()->file().lock(t); } | |
a2fb1b05 ILT |
224 | |
225 | // Unlock the underlying file. | |
226 | void | |
17a1d0a9 ILT |
227 | unlock(const Task* t) |
228 | { this->input_file()->file().unlock(t); } | |
a2fb1b05 ILT |
229 | |
230 | // Return whether the underlying file is locked. | |
231 | bool | |
232 | is_locked() const | |
7004837e | 233 | { return this->input_file()->file().is_locked(); } |
a2fb1b05 | 234 | |
17a1d0a9 ILT |
235 | // Return the token, so that the task can be queued. |
236 | Task_token* | |
237 | token() | |
238 | { return this->input_file()->file().token(); } | |
239 | ||
240 | // Release the underlying file. | |
241 | void | |
242 | release() | |
243 | { this->input_file_->file().release(); } | |
244 | ||
88dd47ac ILT |
245 | // Return whether we should just read symbols from this file. |
246 | bool | |
247 | just_symbols() const | |
248 | { return this->input_file()->just_symbols(); } | |
249 | ||
14bfc3f5 ILT |
250 | // Return the sized target structure associated with this object. |
251 | // This is like the target method but it returns a pointer of | |
252 | // appropriate checked type. | |
253 | template<int size, bool big_endian> | |
254 | Sized_target<size, big_endian>* | |
7d1a9ebb | 255 | sized_target() const; |
bae7f79e | 256 | |
5a6f7e2d ILT |
257 | // Get the number of sections. |
258 | unsigned int | |
259 | shnum() const | |
260 | { return this->shnum_; } | |
a2fb1b05 | 261 | |
f6ce93d6 | 262 | // Return a view of the contents of a section. Set *PLEN to the |
9eb9fa57 | 263 | // size. CACHE is a hint as in File_read::get_view. |
f6ce93d6 | 264 | const unsigned char* |
8383303e | 265 | section_contents(unsigned int shndx, section_size_type* plen, bool cache); |
f6ce93d6 | 266 | |
d491d34e ILT |
267 | // Adjust a symbol's section index as needed. SYMNDX is the index |
268 | // of the symbol and SHNDX is the symbol's section from | |
269 | // get_st_shndx. This returns the section index. It sets | |
270 | // *IS_ORDINARY to indicate whether this is a normal section index, | |
271 | // rather than a special code between SHN_LORESERVE and | |
272 | // SHN_HIRESERVE. | |
273 | unsigned int | |
274 | adjust_sym_shndx(unsigned int symndx, unsigned int shndx, bool* is_ordinary) | |
275 | { | |
276 | if (shndx < elfcpp::SHN_LORESERVE) | |
277 | *is_ordinary = true; | |
278 | else if (shndx == elfcpp::SHN_XINDEX) | |
279 | { | |
280 | if (this->xindex_ == NULL) | |
281 | this->xindex_ = this->do_initialize_xindex(); | |
282 | shndx = this->xindex_->sym_xindex_to_shndx(this, symndx); | |
283 | *is_ordinary = true; | |
284 | } | |
285 | else | |
286 | *is_ordinary = false; | |
287 | return shndx; | |
288 | } | |
289 | ||
a445fddf ILT |
290 | // Return the size of a section given a section index. |
291 | uint64_t | |
292 | section_size(unsigned int shndx) | |
293 | { return this->do_section_size(shndx); } | |
294 | ||
295 | // Return the name of a section given a section index. | |
f6ce93d6 | 296 | std::string |
a3ad94ed ILT |
297 | section_name(unsigned int shndx) |
298 | { return this->do_section_name(shndx); } | |
299 | ||
300 | // Return the section flags given a section index. | |
301 | uint64_t | |
302 | section_flags(unsigned int shndx) | |
303 | { return this->do_section_flags(shndx); } | |
f6ce93d6 | 304 | |
88dd47ac ILT |
305 | // Return the section address given a section index. |
306 | uint64_t | |
307 | section_address(unsigned int shndx) | |
308 | { return this->do_section_address(shndx); } | |
309 | ||
730cdc88 ILT |
310 | // Return the section type given a section index. |
311 | unsigned int | |
312 | section_type(unsigned int shndx) | |
313 | { return this->do_section_type(shndx); } | |
314 | ||
f7e2ee48 ILT |
315 | // Return the section link field given a section index. |
316 | unsigned int | |
317 | section_link(unsigned int shndx) | |
318 | { return this->do_section_link(shndx); } | |
319 | ||
4c50553d ILT |
320 | // Return the section info field given a section index. |
321 | unsigned int | |
322 | section_info(unsigned int shndx) | |
323 | { return this->do_section_info(shndx); } | |
324 | ||
a445fddf ILT |
325 | // Return the required section alignment given a section index. |
326 | uint64_t | |
327 | section_addralign(unsigned int shndx) | |
328 | { return this->do_section_addralign(shndx); } | |
329 | ||
5a6f7e2d ILT |
330 | // Read the symbol information. |
331 | void | |
332 | read_symbols(Read_symbols_data* sd) | |
333 | { return this->do_read_symbols(sd); } | |
334 | ||
335 | // Pass sections which should be included in the link to the Layout | |
336 | // object, and record where the sections go in the output file. | |
337 | void | |
7e1edb90 ILT |
338 | layout(Symbol_table* symtab, Layout* layout, Read_symbols_data* sd) |
339 | { this->do_layout(symtab, layout, sd); } | |
5a6f7e2d ILT |
340 | |
341 | // Add symbol information to the global symbol table. | |
342 | void | |
343 | add_symbols(Symbol_table* symtab, Read_symbols_data* sd) | |
344 | { this->do_add_symbols(symtab, sd); } | |
345 | ||
645f8123 ILT |
346 | // Functions and types for the elfcpp::Elf_file interface. This |
347 | // permit us to use Object as the File template parameter for | |
348 | // elfcpp::Elf_file. | |
349 | ||
350 | // The View class is returned by view. It must support a single | |
351 | // method, data(). This is trivial, because get_view does what we | |
352 | // need. | |
353 | class View | |
354 | { | |
355 | public: | |
356 | View(const unsigned char* p) | |
357 | : p_(p) | |
358 | { } | |
359 | ||
360 | const unsigned char* | |
361 | data() const | |
362 | { return this->p_; } | |
363 | ||
364 | private: | |
365 | const unsigned char* p_; | |
366 | }; | |
367 | ||
368 | // Return a View. | |
369 | View | |
8383303e | 370 | view(off_t file_offset, section_size_type data_size) |
39d0cb0e | 371 | { return View(this->get_view(file_offset, data_size, true, true)); } |
645f8123 ILT |
372 | |
373 | // Report an error. | |
374 | void | |
75f2446e | 375 | error(const char* format, ...) const ATTRIBUTE_PRINTF_2; |
645f8123 ILT |
376 | |
377 | // A location in the file. | |
378 | struct Location | |
379 | { | |
380 | off_t file_offset; | |
381 | off_t data_size; | |
382 | ||
8383303e | 383 | Location(off_t fo, section_size_type ds) |
645f8123 ILT |
384 | : file_offset(fo), data_size(ds) |
385 | { } | |
386 | }; | |
387 | ||
388 | // Get a View given a Location. | |
389 | View view(Location loc) | |
39d0cb0e | 390 | { return View(this->get_view(loc.file_offset, loc.data_size, true, true)); } |
645f8123 | 391 | |
cb295612 ILT |
392 | // Get a view into the underlying file. |
393 | const unsigned char* | |
39d0cb0e | 394 | get_view(off_t start, section_size_type size, bool aligned, bool cache) |
cb295612 | 395 | { |
39d0cb0e ILT |
396 | return this->input_file()->file().get_view(this->offset_, start, size, |
397 | aligned, cache); | |
cb295612 ILT |
398 | } |
399 | ||
400 | // Get a lasting view into the underlying file. | |
401 | File_view* | |
39d0cb0e ILT |
402 | get_lasting_view(off_t start, section_size_type size, bool aligned, |
403 | bool cache) | |
cb295612 | 404 | { |
39d0cb0e ILT |
405 | return this->input_file()->file().get_lasting_view(this->offset_, start, |
406 | size, aligned, cache); | |
cb295612 ILT |
407 | } |
408 | ||
409 | // Read data from the underlying file. | |
410 | void | |
411 | read(off_t start, section_size_type size, void* p) const | |
412 | { this->input_file()->file().read(start + this->offset_, size, p); } | |
413 | ||
414 | // Read multiple data from the underlying file. | |
415 | void | |
416 | read_multiple(const File_read::Read_multiple& rm) | |
417 | { this->input_file()->file().read_multiple(this->offset_, rm); } | |
418 | ||
419 | // Stop caching views in the underlying file. | |
420 | void | |
421 | clear_view_cache_marks() | |
422 | { this->input_file()->file().clear_view_cache_marks(); } | |
423 | ||
f6ce93d6 ILT |
424 | protected: |
425 | // Read the symbols--implemented by child class. | |
426 | virtual void | |
427 | do_read_symbols(Read_symbols_data*) = 0; | |
428 | ||
429 | // Lay out sections--implemented by child class. | |
430 | virtual void | |
7e1edb90 | 431 | do_layout(Symbol_table*, Layout*, Read_symbols_data*) = 0; |
f6ce93d6 ILT |
432 | |
433 | // Add symbol information to the global symbol table--implemented by | |
434 | // child class. | |
435 | virtual void | |
436 | do_add_symbols(Symbol_table*, Read_symbols_data*) = 0; | |
437 | ||
645f8123 ILT |
438 | // Return the location of the contents of a section. Implemented by |
439 | // child class. | |
440 | virtual Location | |
a3ad94ed | 441 | do_section_contents(unsigned int shndx) = 0; |
f6ce93d6 | 442 | |
a445fddf ILT |
443 | // Get the size of a section--implemented by child class. |
444 | virtual uint64_t | |
445 | do_section_size(unsigned int shndx) = 0; | |
446 | ||
f6ce93d6 ILT |
447 | // Get the name of a section--implemented by child class. |
448 | virtual std::string | |
a3ad94ed ILT |
449 | do_section_name(unsigned int shndx) = 0; |
450 | ||
451 | // Get section flags--implemented by child class. | |
452 | virtual uint64_t | |
453 | do_section_flags(unsigned int shndx) = 0; | |
f6ce93d6 | 454 | |
88dd47ac ILT |
455 | // Get section address--implemented by child class. |
456 | virtual uint64_t | |
457 | do_section_address(unsigned int shndx) = 0; | |
458 | ||
730cdc88 ILT |
459 | // Get section type--implemented by child class. |
460 | virtual unsigned int | |
461 | do_section_type(unsigned int shndx) = 0; | |
462 | ||
f7e2ee48 ILT |
463 | // Get section link field--implemented by child class. |
464 | virtual unsigned int | |
465 | do_section_link(unsigned int shndx) = 0; | |
466 | ||
4c50553d ILT |
467 | // Get section info field--implemented by child class. |
468 | virtual unsigned int | |
469 | do_section_info(unsigned int shndx) = 0; | |
470 | ||
a445fddf ILT |
471 | // Get section alignment--implemented by child class. |
472 | virtual uint64_t | |
473 | do_section_addralign(unsigned int shndx) = 0; | |
474 | ||
d491d34e ILT |
475 | // Return the Xindex structure to use. |
476 | virtual Xindex* | |
477 | do_initialize_xindex() = 0; | |
478 | ||
17a1d0a9 | 479 | // Get the file. We pass on const-ness. |
f6ce93d6 | 480 | Input_file* |
7004837e ILT |
481 | input_file() |
482 | { return this->input_file_; } | |
483 | ||
484 | const Input_file* | |
f6ce93d6 ILT |
485 | input_file() const |
486 | { return this->input_file_; } | |
487 | ||
f6ce93d6 ILT |
488 | // Set the target. |
489 | void | |
dbe717ef ILT |
490 | set_target(int machine, int size, bool big_endian, int osabi, |
491 | int abiversion); | |
492 | ||
dbe717ef ILT |
493 | // Set the number of sections. |
494 | void | |
495 | set_shnum(int shnum) | |
496 | { this->shnum_ = shnum; } | |
497 | ||
498 | // Functions used by both Sized_relobj and Sized_dynobj. | |
499 | ||
500 | // Read the section data into a Read_symbols_data object. | |
501 | template<int size, bool big_endian> | |
502 | void | |
503 | read_section_data(elfcpp::Elf_file<size, big_endian, Object>*, | |
504 | Read_symbols_data*); | |
505 | ||
d491d34e ILT |
506 | // Let the child class initialize the xindex object directly. |
507 | void | |
508 | set_xindex(Xindex* xindex) | |
509 | { | |
510 | gold_assert(this->xindex_ == NULL); | |
511 | this->xindex_ = xindex; | |
512 | } | |
513 | ||
dbe717ef ILT |
514 | // If NAME is the name of a special .gnu.warning section, arrange |
515 | // for the warning to be issued. SHNDX is the section index. | |
516 | // Return whether it is a warning section. | |
517 | bool | |
518 | handle_gnu_warning_section(const char* name, unsigned int shndx, | |
519 | Symbol_table*); | |
f6ce93d6 ILT |
520 | |
521 | private: | |
522 | // This class may not be copied. | |
523 | Object(const Object&); | |
524 | Object& operator=(const Object&); | |
525 | ||
526 | // Name of object as printed to user. | |
527 | std::string name_; | |
528 | // For reading the file. | |
529 | Input_file* input_file_; | |
530 | // Offset within the file--0 for an object file, non-0 for an | |
531 | // archive. | |
532 | off_t offset_; | |
dbe717ef ILT |
533 | // Number of input sections. |
534 | unsigned int shnum_; | |
f6ce93d6 ILT |
535 | // Whether this is a dynamic object. |
536 | bool is_dynamic_; | |
537 | // Target functions--may be NULL if the target is not known. | |
538 | Target* target_; | |
d491d34e ILT |
539 | // Many sections for objects with more than SHN_LORESERVE sections. |
540 | Xindex* xindex_; | |
f6ce93d6 ILT |
541 | }; |
542 | ||
543 | // Implement sized_target inline for efficiency. This approach breaks | |
544 | // static type checking, but is made safe using asserts. | |
545 | ||
546 | template<int size, bool big_endian> | |
547 | inline Sized_target<size, big_endian>* | |
7d1a9ebb | 548 | Object::sized_target() const |
f6ce93d6 | 549 | { |
a3ad94ed ILT |
550 | gold_assert(this->target_->get_size() == size); |
551 | gold_assert(this->target_->is_big_endian() ? big_endian : !big_endian); | |
f6ce93d6 ILT |
552 | return static_cast<Sized_target<size, big_endian>*>(this->target_); |
553 | } | |
554 | ||
555 | // A regular object (ET_REL). This is an abstract base class itself. | |
b8e6aad9 | 556 | // The implementation is the template class Sized_relobj. |
f6ce93d6 ILT |
557 | |
558 | class Relobj : public Object | |
559 | { | |
560 | public: | |
561 | Relobj(const std::string& name, Input_file* input_file, off_t offset = 0) | |
4625f782 ILT |
562 | : Object(name, input_file, false, offset), |
563 | map_to_output_(), | |
6a74a719 | 564 | map_to_relocatable_relocs_(NULL), |
4625f782 ILT |
565 | object_merge_map_(NULL), |
566 | relocs_must_follow_section_writes_(false) | |
f6ce93d6 ILT |
567 | { } |
568 | ||
92e059d8 | 569 | // Read the relocs. |
a2fb1b05 | 570 | void |
92e059d8 ILT |
571 | read_relocs(Read_relocs_data* rd) |
572 | { return this->do_read_relocs(rd); } | |
573 | ||
574 | // Scan the relocs and adjust the symbol table. | |
575 | void | |
576 | scan_relocs(const General_options& options, Symbol_table* symtab, | |
ead1e424 ILT |
577 | Layout* layout, Read_relocs_data* rd) |
578 | { return this->do_scan_relocs(options, symtab, layout, rd); } | |
a2fb1b05 | 579 | |
6d013333 ILT |
580 | // The number of local symbols in the input symbol table. |
581 | virtual unsigned int | |
582 | local_symbol_count() const | |
583 | { return this->do_local_symbol_count(); } | |
584 | ||
7bf1f802 ILT |
585 | // Initial local symbol processing: count the number of local symbols |
586 | // in the output symbol table and dynamic symbol table; add local symbol | |
587 | // names to *POOL and *DYNPOOL. | |
588 | void | |
589 | count_local_symbols(Stringpool_template<char>* pool, | |
590 | Stringpool_template<char>* dynpool) | |
591 | { return this->do_count_local_symbols(pool, dynpool); } | |
592 | ||
593 | // Set the values of the local symbols, set the output symbol table | |
594 | // indexes for the local variables, and set the offset where local | |
595 | // symbol information will be stored. Returns the new local symbol index. | |
596 | unsigned int | |
597 | finalize_local_symbols(unsigned int index, off_t off) | |
598 | { return this->do_finalize_local_symbols(index, off); } | |
599 | ||
600 | // Set the output dynamic symbol table indexes for the local variables. | |
c06b7b0b | 601 | unsigned int |
7bf1f802 ILT |
602 | set_local_dynsym_indexes(unsigned int index) |
603 | { return this->do_set_local_dynsym_indexes(index); } | |
604 | ||
605 | // Set the offset where local dynamic symbol information will be stored. | |
606 | unsigned int | |
607 | set_local_dynsym_offset(off_t off) | |
608 | { return this->do_set_local_dynsym_offset(off); } | |
75f65a3e | 609 | |
61ba1cf9 ILT |
610 | // Relocate the input sections and write out the local symbols. |
611 | void | |
612 | relocate(const General_options& options, const Symbol_table* symtab, | |
92e059d8 ILT |
613 | const Layout* layout, Output_file* of) |
614 | { return this->do_relocate(options, symtab, layout, of); } | |
61ba1cf9 | 615 | |
a783673b ILT |
616 | // Return whether an input section is being included in the link. |
617 | bool | |
5a6f7e2d | 618 | is_section_included(unsigned int shndx) const |
a783673b | 619 | { |
5a6f7e2d ILT |
620 | gold_assert(shndx < this->map_to_output_.size()); |
621 | return this->map_to_output_[shndx].output_section != NULL; | |
a783673b ILT |
622 | } |
623 | ||
730cdc88 ILT |
624 | // Return whether an input section requires special |
625 | // handling--whether it is not simply mapped from the input file to | |
626 | // the output file. | |
627 | bool | |
628 | is_section_specially_mapped(unsigned int shndx) const | |
629 | { | |
630 | gold_assert(shndx < this->map_to_output_.size()); | |
631 | return (this->map_to_output_[shndx].output_section != NULL | |
632 | && this->map_to_output_[shndx].offset == -1); | |
633 | } | |
634 | ||
a783673b ILT |
635 | // Given a section index, return the corresponding Output_section |
636 | // (which will be NULL if the section is not included in the link) | |
730cdc88 ILT |
637 | // and set *POFF to the offset within that section. *POFF will be |
638 | // set to -1 if the section requires special handling. | |
a783673b | 639 | inline Output_section* |
8383303e | 640 | output_section(unsigned int shndx, section_offset_type* poff) const; |
a783673b | 641 | |
ead1e424 ILT |
642 | // Set the offset of an input section within its output section. |
643 | void | |
8383303e | 644 | set_section_offset(unsigned int shndx, section_offset_type off) |
ead1e424 | 645 | { |
a3ad94ed | 646 | gold_assert(shndx < this->map_to_output_.size()); |
ead1e424 ILT |
647 | this->map_to_output_[shndx].offset = off; |
648 | } | |
649 | ||
730cdc88 ILT |
650 | // Return true if we need to wait for output sections to be written |
651 | // before we can apply relocations. This is true if the object has | |
652 | // any relocations for sections which require special handling, such | |
653 | // as the exception frame section. | |
654 | bool | |
17a1d0a9 | 655 | relocs_must_follow_section_writes() const |
730cdc88 ILT |
656 | { return this->relocs_must_follow_section_writes_; } |
657 | ||
4625f782 ILT |
658 | // Return the object merge map. |
659 | Object_merge_map* | |
660 | merge_map() const | |
661 | { return this->object_merge_map_; } | |
662 | ||
663 | // Set the object merge map. | |
664 | void | |
665 | set_merge_map(Object_merge_map* object_merge_map) | |
666 | { | |
667 | gold_assert(this->object_merge_map_ == NULL); | |
668 | this->object_merge_map_ = object_merge_map; | |
669 | } | |
670 | ||
6a74a719 ILT |
671 | // Record the relocatable reloc info for an input reloc section. |
672 | void | |
673 | set_relocatable_relocs(unsigned int reloc_shndx, Relocatable_relocs* rr) | |
674 | { | |
675 | gold_assert(reloc_shndx < this->shnum()); | |
676 | (*this->map_to_relocatable_relocs_)[reloc_shndx] = rr; | |
677 | } | |
678 | ||
679 | // Get the relocatable reloc info for an input reloc section. | |
680 | Relocatable_relocs* | |
681 | relocatable_relocs(unsigned int reloc_shndx) | |
682 | { | |
683 | gold_assert(reloc_shndx < this->shnum()); | |
684 | return (*this->map_to_relocatable_relocs_)[reloc_shndx]; | |
685 | } | |
686 | ||
a783673b | 687 | protected: |
a2fb1b05 ILT |
688 | // What we need to know to map an input section to an output |
689 | // section. We keep an array of these, one for each input section, | |
690 | // indexed by the input section number. | |
691 | struct Map_to_output | |
692 | { | |
693 | // The output section. This is NULL if the input section is to be | |
694 | // discarded. | |
695 | Output_section* output_section; | |
b8e6aad9 ILT |
696 | // The offset within the output section. This is -1 if the |
697 | // section requires special handling. | |
8383303e | 698 | section_offset_type offset; |
a2fb1b05 ILT |
699 | }; |
700 | ||
92e059d8 ILT |
701 | // Read the relocs--implemented by child class. |
702 | virtual void | |
703 | do_read_relocs(Read_relocs_data*) = 0; | |
704 | ||
705 | // Scan the relocs--implemented by child class. | |
706 | virtual void | |
ead1e424 ILT |
707 | do_scan_relocs(const General_options&, Symbol_table*, Layout*, |
708 | Read_relocs_data*) = 0; | |
92e059d8 | 709 | |
6d013333 ILT |
710 | // Return the number of local symbols--implemented by child class. |
711 | virtual unsigned int | |
712 | do_local_symbol_count() const = 0; | |
713 | ||
7bf1f802 ILT |
714 | // Count local symbols--implemented by child class. |
715 | virtual void | |
716 | do_count_local_symbols(Stringpool_template<char>*, | |
6a74a719 | 717 | Stringpool_template<char>*) = 0; |
75f65a3e | 718 | |
6a74a719 ILT |
719 | // Finalize the local symbols. Set the output symbol table indexes |
720 | // for the local variables, and set the offset where local symbol | |
721 | // information will be stored. | |
7bf1f802 ILT |
722 | virtual unsigned int |
723 | do_finalize_local_symbols(unsigned int, off_t) = 0; | |
724 | ||
725 | // Set the output dynamic symbol table indexes for the local variables. | |
726 | virtual unsigned int | |
727 | do_set_local_dynsym_indexes(unsigned int) = 0; | |
728 | ||
729 | // Set the offset where local dynamic symbol information will be stored. | |
730 | virtual unsigned int | |
731 | do_set_local_dynsym_offset(off_t) = 0; | |
732 | ||
61ba1cf9 ILT |
733 | // Relocate the input sections and write out the local |
734 | // symbols--implemented by child class. | |
735 | virtual void | |
736 | do_relocate(const General_options& options, const Symbol_table* symtab, | |
92e059d8 ILT |
737 | const Layout*, Output_file* of) = 0; |
738 | ||
a2fb1b05 ILT |
739 | // Return the vector mapping input sections to output sections. |
740 | std::vector<Map_to_output>& | |
741 | map_to_output() | |
742 | { return this->map_to_output_; } | |
743 | ||
b8e6aad9 ILT |
744 | const std::vector<Map_to_output>& |
745 | map_to_output() const | |
746 | { return this->map_to_output_; } | |
747 | ||
6a74a719 ILT |
748 | // Set the size of the relocatable relocs array. |
749 | void | |
750 | size_relocatable_relocs() | |
751 | { | |
752 | this->map_to_relocatable_relocs_ = | |
753 | new std::vector<Relocatable_relocs*>(this->shnum()); | |
754 | } | |
755 | ||
730cdc88 ILT |
756 | // Record that we must wait for the output sections to be written |
757 | // before applying relocations. | |
758 | void | |
759 | set_relocs_must_follow_section_writes() | |
760 | { this->relocs_must_follow_section_writes_ = true; } | |
761 | ||
bae7f79e | 762 | private: |
a2fb1b05 ILT |
763 | // Mapping from input sections to output section. |
764 | std::vector<Map_to_output> map_to_output_; | |
6a74a719 ILT |
765 | // Mapping from input section index to the information recorded for |
766 | // the relocations. This is only used for a relocatable link. | |
767 | std::vector<Relocatable_relocs*>* map_to_relocatable_relocs_; | |
4625f782 ILT |
768 | // Mappings for merge sections. This is managed by the code in the |
769 | // Merge_map class. | |
770 | Object_merge_map* object_merge_map_; | |
730cdc88 ILT |
771 | // Whether we need to wait for output sections to be written before |
772 | // we can apply relocations. | |
773 | bool relocs_must_follow_section_writes_; | |
bae7f79e ILT |
774 | }; |
775 | ||
a783673b ILT |
776 | // Implement Object::output_section inline for efficiency. |
777 | inline Output_section* | |
8383303e | 778 | Relobj::output_section(unsigned int shndx, section_offset_type* poff) const |
a783673b | 779 | { |
5a6f7e2d ILT |
780 | gold_assert(shndx < this->map_to_output_.size()); |
781 | const Map_to_output& mo(this->map_to_output_[shndx]); | |
a783673b ILT |
782 | *poff = mo.offset; |
783 | return mo.output_section; | |
784 | } | |
785 | ||
a9a60db6 ILT |
786 | // This class is used to handle relocations against a section symbol |
787 | // in an SHF_MERGE section. For such a symbol, we need to know the | |
788 | // addend of the relocation before we can determine the final value. | |
789 | // The addend gives us the location in the input section, and we can | |
790 | // determine how it is mapped to the output section. For a | |
791 | // non-section symbol, we apply the addend to the final value of the | |
792 | // symbol; that is done in finalize_local_symbols, and does not use | |
793 | // this class. | |
794 | ||
795 | template<int size> | |
796 | class Merged_symbol_value | |
797 | { | |
798 | public: | |
799 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Value; | |
800 | ||
801 | // We use a hash table to map offsets in the input section to output | |
802 | // addresses. | |
803 | typedef Unordered_map<section_offset_type, Value> Output_addresses; | |
804 | ||
805 | Merged_symbol_value(Value input_value, Value output_start_address) | |
806 | : input_value_(input_value), output_start_address_(output_start_address), | |
807 | output_addresses_() | |
808 | { } | |
809 | ||
810 | // Initialize the hash table. | |
811 | void | |
812 | initialize_input_to_output_map(const Relobj*, unsigned int input_shndx); | |
813 | ||
814 | // Release the hash table to save space. | |
815 | void | |
816 | free_input_to_output_map() | |
817 | { this->output_addresses_.clear(); } | |
818 | ||
819 | // Get the output value corresponding to an addend. The object and | |
820 | // input section index are passed in because the caller will have | |
821 | // them; otherwise we could store them here. | |
822 | Value | |
823 | value(const Relobj* object, unsigned int input_shndx, Value addend) const | |
824 | { | |
825 | Value input_offset = this->input_value_ + addend; | |
826 | typename Output_addresses::const_iterator p = | |
827 | this->output_addresses_.find(input_offset); | |
828 | if (p != this->output_addresses_.end()) | |
829 | return p->second; | |
830 | ||
831 | return this->value_from_output_section(object, input_shndx, input_offset); | |
832 | } | |
833 | ||
834 | private: | |
835 | // Get the output value for an input offset if we couldn't find it | |
836 | // in the hash table. | |
837 | Value | |
838 | value_from_output_section(const Relobj*, unsigned int input_shndx, | |
839 | Value input_offset) const; | |
840 | ||
841 | // The value of the section symbol in the input file. This is | |
842 | // normally zero, but could in principle be something else. | |
843 | Value input_value_; | |
844 | // The start address of this merged section in the output file. | |
845 | Value output_start_address_; | |
846 | // A hash table which maps offsets in the input section to output | |
847 | // addresses. This only maps specific offsets, not all offsets. | |
848 | Output_addresses output_addresses_; | |
849 | }; | |
850 | ||
b8e6aad9 ILT |
851 | // This POD class is holds the value of a symbol. This is used for |
852 | // local symbols, and for all symbols during relocation processing. | |
730cdc88 ILT |
853 | // For special sections, such as SHF_MERGE sections, this calls a |
854 | // function to get the final symbol value. | |
b8e6aad9 ILT |
855 | |
856 | template<int size> | |
857 | class Symbol_value | |
858 | { | |
859 | public: | |
860 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Value; | |
861 | ||
862 | Symbol_value() | |
7bf1f802 | 863 | : output_symtab_index_(0), output_dynsym_index_(-1U), input_shndx_(0), |
d491d34e ILT |
864 | is_ordinary_shndx_(false), is_section_symbol_(false), |
865 | is_tls_symbol_(false), has_output_value_(true) | |
a9a60db6 | 866 | { this->u_.value = 0; } |
b8e6aad9 ILT |
867 | |
868 | // Get the value of this symbol. OBJECT is the object in which this | |
869 | // symbol is defined, and ADDEND is an addend to add to the value. | |
870 | template<bool big_endian> | |
871 | Value | |
872 | value(const Sized_relobj<size, big_endian>* object, Value addend) const | |
873 | { | |
a9a60db6 ILT |
874 | if (this->has_output_value_) |
875 | return this->u_.value + addend; | |
876 | else | |
d491d34e ILT |
877 | { |
878 | gold_assert(this->is_ordinary_shndx_); | |
879 | return this->u_.merged_symbol_value->value(object, this->input_shndx_, | |
880 | addend); | |
881 | } | |
b8e6aad9 ILT |
882 | } |
883 | ||
884 | // Set the value of this symbol in the output symbol table. | |
885 | void | |
886 | set_output_value(Value value) | |
a9a60db6 ILT |
887 | { this->u_.value = value; } |
888 | ||
889 | // For a section symbol in a merged section, we need more | |
890 | // information. | |
891 | void | |
892 | set_merged_symbol_value(Merged_symbol_value<size>* msv) | |
b8e6aad9 | 893 | { |
a9a60db6 ILT |
894 | gold_assert(this->is_section_symbol_); |
895 | this->has_output_value_ = false; | |
896 | this->u_.merged_symbol_value = msv; | |
b8e6aad9 ILT |
897 | } |
898 | ||
a9a60db6 ILT |
899 | // Initialize the input to output map for a section symbol in a |
900 | // merged section. We also initialize the value of a non-section | |
901 | // symbol in a merged section. | |
b8e6aad9 | 902 | void |
a9a60db6 | 903 | initialize_input_to_output_map(const Relobj* object) |
b8e6aad9 | 904 | { |
a9a60db6 ILT |
905 | if (!this->has_output_value_) |
906 | { | |
d491d34e | 907 | gold_assert(this->is_section_symbol_ && this->is_ordinary_shndx_); |
a9a60db6 ILT |
908 | Merged_symbol_value<size>* msv = this->u_.merged_symbol_value; |
909 | msv->initialize_input_to_output_map(object, this->input_shndx_); | |
910 | } | |
b8e6aad9 ILT |
911 | } |
912 | ||
a9a60db6 ILT |
913 | // Free the input to output map for a section symbol in a merged |
914 | // section. | |
915 | void | |
916 | free_input_to_output_map() | |
7bf1f802 | 917 | { |
a9a60db6 ILT |
918 | if (!this->has_output_value_) |
919 | this->u_.merged_symbol_value->free_input_to_output_map(); | |
7bf1f802 ILT |
920 | } |
921 | ||
a9a60db6 ILT |
922 | // Set the value of the symbol from the input file. This is only |
923 | // called by count_local_symbols, to communicate the value to | |
924 | // finalize_local_symbols. | |
925 | void | |
926 | set_input_value(Value value) | |
927 | { this->u_.value = value; } | |
928 | ||
929 | // Return the input value. This is only called by | |
930 | // finalize_local_symbols. | |
931 | Value | |
932 | input_value() const | |
933 | { return this->u_.value; } | |
934 | ||
b8e6aad9 ILT |
935 | // Return whether this symbol should go into the output symbol |
936 | // table. | |
937 | bool | |
938 | needs_output_symtab_entry() const | |
ac1f0c21 | 939 | { return this->output_symtab_index_ != -1U; } |
b8e6aad9 ILT |
940 | |
941 | // Return the index in the output symbol table. | |
942 | unsigned int | |
943 | output_symtab_index() const | |
944 | { | |
945 | gold_assert(this->output_symtab_index_ != 0); | |
946 | return this->output_symtab_index_; | |
947 | } | |
948 | ||
949 | // Set the index in the output symbol table. | |
950 | void | |
951 | set_output_symtab_index(unsigned int i) | |
952 | { | |
953 | gold_assert(this->output_symtab_index_ == 0); | |
954 | this->output_symtab_index_ = i; | |
955 | } | |
956 | ||
957 | // Record that this symbol should not go into the output symbol | |
958 | // table. | |
959 | void | |
960 | set_no_output_symtab_entry() | |
961 | { | |
962 | gold_assert(this->output_symtab_index_ == 0); | |
963 | this->output_symtab_index_ = -1U; | |
964 | } | |
965 | ||
7bf1f802 ILT |
966 | // Set the index in the output dynamic symbol table. |
967 | void | |
968 | set_needs_output_dynsym_entry() | |
969 | { | |
dceae3c1 | 970 | gold_assert(!this->is_section_symbol()); |
7bf1f802 ILT |
971 | this->output_dynsym_index_ = 0; |
972 | } | |
973 | ||
974 | // Return whether this symbol should go into the output symbol | |
975 | // table. | |
976 | bool | |
977 | needs_output_dynsym_entry() const | |
978 | { | |
979 | return this->output_dynsym_index_ != -1U; | |
980 | } | |
981 | ||
982 | // Record that this symbol should go into the dynamic symbol table. | |
983 | void | |
984 | set_output_dynsym_index(unsigned int i) | |
985 | { | |
986 | gold_assert(this->output_dynsym_index_ == 0); | |
987 | this->output_dynsym_index_ = i; | |
988 | } | |
989 | ||
990 | // Return the index in the output dynamic symbol table. | |
991 | unsigned int | |
992 | output_dynsym_index() const | |
993 | { | |
dceae3c1 ILT |
994 | gold_assert(this->output_dynsym_index_ != 0 |
995 | && this->output_dynsym_index_ != -1U); | |
7bf1f802 ILT |
996 | return this->output_dynsym_index_; |
997 | } | |
998 | ||
b8e6aad9 ILT |
999 | // Set the index of the input section in the input file. |
1000 | void | |
d491d34e | 1001 | set_input_shndx(unsigned int i, bool is_ordinary) |
730cdc88 ILT |
1002 | { |
1003 | this->input_shndx_ = i; | |
ac1f0c21 ILT |
1004 | // input_shndx_ field is a bitfield, so make sure that the value |
1005 | // fits. | |
730cdc88 | 1006 | gold_assert(this->input_shndx_ == i); |
d491d34e | 1007 | this->is_ordinary_shndx_ = is_ordinary; |
730cdc88 | 1008 | } |
b8e6aad9 | 1009 | |
7bf1f802 ILT |
1010 | // Return the index of the input section in the input file. |
1011 | unsigned int | |
d491d34e ILT |
1012 | input_shndx(bool* is_ordinary) const |
1013 | { | |
1014 | *is_ordinary = this->is_ordinary_shndx_; | |
1015 | return this->input_shndx_; | |
1016 | } | |
7bf1f802 | 1017 | |
a9a60db6 ILT |
1018 | // Whether this is a section symbol. |
1019 | bool | |
1020 | is_section_symbol() const | |
1021 | { return this->is_section_symbol_; } | |
1022 | ||
063f12a8 ILT |
1023 | // Record that this is a section symbol. |
1024 | void | |
1025 | set_is_section_symbol() | |
dceae3c1 ILT |
1026 | { |
1027 | gold_assert(!this->needs_output_dynsym_entry()); | |
1028 | this->is_section_symbol_ = true; | |
1029 | } | |
063f12a8 | 1030 | |
7bf1f802 ILT |
1031 | // Record that this is a TLS symbol. |
1032 | void | |
1033 | set_is_tls_symbol() | |
1034 | { this->is_tls_symbol_ = true; } | |
1035 | ||
1036 | // Return TRUE if this is a TLS symbol. | |
1037 | bool | |
1038 | is_tls_symbol() const | |
1039 | { return this->is_tls_symbol_; } | |
1040 | ||
b8e6aad9 ILT |
1041 | private: |
1042 | // The index of this local symbol in the output symbol table. This | |
1043 | // will be -1 if the symbol should not go into the symbol table. | |
1044 | unsigned int output_symtab_index_; | |
7bf1f802 ILT |
1045 | // The index of this local symbol in the dynamic symbol table. This |
1046 | // will be -1 if the symbol should not go into the symbol table. | |
1047 | unsigned int output_dynsym_index_; | |
b8e6aad9 ILT |
1048 | // The section index in the input file in which this symbol is |
1049 | // defined. | |
d491d34e ILT |
1050 | unsigned int input_shndx_ : 28; |
1051 | // Whether the section index is an ordinary index, not a special | |
1052 | // value. | |
1053 | bool is_ordinary_shndx_ : 1; | |
063f12a8 ILT |
1054 | // Whether this is a STT_SECTION symbol. |
1055 | bool is_section_symbol_ : 1; | |
7bf1f802 ILT |
1056 | // Whether this is a STT_TLS symbol. |
1057 | bool is_tls_symbol_ : 1; | |
a9a60db6 ILT |
1058 | // Whether this symbol has a value for the output file. This is |
1059 | // normally set to true during Layout::finalize, by | |
1060 | // finalize_local_symbols. It will be false for a section symbol in | |
1061 | // a merge section, as for such symbols we can not determine the | |
1062 | // value to use in a relocation until we see the addend. | |
1063 | bool has_output_value_ : 1; | |
1064 | union | |
1065 | { | |
1066 | // This is used if has_output_value_ is true. Between | |
1067 | // count_local_symbols and finalize_local_symbols, this is the | |
1068 | // value in the input file. After finalize_local_symbols, it is | |
1069 | // the value in the output file. | |
1070 | Value value; | |
1071 | // This is used if has_output_value_ is false. It points to the | |
1072 | // information we need to get the value for a merge section. | |
1073 | Merged_symbol_value<size>* merged_symbol_value; | |
1074 | } u_; | |
b8e6aad9 ILT |
1075 | }; |
1076 | ||
0a65a3a7 CC |
1077 | // A GOT offset list. A symbol may have more than one GOT offset |
1078 | // (e.g., when mixing modules compiled with two different TLS models), | |
1079 | // but will usually have at most one. GOT_TYPE identifies the type of | |
1080 | // GOT entry; its values are specific to each target. | |
1081 | ||
1082 | class Got_offset_list | |
1083 | { | |
1084 | public: | |
1085 | Got_offset_list() | |
1086 | : got_type_(-1U), got_offset_(0), got_next_(NULL) | |
1087 | { } | |
1088 | ||
1089 | Got_offset_list(unsigned int got_type, unsigned int got_offset) | |
1090 | : got_type_(got_type), got_offset_(got_offset), got_next_(NULL) | |
1091 | { } | |
1092 | ||
1093 | ~Got_offset_list() | |
1094 | { | |
1095 | if (this->got_next_ != NULL) | |
1096 | { | |
1097 | delete this->got_next_; | |
1098 | this->got_next_ = NULL; | |
1099 | } | |
1100 | } | |
1101 | ||
1102 | // Initialize the fields to their default values. | |
1103 | void | |
1104 | init() | |
1105 | { | |
1106 | this->got_type_ = -1U; | |
1107 | this->got_offset_ = 0; | |
1108 | this->got_next_ = NULL; | |
1109 | } | |
1110 | ||
1111 | // Set the offset for the GOT entry of type GOT_TYPE. | |
1112 | void | |
1113 | set_offset(unsigned int got_type, unsigned int got_offset) | |
1114 | { | |
1115 | if (this->got_type_ == -1U) | |
1116 | { | |
1117 | this->got_type_ = got_type; | |
1118 | this->got_offset_ = got_offset; | |
1119 | } | |
1120 | else | |
1121 | { | |
1122 | for (Got_offset_list* g = this; g != NULL; g = g->got_next_) | |
1123 | { | |
1124 | if (g->got_type_ == got_type) | |
1125 | { | |
1126 | g->got_offset_ = got_offset; | |
1127 | return; | |
1128 | } | |
1129 | } | |
1130 | Got_offset_list* g = new Got_offset_list(got_type, got_offset); | |
1131 | g->got_next_ = this->got_next_; | |
1132 | this->got_next_ = g; | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | // Return the offset for a GOT entry of type GOT_TYPE. | |
1137 | unsigned int | |
1138 | get_offset(unsigned int got_type) const | |
1139 | { | |
1140 | for (const Got_offset_list* g = this; g != NULL; g = g->got_next_) | |
1141 | { | |
1142 | if (g->got_type_ == got_type) | |
1143 | return g->got_offset_; | |
1144 | } | |
1145 | return -1U; | |
1146 | } | |
1147 | ||
1148 | private: | |
1149 | unsigned int got_type_; | |
1150 | unsigned int got_offset_; | |
1151 | Got_offset_list* got_next_; | |
1152 | }; | |
1153 | ||
14bfc3f5 | 1154 | // A regular object file. This is size and endian specific. |
bae7f79e ILT |
1155 | |
1156 | template<int size, bool big_endian> | |
f6ce93d6 | 1157 | class Sized_relobj : public Relobj |
bae7f79e ILT |
1158 | { |
1159 | public: | |
c06b7b0b | 1160 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Address; |
730cdc88 | 1161 | typedef std::vector<Symbol*> Symbols; |
b8e6aad9 | 1162 | typedef std::vector<Symbol_value<size> > Local_values; |
c06b7b0b | 1163 | |
f6ce93d6 | 1164 | Sized_relobj(const std::string& name, Input_file* input_file, off_t offset, |
bae7f79e ILT |
1165 | const typename elfcpp::Ehdr<size, big_endian>&); |
1166 | ||
f6ce93d6 | 1167 | ~Sized_relobj(); |
bae7f79e | 1168 | |
a2fb1b05 | 1169 | // Set up the object file based on the ELF header. |
bae7f79e ILT |
1170 | void |
1171 | setup(const typename elfcpp::Ehdr<size, big_endian>&); | |
1172 | ||
730cdc88 ILT |
1173 | // If SYM is the index of a global symbol in the object file's |
1174 | // symbol table, return the Symbol object. Otherwise, return NULL. | |
1175 | Symbol* | |
1176 | global_symbol(unsigned int sym) const | |
1177 | { | |
1178 | if (sym >= this->local_symbol_count_) | |
1179 | { | |
1180 | gold_assert(sym - this->local_symbol_count_ < this->symbols_.size()); | |
1181 | return this->symbols_[sym - this->local_symbol_count_]; | |
1182 | } | |
1183 | return NULL; | |
1184 | } | |
1185 | ||
1186 | // Return the section index of symbol SYM. Set *VALUE to its value | |
d491d34e ILT |
1187 | // in the object file. Set *IS_ORDINARY if this is an ordinary |
1188 | // section index, not a special code between SHN_LORESERVE and | |
1189 | // SHN_HIRESERVE. Note that for a symbol which is not defined in | |
1190 | // this object file, this will set *VALUE to 0 and return SHN_UNDEF; | |
1191 | // it will not return the final value of the symbol in the link. | |
730cdc88 | 1192 | unsigned int |
d491d34e | 1193 | symbol_section_and_value(unsigned int sym, Address* value, bool* is_ordinary); |
730cdc88 ILT |
1194 | |
1195 | // Return a pointer to the Symbol_value structure which holds the | |
1196 | // value of a local symbol. | |
1197 | const Symbol_value<size>* | |
1198 | local_symbol(unsigned int sym) const | |
1199 | { | |
1200 | gold_assert(sym < this->local_values_.size()); | |
1201 | return &this->local_values_[sym]; | |
1202 | } | |
1203 | ||
c06b7b0b ILT |
1204 | // Return the index of local symbol SYM in the ordinary symbol |
1205 | // table. A value of -1U means that the symbol is not being output. | |
1206 | unsigned int | |
1207 | symtab_index(unsigned int sym) const | |
1208 | { | |
b8e6aad9 ILT |
1209 | gold_assert(sym < this->local_values_.size()); |
1210 | return this->local_values_[sym].output_symtab_index(); | |
c06b7b0b ILT |
1211 | } |
1212 | ||
7bf1f802 ILT |
1213 | // Return the index of local symbol SYM in the dynamic symbol |
1214 | // table. A value of -1U means that the symbol is not being output. | |
1215 | unsigned int | |
1216 | dynsym_index(unsigned int sym) const | |
1217 | { | |
1218 | gold_assert(sym < this->local_values_.size()); | |
1219 | return this->local_values_[sym].output_dynsym_index(); | |
1220 | } | |
1221 | ||
6a74a719 ILT |
1222 | // Return the input section index of local symbol SYM. |
1223 | unsigned int | |
d491d34e | 1224 | local_symbol_input_shndx(unsigned int sym, bool* is_ordinary) const |
6a74a719 ILT |
1225 | { |
1226 | gold_assert(sym < this->local_values_.size()); | |
d491d34e | 1227 | return this->local_values_[sym].input_shndx(is_ordinary); |
6a74a719 ILT |
1228 | } |
1229 | ||
e727fa71 ILT |
1230 | // Return the appropriate Sized_target structure. |
1231 | Sized_target<size, big_endian>* | |
1232 | sized_target() | |
7d1a9ebb | 1233 | { return this->Object::sized_target<size, big_endian>(); } |
e727fa71 | 1234 | |
d1f003c6 | 1235 | // Record that local symbol SYM needs a dynamic symbol entry. |
7bf1f802 ILT |
1236 | void |
1237 | set_needs_output_dynsym_entry(unsigned int sym) | |
1238 | { | |
1239 | gold_assert(sym < this->local_values_.size()); | |
1240 | this->local_values_[sym].set_needs_output_dynsym_entry(); | |
1241 | } | |
1242 | ||
e727fa71 | 1243 | // Return whether the local symbol SYMNDX has a GOT offset. |
07f397ab | 1244 | // For TLS symbols, the GOT entry will hold its tp-relative offset. |
e727fa71 | 1245 | bool |
0a65a3a7 | 1246 | local_has_got_offset(unsigned int symndx, unsigned int got_type) const |
e727fa71 | 1247 | { |
0a65a3a7 CC |
1248 | Local_got_offsets::const_iterator p = |
1249 | this->local_got_offsets_.find(symndx); | |
1250 | return (p != this->local_got_offsets_.end() | |
1251 | && p->second->get_offset(got_type) != -1U); | |
e727fa71 ILT |
1252 | } |
1253 | ||
1254 | // Return the GOT offset of the local symbol SYMNDX. | |
1255 | unsigned int | |
0a65a3a7 | 1256 | local_got_offset(unsigned int symndx, unsigned int got_type) const |
e727fa71 ILT |
1257 | { |
1258 | Local_got_offsets::const_iterator p = | |
1259 | this->local_got_offsets_.find(symndx); | |
1260 | gold_assert(p != this->local_got_offsets_.end()); | |
0a65a3a7 CC |
1261 | unsigned int off = p->second->get_offset(got_type); |
1262 | gold_assert(off != -1U); | |
1263 | return off; | |
e727fa71 ILT |
1264 | } |
1265 | ||
1266 | // Set the GOT offset of the local symbol SYMNDX to GOT_OFFSET. | |
1267 | void | |
0a65a3a7 CC |
1268 | set_local_got_offset(unsigned int symndx, unsigned int got_type, |
1269 | unsigned int got_offset) | |
07f397ab | 1270 | { |
0a65a3a7 CC |
1271 | Local_got_offsets::const_iterator p = |
1272 | this->local_got_offsets_.find(symndx); | |
1273 | if (p != this->local_got_offsets_.end()) | |
1274 | p->second->set_offset(got_type, got_offset); | |
07f397ab ILT |
1275 | else |
1276 | { | |
0a65a3a7 CC |
1277 | Got_offset_list* g = new Got_offset_list(got_type, got_offset); |
1278 | std::pair<Local_got_offsets::iterator, bool> ins = | |
1279 | this->local_got_offsets_.insert(std::make_pair(symndx, g)); | |
07f397ab ILT |
1280 | gold_assert(ins.second); |
1281 | } | |
1282 | } | |
1283 | ||
f7e2ee48 ILT |
1284 | // Return the name of the symbol that spans the given offset in the |
1285 | // specified section in this object. This is used only for error | |
1286 | // messages and is not particularly efficient. | |
1287 | bool | |
1288 | get_symbol_location_info(unsigned int shndx, off_t offset, | |
1289 | Symbol_location_info* info); | |
1290 | ||
6d013333 | 1291 | protected: |
a2fb1b05 | 1292 | // Read the symbols. |
bae7f79e | 1293 | void |
12e14209 | 1294 | do_read_symbols(Read_symbols_data*); |
14bfc3f5 | 1295 | |
6d013333 ILT |
1296 | // Return the number of local symbols. |
1297 | unsigned int | |
1298 | do_local_symbol_count() const | |
1299 | { return this->local_symbol_count_; } | |
1300 | ||
dbe717ef ILT |
1301 | // Lay out the input sections. |
1302 | void | |
7e1edb90 | 1303 | do_layout(Symbol_table*, Layout*, Read_symbols_data*); |
dbe717ef | 1304 | |
12e14209 ILT |
1305 | // Add the symbols to the symbol table. |
1306 | void | |
1307 | do_add_symbols(Symbol_table*, Read_symbols_data*); | |
a2fb1b05 | 1308 | |
92e059d8 ILT |
1309 | // Read the relocs. |
1310 | void | |
1311 | do_read_relocs(Read_relocs_data*); | |
1312 | ||
1313 | // Scan the relocs and adjust the symbol table. | |
1314 | void | |
ead1e424 ILT |
1315 | do_scan_relocs(const General_options&, Symbol_table*, Layout*, |
1316 | Read_relocs_data*); | |
92e059d8 | 1317 | |
7bf1f802 ILT |
1318 | // Count the local symbols. |
1319 | void | |
1320 | do_count_local_symbols(Stringpool_template<char>*, | |
1321 | Stringpool_template<char>*); | |
1322 | ||
75f65a3e | 1323 | // Finalize the local symbols. |
c06b7b0b | 1324 | unsigned int |
7bf1f802 ILT |
1325 | do_finalize_local_symbols(unsigned int, off_t); |
1326 | ||
1327 | // Set the offset where local dynamic symbol information will be stored. | |
1328 | unsigned int | |
1329 | do_set_local_dynsym_indexes(unsigned int); | |
1330 | ||
1331 | // Set the offset where local dynamic symbol information will be stored. | |
1332 | unsigned int | |
1333 | do_set_local_dynsym_offset(off_t); | |
75f65a3e | 1334 | |
61ba1cf9 ILT |
1335 | // Relocate the input sections and write out the local symbols. |
1336 | void | |
1337 | do_relocate(const General_options& options, const Symbol_table* symtab, | |
92e059d8 ILT |
1338 | const Layout*, Output_file* of); |
1339 | ||
a445fddf ILT |
1340 | // Get the size of a section. |
1341 | uint64_t | |
1342 | do_section_size(unsigned int shndx) | |
1343 | { return this->elf_file_.section_size(shndx); } | |
1344 | ||
92e059d8 ILT |
1345 | // Get the name of a section. |
1346 | std::string | |
645f8123 ILT |
1347 | do_section_name(unsigned int shndx) |
1348 | { return this->elf_file_.section_name(shndx); } | |
61ba1cf9 | 1349 | |
645f8123 | 1350 | // Return the location of the contents of a section. |
dbe717ef | 1351 | Object::Location |
645f8123 ILT |
1352 | do_section_contents(unsigned int shndx) |
1353 | { return this->elf_file_.section_contents(shndx); } | |
f6ce93d6 | 1354 | |
a3ad94ed ILT |
1355 | // Return section flags. |
1356 | uint64_t | |
1357 | do_section_flags(unsigned int shndx) | |
1358 | { return this->elf_file_.section_flags(shndx); } | |
1359 | ||
88dd47ac ILT |
1360 | // Return section address. |
1361 | uint64_t | |
1362 | do_section_address(unsigned int shndx) | |
1363 | { return this->elf_file_.section_addr(shndx); } | |
1364 | ||
730cdc88 ILT |
1365 | // Return section type. |
1366 | unsigned int | |
1367 | do_section_type(unsigned int shndx) | |
1368 | { return this->elf_file_.section_type(shndx); } | |
1369 | ||
f7e2ee48 ILT |
1370 | // Return the section link field. |
1371 | unsigned int | |
1372 | do_section_link(unsigned int shndx) | |
1373 | { return this->elf_file_.section_link(shndx); } | |
1374 | ||
4c50553d ILT |
1375 | // Return the section info field. |
1376 | unsigned int | |
1377 | do_section_info(unsigned int shndx) | |
1378 | { return this->elf_file_.section_info(shndx); } | |
1379 | ||
a445fddf ILT |
1380 | // Return the section alignment. |
1381 | uint64_t | |
1382 | do_section_addralign(unsigned int shndx) | |
1383 | { return this->elf_file_.section_addralign(shndx); } | |
1384 | ||
d491d34e ILT |
1385 | // Return the Xindex structure to use. |
1386 | Xindex* | |
1387 | do_initialize_xindex(); | |
1388 | ||
bae7f79e | 1389 | private: |
a2fb1b05 | 1390 | // For convenience. |
f6ce93d6 | 1391 | typedef Sized_relobj<size, big_endian> This; |
a2fb1b05 ILT |
1392 | static const int ehdr_size = elfcpp::Elf_sizes<size>::ehdr_size; |
1393 | static const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size; | |
1394 | static const int sym_size = elfcpp::Elf_sizes<size>::sym_size; | |
75f65a3e ILT |
1395 | typedef elfcpp::Shdr<size, big_endian> Shdr; |
1396 | ||
d491d34e ILT |
1397 | // Adjust a section index if necessary. |
1398 | unsigned int | |
1399 | adjust_shndx(unsigned int shndx) | |
1400 | { | |
1401 | if (shndx >= elfcpp::SHN_LORESERVE) | |
1402 | shndx += this->elf_file_.large_shndx_offset(); | |
1403 | return shndx; | |
1404 | } | |
1405 | ||
dbe717ef ILT |
1406 | // Find the SHT_SYMTAB section, given the section headers. |
1407 | void | |
1408 | find_symtab(const unsigned char* pshdrs); | |
1409 | ||
730cdc88 ILT |
1410 | // Return whether SHDR has the right flags for a GNU style exception |
1411 | // frame section. | |
1412 | bool | |
1413 | check_eh_frame_flags(const elfcpp::Shdr<size, big_endian>* shdr) const; | |
1414 | ||
1415 | // Return whether there is a section named .eh_frame which might be | |
1416 | // a GNU style exception frame section. | |
1417 | bool | |
1418 | find_eh_frame(const unsigned char* pshdrs, const char* names, | |
8383303e | 1419 | section_size_type names_size) const; |
730cdc88 | 1420 | |
a2fb1b05 ILT |
1421 | // Whether to include a section group in the link. |
1422 | bool | |
6a74a719 | 1423 | include_section_group(Symbol_table*, Layout*, unsigned int, const char*, |
a2fb1b05 ILT |
1424 | const elfcpp::Shdr<size, big_endian>&, |
1425 | std::vector<bool>*); | |
1426 | ||
1427 | // Whether to include a linkonce section in the link. | |
1428 | bool | |
1429 | include_linkonce_section(Layout*, const char*, | |
1430 | const elfcpp::Shdr<size, big_endian>&); | |
1431 | ||
61ba1cf9 ILT |
1432 | // Views and sizes when relocating. |
1433 | struct View_size | |
1434 | { | |
1435 | unsigned char* view; | |
1436 | typename elfcpp::Elf_types<size>::Elf_Addr address; | |
1437 | off_t offset; | |
8383303e | 1438 | section_size_type view_size; |
730cdc88 | 1439 | bool is_input_output_view; |
96803768 | 1440 | bool is_postprocessing_view; |
61ba1cf9 ILT |
1441 | }; |
1442 | ||
1443 | typedef std::vector<View_size> Views; | |
1444 | ||
1445 | // Write section data to the output file. Record the views and | |
1446 | // sizes in VIEWS for use when relocating. | |
1447 | void | |
cb295612 | 1448 | write_sections(const unsigned char* pshdrs, Output_file*, Views*); |
61ba1cf9 ILT |
1449 | |
1450 | // Relocate the sections in the output file. | |
1451 | void | |
92e059d8 ILT |
1452 | relocate_sections(const General_options& options, const Symbol_table*, |
1453 | const Layout*, const unsigned char* pshdrs, Views*); | |
61ba1cf9 | 1454 | |
7019cd25 ILT |
1455 | // Scan the input relocations for --emit-relocs. |
1456 | void | |
1457 | emit_relocs_scan(const General_options&, Symbol_table*, Layout*, | |
1458 | const unsigned char* plocal_syms, | |
1459 | const Read_relocs_data::Relocs_list::iterator&); | |
1460 | ||
1461 | // Scan the input relocations for --emit-relocs, templatized on the | |
1462 | // type of the relocation section. | |
1463 | template<int sh_type> | |
1464 | void | |
1465 | emit_relocs_scan_reltype(const General_options&, Symbol_table*, Layout*, | |
1466 | const unsigned char* plocal_syms, | |
1467 | const Read_relocs_data::Relocs_list::iterator&, | |
1468 | Relocatable_relocs*); | |
1469 | ||
1470 | // Emit the relocs for --emit-relocs. | |
1471 | void | |
1472 | emit_relocs(const Relocate_info<size, big_endian>*, unsigned int, | |
1473 | unsigned int sh_type, const unsigned char* prelocs, | |
1474 | size_t reloc_count, Output_section*, off_t output_offset, | |
1475 | unsigned char* view, Address address, | |
1476 | section_size_type view_size, | |
1477 | unsigned char* reloc_view, section_size_type reloc_view_size); | |
1478 | ||
1479 | // Emit the relocs for --emit-relocs, templatized on the type of the | |
1480 | // relocation section. | |
1481 | template<int sh_type> | |
1482 | void | |
1483 | emit_relocs_reltype(const Relocate_info<size, big_endian>*, unsigned int, | |
1484 | const unsigned char* prelocs, size_t reloc_count, | |
1485 | Output_section*, off_t output_offset, | |
1486 | unsigned char* view, Address address, | |
1487 | section_size_type view_size, | |
1488 | unsigned char* reloc_view, | |
1489 | section_size_type reloc_view_size); | |
1490 | ||
a9a60db6 ILT |
1491 | // Initialize input to output maps for section symbols in merged |
1492 | // sections. | |
1493 | void | |
1494 | initialize_input_to_output_maps(); | |
1495 | ||
1496 | // Free the input to output maps for section symbols in merged | |
1497 | // sections. | |
1498 | void | |
1499 | free_input_to_output_maps(); | |
1500 | ||
61ba1cf9 ILT |
1501 | // Write out the local symbols. |
1502 | void | |
b8e6aad9 | 1503 | write_local_symbols(Output_file*, |
7bf1f802 | 1504 | const Stringpool_template<char>*, |
d491d34e ILT |
1505 | const Stringpool_template<char>*, |
1506 | Output_symtab_xindex*, | |
1507 | Output_symtab_xindex*); | |
61ba1cf9 | 1508 | |
cb295612 ILT |
1509 | // Clear the local symbol information. |
1510 | void | |
1511 | clear_local_symbols() | |
1512 | { | |
1513 | this->local_values_.clear(); | |
1514 | this->local_got_offsets_.clear(); | |
cb295612 ILT |
1515 | } |
1516 | ||
07f397ab ILT |
1517 | // The GOT offsets of local symbols. This map also stores GOT offsets |
1518 | // for tp-relative offsets for TLS symbols. | |
0a65a3a7 | 1519 | typedef Unordered_map<unsigned int, Got_offset_list*> Local_got_offsets; |
e727fa71 | 1520 | |
07f397ab ILT |
1521 | // The TLS GOT offsets of local symbols. The map stores the offsets |
1522 | // for either a single GOT entry that holds the module index of a TLS | |
1523 | // symbol, or a pair of GOT entries containing the module index and | |
1524 | // dtv-relative offset. | |
1525 | struct Tls_got_entry | |
1526 | { | |
1527 | Tls_got_entry(int got_offset, bool have_pair) | |
1528 | : got_offset_(got_offset), | |
1529 | have_pair_(have_pair) | |
1530 | { } | |
1531 | int got_offset_; | |
1532 | bool have_pair_; | |
1533 | }; | |
1534 | typedef Unordered_map<unsigned int, Tls_got_entry> Local_tls_got_offsets; | |
1535 | ||
645f8123 ILT |
1536 | // General access to the ELF file. |
1537 | elfcpp::Elf_file<size, big_endian, Object> elf_file_; | |
bae7f79e | 1538 | // Index of SHT_SYMTAB section. |
645f8123 | 1539 | unsigned int symtab_shndx_; |
61ba1cf9 ILT |
1540 | // The number of local symbols. |
1541 | unsigned int local_symbol_count_; | |
1542 | // The number of local symbols which go into the output file. | |
1543 | unsigned int output_local_symbol_count_; | |
7bf1f802 ILT |
1544 | // The number of local symbols which go into the output file's dynamic |
1545 | // symbol table. | |
1546 | unsigned int output_local_dynsym_count_; | |
14bfc3f5 | 1547 | // The entries in the symbol table for the external symbols. |
730cdc88 | 1548 | Symbols symbols_; |
75f65a3e ILT |
1549 | // File offset for local symbols. |
1550 | off_t local_symbol_offset_; | |
7bf1f802 ILT |
1551 | // File offset for local dynamic symbols. |
1552 | off_t local_dynsym_offset_; | |
61ba1cf9 | 1553 | // Values of local symbols. |
c06b7b0b | 1554 | Local_values local_values_; |
07f397ab ILT |
1555 | // GOT offsets for local non-TLS symbols, and tp-relative offsets |
1556 | // for TLS symbols, indexed by symbol number. | |
e727fa71 | 1557 | Local_got_offsets local_got_offsets_; |
730cdc88 ILT |
1558 | // Whether this object has a GNU style .eh_frame section. |
1559 | bool has_eh_frame_; | |
bae7f79e ILT |
1560 | }; |
1561 | ||
54dc6425 | 1562 | // A class to manage the list of all objects. |
a2fb1b05 | 1563 | |
54dc6425 ILT |
1564 | class Input_objects |
1565 | { | |
1566 | public: | |
1567 | Input_objects() | |
fbfba508 | 1568 | : relobj_list_(), dynobj_list_(), sonames_(), system_library_directory_() |
54dc6425 ILT |
1569 | { } |
1570 | ||
f6ce93d6 ILT |
1571 | // The type of the list of input relocateable objects. |
1572 | typedef std::vector<Relobj*> Relobj_list; | |
1573 | typedef Relobj_list::const_iterator Relobj_iterator; | |
1574 | ||
1575 | // The type of the list of input dynamic objects. | |
1576 | typedef std::vector<Dynobj*> Dynobj_list; | |
1577 | typedef Dynobj_list::const_iterator Dynobj_iterator; | |
54dc6425 | 1578 | |
008db82e ILT |
1579 | // Add an object to the list. Return true if all is well, or false |
1580 | // if this object should be ignored. | |
1581 | bool | |
54dc6425 ILT |
1582 | add_object(Object*); |
1583 | ||
e2827e5f ILT |
1584 | // For each dynamic object, check whether we've seen all of its |
1585 | // explicit dependencies. | |
1586 | void | |
1587 | check_dynamic_dependencies() const; | |
1588 | ||
9a2d6984 ILT |
1589 | // Return whether an object was found in the system library |
1590 | // directory. | |
1591 | bool | |
1592 | found_in_system_library_directory(const Object*) const; | |
1593 | ||
f6ce93d6 ILT |
1594 | // Iterate over all regular objects. |
1595 | ||
1596 | Relobj_iterator | |
1597 | relobj_begin() const | |
1598 | { return this->relobj_list_.begin(); } | |
1599 | ||
1600 | Relobj_iterator | |
1601 | relobj_end() const | |
1602 | { return this->relobj_list_.end(); } | |
1603 | ||
1604 | // Iterate over all dynamic objects. | |
1605 | ||
1606 | Dynobj_iterator | |
1607 | dynobj_begin() const | |
1608 | { return this->dynobj_list_.begin(); } | |
54dc6425 | 1609 | |
f6ce93d6 ILT |
1610 | Dynobj_iterator |
1611 | dynobj_end() const | |
1612 | { return this->dynobj_list_.end(); } | |
54dc6425 ILT |
1613 | |
1614 | // Return whether we have seen any dynamic objects. | |
1615 | bool | |
1616 | any_dynamic() const | |
f6ce93d6 | 1617 | { return !this->dynobj_list_.empty(); } |
54dc6425 | 1618 | |
fe9a4c12 ILT |
1619 | // Return the number of input objects. |
1620 | int | |
1621 | number_of_input_objects() const | |
1622 | { return this->relobj_list_.size() + this->dynobj_list_.size(); } | |
1623 | ||
54dc6425 ILT |
1624 | private: |
1625 | Input_objects(const Input_objects&); | |
1626 | Input_objects& operator=(const Input_objects&); | |
1627 | ||
008db82e | 1628 | // The list of ordinary objects included in the link. |
f6ce93d6 | 1629 | Relobj_list relobj_list_; |
008db82e | 1630 | // The list of dynamic objects included in the link. |
f6ce93d6 | 1631 | Dynobj_list dynobj_list_; |
008db82e ILT |
1632 | // SONAMEs that we have seen. |
1633 | Unordered_set<std::string> sonames_; | |
9a2d6984 ILT |
1634 | // The directory in which we find the libc.so. |
1635 | std::string system_library_directory_; | |
54dc6425 | 1636 | }; |
a2fb1b05 | 1637 | |
92e059d8 ILT |
1638 | // Some of the information we pass to the relocation routines. We |
1639 | // group this together to avoid passing a dozen different arguments. | |
1640 | ||
1641 | template<int size, bool big_endian> | |
1642 | struct Relocate_info | |
1643 | { | |
1644 | // Command line options. | |
1645 | const General_options* options; | |
1646 | // Symbol table. | |
1647 | const Symbol_table* symtab; | |
1648 | // Layout. | |
1649 | const Layout* layout; | |
1650 | // Object being relocated. | |
f6ce93d6 | 1651 | Sized_relobj<size, big_endian>* object; |
92e059d8 ILT |
1652 | // Section index of relocation section. |
1653 | unsigned int reloc_shndx; | |
1654 | // Section index of section being relocated. | |
1655 | unsigned int data_shndx; | |
1656 | ||
1657 | // Return a string showing the location of a relocation. This is | |
1658 | // only used for error messages. | |
1659 | std::string | |
1660 | location(size_t relnum, off_t reloffset) const; | |
1661 | }; | |
1662 | ||
bae7f79e ILT |
1663 | // Return an Object appropriate for the input file. P is BYTES long, |
1664 | // and holds the ELF header. | |
1665 | ||
61ba1cf9 ILT |
1666 | extern Object* |
1667 | make_elf_object(const std::string& name, Input_file*, | |
1668 | off_t offset, const unsigned char* p, | |
8383303e | 1669 | section_offset_type bytes); |
bae7f79e ILT |
1670 | |
1671 | } // end namespace gold | |
1672 | ||
1673 | #endif // !defined(GOLD_OBJECT_H) |