Commit | Line | Data |
---|---|---|
61ba1cf9 ILT |
1 | // reloc.cc -- relocate input files for gold. |
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 | ||
61ba1cf9 ILT |
23 | #include "gold.h" |
24 | ||
cb295612 ILT |
25 | #include <algorithm> |
26 | ||
61ba1cf9 | 27 | #include "workqueue.h" |
5a6f7e2d | 28 | #include "symtab.h" |
61ba1cf9 | 29 | #include "output.h" |
a9a60db6 ILT |
30 | #include "merge.h" |
31 | #include "object.h" | |
61ba1cf9 ILT |
32 | #include "reloc.h" |
33 | ||
34 | namespace gold | |
35 | { | |
36 | ||
92e059d8 ILT |
37 | // Read_relocs methods. |
38 | ||
39 | // These tasks just read the relocation information from the file. | |
40 | // After reading it, the start another task to process the | |
41 | // information. These tasks requires access to the file. | |
42 | ||
17a1d0a9 ILT |
43 | Task_token* |
44 | Read_relocs::is_runnable() | |
92e059d8 | 45 | { |
17a1d0a9 | 46 | return this->object_->is_locked() ? this->object_->token() : NULL; |
92e059d8 ILT |
47 | } |
48 | ||
49 | // Lock the file. | |
50 | ||
17a1d0a9 ILT |
51 | void |
52 | Read_relocs::locks(Task_locker* tl) | |
92e059d8 | 53 | { |
17a1d0a9 | 54 | tl->add(this, this->object_->token()); |
92e059d8 ILT |
55 | } |
56 | ||
57 | // Read the relocations and then start a Scan_relocs_task. | |
58 | ||
59 | void | |
60 | Read_relocs::run(Workqueue* workqueue) | |
61 | { | |
62 | Read_relocs_data *rd = new Read_relocs_data; | |
63 | this->object_->read_relocs(rd); | |
17a1d0a9 ILT |
64 | this->object_->release(); |
65 | ||
92e059d8 | 66 | workqueue->queue_front(new Scan_relocs(this->options_, this->symtab_, |
ead1e424 ILT |
67 | this->layout_, this->object_, rd, |
68 | this->symtab_lock_, this->blocker_)); | |
92e059d8 ILT |
69 | } |
70 | ||
c7912668 ILT |
71 | // Return a debugging name for the task. |
72 | ||
73 | std::string | |
74 | Read_relocs::get_name() const | |
75 | { | |
76 | return "Read_relocs " + this->object_->name(); | |
77 | } | |
78 | ||
92e059d8 ILT |
79 | // Scan_relocs methods. |
80 | ||
81 | // These tasks scan the relocations read by Read_relocs and mark up | |
82 | // the symbol table to indicate which relocations are required. We | |
83 | // use a lock on the symbol table to keep them from interfering with | |
84 | // each other. | |
85 | ||
17a1d0a9 ILT |
86 | Task_token* |
87 | Scan_relocs::is_runnable() | |
92e059d8 | 88 | { |
17a1d0a9 ILT |
89 | if (!this->symtab_lock_->is_writable()) |
90 | return this->symtab_lock_; | |
91 | if (this->object_->is_locked()) | |
92 | return this->object_->token(); | |
93 | return NULL; | |
92e059d8 ILT |
94 | } |
95 | ||
96 | // Return the locks we hold: one on the file, one on the symbol table | |
97 | // and one blocker. | |
98 | ||
17a1d0a9 ILT |
99 | void |
100 | Scan_relocs::locks(Task_locker* tl) | |
92e059d8 | 101 | { |
17a1d0a9 ILT |
102 | tl->add(this, this->object_->token()); |
103 | tl->add(this, this->symtab_lock_); | |
104 | tl->add(this, this->blocker_); | |
92e059d8 ILT |
105 | } |
106 | ||
107 | // Scan the relocs. | |
108 | ||
109 | void | |
110 | Scan_relocs::run(Workqueue*) | |
111 | { | |
ead1e424 ILT |
112 | this->object_->scan_relocs(this->options_, this->symtab_, this->layout_, |
113 | this->rd_); | |
17a1d0a9 | 114 | this->object_->release(); |
92e059d8 ILT |
115 | delete this->rd_; |
116 | this->rd_ = NULL; | |
117 | } | |
118 | ||
c7912668 ILT |
119 | // Return a debugging name for the task. |
120 | ||
121 | std::string | |
122 | Scan_relocs::get_name() const | |
123 | { | |
124 | return "Scan_relocs " + this->object_->name(); | |
125 | } | |
126 | ||
61ba1cf9 ILT |
127 | // Relocate_task methods. |
128 | ||
730cdc88 | 129 | // We may have to wait for the output sections to be written. |
61ba1cf9 | 130 | |
17a1d0a9 ILT |
131 | Task_token* |
132 | Relocate_task::is_runnable() | |
61ba1cf9 | 133 | { |
730cdc88 ILT |
134 | if (this->object_->relocs_must_follow_section_writes() |
135 | && this->output_sections_blocker_->is_blocked()) | |
17a1d0a9 | 136 | return this->output_sections_blocker_; |
730cdc88 | 137 | |
c7912668 | 138 | if (this->object_->is_locked()) |
17a1d0a9 | 139 | return this->object_->token(); |
c7912668 | 140 | |
17a1d0a9 | 141 | return NULL; |
61ba1cf9 ILT |
142 | } |
143 | ||
144 | // We want to lock the file while we run. We want to unblock | |
730cdc88 | 145 | // INPUT_SECTIONS_BLOCKER and FINAL_BLOCKER when we are done. |
17a1d0a9 | 146 | // INPUT_SECTIONS_BLOCKER may be NULL. |
61ba1cf9 | 147 | |
17a1d0a9 ILT |
148 | void |
149 | Relocate_task::locks(Task_locker* tl) | |
61ba1cf9 | 150 | { |
17a1d0a9 ILT |
151 | if (this->input_sections_blocker_ != NULL) |
152 | tl->add(this, this->input_sections_blocker_); | |
153 | tl->add(this, this->final_blocker_); | |
154 | tl->add(this, this->object_->token()); | |
61ba1cf9 ILT |
155 | } |
156 | ||
157 | // Run the task. | |
158 | ||
159 | void | |
160 | Relocate_task::run(Workqueue*) | |
161 | { | |
92e059d8 | 162 | this->object_->relocate(this->options_, this->symtab_, this->layout_, |
61ba1cf9 | 163 | this->of_); |
cb295612 ILT |
164 | |
165 | // This is normally the last thing we will do with an object, so | |
166 | // uncache all views. | |
167 | this->object_->clear_view_cache_marks(); | |
168 | ||
17a1d0a9 | 169 | this->object_->release(); |
61ba1cf9 ILT |
170 | } |
171 | ||
c7912668 ILT |
172 | // Return a debugging name for the task. |
173 | ||
174 | std::string | |
175 | Relocate_task::get_name() const | |
176 | { | |
177 | return "Relocate_task " + this->object_->name(); | |
178 | } | |
179 | ||
92e059d8 ILT |
180 | // Read the relocs and local symbols from the object file and store |
181 | // the information in RD. | |
182 | ||
183 | template<int size, bool big_endian> | |
184 | void | |
f6ce93d6 | 185 | Sized_relobj<size, big_endian>::do_read_relocs(Read_relocs_data* rd) |
92e059d8 ILT |
186 | { |
187 | rd->relocs.clear(); | |
188 | ||
189 | unsigned int shnum = this->shnum(); | |
190 | if (shnum == 0) | |
191 | return; | |
192 | ||
193 | rd->relocs.reserve(shnum / 2); | |
194 | ||
730cdc88 ILT |
195 | std::vector<Map_to_output>& map_sections(this->map_to_output()); |
196 | ||
645f8123 | 197 | const unsigned char *pshdrs = this->get_view(this->elf_file_.shoff(), |
9eb9fa57 ILT |
198 | shnum * This::shdr_size, |
199 | true); | |
92e059d8 ILT |
200 | // Skip the first, dummy, section. |
201 | const unsigned char *ps = pshdrs + This::shdr_size; | |
202 | for (unsigned int i = 1; i < shnum; ++i, ps += This::shdr_size) | |
203 | { | |
204 | typename This::Shdr shdr(ps); | |
205 | ||
206 | unsigned int sh_type = shdr.get_sh_type(); | |
207 | if (sh_type != elfcpp::SHT_REL && sh_type != elfcpp::SHT_RELA) | |
208 | continue; | |
209 | ||
210 | unsigned int shndx = shdr.get_sh_info(); | |
211 | if (shndx >= shnum) | |
212 | { | |
75f2446e ILT |
213 | this->error(_("relocation section %u has bad info %u"), |
214 | i, shndx); | |
215 | continue; | |
92e059d8 ILT |
216 | } |
217 | ||
730cdc88 ILT |
218 | Output_section* os = map_sections[shndx].output_section; |
219 | if (os == NULL) | |
92e059d8 ILT |
220 | continue; |
221 | ||
ead1e424 ILT |
222 | // We are scanning relocations in order to fill out the GOT and |
223 | // PLT sections. Relocations for sections which are not | |
224 | // allocated (typically debugging sections) should not add new | |
6a74a719 ILT |
225 | // GOT and PLT entries. So we skip them unless this is a |
226 | // relocatable link. | |
227 | if (!parameters->output_is_object()) | |
228 | { | |
229 | typename This::Shdr secshdr(pshdrs + shndx * This::shdr_size); | |
230 | if ((secshdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0) | |
231 | continue; | |
232 | } | |
ead1e424 | 233 | |
645f8123 | 234 | if (shdr.get_sh_link() != this->symtab_shndx_) |
92e059d8 | 235 | { |
75f2446e ILT |
236 | this->error(_("relocation section %u uses unexpected " |
237 | "symbol table %u"), | |
238 | i, shdr.get_sh_link()); | |
239 | continue; | |
92e059d8 ILT |
240 | } |
241 | ||
242 | off_t sh_size = shdr.get_sh_size(); | |
243 | ||
244 | unsigned int reloc_size; | |
245 | if (sh_type == elfcpp::SHT_REL) | |
246 | reloc_size = elfcpp::Elf_sizes<size>::rel_size; | |
247 | else | |
248 | reloc_size = elfcpp::Elf_sizes<size>::rela_size; | |
249 | if (reloc_size != shdr.get_sh_entsize()) | |
250 | { | |
75f2446e ILT |
251 | this->error(_("unexpected entsize for reloc section %u: %lu != %u"), |
252 | i, static_cast<unsigned long>(shdr.get_sh_entsize()), | |
253 | reloc_size); | |
254 | continue; | |
92e059d8 ILT |
255 | } |
256 | ||
257 | size_t reloc_count = sh_size / reloc_size; | |
f5c3f225 | 258 | if (static_cast<off_t>(reloc_count * reloc_size) != sh_size) |
92e059d8 | 259 | { |
75f2446e ILT |
260 | this->error(_("reloc section %u size %lu uneven"), |
261 | i, static_cast<unsigned long>(sh_size)); | |
262 | continue; | |
92e059d8 ILT |
263 | } |
264 | ||
265 | rd->relocs.push_back(Section_relocs()); | |
266 | Section_relocs& sr(rd->relocs.back()); | |
267 | sr.reloc_shndx = i; | |
268 | sr.data_shndx = shndx; | |
9eb9fa57 ILT |
269 | sr.contents = this->get_lasting_view(shdr.get_sh_offset(), sh_size, |
270 | true); | |
92e059d8 ILT |
271 | sr.sh_type = sh_type; |
272 | sr.reloc_count = reloc_count; | |
730cdc88 ILT |
273 | sr.output_section = os; |
274 | sr.needs_special_offset_handling = map_sections[shndx].offset == -1; | |
92e059d8 ILT |
275 | } |
276 | ||
277 | // Read the local symbols. | |
a3ad94ed | 278 | gold_assert(this->symtab_shndx_ != -1U); |
645f8123 | 279 | if (this->symtab_shndx_ == 0 || this->local_symbol_count_ == 0) |
92e059d8 ILT |
280 | rd->local_symbols = NULL; |
281 | else | |
282 | { | |
283 | typename This::Shdr symtabshdr(pshdrs | |
645f8123 | 284 | + this->symtab_shndx_ * This::shdr_size); |
a3ad94ed | 285 | gold_assert(symtabshdr.get_sh_type() == elfcpp::SHT_SYMTAB); |
92e059d8 ILT |
286 | const int sym_size = This::sym_size; |
287 | const unsigned int loccount = this->local_symbol_count_; | |
a3ad94ed | 288 | gold_assert(loccount == symtabshdr.get_sh_info()); |
92e059d8 ILT |
289 | off_t locsize = loccount * sym_size; |
290 | rd->local_symbols = this->get_lasting_view(symtabshdr.get_sh_offset(), | |
9eb9fa57 | 291 | locsize, true); |
92e059d8 ILT |
292 | } |
293 | } | |
294 | ||
295 | // Scan the relocs and adjust the symbol table. This looks for | |
296 | // relocations which require GOT/PLT/COPY relocations. | |
297 | ||
298 | template<int size, bool big_endian> | |
299 | void | |
f6ce93d6 | 300 | Sized_relobj<size, big_endian>::do_scan_relocs(const General_options& options, |
92e059d8 | 301 | Symbol_table* symtab, |
ead1e424 | 302 | Layout* layout, |
92e059d8 ILT |
303 | Read_relocs_data* rd) |
304 | { | |
305 | Sized_target<size, big_endian>* target = this->sized_target(); | |
306 | ||
307 | const unsigned char* local_symbols; | |
308 | if (rd->local_symbols == NULL) | |
309 | local_symbols = NULL; | |
310 | else | |
311 | local_symbols = rd->local_symbols->data(); | |
312 | ||
313 | for (Read_relocs_data::Relocs_list::iterator p = rd->relocs.begin(); | |
314 | p != rd->relocs.end(); | |
315 | ++p) | |
316 | { | |
6a74a719 ILT |
317 | if (!parameters->output_is_object()) |
318 | target->scan_relocs(options, symtab, layout, this, p->data_shndx, | |
319 | p->sh_type, p->contents->data(), p->reloc_count, | |
320 | p->output_section, | |
321 | p->needs_special_offset_handling, | |
322 | this->local_symbol_count_, | |
323 | local_symbols); | |
324 | else | |
325 | { | |
326 | Relocatable_relocs* rr = this->relocatable_relocs(p->reloc_shndx); | |
327 | gold_assert(rr != NULL); | |
328 | rr->set_reloc_count(p->reloc_count); | |
329 | target->scan_relocatable_relocs(options, symtab, layout, this, | |
330 | p->data_shndx, p->sh_type, | |
331 | p->contents->data(), | |
332 | p->reloc_count, | |
333 | p->output_section, | |
334 | p->needs_special_offset_handling, | |
335 | this->local_symbol_count_, | |
336 | local_symbols, | |
337 | rr); | |
338 | } | |
339 | ||
92e059d8 ILT |
340 | delete p->contents; |
341 | p->contents = NULL; | |
342 | } | |
343 | ||
344 | if (rd->local_symbols != NULL) | |
345 | { | |
346 | delete rd->local_symbols; | |
347 | rd->local_symbols = NULL; | |
348 | } | |
349 | } | |
350 | ||
61ba1cf9 ILT |
351 | // Relocate the input sections and write out the local symbols. |
352 | ||
353 | template<int size, bool big_endian> | |
354 | void | |
f6ce93d6 | 355 | Sized_relobj<size, big_endian>::do_relocate(const General_options& options, |
61ba1cf9 | 356 | const Symbol_table* symtab, |
92e059d8 | 357 | const Layout* layout, |
61ba1cf9 ILT |
358 | Output_file* of) |
359 | { | |
360 | unsigned int shnum = this->shnum(); | |
361 | ||
362 | // Read the section headers. | |
645f8123 | 363 | const unsigned char* pshdrs = this->get_view(this->elf_file_.shoff(), |
9eb9fa57 ILT |
364 | shnum * This::shdr_size, |
365 | true); | |
61ba1cf9 ILT |
366 | |
367 | Views views; | |
368 | views.resize(shnum); | |
369 | ||
370 | // Make two passes over the sections. The first one copies the | |
371 | // section data to the output file. The second one applies | |
372 | // relocations. | |
373 | ||
374 | this->write_sections(pshdrs, of, &views); | |
375 | ||
a9a60db6 ILT |
376 | // To speed up relocations, we set up hash tables for fast lookup of |
377 | // input offsets to output addresses. | |
378 | this->initialize_input_to_output_maps(); | |
379 | ||
61ba1cf9 ILT |
380 | // Apply relocations. |
381 | ||
92e059d8 | 382 | this->relocate_sections(options, symtab, layout, pshdrs, &views); |
61ba1cf9 | 383 | |
a9a60db6 ILT |
384 | // After we've done the relocations, we release the hash tables, |
385 | // since we no longer need them. | |
386 | this->free_input_to_output_maps(); | |
387 | ||
61ba1cf9 ILT |
388 | // Write out the accumulated views. |
389 | for (unsigned int i = 1; i < shnum; ++i) | |
390 | { | |
391 | if (views[i].view != NULL) | |
730cdc88 | 392 | { |
96803768 ILT |
393 | if (!views[i].is_postprocessing_view) |
394 | { | |
395 | if (views[i].is_input_output_view) | |
396 | of->write_input_output_view(views[i].offset, | |
397 | views[i].view_size, | |
398 | views[i].view); | |
399 | else | |
400 | of->write_output_view(views[i].offset, views[i].view_size, | |
401 | views[i].view); | |
402 | } | |
730cdc88 | 403 | } |
61ba1cf9 ILT |
404 | } |
405 | ||
406 | // Write out the local symbols. | |
7bf1f802 | 407 | this->write_local_symbols(of, layout->sympool(), layout->dynpool()); |
cb295612 ILT |
408 | |
409 | // We should no longer need the local symbol values. | |
410 | this->clear_local_symbols(); | |
61ba1cf9 ILT |
411 | } |
412 | ||
cb295612 ILT |
413 | // Sort a Read_multiple vector by file offset. |
414 | struct Read_multiple_compare | |
415 | { | |
416 | inline bool | |
417 | operator()(const File_read::Read_multiple_entry& rme1, | |
418 | const File_read::Read_multiple_entry& rme2) const | |
419 | { return rme1.file_offset < rme2.file_offset; } | |
420 | }; | |
421 | ||
61ba1cf9 ILT |
422 | // Write section data to the output file. PSHDRS points to the |
423 | // section headers. Record the views in *PVIEWS for use when | |
424 | // relocating. | |
425 | ||
426 | template<int size, bool big_endian> | |
427 | void | |
f6ce93d6 | 428 | Sized_relobj<size, big_endian>::write_sections(const unsigned char* pshdrs, |
61ba1cf9 | 429 | Output_file* of, |
cb295612 | 430 | Views* pviews) |
61ba1cf9 ILT |
431 | { |
432 | unsigned int shnum = this->shnum(); | |
17a1d0a9 | 433 | const std::vector<Map_to_output>& map_sections(this->map_to_output()); |
61ba1cf9 | 434 | |
cb295612 ILT |
435 | File_read::Read_multiple rm; |
436 | bool is_sorted = true; | |
437 | ||
61ba1cf9 ILT |
438 | const unsigned char* p = pshdrs + This::shdr_size; |
439 | for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size) | |
440 | { | |
441 | View_size* pvs = &(*pviews)[i]; | |
442 | ||
443 | pvs->view = NULL; | |
444 | ||
445 | const Output_section* os = map_sections[i].output_section; | |
446 | if (os == NULL) | |
447 | continue; | |
730cdc88 | 448 | off_t output_offset = map_sections[i].offset; |
61ba1cf9 ILT |
449 | |
450 | typename This::Shdr shdr(p); | |
451 | ||
452 | if (shdr.get_sh_type() == elfcpp::SHT_NOBITS) | |
453 | continue; | |
454 | ||
6a74a719 ILT |
455 | if (parameters->output_is_object() |
456 | && (shdr.get_sh_type() == elfcpp::SHT_REL | |
457 | || shdr.get_sh_type() == elfcpp::SHT_RELA) | |
458 | && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0) | |
459 | { | |
460 | // This is a reloc section in a relocatable link. We don't | |
461 | // need to read the input file. The size and file offset | |
462 | // are stored in the Relocatable_relocs structure. | |
463 | Relocatable_relocs* rr = this->relocatable_relocs(i); | |
464 | gold_assert(rr != NULL); | |
465 | Output_data* posd = rr->output_data(); | |
466 | gold_assert(posd != NULL); | |
467 | ||
468 | pvs->offset = posd->offset(); | |
469 | pvs->view_size = posd->data_size(); | |
470 | pvs->view = of->get_output_view(pvs->offset, pvs->view_size); | |
471 | pvs->address = posd->address(); | |
472 | pvs->is_input_output_view = false; | |
473 | pvs->is_postprocessing_view = false; | |
474 | ||
475 | continue; | |
476 | } | |
477 | ||
96803768 ILT |
478 | // In the normal case, this input section is simply mapped to |
479 | // the output section at offset OUTPUT_OFFSET. | |
480 | ||
481 | // However, if OUTPUT_OFFSET == -1, then input data is handled | |
482 | // specially--e.g., a .eh_frame section. The relocation | |
483 | // routines need to check for each reloc where it should be | |
484 | // applied. For this case, we need an input/output view for the | |
485 | // entire contents of the section in the output file. We don't | |
486 | // want to copy the contents of the input section to the output | |
487 | // section; the output section contents were already written, | |
488 | // and we waited for them in Relocate_task::is_runnable because | |
489 | // relocs_must_follow_section_writes is set for the object. | |
490 | ||
491 | // Regardless of which of the above cases is true, we have to | |
492 | // check requires_postprocessing of the output section. If that | |
493 | // is false, then we work with views of the output file | |
494 | // directly. If it is true, then we work with a separate | |
495 | // buffer, and the output section is responsible for writing the | |
496 | // final data to the output file. | |
497 | ||
498 | off_t output_section_offset; | |
499 | off_t output_section_size; | |
500 | if (!os->requires_postprocessing()) | |
501 | { | |
502 | output_section_offset = os->offset(); | |
503 | output_section_size = os->data_size(); | |
504 | } | |
505 | else | |
506 | { | |
507 | output_section_offset = 0; | |
508 | output_section_size = os->postprocessing_buffer_size(); | |
509 | } | |
510 | ||
730cdc88 | 511 | off_t view_start; |
fe8718a4 | 512 | section_size_type view_size; |
730cdc88 ILT |
513 | if (output_offset != -1) |
514 | { | |
96803768 | 515 | view_start = output_section_offset + output_offset; |
fe8718a4 | 516 | view_size = convert_to_section_size_type(shdr.get_sh_size()); |
730cdc88 ILT |
517 | } |
518 | else | |
519 | { | |
96803768 | 520 | view_start = output_section_offset; |
fe8718a4 | 521 | view_size = convert_to_section_size_type(output_section_size); |
730cdc88 | 522 | } |
61ba1cf9 | 523 | |
730cdc88 | 524 | if (view_size == 0) |
ead1e424 ILT |
525 | continue; |
526 | ||
730cdc88 ILT |
527 | gold_assert(output_offset == -1 |
528 | || (output_offset >= 0 | |
8d32f935 ILT |
529 | && (output_offset + static_cast<off_t>(view_size) |
530 | <= output_section_size))); | |
ead1e424 | 531 | |
730cdc88 | 532 | unsigned char* view; |
96803768 ILT |
533 | if (os->requires_postprocessing()) |
534 | { | |
535 | unsigned char* buffer = os->postprocessing_buffer(); | |
536 | view = buffer + view_start; | |
537 | if (output_offset != -1) | |
cb295612 ILT |
538 | { |
539 | off_t sh_offset = shdr.get_sh_offset(); | |
540 | if (!rm.empty() && rm.back().file_offset > sh_offset) | |
541 | is_sorted = false; | |
542 | rm.push_back(File_read::Read_multiple_entry(sh_offset, | |
543 | view_size, view)); | |
544 | } | |
96803768 | 545 | } |
730cdc88 ILT |
546 | else |
547 | { | |
96803768 ILT |
548 | if (output_offset == -1) |
549 | view = of->get_input_output_view(view_start, view_size); | |
550 | else | |
551 | { | |
552 | view = of->get_output_view(view_start, view_size); | |
cb295612 ILT |
553 | off_t sh_offset = shdr.get_sh_offset(); |
554 | if (!rm.empty() && rm.back().file_offset > sh_offset) | |
555 | is_sorted = false; | |
556 | rm.push_back(File_read::Read_multiple_entry(sh_offset, | |
557 | view_size, view)); | |
96803768 | 558 | } |
730cdc88 | 559 | } |
92e059d8 | 560 | |
61ba1cf9 | 561 | pvs->view = view; |
730cdc88 ILT |
562 | pvs->address = os->address(); |
563 | if (output_offset != -1) | |
564 | pvs->address += output_offset; | |
565 | pvs->offset = view_start; | |
566 | pvs->view_size = view_size; | |
567 | pvs->is_input_output_view = output_offset == -1; | |
96803768 | 568 | pvs->is_postprocessing_view = os->requires_postprocessing(); |
61ba1cf9 | 569 | } |
cb295612 ILT |
570 | |
571 | // Actually read the data. | |
572 | if (!rm.empty()) | |
573 | { | |
574 | if (!is_sorted) | |
575 | std::sort(rm.begin(), rm.end(), Read_multiple_compare()); | |
576 | this->read_multiple(rm); | |
577 | } | |
61ba1cf9 ILT |
578 | } |
579 | ||
580 | // Relocate section data. VIEWS points to the section data as views | |
581 | // in the output file. | |
582 | ||
583 | template<int size, bool big_endian> | |
584 | void | |
f6ce93d6 | 585 | Sized_relobj<size, big_endian>::relocate_sections( |
92e059d8 ILT |
586 | const General_options& options, |
587 | const Symbol_table* symtab, | |
588 | const Layout* layout, | |
589 | const unsigned char* pshdrs, | |
590 | Views* pviews) | |
61ba1cf9 ILT |
591 | { |
592 | unsigned int shnum = this->shnum(); | |
61ba1cf9 ILT |
593 | Sized_target<size, big_endian>* target = this->sized_target(); |
594 | ||
17a1d0a9 | 595 | const std::vector<Map_to_output>& map_sections(this->map_to_output()); |
730cdc88 | 596 | |
92e059d8 ILT |
597 | Relocate_info<size, big_endian> relinfo; |
598 | relinfo.options = &options; | |
599 | relinfo.symtab = symtab; | |
600 | relinfo.layout = layout; | |
601 | relinfo.object = this; | |
92e059d8 | 602 | |
61ba1cf9 ILT |
603 | const unsigned char* p = pshdrs + This::shdr_size; |
604 | for (unsigned int i = 1; i < shnum; ++i, p += This::shdr_size) | |
605 | { | |
606 | typename This::Shdr shdr(p); | |
607 | ||
608 | unsigned int sh_type = shdr.get_sh_type(); | |
609 | if (sh_type != elfcpp::SHT_REL && sh_type != elfcpp::SHT_RELA) | |
610 | continue; | |
611 | ||
612 | unsigned int index = shdr.get_sh_info(); | |
613 | if (index >= this->shnum()) | |
614 | { | |
75f2446e ILT |
615 | this->error(_("relocation section %u has bad info %u"), |
616 | i, index); | |
617 | continue; | |
61ba1cf9 ILT |
618 | } |
619 | ||
730cdc88 ILT |
620 | Output_section* os = map_sections[index].output_section; |
621 | if (os == NULL) | |
61ba1cf9 ILT |
622 | { |
623 | // This relocation section is against a section which we | |
624 | // discarded. | |
625 | continue; | |
626 | } | |
730cdc88 | 627 | off_t output_offset = map_sections[index].offset; |
61ba1cf9 | 628 | |
a3ad94ed | 629 | gold_assert((*pviews)[index].view != NULL); |
6a74a719 ILT |
630 | if (parameters->output_is_object()) |
631 | gold_assert((*pviews)[i].view != NULL); | |
61ba1cf9 | 632 | |
645f8123 | 633 | if (shdr.get_sh_link() != this->symtab_shndx_) |
61ba1cf9 | 634 | { |
75f2446e ILT |
635 | gold_error(_("relocation section %u uses unexpected " |
636 | "symbol table %u"), | |
637 | i, shdr.get_sh_link()); | |
638 | continue; | |
61ba1cf9 ILT |
639 | } |
640 | ||
641 | off_t sh_size = shdr.get_sh_size(); | |
642 | const unsigned char* prelocs = this->get_view(shdr.get_sh_offset(), | |
9eb9fa57 | 643 | sh_size, false); |
61ba1cf9 ILT |
644 | |
645 | unsigned int reloc_size; | |
646 | if (sh_type == elfcpp::SHT_REL) | |
647 | reloc_size = elfcpp::Elf_sizes<size>::rel_size; | |
648 | else | |
649 | reloc_size = elfcpp::Elf_sizes<size>::rela_size; | |
650 | ||
651 | if (reloc_size != shdr.get_sh_entsize()) | |
652 | { | |
75f2446e ILT |
653 | gold_error(_("unexpected entsize for reloc section %u: %lu != %u"), |
654 | i, static_cast<unsigned long>(shdr.get_sh_entsize()), | |
730cdc88 | 655 | reloc_size); |
75f2446e | 656 | continue; |
61ba1cf9 ILT |
657 | } |
658 | ||
659 | size_t reloc_count = sh_size / reloc_size; | |
f5c3f225 | 660 | if (static_cast<off_t>(reloc_count * reloc_size) != sh_size) |
61ba1cf9 | 661 | { |
75f2446e ILT |
662 | gold_error(_("reloc section %u size %lu uneven"), |
663 | i, static_cast<unsigned long>(sh_size)); | |
664 | continue; | |
61ba1cf9 ILT |
665 | } |
666 | ||
96803768 ILT |
667 | gold_assert(output_offset != -1 |
668 | || this->relocs_must_follow_section_writes()); | |
669 | ||
92e059d8 ILT |
670 | relinfo.reloc_shndx = i; |
671 | relinfo.data_shndx = index; | |
6a74a719 ILT |
672 | if (!parameters->output_is_object()) |
673 | target->relocate_section(&relinfo, | |
674 | sh_type, | |
675 | prelocs, | |
676 | reloc_count, | |
677 | os, | |
678 | output_offset == -1, | |
679 | (*pviews)[index].view, | |
680 | (*pviews)[index].address, | |
681 | (*pviews)[index].view_size); | |
682 | else | |
683 | { | |
684 | Relocatable_relocs* rr = this->relocatable_relocs(i); | |
685 | target->relocate_for_relocatable(&relinfo, | |
686 | sh_type, | |
687 | prelocs, | |
688 | reloc_count, | |
689 | os, | |
690 | output_offset, | |
691 | rr, | |
692 | (*pviews)[index].view, | |
693 | (*pviews)[index].address, | |
694 | (*pviews)[index].view_size, | |
695 | (*pviews)[i].view, | |
696 | (*pviews)[i].view_size); | |
697 | } | |
61ba1cf9 ILT |
698 | } |
699 | } | |
700 | ||
a9a60db6 ILT |
701 | // Create merge hash tables for the local symbols. These are used to |
702 | // speed up relocations. | |
703 | ||
704 | template<int size, bool big_endian> | |
705 | void | |
706 | Sized_relobj<size, big_endian>::initialize_input_to_output_maps() | |
707 | { | |
708 | const unsigned int loccount = this->local_symbol_count_; | |
709 | for (unsigned int i = 1; i < loccount; ++i) | |
710 | { | |
711 | Symbol_value<size>& lv(this->local_values_[i]); | |
712 | lv.initialize_input_to_output_map(this); | |
713 | } | |
714 | } | |
715 | ||
716 | // Free merge hash tables for the local symbols. | |
717 | ||
718 | template<int size, bool big_endian> | |
719 | void | |
720 | Sized_relobj<size, big_endian>::free_input_to_output_maps() | |
721 | { | |
722 | const unsigned int loccount = this->local_symbol_count_; | |
723 | for (unsigned int i = 1; i < loccount; ++i) | |
724 | { | |
725 | Symbol_value<size>& lv(this->local_values_[i]); | |
726 | lv.free_input_to_output_map(); | |
727 | } | |
728 | } | |
729 | ||
730 | // Class Merged_symbol_value. | |
731 | ||
732 | template<int size> | |
733 | void | |
734 | Merged_symbol_value<size>::initialize_input_to_output_map( | |
735 | const Relobj* object, | |
736 | unsigned int input_shndx) | |
737 | { | |
738 | Object_merge_map* map = object->merge_map(); | |
739 | map->initialize_input_to_output_map<size>(input_shndx, | |
740 | this->output_start_address_, | |
741 | &this->output_addresses_); | |
742 | } | |
743 | ||
744 | // Get the output value corresponding to an input offset if we | |
745 | // couldn't find it in the hash table. | |
746 | ||
747 | template<int size> | |
748 | typename elfcpp::Elf_types<size>::Elf_Addr | |
749 | Merged_symbol_value<size>::value_from_output_section( | |
750 | const Relobj* object, | |
751 | unsigned int input_shndx, | |
752 | typename elfcpp::Elf_types<size>::Elf_Addr input_offset) const | |
753 | { | |
754 | section_offset_type output_offset; | |
755 | bool found = object->merge_map()->get_output_offset(NULL, input_shndx, | |
756 | input_offset, | |
757 | &output_offset); | |
758 | ||
759 | // If this assertion fails, it means that some relocation was | |
760 | // against a portion of an input merge section which we didn't map | |
761 | // to the output file and we didn't explicitly discard. We should | |
762 | // always map all portions of input merge sections. | |
763 | gold_assert(found); | |
764 | ||
765 | if (output_offset == -1) | |
766 | return 0; | |
767 | else | |
768 | return this->output_start_address_ + output_offset; | |
769 | } | |
770 | ||
5a6f7e2d ILT |
771 | // Copy_relocs::Copy_reloc_entry methods. |
772 | ||
773 | // Return whether we should emit this reloc. We should emit it if the | |
774 | // symbol is still defined in a dynamic object. If we should not emit | |
775 | // it, we clear it, to save ourselves the test next time. | |
776 | ||
777 | template<int size, bool big_endian> | |
778 | bool | |
779 | Copy_relocs<size, big_endian>::Copy_reloc_entry::should_emit() | |
780 | { | |
781 | if (this->sym_ == NULL) | |
782 | return false; | |
14b31740 | 783 | if (this->sym_->is_from_dynobj()) |
5a6f7e2d ILT |
784 | return true; |
785 | this->sym_ = NULL; | |
786 | return false; | |
787 | } | |
788 | ||
789 | // Emit a reloc into a SHT_REL section. | |
790 | ||
791 | template<int size, bool big_endian> | |
792 | void | |
793 | Copy_relocs<size, big_endian>::Copy_reloc_entry::emit( | |
794 | Output_data_reloc<elfcpp::SHT_REL, true, size, big_endian>* reloc_data) | |
795 | { | |
16649710 | 796 | this->sym_->set_needs_dynsym_entry(); |
4f4c5f80 ILT |
797 | reloc_data->add_global(this->sym_, this->reloc_type_, this->output_section_, |
798 | this->relobj_, this->shndx_, this->address_); | |
5a6f7e2d ILT |
799 | } |
800 | ||
801 | // Emit a reloc into a SHT_RELA section. | |
802 | ||
803 | template<int size, bool big_endian> | |
804 | void | |
805 | Copy_relocs<size, big_endian>::Copy_reloc_entry::emit( | |
806 | Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian>* reloc_data) | |
807 | { | |
16649710 | 808 | this->sym_->set_needs_dynsym_entry(); |
4f4c5f80 ILT |
809 | reloc_data->add_global(this->sym_, this->reloc_type_, this->output_section_, |
810 | this->relobj_, this->shndx_, this->address_, | |
811 | this->addend_); | |
5a6f7e2d ILT |
812 | } |
813 | ||
814 | // Copy_relocs methods. | |
a3ad94ed ILT |
815 | |
816 | // Return whether we need a COPY reloc for a relocation against GSYM. | |
817 | // The relocation is being applied to section SHNDX in OBJECT. | |
818 | ||
819 | template<int size, bool big_endian> | |
820 | bool | |
5a6f7e2d | 821 | Copy_relocs<size, big_endian>::need_copy_reloc( |
a3ad94ed ILT |
822 | const General_options*, |
823 | Relobj* object, | |
824 | unsigned int shndx, | |
5a6f7e2d | 825 | Sized_symbol<size>* sym) |
a3ad94ed ILT |
826 | { |
827 | // FIXME: Handle -z nocopyrelocs. | |
828 | ||
5a6f7e2d ILT |
829 | if (sym->symsize() == 0) |
830 | return false; | |
831 | ||
a3ad94ed ILT |
832 | // If this is a readonly section, then we need a COPY reloc. |
833 | // Otherwise we can use a dynamic reloc. | |
834 | if ((object->section_flags(shndx) & elfcpp::SHF_WRITE) == 0) | |
835 | return true; | |
836 | ||
837 | return false; | |
838 | } | |
839 | ||
5a6f7e2d ILT |
840 | // Save a Rel reloc. |
841 | ||
842 | template<int size, bool big_endian> | |
843 | void | |
844 | Copy_relocs<size, big_endian>::save( | |
845 | Symbol* sym, | |
846 | Relobj* relobj, | |
847 | unsigned int shndx, | |
4f4c5f80 | 848 | Output_section* output_section, |
5a6f7e2d ILT |
849 | const elfcpp::Rel<size, big_endian>& rel) |
850 | { | |
851 | unsigned int reloc_type = elfcpp::elf_r_type<size>(rel.get_r_info()); | |
852 | this->entries_.push_back(Copy_reloc_entry(sym, reloc_type, relobj, shndx, | |
4f4c5f80 ILT |
853 | output_section, |
854 | rel.get_r_offset(), 0)); | |
5a6f7e2d ILT |
855 | } |
856 | ||
857 | // Save a Rela reloc. | |
858 | ||
859 | template<int size, bool big_endian> | |
860 | void | |
861 | Copy_relocs<size, big_endian>::save( | |
862 | Symbol* sym, | |
863 | Relobj* relobj, | |
864 | unsigned int shndx, | |
4f4c5f80 | 865 | Output_section* output_section, |
5a6f7e2d ILT |
866 | const elfcpp::Rela<size, big_endian>& rela) |
867 | { | |
868 | unsigned int reloc_type = elfcpp::elf_r_type<size>(rela.get_r_info()); | |
869 | this->entries_.push_back(Copy_reloc_entry(sym, reloc_type, relobj, shndx, | |
4f4c5f80 | 870 | output_section, |
5a6f7e2d ILT |
871 | rela.get_r_offset(), |
872 | rela.get_r_addend())); | |
873 | } | |
874 | ||
875 | // Return whether there are any relocs to emit. We don't want to emit | |
876 | // a reloc if the symbol is no longer defined in a dynamic object. | |
877 | ||
878 | template<int size, bool big_endian> | |
879 | bool | |
880 | Copy_relocs<size, big_endian>::any_to_emit() | |
881 | { | |
882 | for (typename Copy_reloc_entries::iterator p = this->entries_.begin(); | |
883 | p != this->entries_.end(); | |
884 | ++p) | |
885 | { | |
886 | if (p->should_emit()) | |
887 | return true; | |
888 | } | |
889 | return false; | |
890 | } | |
891 | ||
892 | // Emit relocs. | |
893 | ||
894 | template<int size, bool big_endian> | |
895 | template<int sh_type> | |
896 | void | |
897 | Copy_relocs<size, big_endian>::emit( | |
898 | Output_data_reloc<sh_type, true, size, big_endian>* reloc_data) | |
899 | { | |
900 | for (typename Copy_reloc_entries::iterator p = this->entries_.begin(); | |
901 | p != this->entries_.end(); | |
902 | ++p) | |
903 | { | |
904 | if (p->should_emit()) | |
905 | p->emit(reloc_data); | |
906 | } | |
907 | } | |
908 | ||
730cdc88 ILT |
909 | // Track_relocs methods. |
910 | ||
911 | // Initialize the class to track the relocs. This gets the object, | |
912 | // the reloc section index, and the type of the relocs. This returns | |
913 | // false if something goes wrong. | |
914 | ||
915 | template<int size, bool big_endian> | |
916 | bool | |
917 | Track_relocs<size, big_endian>::initialize( | |
b696e6d4 | 918 | Object* object, |
730cdc88 ILT |
919 | unsigned int reloc_shndx, |
920 | unsigned int reloc_type) | |
921 | { | |
730cdc88 ILT |
922 | // If RELOC_SHNDX is -1U, it means there is more than one reloc |
923 | // section for the .eh_frame section. We can't handle that case. | |
924 | if (reloc_shndx == -1U) | |
925 | return false; | |
926 | ||
927 | // If RELOC_SHNDX is 0, there is no reloc section. | |
928 | if (reloc_shndx == 0) | |
929 | return true; | |
930 | ||
931 | // Get the contents of the reloc section. | |
932 | this->prelocs_ = object->section_contents(reloc_shndx, &this->len_, false); | |
933 | ||
934 | if (reloc_type == elfcpp::SHT_REL) | |
935 | this->reloc_size_ = elfcpp::Elf_sizes<size>::rel_size; | |
936 | else if (reloc_type == elfcpp::SHT_RELA) | |
937 | this->reloc_size_ = elfcpp::Elf_sizes<size>::rela_size; | |
938 | else | |
939 | gold_unreachable(); | |
940 | ||
941 | if (this->len_ % this->reloc_size_ != 0) | |
942 | { | |
943 | object->error(_("reloc section size %zu is not a multiple of " | |
944 | "reloc size %d\n"), | |
945 | static_cast<size_t>(this->len_), | |
946 | this->reloc_size_); | |
947 | return false; | |
948 | } | |
949 | ||
950 | return true; | |
951 | } | |
952 | ||
953 | // Return the offset of the next reloc, or -1 if there isn't one. | |
954 | ||
955 | template<int size, bool big_endian> | |
956 | off_t | |
957 | Track_relocs<size, big_endian>::next_offset() const | |
958 | { | |
959 | if (this->pos_ >= this->len_) | |
960 | return -1; | |
961 | ||
962 | // Rel and Rela start out the same, so we can always use Rel to find | |
963 | // the r_offset value. | |
964 | elfcpp::Rel<size, big_endian> rel(this->prelocs_ + this->pos_); | |
965 | return rel.get_r_offset(); | |
966 | } | |
967 | ||
968 | // Return the index of the symbol referenced by the next reloc, or -1U | |
969 | // if there aren't any more relocs. | |
970 | ||
971 | template<int size, bool big_endian> | |
972 | unsigned int | |
973 | Track_relocs<size, big_endian>::next_symndx() const | |
974 | { | |
975 | if (this->pos_ >= this->len_) | |
976 | return -1U; | |
977 | ||
978 | // Rel and Rela start out the same, so we can use Rel to find the | |
979 | // symbol index. | |
980 | elfcpp::Rel<size, big_endian> rel(this->prelocs_ + this->pos_); | |
981 | return elfcpp::elf_r_sym<size>(rel.get_r_info()); | |
982 | } | |
983 | ||
984 | // Advance to the next reloc whose r_offset is greater than or equal | |
985 | // to OFFSET. Return the number of relocs we skip. | |
986 | ||
987 | template<int size, bool big_endian> | |
988 | int | |
989 | Track_relocs<size, big_endian>::advance(off_t offset) | |
990 | { | |
991 | int ret = 0; | |
992 | while (this->pos_ < this->len_) | |
993 | { | |
994 | // Rel and Rela start out the same, so we can always use Rel to | |
995 | // find the r_offset value. | |
996 | elfcpp::Rel<size, big_endian> rel(this->prelocs_ + this->pos_); | |
997 | if (static_cast<off_t>(rel.get_r_offset()) >= offset) | |
998 | break; | |
999 | ++ret; | |
1000 | this->pos_ += this->reloc_size_; | |
1001 | } | |
1002 | return ret; | |
1003 | } | |
1004 | ||
61ba1cf9 ILT |
1005 | // Instantiate the templates we need. We could use the configure |
1006 | // script to restrict this to only the ones for implemented targets. | |
1007 | ||
193a53d9 | 1008 | #ifdef HAVE_TARGET_32_LITTLE |
92e059d8 ILT |
1009 | template |
1010 | void | |
f6ce93d6 | 1011 | Sized_relobj<32, false>::do_read_relocs(Read_relocs_data* rd); |
193a53d9 | 1012 | #endif |
92e059d8 | 1013 | |
193a53d9 | 1014 | #ifdef HAVE_TARGET_32_BIG |
92e059d8 ILT |
1015 | template |
1016 | void | |
f6ce93d6 | 1017 | Sized_relobj<32, true>::do_read_relocs(Read_relocs_data* rd); |
193a53d9 | 1018 | #endif |
92e059d8 | 1019 | |
193a53d9 | 1020 | #ifdef HAVE_TARGET_64_LITTLE |
92e059d8 ILT |
1021 | template |
1022 | void | |
f6ce93d6 | 1023 | Sized_relobj<64, false>::do_read_relocs(Read_relocs_data* rd); |
193a53d9 | 1024 | #endif |
92e059d8 | 1025 | |
193a53d9 | 1026 | #ifdef HAVE_TARGET_64_BIG |
92e059d8 ILT |
1027 | template |
1028 | void | |
f6ce93d6 | 1029 | Sized_relobj<64, true>::do_read_relocs(Read_relocs_data* rd); |
193a53d9 | 1030 | #endif |
92e059d8 | 1031 | |
193a53d9 | 1032 | #ifdef HAVE_TARGET_32_LITTLE |
92e059d8 ILT |
1033 | template |
1034 | void | |
f6ce93d6 | 1035 | Sized_relobj<32, false>::do_scan_relocs(const General_options& options, |
92e059d8 | 1036 | Symbol_table* symtab, |
ead1e424 | 1037 | Layout* layout, |
92e059d8 | 1038 | Read_relocs_data* rd); |
193a53d9 | 1039 | #endif |
92e059d8 | 1040 | |
193a53d9 | 1041 | #ifdef HAVE_TARGET_32_BIG |
92e059d8 ILT |
1042 | template |
1043 | void | |
f6ce93d6 | 1044 | Sized_relobj<32, true>::do_scan_relocs(const General_options& options, |
92e059d8 | 1045 | Symbol_table* symtab, |
ead1e424 | 1046 | Layout* layout, |
92e059d8 | 1047 | Read_relocs_data* rd); |
193a53d9 | 1048 | #endif |
92e059d8 | 1049 | |
193a53d9 | 1050 | #ifdef HAVE_TARGET_64_LITTLE |
92e059d8 ILT |
1051 | template |
1052 | void | |
f6ce93d6 | 1053 | Sized_relobj<64, false>::do_scan_relocs(const General_options& options, |
92e059d8 | 1054 | Symbol_table* symtab, |
ead1e424 | 1055 | Layout* layout, |
92e059d8 | 1056 | Read_relocs_data* rd); |
193a53d9 | 1057 | #endif |
92e059d8 | 1058 | |
193a53d9 | 1059 | #ifdef HAVE_TARGET_64_BIG |
92e059d8 ILT |
1060 | template |
1061 | void | |
f6ce93d6 | 1062 | Sized_relobj<64, true>::do_scan_relocs(const General_options& options, |
92e059d8 | 1063 | Symbol_table* symtab, |
ead1e424 | 1064 | Layout* layout, |
92e059d8 | 1065 | Read_relocs_data* rd); |
193a53d9 | 1066 | #endif |
92e059d8 | 1067 | |
193a53d9 | 1068 | #ifdef HAVE_TARGET_32_LITTLE |
61ba1cf9 ILT |
1069 | template |
1070 | void | |
f6ce93d6 | 1071 | Sized_relobj<32, false>::do_relocate(const General_options& options, |
61ba1cf9 | 1072 | const Symbol_table* symtab, |
92e059d8 | 1073 | const Layout* layout, |
61ba1cf9 | 1074 | Output_file* of); |
193a53d9 | 1075 | #endif |
61ba1cf9 | 1076 | |
193a53d9 | 1077 | #ifdef HAVE_TARGET_32_BIG |
61ba1cf9 ILT |
1078 | template |
1079 | void | |
f6ce93d6 | 1080 | Sized_relobj<32, true>::do_relocate(const General_options& options, |
61ba1cf9 | 1081 | const Symbol_table* symtab, |
92e059d8 | 1082 | const Layout* layout, |
61ba1cf9 | 1083 | Output_file* of); |
193a53d9 | 1084 | #endif |
61ba1cf9 | 1085 | |
193a53d9 | 1086 | #ifdef HAVE_TARGET_64_LITTLE |
61ba1cf9 ILT |
1087 | template |
1088 | void | |
f6ce93d6 | 1089 | Sized_relobj<64, false>::do_relocate(const General_options& options, |
61ba1cf9 | 1090 | const Symbol_table* symtab, |
92e059d8 | 1091 | const Layout* layout, |
61ba1cf9 | 1092 | Output_file* of); |
193a53d9 | 1093 | #endif |
61ba1cf9 | 1094 | |
193a53d9 | 1095 | #ifdef HAVE_TARGET_64_BIG |
61ba1cf9 ILT |
1096 | template |
1097 | void | |
f6ce93d6 | 1098 | Sized_relobj<64, true>::do_relocate(const General_options& options, |
61ba1cf9 | 1099 | const Symbol_table* symtab, |
92e059d8 | 1100 | const Layout* layout, |
61ba1cf9 | 1101 | Output_file* of); |
193a53d9 | 1102 | #endif |
61ba1cf9 | 1103 | |
a9a60db6 ILT |
1104 | #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) |
1105 | template | |
1106 | class Merged_symbol_value<32>; | |
1107 | #endif | |
1108 | ||
1109 | #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) | |
1110 | template | |
1111 | class Merged_symbol_value<64>; | |
1112 | #endif | |
1113 | ||
1114 | #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) | |
1115 | template | |
1116 | class Symbol_value<32>; | |
1117 | #endif | |
1118 | ||
1119 | #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG) | |
1120 | template | |
1121 | class Symbol_value<64>; | |
1122 | #endif | |
1123 | ||
193a53d9 | 1124 | #ifdef HAVE_TARGET_32_LITTLE |
a3ad94ed | 1125 | template |
5a6f7e2d | 1126 | class Copy_relocs<32, false>; |
193a53d9 | 1127 | #endif |
a3ad94ed | 1128 | |
193a53d9 | 1129 | #ifdef HAVE_TARGET_32_BIG |
a3ad94ed | 1130 | template |
5a6f7e2d | 1131 | class Copy_relocs<32, true>; |
193a53d9 | 1132 | #endif |
a3ad94ed | 1133 | |
193a53d9 | 1134 | #ifdef HAVE_TARGET_64_LITTLE |
a3ad94ed | 1135 | template |
5a6f7e2d | 1136 | class Copy_relocs<64, false>; |
193a53d9 | 1137 | #endif |
a3ad94ed | 1138 | |
193a53d9 | 1139 | #ifdef HAVE_TARGET_64_BIG |
a3ad94ed | 1140 | template |
5a6f7e2d | 1141 | class Copy_relocs<64, true>; |
193a53d9 | 1142 | #endif |
5a6f7e2d | 1143 | |
193a53d9 | 1144 | #ifdef HAVE_TARGET_32_LITTLE |
5a6f7e2d ILT |
1145 | template |
1146 | void | |
1147 | Copy_relocs<32, false>::emit<elfcpp::SHT_REL>( | |
1148 | Output_data_reloc<elfcpp::SHT_REL, true, 32, false>*); | |
193a53d9 | 1149 | #endif |
5a6f7e2d | 1150 | |
193a53d9 | 1151 | #ifdef HAVE_TARGET_32_BIG |
5a6f7e2d ILT |
1152 | template |
1153 | void | |
1154 | Copy_relocs<32, true>::emit<elfcpp::SHT_REL>( | |
1155 | Output_data_reloc<elfcpp::SHT_REL, true, 32, true>*); | |
193a53d9 | 1156 | #endif |
5a6f7e2d | 1157 | |
193a53d9 | 1158 | #ifdef HAVE_TARGET_64_LITTLE |
5a6f7e2d ILT |
1159 | template |
1160 | void | |
1161 | Copy_relocs<64, false>::emit<elfcpp::SHT_REL>( | |
1162 | Output_data_reloc<elfcpp::SHT_REL, true, 64, false>*); | |
193a53d9 | 1163 | #endif |
5a6f7e2d | 1164 | |
193a53d9 | 1165 | #ifdef HAVE_TARGET_64_BIG |
5a6f7e2d ILT |
1166 | template |
1167 | void | |
1168 | Copy_relocs<64, true>::emit<elfcpp::SHT_REL>( | |
1169 | Output_data_reloc<elfcpp::SHT_REL, true, 64, true>*); | |
193a53d9 | 1170 | #endif |
5a6f7e2d | 1171 | |
193a53d9 | 1172 | #ifdef HAVE_TARGET_32_LITTLE |
5a6f7e2d ILT |
1173 | template |
1174 | void | |
1175 | Copy_relocs<32, false>::emit<elfcpp::SHT_RELA>( | |
1176 | Output_data_reloc<elfcpp::SHT_RELA , true, 32, false>*); | |
193a53d9 | 1177 | #endif |
5a6f7e2d | 1178 | |
193a53d9 | 1179 | #ifdef HAVE_TARGET_32_BIG |
5a6f7e2d ILT |
1180 | template |
1181 | void | |
1182 | Copy_relocs<32, true>::emit<elfcpp::SHT_RELA>( | |
1183 | Output_data_reloc<elfcpp::SHT_RELA, true, 32, true>*); | |
193a53d9 | 1184 | #endif |
5a6f7e2d | 1185 | |
193a53d9 | 1186 | #ifdef HAVE_TARGET_64_LITTLE |
5a6f7e2d ILT |
1187 | template |
1188 | void | |
1189 | Copy_relocs<64, false>::emit<elfcpp::SHT_RELA>( | |
1190 | Output_data_reloc<elfcpp::SHT_RELA, true, 64, false>*); | |
193a53d9 | 1191 | #endif |
5a6f7e2d | 1192 | |
193a53d9 | 1193 | #ifdef HAVE_TARGET_64_BIG |
5a6f7e2d ILT |
1194 | template |
1195 | void | |
1196 | Copy_relocs<64, true>::emit<elfcpp::SHT_RELA>( | |
1197 | Output_data_reloc<elfcpp::SHT_RELA, true, 64, true>*); | |
193a53d9 | 1198 | #endif |
61ba1cf9 | 1199 | |
730cdc88 ILT |
1200 | #ifdef HAVE_TARGET_32_LITTLE |
1201 | template | |
1202 | class Track_relocs<32, false>; | |
1203 | #endif | |
1204 | ||
1205 | #ifdef HAVE_TARGET_32_BIG | |
1206 | template | |
1207 | class Track_relocs<32, true>; | |
1208 | #endif | |
1209 | ||
1210 | #ifdef HAVE_TARGET_64_LITTLE | |
1211 | template | |
1212 | class Track_relocs<64, false>; | |
1213 | #endif | |
1214 | ||
1215 | #ifdef HAVE_TARGET_64_BIG | |
1216 | template | |
1217 | class Track_relocs<64, true>; | |
1218 | #endif | |
1219 | ||
61ba1cf9 | 1220 | } // End namespace gold. |