1 // reloc.cc -- relocate input files for gold.
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
25 #include "workqueue.h"
35 // Read_relocs methods.
37 // These tasks just read the relocation information from the file.
38 // After reading it, the start another task to process the
39 // information. These tasks requires access to the file.
42 Read_relocs::is_runnable()
44 return this->object_
->is_locked() ? this->object_
->token() : NULL
;
50 Read_relocs::locks(Task_locker
* tl
)
52 tl
->add(this, this->object_
->token());
55 // Read the relocations and then start a Scan_relocs_task.
58 Read_relocs::run(Workqueue
* workqueue
)
60 Read_relocs_data
*rd
= new Read_relocs_data
;
61 this->object_
->read_relocs(rd
);
62 this->object_
->release();
64 workqueue
->queue_front(new Scan_relocs(this->options_
, this->symtab_
,
65 this->layout_
, this->object_
, rd
,
66 this->symtab_lock_
, this->blocker_
));
69 // Return a debugging name for the task.
72 Read_relocs::get_name() const
74 return "Read_relocs " + this->object_
->name();
77 // Scan_relocs methods.
79 // These tasks scan the relocations read by Read_relocs and mark up
80 // the symbol table to indicate which relocations are required. We
81 // use a lock on the symbol table to keep them from interfering with
85 Scan_relocs::is_runnable()
87 if (!this->symtab_lock_
->is_writable())
88 return this->symtab_lock_
;
89 if (this->object_
->is_locked())
90 return this->object_
->token();
94 // Return the locks we hold: one on the file, one on the symbol table
98 Scan_relocs::locks(Task_locker
* tl
)
100 tl
->add(this, this->object_
->token());
101 tl
->add(this, this->symtab_lock_
);
102 tl
->add(this, this->blocker_
);
108 Scan_relocs::run(Workqueue
*)
110 this->object_
->scan_relocs(this->options_
, this->symtab_
, this->layout_
,
112 this->object_
->release();
117 // Return a debugging name for the task.
120 Scan_relocs::get_name() const
122 return "Scan_relocs " + this->object_
->name();
125 // Relocate_task methods.
127 // We may have to wait for the output sections to be written.
130 Relocate_task::is_runnable()
132 if (this->object_
->relocs_must_follow_section_writes()
133 && this->output_sections_blocker_
->is_blocked())
134 return this->output_sections_blocker_
;
136 if (this->object_
->is_locked())
137 return this->object_
->token();
142 // We want to lock the file while we run. We want to unblock
143 // INPUT_SECTIONS_BLOCKER and FINAL_BLOCKER when we are done.
144 // INPUT_SECTIONS_BLOCKER may be NULL.
147 Relocate_task::locks(Task_locker
* tl
)
149 if (this->input_sections_blocker_
!= NULL
)
150 tl
->add(this, this->input_sections_blocker_
);
151 tl
->add(this, this->final_blocker_
);
152 tl
->add(this, this->object_
->token());
158 Relocate_task::run(Workqueue
*)
160 this->object_
->relocate(this->options_
, this->symtab_
, this->layout_
,
162 this->object_
->release();
165 // Return a debugging name for the task.
168 Relocate_task::get_name() const
170 return "Relocate_task " + this->object_
->name();
173 // Read the relocs and local symbols from the object file and store
174 // the information in RD.
176 template<int size
, bool big_endian
>
178 Sized_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
182 unsigned int shnum
= this->shnum();
186 rd
->relocs
.reserve(shnum
/ 2);
188 std::vector
<Map_to_output
>& map_sections(this->map_to_output());
190 const unsigned char *pshdrs
= this->get_view(this->elf_file_
.shoff(),
191 shnum
* This::shdr_size
,
193 // Skip the first, dummy, section.
194 const unsigned char *ps
= pshdrs
+ This::shdr_size
;
195 for (unsigned int i
= 1; i
< shnum
; ++i
, ps
+= This::shdr_size
)
197 typename
This::Shdr
shdr(ps
);
199 unsigned int sh_type
= shdr
.get_sh_type();
200 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
203 unsigned int shndx
= shdr
.get_sh_info();
206 this->error(_("relocation section %u has bad info %u"),
211 Output_section
* os
= map_sections
[shndx
].output_section
;
215 // We are scanning relocations in order to fill out the GOT and
216 // PLT sections. Relocations for sections which are not
217 // allocated (typically debugging sections) should not add new
218 // GOT and PLT entries. So we skip them.
219 typename
This::Shdr
secshdr(pshdrs
+ shndx
* This::shdr_size
);
220 if ((secshdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
223 if (shdr
.get_sh_link() != this->symtab_shndx_
)
225 this->error(_("relocation section %u uses unexpected "
227 i
, shdr
.get_sh_link());
231 off_t sh_size
= shdr
.get_sh_size();
233 unsigned int reloc_size
;
234 if (sh_type
== elfcpp::SHT_REL
)
235 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
237 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
238 if (reloc_size
!= shdr
.get_sh_entsize())
240 this->error(_("unexpected entsize for reloc section %u: %lu != %u"),
241 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
246 size_t reloc_count
= sh_size
/ reloc_size
;
247 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
249 this->error(_("reloc section %u size %lu uneven"),
250 i
, static_cast<unsigned long>(sh_size
));
254 rd
->relocs
.push_back(Section_relocs());
255 Section_relocs
& sr(rd
->relocs
.back());
257 sr
.data_shndx
= shndx
;
258 sr
.contents
= this->get_lasting_view(shdr
.get_sh_offset(), sh_size
,
260 sr
.sh_type
= sh_type
;
261 sr
.reloc_count
= reloc_count
;
262 sr
.output_section
= os
;
263 sr
.needs_special_offset_handling
= map_sections
[shndx
].offset
== -1;
266 // Read the local symbols.
267 gold_assert(this->symtab_shndx_
!= -1U);
268 if (this->symtab_shndx_
== 0 || this->local_symbol_count_
== 0)
269 rd
->local_symbols
= NULL
;
272 typename
This::Shdr
symtabshdr(pshdrs
273 + this->symtab_shndx_
* This::shdr_size
);
274 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
275 const int sym_size
= This::sym_size
;
276 const unsigned int loccount
= this->local_symbol_count_
;
277 gold_assert(loccount
== symtabshdr
.get_sh_info());
278 off_t locsize
= loccount
* sym_size
;
279 rd
->local_symbols
= this->get_lasting_view(symtabshdr
.get_sh_offset(),
284 // Scan the relocs and adjust the symbol table. This looks for
285 // relocations which require GOT/PLT/COPY relocations.
287 template<int size
, bool big_endian
>
289 Sized_relobj
<size
, big_endian
>::do_scan_relocs(const General_options
& options
,
290 Symbol_table
* symtab
,
292 Read_relocs_data
* rd
)
294 Sized_target
<size
, big_endian
>* target
= this->sized_target();
296 const unsigned char* local_symbols
;
297 if (rd
->local_symbols
== NULL
)
298 local_symbols
= NULL
;
300 local_symbols
= rd
->local_symbols
->data();
302 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
303 p
!= rd
->relocs
.end();
306 target
->scan_relocs(options
, symtab
, layout
, this, p
->data_shndx
,
307 p
->sh_type
, p
->contents
->data(), p
->reloc_count
,
308 p
->output_section
, p
->needs_special_offset_handling
,
309 this->local_symbol_count_
,
315 if (rd
->local_symbols
!= NULL
)
317 delete rd
->local_symbols
;
318 rd
->local_symbols
= NULL
;
322 // Relocate the input sections and write out the local symbols.
324 template<int size
, bool big_endian
>
326 Sized_relobj
<size
, big_endian
>::do_relocate(const General_options
& options
,
327 const Symbol_table
* symtab
,
328 const Layout
* layout
,
331 unsigned int shnum
= this->shnum();
333 // Read the section headers.
334 const unsigned char* pshdrs
= this->get_view(this->elf_file_
.shoff(),
335 shnum
* This::shdr_size
,
341 // Make two passes over the sections. The first one copies the
342 // section data to the output file. The second one applies
345 this->write_sections(pshdrs
, of
, &views
);
347 // To speed up relocations, we set up hash tables for fast lookup of
348 // input offsets to output addresses.
349 this->initialize_input_to_output_maps();
351 // Apply relocations.
353 this->relocate_sections(options
, symtab
, layout
, pshdrs
, &views
);
355 // After we've done the relocations, we release the hash tables,
356 // since we no longer need them.
357 this->free_input_to_output_maps();
359 // Write out the accumulated views.
360 for (unsigned int i
= 1; i
< shnum
; ++i
)
362 if (views
[i
].view
!= NULL
)
364 if (!views
[i
].is_postprocessing_view
)
366 if (views
[i
].is_input_output_view
)
367 of
->write_input_output_view(views
[i
].offset
,
371 of
->write_output_view(views
[i
].offset
, views
[i
].view_size
,
377 // Write out the local symbols.
378 this->write_local_symbols(of
, layout
->sympool(), layout
->dynpool());
381 // Write section data to the output file. PSHDRS points to the
382 // section headers. Record the views in *PVIEWS for use when
385 template<int size
, bool big_endian
>
387 Sized_relobj
<size
, big_endian
>::write_sections(const unsigned char* pshdrs
,
391 unsigned int shnum
= this->shnum();
392 const std::vector
<Map_to_output
>& map_sections(this->map_to_output());
394 const unsigned char* p
= pshdrs
+ This::shdr_size
;
395 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
397 View_size
* pvs
= &(*pviews
)[i
];
401 const Output_section
* os
= map_sections
[i
].output_section
;
404 off_t output_offset
= map_sections
[i
].offset
;
406 typename
This::Shdr
shdr(p
);
408 if (shdr
.get_sh_type() == elfcpp::SHT_NOBITS
)
411 // In the normal case, this input section is simply mapped to
412 // the output section at offset OUTPUT_OFFSET.
414 // However, if OUTPUT_OFFSET == -1, then input data is handled
415 // specially--e.g., a .eh_frame section. The relocation
416 // routines need to check for each reloc where it should be
417 // applied. For this case, we need an input/output view for the
418 // entire contents of the section in the output file. We don't
419 // want to copy the contents of the input section to the output
420 // section; the output section contents were already written,
421 // and we waited for them in Relocate_task::is_runnable because
422 // relocs_must_follow_section_writes is set for the object.
424 // Regardless of which of the above cases is true, we have to
425 // check requires_postprocessing of the output section. If that
426 // is false, then we work with views of the output file
427 // directly. If it is true, then we work with a separate
428 // buffer, and the output section is responsible for writing the
429 // final data to the output file.
431 off_t output_section_offset
;
432 off_t output_section_size
;
433 if (!os
->requires_postprocessing())
435 output_section_offset
= os
->offset();
436 output_section_size
= os
->data_size();
440 output_section_offset
= 0;
441 output_section_size
= os
->postprocessing_buffer_size();
445 section_size_type view_size
;
446 if (output_offset
!= -1)
448 view_start
= output_section_offset
+ output_offset
;
449 view_size
= convert_to_section_size_type(shdr
.get_sh_size());
453 view_start
= output_section_offset
;
454 view_size
= convert_to_section_size_type(output_section_size
);
460 gold_assert(output_offset
== -1
461 || (output_offset
>= 0
462 && (output_offset
+ static_cast<off_t
>(view_size
)
463 <= output_section_size
)));
466 if (os
->requires_postprocessing())
468 unsigned char* buffer
= os
->postprocessing_buffer();
469 view
= buffer
+ view_start
;
470 if (output_offset
!= -1)
471 this->read(shdr
.get_sh_offset(), view_size
, view
);
475 if (output_offset
== -1)
476 view
= of
->get_input_output_view(view_start
, view_size
);
479 view
= of
->get_output_view(view_start
, view_size
);
480 this->read(shdr
.get_sh_offset(), view_size
, view
);
485 pvs
->address
= os
->address();
486 if (output_offset
!= -1)
487 pvs
->address
+= output_offset
;
488 pvs
->offset
= view_start
;
489 pvs
->view_size
= view_size
;
490 pvs
->is_input_output_view
= output_offset
== -1;
491 pvs
->is_postprocessing_view
= os
->requires_postprocessing();
495 // Relocate section data. VIEWS points to the section data as views
496 // in the output file.
498 template<int size
, bool big_endian
>
500 Sized_relobj
<size
, big_endian
>::relocate_sections(
501 const General_options
& options
,
502 const Symbol_table
* symtab
,
503 const Layout
* layout
,
504 const unsigned char* pshdrs
,
507 unsigned int shnum
= this->shnum();
508 Sized_target
<size
, big_endian
>* target
= this->sized_target();
510 const std::vector
<Map_to_output
>& map_sections(this->map_to_output());
512 Relocate_info
<size
, big_endian
> relinfo
;
513 relinfo
.options
= &options
;
514 relinfo
.symtab
= symtab
;
515 relinfo
.layout
= layout
;
516 relinfo
.object
= this;
518 const unsigned char* p
= pshdrs
+ This::shdr_size
;
519 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
521 typename
This::Shdr
shdr(p
);
523 unsigned int sh_type
= shdr
.get_sh_type();
524 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
527 unsigned int index
= shdr
.get_sh_info();
528 if (index
>= this->shnum())
530 this->error(_("relocation section %u has bad info %u"),
535 Output_section
* os
= map_sections
[index
].output_section
;
538 // This relocation section is against a section which we
542 off_t output_offset
= map_sections
[index
].offset
;
544 gold_assert((*pviews
)[index
].view
!= NULL
);
546 if (shdr
.get_sh_link() != this->symtab_shndx_
)
548 gold_error(_("relocation section %u uses unexpected "
550 i
, shdr
.get_sh_link());
554 off_t sh_size
= shdr
.get_sh_size();
555 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
558 unsigned int reloc_size
;
559 if (sh_type
== elfcpp::SHT_REL
)
560 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
562 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
564 if (reloc_size
!= shdr
.get_sh_entsize())
566 gold_error(_("unexpected entsize for reloc section %u: %lu != %u"),
567 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
572 size_t reloc_count
= sh_size
/ reloc_size
;
573 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
575 gold_error(_("reloc section %u size %lu uneven"),
576 i
, static_cast<unsigned long>(sh_size
));
580 gold_assert(output_offset
!= -1
581 || this->relocs_must_follow_section_writes());
583 relinfo
.reloc_shndx
= i
;
584 relinfo
.data_shndx
= index
;
585 target
->relocate_section(&relinfo
,
591 (*pviews
)[index
].view
,
592 (*pviews
)[index
].address
,
593 (*pviews
)[index
].view_size
);
597 // Create merge hash tables for the local symbols. These are used to
598 // speed up relocations.
600 template<int size
, bool big_endian
>
602 Sized_relobj
<size
, big_endian
>::initialize_input_to_output_maps()
604 const unsigned int loccount
= this->local_symbol_count_
;
605 for (unsigned int i
= 1; i
< loccount
; ++i
)
607 Symbol_value
<size
>& lv(this->local_values_
[i
]);
608 lv
.initialize_input_to_output_map(this);
612 // Free merge hash tables for the local symbols.
614 template<int size
, bool big_endian
>
616 Sized_relobj
<size
, big_endian
>::free_input_to_output_maps()
618 const unsigned int loccount
= this->local_symbol_count_
;
619 for (unsigned int i
= 1; i
< loccount
; ++i
)
621 Symbol_value
<size
>& lv(this->local_values_
[i
]);
622 lv
.free_input_to_output_map();
626 // Class Merged_symbol_value.
630 Merged_symbol_value
<size
>::initialize_input_to_output_map(
631 const Relobj
* object
,
632 unsigned int input_shndx
)
634 Object_merge_map
* map
= object
->merge_map();
635 map
->initialize_input_to_output_map
<size
>(input_shndx
,
636 this->output_start_address_
,
637 &this->output_addresses_
);
640 // Get the output value corresponding to an input offset if we
641 // couldn't find it in the hash table.
644 typename
elfcpp::Elf_types
<size
>::Elf_Addr
645 Merged_symbol_value
<size
>::value_from_output_section(
646 const Relobj
* object
,
647 unsigned int input_shndx
,
648 typename
elfcpp::Elf_types
<size
>::Elf_Addr input_offset
) const
650 section_offset_type output_offset
;
651 bool found
= object
->merge_map()->get_output_offset(NULL
, input_shndx
,
655 // If this assertion fails, it means that some relocation was
656 // against a portion of an input merge section which we didn't map
657 // to the output file and we didn't explicitly discard. We should
658 // always map all portions of input merge sections.
661 if (output_offset
== -1)
664 return this->output_start_address_
+ output_offset
;
667 // Copy_relocs::Copy_reloc_entry methods.
669 // Return whether we should emit this reloc. We should emit it if the
670 // symbol is still defined in a dynamic object. If we should not emit
671 // it, we clear it, to save ourselves the test next time.
673 template<int size
, bool big_endian
>
675 Copy_relocs
<size
, big_endian
>::Copy_reloc_entry::should_emit()
677 if (this->sym_
== NULL
)
679 if (this->sym_
->is_from_dynobj())
685 // Emit a reloc into a SHT_REL section.
687 template<int size
, bool big_endian
>
689 Copy_relocs
<size
, big_endian
>::Copy_reloc_entry::emit(
690 Output_data_reloc
<elfcpp::SHT_REL
, true, size
, big_endian
>* reloc_data
)
692 this->sym_
->set_needs_dynsym_entry();
693 reloc_data
->add_global(this->sym_
, this->reloc_type_
, this->output_section_
,
694 this->relobj_
, this->shndx_
, this->address_
);
697 // Emit a reloc into a SHT_RELA section.
699 template<int size
, bool big_endian
>
701 Copy_relocs
<size
, big_endian
>::Copy_reloc_entry::emit(
702 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
>* reloc_data
)
704 this->sym_
->set_needs_dynsym_entry();
705 reloc_data
->add_global(this->sym_
, this->reloc_type_
, this->output_section_
,
706 this->relobj_
, this->shndx_
, this->address_
,
710 // Copy_relocs methods.
712 // Return whether we need a COPY reloc for a relocation against GSYM.
713 // The relocation is being applied to section SHNDX in OBJECT.
715 template<int size
, bool big_endian
>
717 Copy_relocs
<size
, big_endian
>::need_copy_reloc(
718 const General_options
*,
721 Sized_symbol
<size
>* sym
)
723 // FIXME: Handle -z nocopyrelocs.
725 if (sym
->symsize() == 0)
728 // If this is a readonly section, then we need a COPY reloc.
729 // Otherwise we can use a dynamic reloc.
730 if ((object
->section_flags(shndx
) & elfcpp::SHF_WRITE
) == 0)
738 template<int size
, bool big_endian
>
740 Copy_relocs
<size
, big_endian
>::save(
744 Output_section
* output_section
,
745 const elfcpp::Rel
<size
, big_endian
>& rel
)
747 unsigned int reloc_type
= elfcpp::elf_r_type
<size
>(rel
.get_r_info());
748 this->entries_
.push_back(Copy_reloc_entry(sym
, reloc_type
, relobj
, shndx
,
750 rel
.get_r_offset(), 0));
753 // Save a Rela reloc.
755 template<int size
, bool big_endian
>
757 Copy_relocs
<size
, big_endian
>::save(
761 Output_section
* output_section
,
762 const elfcpp::Rela
<size
, big_endian
>& rela
)
764 unsigned int reloc_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
765 this->entries_
.push_back(Copy_reloc_entry(sym
, reloc_type
, relobj
, shndx
,
768 rela
.get_r_addend()));
771 // Return whether there are any relocs to emit. We don't want to emit
772 // a reloc if the symbol is no longer defined in a dynamic object.
774 template<int size
, bool big_endian
>
776 Copy_relocs
<size
, big_endian
>::any_to_emit()
778 for (typename
Copy_reloc_entries::iterator p
= this->entries_
.begin();
779 p
!= this->entries_
.end();
782 if (p
->should_emit())
790 template<int size
, bool big_endian
>
791 template<int sh_type
>
793 Copy_relocs
<size
, big_endian
>::emit(
794 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_data
)
796 for (typename
Copy_reloc_entries::iterator p
= this->entries_
.begin();
797 p
!= this->entries_
.end();
800 if (p
->should_emit())
805 // Track_relocs methods.
807 // Initialize the class to track the relocs. This gets the object,
808 // the reloc section index, and the type of the relocs. This returns
809 // false if something goes wrong.
811 template<int size
, bool big_endian
>
813 Track_relocs
<size
, big_endian
>::initialize(
815 unsigned int reloc_shndx
,
816 unsigned int reloc_type
)
818 // If RELOC_SHNDX is -1U, it means there is more than one reloc
819 // section for the .eh_frame section. We can't handle that case.
820 if (reloc_shndx
== -1U)
823 // If RELOC_SHNDX is 0, there is no reloc section.
824 if (reloc_shndx
== 0)
827 // Get the contents of the reloc section.
828 this->prelocs_
= object
->section_contents(reloc_shndx
, &this->len_
, false);
830 if (reloc_type
== elfcpp::SHT_REL
)
831 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rel_size
;
832 else if (reloc_type
== elfcpp::SHT_RELA
)
833 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rela_size
;
837 if (this->len_
% this->reloc_size_
!= 0)
839 object
->error(_("reloc section size %zu is not a multiple of "
841 static_cast<size_t>(this->len_
),
849 // Return the offset of the next reloc, or -1 if there isn't one.
851 template<int size
, bool big_endian
>
853 Track_relocs
<size
, big_endian
>::next_offset() const
855 if (this->pos_
>= this->len_
)
858 // Rel and Rela start out the same, so we can always use Rel to find
859 // the r_offset value.
860 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
861 return rel
.get_r_offset();
864 // Return the index of the symbol referenced by the next reloc, or -1U
865 // if there aren't any more relocs.
867 template<int size
, bool big_endian
>
869 Track_relocs
<size
, big_endian
>::next_symndx() const
871 if (this->pos_
>= this->len_
)
874 // Rel and Rela start out the same, so we can use Rel to find the
876 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
877 return elfcpp::elf_r_sym
<size
>(rel
.get_r_info());
880 // Advance to the next reloc whose r_offset is greater than or equal
881 // to OFFSET. Return the number of relocs we skip.
883 template<int size
, bool big_endian
>
885 Track_relocs
<size
, big_endian
>::advance(off_t offset
)
888 while (this->pos_
< this->len_
)
890 // Rel and Rela start out the same, so we can always use Rel to
891 // find the r_offset value.
892 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
893 if (static_cast<off_t
>(rel
.get_r_offset()) >= offset
)
896 this->pos_
+= this->reloc_size_
;
901 // Instantiate the templates we need. We could use the configure
902 // script to restrict this to only the ones for implemented targets.
904 #ifdef HAVE_TARGET_32_LITTLE
907 Sized_relobj
<32, false>::do_read_relocs(Read_relocs_data
* rd
);
910 #ifdef HAVE_TARGET_32_BIG
913 Sized_relobj
<32, true>::do_read_relocs(Read_relocs_data
* rd
);
916 #ifdef HAVE_TARGET_64_LITTLE
919 Sized_relobj
<64, false>::do_read_relocs(Read_relocs_data
* rd
);
922 #ifdef HAVE_TARGET_64_BIG
925 Sized_relobj
<64, true>::do_read_relocs(Read_relocs_data
* rd
);
928 #ifdef HAVE_TARGET_32_LITTLE
931 Sized_relobj
<32, false>::do_scan_relocs(const General_options
& options
,
932 Symbol_table
* symtab
,
934 Read_relocs_data
* rd
);
937 #ifdef HAVE_TARGET_32_BIG
940 Sized_relobj
<32, true>::do_scan_relocs(const General_options
& options
,
941 Symbol_table
* symtab
,
943 Read_relocs_data
* rd
);
946 #ifdef HAVE_TARGET_64_LITTLE
949 Sized_relobj
<64, false>::do_scan_relocs(const General_options
& options
,
950 Symbol_table
* symtab
,
952 Read_relocs_data
* rd
);
955 #ifdef HAVE_TARGET_64_BIG
958 Sized_relobj
<64, true>::do_scan_relocs(const General_options
& options
,
959 Symbol_table
* symtab
,
961 Read_relocs_data
* rd
);
964 #ifdef HAVE_TARGET_32_LITTLE
967 Sized_relobj
<32, false>::do_relocate(const General_options
& options
,
968 const Symbol_table
* symtab
,
969 const Layout
* layout
,
973 #ifdef HAVE_TARGET_32_BIG
976 Sized_relobj
<32, true>::do_relocate(const General_options
& options
,
977 const Symbol_table
* symtab
,
978 const Layout
* layout
,
982 #ifdef HAVE_TARGET_64_LITTLE
985 Sized_relobj
<64, false>::do_relocate(const General_options
& options
,
986 const Symbol_table
* symtab
,
987 const Layout
* layout
,
991 #ifdef HAVE_TARGET_64_BIG
994 Sized_relobj
<64, true>::do_relocate(const General_options
& options
,
995 const Symbol_table
* symtab
,
996 const Layout
* layout
,
1000 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1002 class Merged_symbol_value
<32>;
1005 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1007 class Merged_symbol_value
<64>;
1010 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1012 class Symbol_value
<32>;
1015 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1017 class Symbol_value
<64>;
1020 #ifdef HAVE_TARGET_32_LITTLE
1022 class Copy_relocs
<32, false>;
1025 #ifdef HAVE_TARGET_32_BIG
1027 class Copy_relocs
<32, true>;
1030 #ifdef HAVE_TARGET_64_LITTLE
1032 class Copy_relocs
<64, false>;
1035 #ifdef HAVE_TARGET_64_BIG
1037 class Copy_relocs
<64, true>;
1040 #ifdef HAVE_TARGET_32_LITTLE
1043 Copy_relocs
<32, false>::emit
<elfcpp::SHT_REL
>(
1044 Output_data_reloc
<elfcpp::SHT_REL
, true, 32, false>*);
1047 #ifdef HAVE_TARGET_32_BIG
1050 Copy_relocs
<32, true>::emit
<elfcpp::SHT_REL
>(
1051 Output_data_reloc
<elfcpp::SHT_REL
, true, 32, true>*);
1054 #ifdef HAVE_TARGET_64_LITTLE
1057 Copy_relocs
<64, false>::emit
<elfcpp::SHT_REL
>(
1058 Output_data_reloc
<elfcpp::SHT_REL
, true, 64, false>*);
1061 #ifdef HAVE_TARGET_64_BIG
1064 Copy_relocs
<64, true>::emit
<elfcpp::SHT_REL
>(
1065 Output_data_reloc
<elfcpp::SHT_REL
, true, 64, true>*);
1068 #ifdef HAVE_TARGET_32_LITTLE
1071 Copy_relocs
<32, false>::emit
<elfcpp::SHT_RELA
>(
1072 Output_data_reloc
<elfcpp::SHT_RELA
, true, 32, false>*);
1075 #ifdef HAVE_TARGET_32_BIG
1078 Copy_relocs
<32, true>::emit
<elfcpp::SHT_RELA
>(
1079 Output_data_reloc
<elfcpp::SHT_RELA
, true, 32, true>*);
1082 #ifdef HAVE_TARGET_64_LITTLE
1085 Copy_relocs
<64, false>::emit
<elfcpp::SHT_RELA
>(
1086 Output_data_reloc
<elfcpp::SHT_RELA
, true, 64, false>*);
1089 #ifdef HAVE_TARGET_64_BIG
1092 Copy_relocs
<64, true>::emit
<elfcpp::SHT_RELA
>(
1093 Output_data_reloc
<elfcpp::SHT_RELA
, true, 64, true>*);
1096 #ifdef HAVE_TARGET_32_LITTLE
1098 class Track_relocs
<32, false>;
1101 #ifdef HAVE_TARGET_32_BIG
1103 class Track_relocs
<32, true>;
1106 #ifdef HAVE_TARGET_64_LITTLE
1108 class Track_relocs
<64, false>;
1111 #ifdef HAVE_TARGET_64_BIG
1113 class Track_relocs
<64, true>;
1116 } // End namespace gold.