1 // reloc.cc -- relocate input files for gold.
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 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.
27 #include "workqueue.h"
33 #include "target-reloc.h"
36 #include "compressed_output.h"
37 #include "incremental.h"
42 // Read_relocs methods.
44 // These tasks just read the relocation information from the file.
45 // After reading it, the start another task to process the
46 // information. These tasks requires access to the file.
49 Read_relocs::is_runnable()
51 return this->object_
->is_locked() ? this->object_
->token() : NULL
;
57 Read_relocs::locks(Task_locker
* tl
)
59 Task_token
* token
= this->object_
->token();
64 // Read the relocations and then start a Scan_relocs_task.
67 Read_relocs::run(Workqueue
* workqueue
)
69 Read_relocs_data
* rd
= new Read_relocs_data
;
70 this->object_
->read_relocs(rd
);
71 this->object_
->set_relocs_data(rd
);
72 this->object_
->release();
74 // If garbage collection or identical comdat folding is desired, we
75 // process the relocs first before scanning them. Scanning of relocs is
76 // done only after garbage or identical sections is identified.
77 if (parameters
->options().gc_sections()
78 || parameters
->options().icf_enabled())
80 workqueue
->queue_next(new Gc_process_relocs(this->symtab_
,
84 this->next_blocker_
));
88 workqueue
->queue_next(new Scan_relocs(this->symtab_
, this->layout_
,
91 this->next_blocker_
));
95 // Return a debugging name for the task.
98 Read_relocs::get_name() const
100 return "Read_relocs " + this->object_
->name();
103 // Gc_process_relocs methods.
105 Gc_process_relocs::~Gc_process_relocs()
107 if (this->this_blocker_
!= NULL
)
108 delete this->this_blocker_
;
111 // These tasks process the relocations read by Read_relocs and
112 // determine which sections are referenced and which are garbage.
113 // This task is done only when --gc-sections is used. This is blocked
114 // by THIS_BLOCKER_. It unblocks NEXT_BLOCKER_.
117 Gc_process_relocs::is_runnable()
119 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
120 return this->this_blocker_
;
121 if (this->object_
->is_locked())
122 return this->object_
->token();
127 Gc_process_relocs::locks(Task_locker
* tl
)
129 tl
->add(this, this->object_
->token());
130 tl
->add(this, this->next_blocker_
);
134 Gc_process_relocs::run(Workqueue
*)
136 this->object_
->gc_process_relocs(this->symtab_
, this->layout_
, this->rd_
);
137 this->object_
->release();
140 // Return a debugging name for the task.
143 Gc_process_relocs::get_name() const
145 return "Gc_process_relocs " + this->object_
->name();
148 // Scan_relocs methods.
150 Scan_relocs::~Scan_relocs()
152 if (this->this_blocker_
!= NULL
)
153 delete this->this_blocker_
;
156 // These tasks scan the relocations read by Read_relocs and mark up
157 // the symbol table to indicate which relocations are required. We
158 // use a lock on the symbol table to keep them from interfering with
162 Scan_relocs::is_runnable()
164 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
165 return this->this_blocker_
;
166 if (this->object_
->is_locked())
167 return this->object_
->token();
171 // Return the locks we hold: one on the file, one on the symbol table
175 Scan_relocs::locks(Task_locker
* tl
)
177 Task_token
* token
= this->object_
->token();
179 tl
->add(this, token
);
180 tl
->add(this, this->next_blocker_
);
186 Scan_relocs::run(Workqueue
*)
188 this->object_
->scan_relocs(this->symtab_
, this->layout_
, this->rd_
);
191 this->object_
->release();
194 // Return a debugging name for the task.
197 Scan_relocs::get_name() const
199 return "Scan_relocs " + this->object_
->name();
202 // Relocate_task methods.
204 // We may have to wait for the output sections to be written.
207 Relocate_task::is_runnable()
209 if (this->object_
->relocs_must_follow_section_writes()
210 && this->output_sections_blocker_
->is_blocked())
211 return this->output_sections_blocker_
;
213 if (this->object_
->is_locked())
214 return this->object_
->token();
219 // We want to lock the file while we run. We want to unblock
220 // INPUT_SECTIONS_BLOCKER and FINAL_BLOCKER when we are done.
221 // INPUT_SECTIONS_BLOCKER may be NULL.
224 Relocate_task::locks(Task_locker
* tl
)
226 if (this->input_sections_blocker_
!= NULL
)
227 tl
->add(this, this->input_sections_blocker_
);
228 tl
->add(this, this->final_blocker_
);
229 Task_token
* token
= this->object_
->token();
231 tl
->add(this, token
);
237 Relocate_task::run(Workqueue
*)
239 this->object_
->relocate(this->symtab_
, this->layout_
, this->of_
);
241 // This is normally the last thing we will do with an object, so
242 // uncache all views.
243 this->object_
->clear_view_cache_marks();
245 this->object_
->release();
248 // Return a debugging name for the task.
251 Relocate_task::get_name() const
253 return "Relocate_task " + this->object_
->name();
256 // Read the relocs and local symbols from the object file and store
257 // the information in RD.
259 template<int size
, bool big_endian
>
261 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
265 unsigned int shnum
= this->shnum();
269 rd
->relocs
.reserve(shnum
/ 2);
271 const Output_sections
& out_sections(this->output_sections());
272 const std::vector
<Address
>& out_offsets(this->section_offsets());
274 const unsigned char* pshdrs
= this->get_view(this->elf_file_
.shoff(),
275 shnum
* This::shdr_size
,
277 // Skip the first, dummy, section.
278 const unsigned char* ps
= pshdrs
+ This::shdr_size
;
279 for (unsigned int i
= 1; i
< shnum
; ++i
, ps
+= This::shdr_size
)
281 typename
This::Shdr
shdr(ps
);
283 unsigned int sh_type
= shdr
.get_sh_type();
284 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
287 unsigned int shndx
= this->adjust_shndx(shdr
.get_sh_info());
290 this->error(_("relocation section %u has bad info %u"),
295 Output_section
* os
= out_sections
[shndx
];
299 // We are scanning relocations in order to fill out the GOT and
300 // PLT sections. Relocations for sections which are not
301 // allocated (typically debugging sections) should not add new
302 // GOT and PLT entries. So we skip them unless this is a
303 // relocatable link or we need to emit relocations. FIXME: What
304 // should we do if a linker script maps a section with SHF_ALLOC
305 // clear to a section with SHF_ALLOC set?
306 typename
This::Shdr
secshdr(pshdrs
+ shndx
* This::shdr_size
);
307 bool is_section_allocated
= ((secshdr
.get_sh_flags() & elfcpp::SHF_ALLOC
)
309 if (!is_section_allocated
310 && !parameters
->options().relocatable()
311 && !parameters
->options().emit_relocs()
312 && !parameters
->incremental())
315 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx_
)
317 this->error(_("relocation section %u uses unexpected "
319 i
, this->adjust_shndx(shdr
.get_sh_link()));
323 off_t sh_size
= shdr
.get_sh_size();
328 unsigned int reloc_size
;
329 if (sh_type
== elfcpp::SHT_REL
)
330 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
332 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
333 if (reloc_size
!= shdr
.get_sh_entsize())
335 this->error(_("unexpected entsize for reloc section %u: %lu != %u"),
336 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
341 size_t reloc_count
= sh_size
/ reloc_size
;
342 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
344 this->error(_("reloc section %u size %lu uneven"),
345 i
, static_cast<unsigned long>(sh_size
));
349 rd
->relocs
.push_back(Section_relocs());
350 Section_relocs
& sr(rd
->relocs
.back());
352 sr
.data_shndx
= shndx
;
353 sr
.contents
= this->get_lasting_view(shdr
.get_sh_offset(), sh_size
,
355 sr
.sh_type
= sh_type
;
356 sr
.reloc_count
= reloc_count
;
357 sr
.output_section
= os
;
358 sr
.needs_special_offset_handling
= out_offsets
[shndx
] == invalid_address
;
359 sr
.is_data_section_allocated
= is_section_allocated
;
362 // Read the local symbols.
363 gold_assert(this->symtab_shndx_
!= -1U);
364 if (this->symtab_shndx_
== 0 || this->local_symbol_count_
== 0)
365 rd
->local_symbols
= NULL
;
368 typename
This::Shdr
symtabshdr(pshdrs
369 + this->symtab_shndx_
* This::shdr_size
);
370 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
371 const int sym_size
= This::sym_size
;
372 const unsigned int loccount
= this->local_symbol_count_
;
373 gold_assert(loccount
== symtabshdr
.get_sh_info());
374 off_t locsize
= loccount
* sym_size
;
375 rd
->local_symbols
= this->get_lasting_view(symtabshdr
.get_sh_offset(),
376 locsize
, true, true);
380 // Process the relocs to generate mappings from source sections to referenced
381 // sections. This is used during garbage collection to determine garbage
384 template<int size
, bool big_endian
>
386 Sized_relobj_file
<size
, big_endian
>::do_gc_process_relocs(Symbol_table
* symtab
,
388 Read_relocs_data
* rd
)
390 Sized_target
<size
, big_endian
>* target
=
391 parameters
->sized_target
<size
, big_endian
>();
393 const unsigned char* local_symbols
;
394 if (rd
->local_symbols
== NULL
)
395 local_symbols
= NULL
;
397 local_symbols
= rd
->local_symbols
->data();
399 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
400 p
!= rd
->relocs
.end();
403 if (!parameters
->options().relocatable())
405 // As noted above, when not generating an object file, we
406 // only scan allocated sections. We may see a non-allocated
407 // section here if we are emitting relocs.
408 if (p
->is_data_section_allocated
)
409 target
->gc_process_relocs(symtab
, layout
, this,
410 p
->data_shndx
, p
->sh_type
,
411 p
->contents
->data(), p
->reloc_count
,
413 p
->needs_special_offset_handling
,
414 this->local_symbol_count_
,
421 // Scan the relocs and adjust the symbol table. This looks for
422 // relocations which require GOT/PLT/COPY relocations.
424 template<int size
, bool big_endian
>
426 Sized_relobj_file
<size
, big_endian
>::do_scan_relocs(Symbol_table
* symtab
,
428 Read_relocs_data
* rd
)
430 Sized_target
<size
, big_endian
>* target
=
431 parameters
->sized_target
<size
, big_endian
>();
433 const unsigned char* local_symbols
;
434 if (rd
->local_symbols
== NULL
)
435 local_symbols
= NULL
;
437 local_symbols
= rd
->local_symbols
->data();
439 // For incremental links, allocate the counters for incremental relocations.
440 if (layout
->incremental_inputs() != NULL
)
441 this->allocate_incremental_reloc_counts();
443 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
444 p
!= rd
->relocs
.end();
447 // When garbage collection is on, unreferenced sections are not included
448 // in the link that would have been included normally. This is known only
449 // after Read_relocs hence this check has to be done again.
450 if (parameters
->options().gc_sections()
451 || parameters
->options().icf_enabled())
453 if (p
->output_section
== NULL
)
456 if (!parameters
->options().relocatable())
458 // As noted above, when not generating an object file, we
459 // only scan allocated sections. We may see a non-allocated
460 // section here if we are emitting relocs.
461 if (p
->is_data_section_allocated
)
462 target
->scan_relocs(symtab
, layout
, this, p
->data_shndx
,
463 p
->sh_type
, p
->contents
->data(),
464 p
->reloc_count
, p
->output_section
,
465 p
->needs_special_offset_handling
,
466 this->local_symbol_count_
,
468 if (parameters
->options().emit_relocs())
469 this->emit_relocs_scan(symtab
, layout
, local_symbols
, p
);
470 if (layout
->incremental_inputs() != NULL
)
471 this->incremental_relocs_scan(p
);
475 Relocatable_relocs
* rr
= this->relocatable_relocs(p
->reloc_shndx
);
476 gold_assert(rr
!= NULL
);
477 rr
->set_reloc_count(p
->reloc_count
);
478 target
->scan_relocatable_relocs(symtab
, layout
, this,
479 p
->data_shndx
, p
->sh_type
,
483 p
->needs_special_offset_handling
,
484 this->local_symbol_count_
,
493 // For incremental links, finalize the allocation of relocations.
494 if (layout
->incremental_inputs() != NULL
)
495 this->finalize_incremental_relocs(layout
, true);
497 if (rd
->local_symbols
!= NULL
)
499 delete rd
->local_symbols
;
500 rd
->local_symbols
= NULL
;
504 // This is a strategy class we use when scanning for --emit-relocs.
506 template<int sh_type
>
507 class Emit_relocs_strategy
510 // A local non-section symbol.
511 inline Relocatable_relocs::Reloc_strategy
512 local_non_section_strategy(unsigned int, Relobj
*, unsigned int)
513 { return Relocatable_relocs::RELOC_COPY
; }
515 // A local section symbol.
516 inline Relocatable_relocs::Reloc_strategy
517 local_section_strategy(unsigned int, Relobj
*)
519 if (sh_type
== elfcpp::SHT_RELA
)
520 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
523 // The addend is stored in the section contents. Since this
524 // is not a relocatable link, we are going to apply the
525 // relocation contents to the section as usual. This means
526 // that we have no way to record the original addend. If the
527 // original addend is not zero, there is basically no way for
528 // the user to handle this correctly. Caveat emptor.
529 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
;
534 inline Relocatable_relocs::Reloc_strategy
535 global_strategy(unsigned int, Relobj
*, unsigned int)
536 { return Relocatable_relocs::RELOC_COPY
; }
539 // Scan the input relocations for --emit-relocs.
541 template<int size
, bool big_endian
>
543 Sized_relobj_file
<size
, big_endian
>::emit_relocs_scan(
544 Symbol_table
* symtab
,
546 const unsigned char* plocal_syms
,
547 const Read_relocs_data::Relocs_list::iterator
& p
)
549 Relocatable_relocs
* rr
= this->relocatable_relocs(p
->reloc_shndx
);
550 gold_assert(rr
!= NULL
);
551 rr
->set_reloc_count(p
->reloc_count
);
553 if (p
->sh_type
== elfcpp::SHT_REL
)
554 this->emit_relocs_scan_reltype
<elfcpp::SHT_REL
>(symtab
, layout
,
558 gold_assert(p
->sh_type
== elfcpp::SHT_RELA
);
559 this->emit_relocs_scan_reltype
<elfcpp::SHT_RELA
>(symtab
, layout
,
564 // Scan the input relocation for --emit-relocs, templatized on the
565 // type of the relocation section.
567 template<int size
, bool big_endian
>
568 template<int sh_type
>
570 Sized_relobj_file
<size
, big_endian
>::emit_relocs_scan_reltype(
571 Symbol_table
* symtab
,
573 const unsigned char* plocal_syms
,
574 const Read_relocs_data::Relocs_list::iterator
& p
,
575 Relocatable_relocs
* rr
)
577 scan_relocatable_relocs
<size
, big_endian
, sh_type
,
578 Emit_relocs_strategy
<sh_type
> >(
586 p
->needs_special_offset_handling
,
587 this->local_symbol_count_
,
592 // Scan the input relocations for --incremental.
594 template<int size
, bool big_endian
>
596 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_scan(
597 const Read_relocs_data::Relocs_list::iterator
& p
)
599 if (p
->sh_type
== elfcpp::SHT_REL
)
600 this->incremental_relocs_scan_reltype
<elfcpp::SHT_REL
>(p
);
603 gold_assert(p
->sh_type
== elfcpp::SHT_RELA
);
604 this->incremental_relocs_scan_reltype
<elfcpp::SHT_RELA
>(p
);
608 // Scan the input relocation for --incremental, templatized on the
609 // type of the relocation section.
611 template<int size
, bool big_endian
>
612 template<int sh_type
>
614 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_scan_reltype(
615 const Read_relocs_data::Relocs_list::iterator
& p
)
617 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
618 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
619 const unsigned char* prelocs
= p
->contents
->data();
620 size_t reloc_count
= p
->reloc_count
;
622 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
624 Reltype
reloc(prelocs
);
626 if (p
->needs_special_offset_handling
627 && !p
->output_section
->is_input_address_mapped(this, p
->data_shndx
,
628 reloc
.get_r_offset()))
631 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
=
633 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
635 if (r_sym
>= this->local_symbol_count_
)
636 this->count_incremental_reloc(r_sym
- this->local_symbol_count_
);
640 // Relocate the input sections and write out the local symbols.
642 template<int size
, bool big_endian
>
644 Sized_relobj_file
<size
, big_endian
>::do_relocate(const Symbol_table
* symtab
,
645 const Layout
* layout
,
648 unsigned int shnum
= this->shnum();
650 // Read the section headers.
651 const unsigned char* pshdrs
= this->get_view(this->elf_file_
.shoff(),
652 shnum
* This::shdr_size
,
658 // Make two passes over the sections. The first one copies the
659 // section data to the output file. The second one applies
662 this->write_sections(pshdrs
, of
, &views
);
664 // To speed up relocations, we set up hash tables for fast lookup of
665 // input offsets to output addresses.
666 this->initialize_input_to_output_maps();
668 // Apply relocations.
670 this->relocate_sections(symtab
, layout
, pshdrs
, of
, &views
);
672 // After we've done the relocations, we release the hash tables,
673 // since we no longer need them.
674 this->free_input_to_output_maps();
676 // Write out the accumulated views.
677 for (unsigned int i
= 1; i
< shnum
; ++i
)
679 if (views
[i
].view
!= NULL
)
681 if (!views
[i
].is_postprocessing_view
)
683 if (views
[i
].is_input_output_view
)
684 of
->write_input_output_view(views
[i
].offset
,
688 of
->write_output_view(views
[i
].offset
, views
[i
].view_size
,
694 // Write out the local symbols.
695 this->write_local_symbols(of
, layout
->sympool(), layout
->dynpool(),
696 layout
->symtab_xindex(), layout
->dynsym_xindex(),
697 layout
->symtab_section_offset());
700 // Sort a Read_multiple vector by file offset.
701 struct Read_multiple_compare
704 operator()(const File_read::Read_multiple_entry
& rme1
,
705 const File_read::Read_multiple_entry
& rme2
) const
706 { return rme1
.file_offset
< rme2
.file_offset
; }
709 // Write section data to the output file. PSHDRS points to the
710 // section headers. Record the views in *PVIEWS for use when
713 template<int size
, bool big_endian
>
715 Sized_relobj_file
<size
, big_endian
>::write_sections(const unsigned char* pshdrs
,
719 unsigned int shnum
= this->shnum();
720 const Output_sections
& out_sections(this->output_sections());
721 const std::vector
<Address
>& out_offsets(this->section_offsets());
723 File_read::Read_multiple rm
;
724 bool is_sorted
= true;
726 const unsigned char* p
= pshdrs
+ This::shdr_size
;
727 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
729 View_size
* pvs
= &(*pviews
)[i
];
733 const Output_section
* os
= out_sections
[i
];
736 Address output_offset
= out_offsets
[i
];
738 typename
This::Shdr
shdr(p
);
740 if (shdr
.get_sh_type() == elfcpp::SHT_NOBITS
)
743 if ((parameters
->options().relocatable()
744 || parameters
->options().emit_relocs())
745 && (shdr
.get_sh_type() == elfcpp::SHT_REL
746 || shdr
.get_sh_type() == elfcpp::SHT_RELA
)
747 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
749 // This is a reloc section in a relocatable link or when
750 // emitting relocs. We don't need to read the input file.
751 // The size and file offset are stored in the
752 // Relocatable_relocs structure.
753 Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
754 gold_assert(rr
!= NULL
);
755 Output_data
* posd
= rr
->output_data();
756 gold_assert(posd
!= NULL
);
758 pvs
->offset
= posd
->offset();
759 pvs
->view_size
= posd
->data_size();
760 pvs
->view
= of
->get_output_view(pvs
->offset
, pvs
->view_size
);
761 pvs
->address
= posd
->address();
762 pvs
->is_input_output_view
= false;
763 pvs
->is_postprocessing_view
= false;
768 // In the normal case, this input section is simply mapped to
769 // the output section at offset OUTPUT_OFFSET.
771 // However, if OUTPUT_OFFSET == INVALID_ADDRESS, then input data is
772 // handled specially--e.g., a .eh_frame section. The relocation
773 // routines need to check for each reloc where it should be
774 // applied. For this case, we need an input/output view for the
775 // entire contents of the section in the output file. We don't
776 // want to copy the contents of the input section to the output
777 // section; the output section contents were already written,
778 // and we waited for them in Relocate_task::is_runnable because
779 // relocs_must_follow_section_writes is set for the object.
781 // Regardless of which of the above cases is true, we have to
782 // check requires_postprocessing of the output section. If that
783 // is false, then we work with views of the output file
784 // directly. If it is true, then we work with a separate
785 // buffer, and the output section is responsible for writing the
786 // final data to the output file.
788 off_t output_section_offset
;
789 Address output_section_size
;
790 if (!os
->requires_postprocessing())
792 output_section_offset
= os
->offset();
793 output_section_size
= convert_types
<Address
, off_t
>(os
->data_size());
797 output_section_offset
= 0;
798 output_section_size
=
799 convert_types
<Address
, off_t
>(os
->postprocessing_buffer_size());
803 section_size_type view_size
;
804 bool must_decompress
= false;
805 if (output_offset
!= invalid_address
)
807 view_start
= output_section_offset
+ output_offset
;
808 view_size
= convert_to_section_size_type(shdr
.get_sh_size());
809 section_size_type uncompressed_size
;
810 if (this->section_is_compressed(i
, &uncompressed_size
))
812 view_size
= uncompressed_size
;
813 must_decompress
= true;
818 view_start
= output_section_offset
;
819 view_size
= convert_to_section_size_type(output_section_size
);
825 gold_assert(output_offset
== invalid_address
826 || output_offset
+ view_size
<= output_section_size
);
829 if (os
->requires_postprocessing())
831 unsigned char* buffer
= os
->postprocessing_buffer();
832 view
= buffer
+ view_start
;
833 if (output_offset
!= invalid_address
&& !must_decompress
)
835 off_t sh_offset
= shdr
.get_sh_offset();
836 if (!rm
.empty() && rm
.back().file_offset
> sh_offset
)
838 rm
.push_back(File_read::Read_multiple_entry(sh_offset
,
844 if (output_offset
== invalid_address
)
845 view
= of
->get_input_output_view(view_start
, view_size
);
848 view
= of
->get_output_view(view_start
, view_size
);
849 if (!must_decompress
)
851 off_t sh_offset
= shdr
.get_sh_offset();
852 if (!rm
.empty() && rm
.back().file_offset
> sh_offset
)
854 rm
.push_back(File_read::Read_multiple_entry(sh_offset
,
862 // Read and decompress the section.
863 section_size_type len
;
864 const unsigned char* p
= this->section_contents(i
, &len
, false);
865 if (!decompress_input_section(p
, len
, view
, view_size
))
866 this->error(_("could not decompress section %s"),
867 this->section_name(i
).c_str());
871 pvs
->address
= os
->address();
872 if (output_offset
!= invalid_address
)
873 pvs
->address
+= output_offset
;
874 pvs
->offset
= view_start
;
875 pvs
->view_size
= view_size
;
876 pvs
->is_input_output_view
= output_offset
== invalid_address
;
877 pvs
->is_postprocessing_view
= os
->requires_postprocessing();
880 // Actually read the data.
884 std::sort(rm
.begin(), rm
.end(), Read_multiple_compare());
885 this->read_multiple(rm
);
889 // Relocate section data. VIEWS points to the section data as views
890 // in the output file.
892 template<int size
, bool big_endian
>
894 Sized_relobj_file
<size
, big_endian
>::do_relocate_sections(
895 const Symbol_table
* symtab
,
896 const Layout
* layout
,
897 const unsigned char* pshdrs
,
901 unsigned int shnum
= this->shnum();
902 Sized_target
<size
, big_endian
>* target
=
903 parameters
->sized_target
<size
, big_endian
>();
905 const Output_sections
& out_sections(this->output_sections());
906 const std::vector
<Address
>& out_offsets(this->section_offsets());
908 Relocate_info
<size
, big_endian
> relinfo
;
909 relinfo
.symtab
= symtab
;
910 relinfo
.layout
= layout
;
911 relinfo
.object
= this;
913 const unsigned char* p
= pshdrs
+ This::shdr_size
;
914 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
916 typename
This::Shdr
shdr(p
);
918 unsigned int sh_type
= shdr
.get_sh_type();
919 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
922 off_t sh_size
= shdr
.get_sh_size();
926 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
927 if (index
>= this->shnum())
929 this->error(_("relocation section %u has bad info %u"),
934 Output_section
* os
= out_sections
[index
];
937 // This relocation section is against a section which we
941 Address output_offset
= out_offsets
[index
];
943 gold_assert((*pviews
)[index
].view
!= NULL
);
944 if (parameters
->options().relocatable())
945 gold_assert((*pviews
)[i
].view
!= NULL
);
947 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx_
)
949 gold_error(_("relocation section %u uses unexpected "
951 i
, this->adjust_shndx(shdr
.get_sh_link()));
955 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
956 sh_size
, true, false);
958 unsigned int reloc_size
;
959 if (sh_type
== elfcpp::SHT_REL
)
960 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
962 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
964 if (reloc_size
!= shdr
.get_sh_entsize())
966 gold_error(_("unexpected entsize for reloc section %u: %lu != %u"),
967 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
972 size_t reloc_count
= sh_size
/ reloc_size
;
973 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
975 gold_error(_("reloc section %u size %lu uneven"),
976 i
, static_cast<unsigned long>(sh_size
));
980 gold_assert(output_offset
!= invalid_address
981 || this->relocs_must_follow_section_writes());
983 relinfo
.reloc_shndx
= i
;
984 relinfo
.reloc_shdr
= p
;
985 relinfo
.data_shndx
= index
;
986 relinfo
.data_shdr
= pshdrs
+ index
* This::shdr_size
;
987 unsigned char* view
= (*pviews
)[index
].view
;
988 Address address
= (*pviews
)[index
].address
;
989 section_size_type view_size
= (*pviews
)[index
].view_size
;
991 Reloc_symbol_changes
* reloc_map
= NULL
;
992 if (this->uses_split_stack() && output_offset
!= invalid_address
)
994 typename
This::Shdr
data_shdr(pshdrs
+ index
* This::shdr_size
);
995 if ((data_shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
996 this->split_stack_adjust(symtab
, pshdrs
, sh_type
, index
,
997 prelocs
, reloc_count
, view
, view_size
,
1001 if (!parameters
->options().relocatable())
1003 target
->relocate_section(&relinfo
, sh_type
, prelocs
, reloc_count
, os
,
1004 output_offset
== invalid_address
,
1005 view
, address
, view_size
, reloc_map
);
1006 if (parameters
->options().emit_relocs())
1007 this->emit_relocs(&relinfo
, i
, sh_type
, prelocs
, reloc_count
,
1008 os
, output_offset
, view
, address
, view_size
,
1009 (*pviews
)[i
].view
, (*pviews
)[i
].view_size
);
1010 if (parameters
->incremental())
1011 this->incremental_relocs_write(&relinfo
, sh_type
, prelocs
,
1012 reloc_count
, os
, output_offset
, of
);
1016 Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
1017 target
->relocate_for_relocatable(&relinfo
, sh_type
, prelocs
,
1018 reloc_count
, os
, output_offset
, rr
,
1019 view
, address
, view_size
,
1021 (*pviews
)[i
].view_size
);
1026 // Emit the relocs for --emit-relocs.
1028 template<int size
, bool big_endian
>
1030 Sized_relobj_file
<size
, big_endian
>::emit_relocs(
1031 const Relocate_info
<size
, big_endian
>* relinfo
,
1033 unsigned int sh_type
,
1034 const unsigned char* prelocs
,
1036 Output_section
* output_section
,
1037 typename
elfcpp::Elf_types
<size
>::Elf_Addr offset_in_output_section
,
1038 unsigned char* view
,
1039 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
1040 section_size_type view_size
,
1041 unsigned char* reloc_view
,
1042 section_size_type reloc_view_size
)
1044 if (sh_type
== elfcpp::SHT_REL
)
1045 this->emit_relocs_reltype
<elfcpp::SHT_REL
>(relinfo
, i
, prelocs
,
1046 reloc_count
, output_section
,
1047 offset_in_output_section
,
1048 view
, address
, view_size
,
1049 reloc_view
, reloc_view_size
);
1052 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1053 this->emit_relocs_reltype
<elfcpp::SHT_RELA
>(relinfo
, i
, prelocs
,
1054 reloc_count
, output_section
,
1055 offset_in_output_section
,
1056 view
, address
, view_size
,
1057 reloc_view
, reloc_view_size
);
1061 // Emit the relocs for --emit-relocs, templatized on the type of the
1062 // relocation section.
1064 template<int size
, bool big_endian
>
1065 template<int sh_type
>
1067 Sized_relobj_file
<size
, big_endian
>::emit_relocs_reltype(
1068 const Relocate_info
<size
, big_endian
>* relinfo
,
1070 const unsigned char* prelocs
,
1072 Output_section
* output_section
,
1073 typename
elfcpp::Elf_types
<size
>::Elf_Addr offset_in_output_section
,
1074 unsigned char* view
,
1075 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
1076 section_size_type view_size
,
1077 unsigned char* reloc_view
,
1078 section_size_type reloc_view_size
)
1080 const Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
1081 relocate_for_relocatable
<size
, big_endian
, sh_type
>(
1086 offset_in_output_section
,
1095 // Write the incremental relocs.
1097 template<int size
, bool big_endian
>
1099 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_write(
1100 const Relocate_info
<size
, big_endian
>* relinfo
,
1101 unsigned int sh_type
,
1102 const unsigned char* prelocs
,
1104 Output_section
* output_section
,
1105 Address output_offset
,
1108 if (sh_type
== elfcpp::SHT_REL
)
1109 this->incremental_relocs_write_reltype
<elfcpp::SHT_REL
>(
1118 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1119 this->incremental_relocs_write_reltype
<elfcpp::SHT_RELA
>(
1129 // Write the incremental relocs, templatized on the type of the
1130 // relocation section.
1132 template<int size
, bool big_endian
>
1133 template<int sh_type
>
1135 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_write_reltype(
1136 const Relocate_info
<size
, big_endian
>* relinfo
,
1137 const unsigned char* prelocs
,
1139 Output_section
* output_section
,
1140 Address output_offset
,
1143 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reloc
;
1144 const unsigned int reloc_size
=
1145 Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
1146 const unsigned int sizeof_addr
= size
/ 8;
1147 const unsigned int incr_reloc_size
=
1148 Incremental_relocs_reader
<size
, big_endian
>::reloc_size
;
1150 unsigned int out_shndx
= output_section
->out_shndx();
1152 // Get a view for the .gnu_incremental_relocs section.
1154 Incremental_inputs
* inputs
= relinfo
->layout
->incremental_inputs();
1155 gold_assert(inputs
!= NULL
);
1156 const off_t relocs_off
= inputs
->relocs_section()->offset();
1157 const off_t relocs_size
= inputs
->relocs_section()->data_size();
1158 unsigned char* const view
= of
->get_output_view(relocs_off
, relocs_size
);
1160 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1162 Reloc
reloc(prelocs
);
1164 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
1165 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1166 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1168 if (r_sym
< this->local_symbol_count_
)
1171 // Get the new offset--the location in the output section where
1172 // this relocation should be applied.
1174 Address offset
= reloc
.get_r_offset();
1175 if (output_offset
!= invalid_address
)
1176 offset
+= output_offset
;
1179 section_offset_type sot_offset
=
1180 convert_types
<section_offset_type
, Address
>(offset
);
1181 section_offset_type new_sot_offset
=
1182 output_section
->output_offset(relinfo
->object
,
1183 relinfo
->data_shndx
,
1185 gold_assert(new_sot_offset
!= -1);
1186 offset
+= new_sot_offset
;
1190 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
;
1191 if (sh_type
== elfcpp::SHT_RELA
)
1193 Reloc_types
<sh_type
, size
, big_endian
>::get_reloc_addend(&reloc
);
1196 // FIXME: Get the addend for SHT_REL.
1200 // Get the index of the output relocation.
1202 unsigned int reloc_index
=
1203 this->next_incremental_reloc_index(r_sym
- this->local_symbol_count_
);
1205 // Write the relocation.
1207 unsigned char* pov
= view
+ reloc_index
* incr_reloc_size
;
1208 elfcpp::Swap
<32, big_endian
>::writeval(pov
, r_type
);
1209 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, out_shndx
);
1210 elfcpp::Swap
<size
, big_endian
>::writeval(pov
+ 8, offset
);
1211 elfcpp::Swap
<size
, big_endian
>::writeval(pov
+ 8 + sizeof_addr
, addend
);
1212 of
->write_output_view(pov
- view
, incr_reloc_size
, view
);
1216 // Create merge hash tables for the local symbols. These are used to
1217 // speed up relocations.
1219 template<int size
, bool big_endian
>
1221 Sized_relobj_file
<size
, big_endian
>::initialize_input_to_output_maps()
1223 const unsigned int loccount
= this->local_symbol_count_
;
1224 for (unsigned int i
= 1; i
< loccount
; ++i
)
1226 Symbol_value
<size
>& lv(this->local_values_
[i
]);
1227 lv
.initialize_input_to_output_map(this);
1231 // Free merge hash tables for the local symbols.
1233 template<int size
, bool big_endian
>
1235 Sized_relobj_file
<size
, big_endian
>::free_input_to_output_maps()
1237 const unsigned int loccount
= this->local_symbol_count_
;
1238 for (unsigned int i
= 1; i
< loccount
; ++i
)
1240 Symbol_value
<size
>& lv(this->local_values_
[i
]);
1241 lv
.free_input_to_output_map();
1245 // If an object was compiled with -fsplit-stack, this is called to
1246 // check whether any relocations refer to functions defined in objects
1247 // which were not compiled with -fsplit-stack. If they were, then we
1248 // need to apply some target-specific adjustments to request
1249 // additional stack space.
1251 template<int size
, bool big_endian
>
1253 Sized_relobj_file
<size
, big_endian
>::split_stack_adjust(
1254 const Symbol_table
* symtab
,
1255 const unsigned char* pshdrs
,
1256 unsigned int sh_type
,
1258 const unsigned char* prelocs
,
1260 unsigned char* view
,
1261 section_size_type view_size
,
1262 Reloc_symbol_changes
** reloc_map
)
1264 if (sh_type
== elfcpp::SHT_REL
)
1265 this->split_stack_adjust_reltype
<elfcpp::SHT_REL
>(symtab
, pshdrs
, shndx
,
1266 prelocs
, reloc_count
,
1271 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1272 this->split_stack_adjust_reltype
<elfcpp::SHT_RELA
>(symtab
, pshdrs
, shndx
,
1273 prelocs
, reloc_count
,
1279 // Adjust for -fsplit-stack, templatized on the type of the relocation
1282 template<int size
, bool big_endian
>
1283 template<int sh_type
>
1285 Sized_relobj_file
<size
, big_endian
>::split_stack_adjust_reltype(
1286 const Symbol_table
* symtab
,
1287 const unsigned char* pshdrs
,
1289 const unsigned char* prelocs
,
1291 unsigned char* view
,
1292 section_size_type view_size
,
1293 Reloc_symbol_changes
** reloc_map
)
1295 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
1296 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
1298 size_t local_count
= this->local_symbol_count();
1300 std::vector
<section_offset_type
> non_split_refs
;
1302 const unsigned char* pr
= prelocs
;
1303 for (size_t i
= 0; i
< reloc_count
; ++i
, pr
+= reloc_size
)
1307 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
1308 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1309 if (r_sym
< local_count
)
1312 const Symbol
* gsym
= this->global_symbol(r_sym
);
1313 gold_assert(gsym
!= NULL
);
1314 if (gsym
->is_forwarder())
1315 gsym
= symtab
->resolve_forwards(gsym
);
1317 // See if this relocation refers to a function defined in an
1318 // object compiled without -fsplit-stack. Note that we don't
1319 // care about the type of relocation--this means that in some
1320 // cases we will ask for a large stack unnecessarily, but this
1321 // is not fatal. FIXME: Some targets have symbols which are
1322 // functions but are not type STT_FUNC, e.g., STT_ARM_TFUNC.
1323 if (!gsym
->is_undefined()
1324 && gsym
->source() == Symbol::FROM_OBJECT
1325 && !gsym
->object()->uses_split_stack())
1327 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1328 if (parameters
->target().is_call_to_non_split(gsym
, r_type
))
1330 section_offset_type offset
=
1331 convert_to_section_size_type(reloc
.get_r_offset());
1332 non_split_refs
.push_back(offset
);
1337 if (non_split_refs
.empty())
1340 // At this point, every entry in NON_SPLIT_REFS indicates a
1341 // relocation which refers to a function in an object compiled
1342 // without -fsplit-stack. We now have to convert that list into a
1343 // set of offsets to functions. First, we find all the functions.
1345 Function_offsets function_offsets
;
1346 this->find_functions(pshdrs
, shndx
, &function_offsets
);
1347 if (function_offsets
.empty())
1350 // Now get a list of the function with references to non split-stack
1353 Function_offsets calls_non_split
;
1354 for (std::vector
<section_offset_type
>::const_iterator p
1355 = non_split_refs
.begin();
1356 p
!= non_split_refs
.end();
1359 Function_offsets::const_iterator low
= function_offsets
.lower_bound(*p
);
1360 if (low
== function_offsets
.end())
1362 else if (low
->first
== *p
)
1364 else if (low
== function_offsets
.begin())
1369 calls_non_split
.insert(*low
);
1371 if (calls_non_split
.empty())
1374 // Now we have a set of functions to adjust. The adjustments are
1375 // target specific. Besides changing the output section view
1376 // however, it likes, the target may request a relocation change
1377 // from one global symbol name to another.
1379 for (Function_offsets::const_iterator p
= calls_non_split
.begin();
1380 p
!= calls_non_split
.end();
1385 parameters
->target().calls_non_split(this, shndx
, p
->first
, p
->second
,
1386 view
, view_size
, &from
, &to
);
1389 gold_assert(!to
.empty());
1390 Symbol
* tosym
= NULL
;
1392 // Find relocations in the relevant function which are for
1395 for (size_t i
= 0; i
< reloc_count
; ++i
, pr
+= reloc_size
)
1399 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
=
1401 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1402 if (r_sym
< local_count
)
1405 section_offset_type offset
=
1406 convert_to_section_size_type(reloc
.get_r_offset());
1407 if (offset
< p
->first
1410 + static_cast<section_offset_type
>(p
->second
))))
1413 const Symbol
* gsym
= this->global_symbol(r_sym
);
1414 if (from
== gsym
->name())
1418 tosym
= symtab
->lookup(to
.c_str());
1421 this->error(_("could not convert call "
1423 from
.c_str(), to
.c_str());
1428 if (*reloc_map
== NULL
)
1429 *reloc_map
= new Reloc_symbol_changes(reloc_count
);
1430 (*reloc_map
)->set(i
, tosym
);
1437 // Find all the function in this object defined in section SHNDX.
1438 // Store their offsets in the section in FUNCTION_OFFSETS.
1440 template<int size
, bool big_endian
>
1442 Sized_relobj_file
<size
, big_endian
>::find_functions(
1443 const unsigned char* pshdrs
,
1445 Sized_relobj_file
<size
, big_endian
>::Function_offsets
* function_offsets
)
1447 // We need to read the symbols to find the functions. If we wanted
1448 // to, we could cache reading the symbols across all sections in the
1450 const unsigned int symtab_shndx
= this->symtab_shndx_
;
1451 typename
This::Shdr
symtabshdr(pshdrs
+ symtab_shndx
* This::shdr_size
);
1452 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
1454 typename
elfcpp::Elf_types
<size
>::Elf_WXword sh_size
=
1455 symtabshdr
.get_sh_size();
1456 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
1457 sh_size
, true, true);
1459 const int sym_size
= This::sym_size
;
1460 const unsigned int symcount
= sh_size
/ sym_size
;
1461 for (unsigned int i
= 0; i
< symcount
; ++i
, psyms
+= sym_size
)
1463 typename
elfcpp::Sym
<size
, big_endian
> isym(psyms
);
1465 // FIXME: Some targets can have functions which do not have type
1466 // STT_FUNC, e.g., STT_ARM_TFUNC.
1467 if (isym
.get_st_type() != elfcpp::STT_FUNC
1468 || isym
.get_st_size() == 0)
1472 unsigned int sym_shndx
= this->adjust_sym_shndx(i
, isym
.get_st_shndx(),
1474 if (!is_ordinary
|| sym_shndx
!= shndx
)
1477 section_offset_type value
=
1478 convert_to_section_size_type(isym
.get_st_value());
1479 section_size_type fnsize
=
1480 convert_to_section_size_type(isym
.get_st_size());
1482 (*function_offsets
)[value
] = fnsize
;
1486 // Class Merged_symbol_value.
1490 Merged_symbol_value
<size
>::initialize_input_to_output_map(
1491 const Relobj
* object
,
1492 unsigned int input_shndx
)
1494 Object_merge_map
* map
= object
->merge_map();
1495 map
->initialize_input_to_output_map
<size
>(input_shndx
,
1496 this->output_start_address_
,
1497 &this->output_addresses_
);
1500 // Get the output value corresponding to an input offset if we
1501 // couldn't find it in the hash table.
1504 typename
elfcpp::Elf_types
<size
>::Elf_Addr
1505 Merged_symbol_value
<size
>::value_from_output_section(
1506 const Relobj
* object
,
1507 unsigned int input_shndx
,
1508 typename
elfcpp::Elf_types
<size
>::Elf_Addr input_offset
) const
1510 section_offset_type output_offset
;
1511 bool found
= object
->merge_map()->get_output_offset(NULL
, input_shndx
,
1515 // If this assertion fails, it means that some relocation was
1516 // against a portion of an input merge section which we didn't map
1517 // to the output file and we didn't explicitly discard. We should
1518 // always map all portions of input merge sections.
1521 if (output_offset
== -1)
1524 return this->output_start_address_
+ output_offset
;
1527 // Track_relocs methods.
1529 // Initialize the class to track the relocs. This gets the object,
1530 // the reloc section index, and the type of the relocs. This returns
1531 // false if something goes wrong.
1533 template<int size
, bool big_endian
>
1535 Track_relocs
<size
, big_endian
>::initialize(
1537 unsigned int reloc_shndx
,
1538 unsigned int reloc_type
)
1540 // If RELOC_SHNDX is -1U, it means there is more than one reloc
1541 // section for the .eh_frame section. We can't handle that case.
1542 if (reloc_shndx
== -1U)
1545 // If RELOC_SHNDX is 0, there is no reloc section.
1546 if (reloc_shndx
== 0)
1549 // Get the contents of the reloc section.
1550 this->prelocs_
= object
->section_contents(reloc_shndx
, &this->len_
, false);
1552 if (reloc_type
== elfcpp::SHT_REL
)
1553 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rel_size
;
1554 else if (reloc_type
== elfcpp::SHT_RELA
)
1555 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rela_size
;
1559 if (this->len_
% this->reloc_size_
!= 0)
1561 object
->error(_("reloc section size %zu is not a multiple of "
1563 static_cast<size_t>(this->len_
),
1571 // Return the offset of the next reloc, or -1 if there isn't one.
1573 template<int size
, bool big_endian
>
1575 Track_relocs
<size
, big_endian
>::next_offset() const
1577 if (this->pos_
>= this->len_
)
1580 // Rel and Rela start out the same, so we can always use Rel to find
1581 // the r_offset value.
1582 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1583 return rel
.get_r_offset();
1586 // Return the index of the symbol referenced by the next reloc, or -1U
1587 // if there aren't any more relocs.
1589 template<int size
, bool big_endian
>
1591 Track_relocs
<size
, big_endian
>::next_symndx() const
1593 if (this->pos_
>= this->len_
)
1596 // Rel and Rela start out the same, so we can use Rel to find the
1598 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1599 return elfcpp::elf_r_sym
<size
>(rel
.get_r_info());
1602 // Return the addend of the next reloc, or 0 if there isn't one.
1604 template<int size
, bool big_endian
>
1606 Track_relocs
<size
, big_endian
>::next_addend() const
1608 if (this->pos_
>= this->len_
)
1610 if (this->reloc_size_
== elfcpp::Elf_sizes
<size
>::rel_size
)
1612 elfcpp::Rela
<size
, big_endian
> rela(this->prelocs_
+ this->pos_
);
1613 return rela
.get_r_addend();
1616 // Advance to the next reloc whose r_offset is greater than or equal
1617 // to OFFSET. Return the number of relocs we skip.
1619 template<int size
, bool big_endian
>
1621 Track_relocs
<size
, big_endian
>::advance(off_t offset
)
1624 while (this->pos_
< this->len_
)
1626 // Rel and Rela start out the same, so we can always use Rel to
1627 // find the r_offset value.
1628 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1629 if (static_cast<off_t
>(rel
.get_r_offset()) >= offset
)
1632 this->pos_
+= this->reloc_size_
;
1637 // Instantiate the templates we need.
1639 #ifdef HAVE_TARGET_32_LITTLE
1642 Sized_relobj_file
<32, false>::do_read_relocs(Read_relocs_data
* rd
);
1645 #ifdef HAVE_TARGET_32_BIG
1648 Sized_relobj_file
<32, true>::do_read_relocs(Read_relocs_data
* rd
);
1651 #ifdef HAVE_TARGET_64_LITTLE
1654 Sized_relobj_file
<64, false>::do_read_relocs(Read_relocs_data
* rd
);
1657 #ifdef HAVE_TARGET_64_BIG
1660 Sized_relobj_file
<64, true>::do_read_relocs(Read_relocs_data
* rd
);
1663 #ifdef HAVE_TARGET_32_LITTLE
1666 Sized_relobj_file
<32, false>::do_gc_process_relocs(Symbol_table
* symtab
,
1668 Read_relocs_data
* rd
);
1671 #ifdef HAVE_TARGET_32_BIG
1674 Sized_relobj_file
<32, true>::do_gc_process_relocs(Symbol_table
* symtab
,
1676 Read_relocs_data
* rd
);
1679 #ifdef HAVE_TARGET_64_LITTLE
1682 Sized_relobj_file
<64, false>::do_gc_process_relocs(Symbol_table
* symtab
,
1684 Read_relocs_data
* rd
);
1687 #ifdef HAVE_TARGET_64_BIG
1690 Sized_relobj_file
<64, true>::do_gc_process_relocs(Symbol_table
* symtab
,
1692 Read_relocs_data
* rd
);
1695 #ifdef HAVE_TARGET_32_LITTLE
1698 Sized_relobj_file
<32, false>::do_scan_relocs(Symbol_table
* symtab
,
1700 Read_relocs_data
* rd
);
1703 #ifdef HAVE_TARGET_32_BIG
1706 Sized_relobj_file
<32, true>::do_scan_relocs(Symbol_table
* symtab
,
1708 Read_relocs_data
* rd
);
1711 #ifdef HAVE_TARGET_64_LITTLE
1714 Sized_relobj_file
<64, false>::do_scan_relocs(Symbol_table
* symtab
,
1716 Read_relocs_data
* rd
);
1719 #ifdef HAVE_TARGET_64_BIG
1722 Sized_relobj_file
<64, true>::do_scan_relocs(Symbol_table
* symtab
,
1724 Read_relocs_data
* rd
);
1727 #ifdef HAVE_TARGET_32_LITTLE
1730 Sized_relobj_file
<32, false>::do_relocate(const Symbol_table
* symtab
,
1731 const Layout
* layout
,
1735 #ifdef HAVE_TARGET_32_BIG
1738 Sized_relobj_file
<32, true>::do_relocate(const Symbol_table
* symtab
,
1739 const Layout
* layout
,
1743 #ifdef HAVE_TARGET_64_LITTLE
1746 Sized_relobj_file
<64, false>::do_relocate(const Symbol_table
* symtab
,
1747 const Layout
* layout
,
1751 #ifdef HAVE_TARGET_64_BIG
1754 Sized_relobj_file
<64, true>::do_relocate(const Symbol_table
* symtab
,
1755 const Layout
* layout
,
1759 #ifdef HAVE_TARGET_32_LITTLE
1762 Sized_relobj_file
<32, false>::do_relocate_sections(
1763 const Symbol_table
* symtab
,
1764 const Layout
* layout
,
1765 const unsigned char* pshdrs
,
1770 #ifdef HAVE_TARGET_32_BIG
1773 Sized_relobj_file
<32, true>::do_relocate_sections(
1774 const Symbol_table
* symtab
,
1775 const Layout
* layout
,
1776 const unsigned char* pshdrs
,
1781 #ifdef HAVE_TARGET_64_LITTLE
1784 Sized_relobj_file
<64, false>::do_relocate_sections(
1785 const Symbol_table
* symtab
,
1786 const Layout
* layout
,
1787 const unsigned char* pshdrs
,
1792 #ifdef HAVE_TARGET_64_BIG
1795 Sized_relobj_file
<64, true>::do_relocate_sections(
1796 const Symbol_table
* symtab
,
1797 const Layout
* layout
,
1798 const unsigned char* pshdrs
,
1803 #ifdef HAVE_TARGET_32_LITTLE
1806 Sized_relobj_file
<32, false>::initialize_input_to_output_maps();
1810 Sized_relobj_file
<32, false>::free_input_to_output_maps();
1813 #ifdef HAVE_TARGET_32_BIG
1816 Sized_relobj_file
<32, true>::initialize_input_to_output_maps();
1820 Sized_relobj_file
<32, true>::free_input_to_output_maps();
1823 #ifdef HAVE_TARGET_64_LITTLE
1826 Sized_relobj_file
<64, false>::initialize_input_to_output_maps();
1830 Sized_relobj_file
<64, false>::free_input_to_output_maps();
1833 #ifdef HAVE_TARGET_64_BIG
1836 Sized_relobj_file
<64, true>::initialize_input_to_output_maps();
1840 Sized_relobj_file
<64, true>::free_input_to_output_maps();
1843 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1845 class Merged_symbol_value
<32>;
1848 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1850 class Merged_symbol_value
<64>;
1853 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1855 class Symbol_value
<32>;
1858 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1860 class Symbol_value
<64>;
1863 #ifdef HAVE_TARGET_32_LITTLE
1865 class Track_relocs
<32, false>;
1868 #ifdef HAVE_TARGET_32_BIG
1870 class Track_relocs
<32, true>;
1873 #ifdef HAVE_TARGET_64_LITTLE
1875 class Track_relocs
<64, false>;
1878 #ifdef HAVE_TARGET_64_BIG
1880 class Track_relocs
<64, true>;
1883 } // End namespace gold.