1 // reloc.cc -- relocate input files for gold.
3 // Copyright 2006, 2007, 2008, 2009, 2010 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 tl
->add(this, this->object_
->token());
62 // Read the relocations and then start a Scan_relocs_task.
65 Read_relocs::run(Workqueue
* workqueue
)
67 Read_relocs_data
* rd
= new Read_relocs_data
;
68 this->object_
->read_relocs(rd
);
69 this->object_
->set_relocs_data(rd
);
70 this->object_
->release();
72 // If garbage collection or identical comdat folding is desired, we
73 // process the relocs first before scanning them. Scanning of relocs is
74 // done only after garbage or identical sections is identified.
75 if (parameters
->options().gc_sections()
76 || parameters
->options().icf_enabled())
78 workqueue
->queue_next(new Gc_process_relocs(this->symtab_
,
82 this->next_blocker_
));
86 workqueue
->queue_next(new Scan_relocs(this->symtab_
, this->layout_
,
89 this->next_blocker_
));
93 // Return a debugging name for the task.
96 Read_relocs::get_name() const
98 return "Read_relocs " + this->object_
->name();
101 // Gc_process_relocs methods.
103 Gc_process_relocs::~Gc_process_relocs()
105 if (this->this_blocker_
!= NULL
)
106 delete this->this_blocker_
;
109 // These tasks process the relocations read by Read_relocs and
110 // determine which sections are referenced and which are garbage.
111 // This task is done only when --gc-sections is used. This is blocked
112 // by THIS_BLOCKER_. It unblocks NEXT_BLOCKER_.
115 Gc_process_relocs::is_runnable()
117 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
118 return this->this_blocker_
;
119 if (this->object_
->is_locked())
120 return this->object_
->token();
125 Gc_process_relocs::locks(Task_locker
* tl
)
127 tl
->add(this, this->object_
->token());
128 tl
->add(this, this->next_blocker_
);
132 Gc_process_relocs::run(Workqueue
*)
134 this->object_
->gc_process_relocs(this->symtab_
, this->layout_
, this->rd_
);
135 this->object_
->release();
138 // Return a debugging name for the task.
141 Gc_process_relocs::get_name() const
143 return "Gc_process_relocs " + this->object_
->name();
146 // Scan_relocs methods.
148 Scan_relocs::~Scan_relocs()
150 if (this->this_blocker_
!= NULL
)
151 delete this->this_blocker_
;
154 // These tasks scan the relocations read by Read_relocs and mark up
155 // the symbol table to indicate which relocations are required. We
156 // use a lock on the symbol table to keep them from interfering with
160 Scan_relocs::is_runnable()
162 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
163 return this->this_blocker_
;
164 if (this->object_
->is_locked())
165 return this->object_
->token();
169 // Return the locks we hold: one on the file, one on the symbol table
173 Scan_relocs::locks(Task_locker
* tl
)
175 tl
->add(this, this->object_
->token());
176 tl
->add(this, this->next_blocker_
);
182 Scan_relocs::run(Workqueue
*)
184 this->object_
->scan_relocs(this->symtab_
, this->layout_
, this->rd_
);
187 this->object_
->release();
190 // Return a debugging name for the task.
193 Scan_relocs::get_name() const
195 return "Scan_relocs " + this->object_
->name();
198 // Relocate_task methods.
200 // We may have to wait for the output sections to be written.
203 Relocate_task::is_runnable()
205 if (this->object_
->relocs_must_follow_section_writes()
206 && this->output_sections_blocker_
->is_blocked())
207 return this->output_sections_blocker_
;
209 if (this->object_
->is_locked())
210 return this->object_
->token();
215 // We want to lock the file while we run. We want to unblock
216 // INPUT_SECTIONS_BLOCKER and FINAL_BLOCKER when we are done.
217 // INPUT_SECTIONS_BLOCKER may be NULL.
220 Relocate_task::locks(Task_locker
* tl
)
222 if (this->input_sections_blocker_
!= NULL
)
223 tl
->add(this, this->input_sections_blocker_
);
224 tl
->add(this, this->final_blocker_
);
225 tl
->add(this, this->object_
->token());
231 Relocate_task::run(Workqueue
*)
233 this->object_
->relocate(this->symtab_
, this->layout_
, this->of_
);
235 // This is normally the last thing we will do with an object, so
236 // uncache all views.
237 this->object_
->clear_view_cache_marks();
239 this->object_
->release();
242 // Return a debugging name for the task.
245 Relocate_task::get_name() const
247 return "Relocate_task " + this->object_
->name();
250 // Read the relocs and local symbols from the object file and store
251 // the information in RD.
253 template<int size
, bool big_endian
>
255 Sized_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
259 unsigned int shnum
= this->shnum();
263 rd
->relocs
.reserve(shnum
/ 2);
265 const Output_sections
& out_sections(this->output_sections());
266 const std::vector
<Address
>& out_offsets(this->section_offsets_
);
268 const unsigned char* pshdrs
= this->get_view(this->elf_file_
.shoff(),
269 shnum
* This::shdr_size
,
271 // Skip the first, dummy, section.
272 const unsigned char* ps
= pshdrs
+ This::shdr_size
;
273 for (unsigned int i
= 1; i
< shnum
; ++i
, ps
+= This::shdr_size
)
275 typename
This::Shdr
shdr(ps
);
277 unsigned int sh_type
= shdr
.get_sh_type();
278 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
281 unsigned int shndx
= this->adjust_shndx(shdr
.get_sh_info());
284 this->error(_("relocation section %u has bad info %u"),
289 Output_section
* os
= out_sections
[shndx
];
293 // We are scanning relocations in order to fill out the GOT and
294 // PLT sections. Relocations for sections which are not
295 // allocated (typically debugging sections) should not add new
296 // GOT and PLT entries. So we skip them unless this is a
297 // relocatable link or we need to emit relocations. FIXME: What
298 // should we do if a linker script maps a section with SHF_ALLOC
299 // clear to a section with SHF_ALLOC set?
300 typename
This::Shdr
secshdr(pshdrs
+ shndx
* This::shdr_size
);
301 bool is_section_allocated
= ((secshdr
.get_sh_flags() & elfcpp::SHF_ALLOC
)
303 if (!is_section_allocated
304 && !parameters
->options().relocatable()
305 && !parameters
->options().emit_relocs()
306 && !parameters
->options().incremental())
309 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx_
)
311 this->error(_("relocation section %u uses unexpected "
313 i
, this->adjust_shndx(shdr
.get_sh_link()));
317 off_t sh_size
= shdr
.get_sh_size();
319 unsigned int reloc_size
;
320 if (sh_type
== elfcpp::SHT_REL
)
321 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
323 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
324 if (reloc_size
!= shdr
.get_sh_entsize())
326 this->error(_("unexpected entsize for reloc section %u: %lu != %u"),
327 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
332 size_t reloc_count
= sh_size
/ reloc_size
;
333 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
335 this->error(_("reloc section %u size %lu uneven"),
336 i
, static_cast<unsigned long>(sh_size
));
340 rd
->relocs
.push_back(Section_relocs());
341 Section_relocs
& sr(rd
->relocs
.back());
343 sr
.data_shndx
= shndx
;
344 sr
.contents
= this->get_lasting_view(shdr
.get_sh_offset(), sh_size
,
346 sr
.sh_type
= sh_type
;
347 sr
.reloc_count
= reloc_count
;
348 sr
.output_section
= os
;
349 sr
.needs_special_offset_handling
= out_offsets
[shndx
] == invalid_address
;
350 sr
.is_data_section_allocated
= is_section_allocated
;
353 // Read the local symbols.
354 gold_assert(this->symtab_shndx_
!= -1U);
355 if (this->symtab_shndx_
== 0 || this->local_symbol_count_
== 0)
356 rd
->local_symbols
= NULL
;
359 typename
This::Shdr
symtabshdr(pshdrs
360 + this->symtab_shndx_
* This::shdr_size
);
361 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
362 const int sym_size
= This::sym_size
;
363 const unsigned int loccount
= this->local_symbol_count_
;
364 gold_assert(loccount
== symtabshdr
.get_sh_info());
365 off_t locsize
= loccount
* sym_size
;
366 rd
->local_symbols
= this->get_lasting_view(symtabshdr
.get_sh_offset(),
367 locsize
, true, true);
371 // Process the relocs to generate mappings from source sections to referenced
372 // sections. This is used during garbage colletion to determine garbage
375 template<int size
, bool big_endian
>
377 Sized_relobj
<size
, big_endian
>::do_gc_process_relocs(Symbol_table
* symtab
,
379 Read_relocs_data
* rd
)
381 Sized_target
<size
, big_endian
>* target
=
382 parameters
->sized_target
<size
, big_endian
>();
384 const unsigned char* local_symbols
;
385 if (rd
->local_symbols
== NULL
)
386 local_symbols
= NULL
;
388 local_symbols
= rd
->local_symbols
->data();
390 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
391 p
!= rd
->relocs
.end();
394 if (!parameters
->options().relocatable())
396 // As noted above, when not generating an object file, we
397 // only scan allocated sections. We may see a non-allocated
398 // section here if we are emitting relocs.
399 if (p
->is_data_section_allocated
)
400 target
->gc_process_relocs(symtab
, layout
, this,
401 p
->data_shndx
, p
->sh_type
,
402 p
->contents
->data(), p
->reloc_count
,
404 p
->needs_special_offset_handling
,
405 this->local_symbol_count_
,
412 // Scan the relocs and adjust the symbol table. This looks for
413 // relocations which require GOT/PLT/COPY relocations.
415 template<int size
, bool big_endian
>
417 Sized_relobj
<size
, big_endian
>::do_scan_relocs(Symbol_table
* symtab
,
419 Read_relocs_data
* rd
)
421 Sized_target
<size
, big_endian
>* target
=
422 parameters
->sized_target
<size
, big_endian
>();
424 const unsigned char* local_symbols
;
425 if (rd
->local_symbols
== NULL
)
426 local_symbols
= NULL
;
428 local_symbols
= rd
->local_symbols
->data();
430 // For incremental links, allocate the counters for incremental relocations.
431 if (layout
->incremental_inputs() != NULL
)
432 this->allocate_incremental_reloc_counts();
434 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
435 p
!= rd
->relocs
.end();
438 // When garbage collection is on, unreferenced sections are not included
439 // in the link that would have been included normally. This is known only
440 // after Read_relocs hence this check has to be done again.
441 if (parameters
->options().gc_sections()
442 || parameters
->options().icf_enabled())
444 if (p
->output_section
== NULL
)
447 if (!parameters
->options().relocatable())
449 // As noted above, when not generating an object file, we
450 // only scan allocated sections. We may see a non-allocated
451 // section here if we are emitting relocs.
452 if (p
->is_data_section_allocated
)
453 target
->scan_relocs(symtab
, layout
, this, p
->data_shndx
,
454 p
->sh_type
, p
->contents
->data(),
455 p
->reloc_count
, p
->output_section
,
456 p
->needs_special_offset_handling
,
457 this->local_symbol_count_
,
459 if (parameters
->options().emit_relocs())
460 this->emit_relocs_scan(symtab
, layout
, local_symbols
, p
);
461 if (layout
->incremental_inputs() != NULL
)
462 this->incremental_relocs_scan(p
);
466 Relocatable_relocs
* rr
= this->relocatable_relocs(p
->reloc_shndx
);
467 gold_assert(rr
!= NULL
);
468 rr
->set_reloc_count(p
->reloc_count
);
469 target
->scan_relocatable_relocs(symtab
, layout
, this,
470 p
->data_shndx
, p
->sh_type
,
474 p
->needs_special_offset_handling
,
475 this->local_symbol_count_
,
484 // For incremental links, finalize the allocation of relocations.
485 if (layout
->incremental_inputs() != NULL
)
486 this->finalize_incremental_relocs(layout
);
488 if (rd
->local_symbols
!= NULL
)
490 delete rd
->local_symbols
;
491 rd
->local_symbols
= NULL
;
495 // This is a strategy class we use when scanning for --emit-relocs.
497 template<int sh_type
>
498 class Emit_relocs_strategy
501 // A local non-section symbol.
502 inline Relocatable_relocs::Reloc_strategy
503 local_non_section_strategy(unsigned int, Relobj
*, unsigned int)
504 { return Relocatable_relocs::RELOC_COPY
; }
506 // A local section symbol.
507 inline Relocatable_relocs::Reloc_strategy
508 local_section_strategy(unsigned int, Relobj
*)
510 if (sh_type
== elfcpp::SHT_RELA
)
511 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
514 // The addend is stored in the section contents. Since this
515 // is not a relocatable link, we are going to apply the
516 // relocation contents to the section as usual. This means
517 // that we have no way to record the original addend. If the
518 // original addend is not zero, there is basically no way for
519 // the user to handle this correctly. Caveat emptor.
520 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
;
525 inline Relocatable_relocs::Reloc_strategy
526 global_strategy(unsigned int, Relobj
*, unsigned int)
527 { return Relocatable_relocs::RELOC_COPY
; }
530 // Scan the input relocations for --emit-relocs.
532 template<int size
, bool big_endian
>
534 Sized_relobj
<size
, big_endian
>::emit_relocs_scan(
535 Symbol_table
* symtab
,
537 const unsigned char* plocal_syms
,
538 const Read_relocs_data::Relocs_list::iterator
& p
)
540 Relocatable_relocs
* rr
= this->relocatable_relocs(p
->reloc_shndx
);
541 gold_assert(rr
!= NULL
);
542 rr
->set_reloc_count(p
->reloc_count
);
544 if (p
->sh_type
== elfcpp::SHT_REL
)
545 this->emit_relocs_scan_reltype
<elfcpp::SHT_REL
>(symtab
, layout
,
549 gold_assert(p
->sh_type
== elfcpp::SHT_RELA
);
550 this->emit_relocs_scan_reltype
<elfcpp::SHT_RELA
>(symtab
, layout
,
555 // Scan the input relocation for --emit-relocs, templatized on the
556 // type of the relocation section.
558 template<int size
, bool big_endian
>
559 template<int sh_type
>
561 Sized_relobj
<size
, big_endian
>::emit_relocs_scan_reltype(
562 Symbol_table
* symtab
,
564 const unsigned char* plocal_syms
,
565 const Read_relocs_data::Relocs_list::iterator
& p
,
566 Relocatable_relocs
* rr
)
568 scan_relocatable_relocs
<size
, big_endian
, sh_type
,
569 Emit_relocs_strategy
<sh_type
> >(
577 p
->needs_special_offset_handling
,
578 this->local_symbol_count_
,
583 // Scan the input relocations for --incremental.
585 template<int size
, bool big_endian
>
587 Sized_relobj
<size
, big_endian
>::incremental_relocs_scan(
588 const Read_relocs_data::Relocs_list::iterator
& p
)
590 if (p
->sh_type
== elfcpp::SHT_REL
)
591 this->incremental_relocs_scan_reltype
<elfcpp::SHT_REL
>(p
);
594 gold_assert(p
->sh_type
== elfcpp::SHT_RELA
);
595 this->incremental_relocs_scan_reltype
<elfcpp::SHT_RELA
>(p
);
599 // Scan the input relocation for --emit-relocs, templatized on the
600 // type of the relocation section.
602 template<int size
, bool big_endian
>
603 template<int sh_type
>
605 Sized_relobj
<size
, big_endian
>::incremental_relocs_scan_reltype(
606 const Read_relocs_data::Relocs_list::iterator
& p
)
608 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
609 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
610 const unsigned char* prelocs
= p
->contents
->data();
611 size_t reloc_count
= p
->reloc_count
;
613 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
615 Reltype
reloc(prelocs
);
617 if (p
->needs_special_offset_handling
618 && !p
->output_section
->is_input_address_mapped(this, p
->data_shndx
,
619 reloc
.get_r_offset()))
622 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
=
624 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
626 if (r_sym
>= this->local_symbol_count_
)
627 this->count_incremental_reloc(r_sym
- this->local_symbol_count_
);
631 // Relocate the input sections and write out the local symbols.
633 template<int size
, bool big_endian
>
635 Sized_relobj
<size
, big_endian
>::do_relocate(const Symbol_table
* symtab
,
636 const Layout
* layout
,
639 unsigned int shnum
= this->shnum();
641 // Read the section headers.
642 const unsigned char* pshdrs
= this->get_view(this->elf_file_
.shoff(),
643 shnum
* This::shdr_size
,
649 // Make two passes over the sections. The first one copies the
650 // section data to the output file. The second one applies
653 this->write_sections(pshdrs
, of
, &views
);
655 // To speed up relocations, we set up hash tables for fast lookup of
656 // input offsets to output addresses.
657 this->initialize_input_to_output_maps();
659 // Apply relocations.
661 this->relocate_sections(symtab
, layout
, pshdrs
, of
, &views
);
663 // After we've done the relocations, we release the hash tables,
664 // since we no longer need them.
665 this->free_input_to_output_maps();
667 // Write out the accumulated views.
668 for (unsigned int i
= 1; i
< shnum
; ++i
)
670 if (views
[i
].view
!= NULL
)
672 if (!views
[i
].is_postprocessing_view
)
674 if (views
[i
].is_input_output_view
)
675 of
->write_input_output_view(views
[i
].offset
,
679 of
->write_output_view(views
[i
].offset
, views
[i
].view_size
,
685 // Write out the local symbols.
686 this->write_local_symbols(of
, layout
->sympool(), layout
->dynpool(),
687 layout
->symtab_xindex(), layout
->dynsym_xindex());
689 // We should no longer need the local symbol values.
690 this->clear_local_symbols();
693 // Sort a Read_multiple vector by file offset.
694 struct Read_multiple_compare
697 operator()(const File_read::Read_multiple_entry
& rme1
,
698 const File_read::Read_multiple_entry
& rme2
) const
699 { return rme1
.file_offset
< rme2
.file_offset
; }
702 // Write section data to the output file. PSHDRS points to the
703 // section headers. Record the views in *PVIEWS for use when
706 template<int size
, bool big_endian
>
708 Sized_relobj
<size
, big_endian
>::write_sections(const unsigned char* pshdrs
,
712 unsigned int shnum
= this->shnum();
713 const Output_sections
& out_sections(this->output_sections());
714 const std::vector
<Address
>& out_offsets(this->section_offsets_
);
716 File_read::Read_multiple rm
;
717 bool is_sorted
= true;
719 const unsigned char* p
= pshdrs
+ This::shdr_size
;
720 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
722 View_size
* pvs
= &(*pviews
)[i
];
726 const Output_section
* os
= out_sections
[i
];
729 Address output_offset
= out_offsets
[i
];
731 typename
This::Shdr
shdr(p
);
733 if (shdr
.get_sh_type() == elfcpp::SHT_NOBITS
)
736 if ((parameters
->options().relocatable()
737 || parameters
->options().emit_relocs())
738 && (shdr
.get_sh_type() == elfcpp::SHT_REL
739 || shdr
.get_sh_type() == elfcpp::SHT_RELA
)
740 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
742 // This is a reloc section in a relocatable link or when
743 // emitting relocs. We don't need to read the input file.
744 // The size and file offset are stored in the
745 // Relocatable_relocs structure.
746 Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
747 gold_assert(rr
!= NULL
);
748 Output_data
* posd
= rr
->output_data();
749 gold_assert(posd
!= NULL
);
751 pvs
->offset
= posd
->offset();
752 pvs
->view_size
= posd
->data_size();
753 pvs
->view
= of
->get_output_view(pvs
->offset
, pvs
->view_size
);
754 pvs
->address
= posd
->address();
755 pvs
->is_input_output_view
= false;
756 pvs
->is_postprocessing_view
= false;
761 // In the normal case, this input section is simply mapped to
762 // the output section at offset OUTPUT_OFFSET.
764 // However, if OUTPUT_OFFSET == INVALID_ADDRESS, then input data is
765 // handled specially--e.g., a .eh_frame section. The relocation
766 // routines need to check for each reloc where it should be
767 // applied. For this case, we need an input/output view for the
768 // entire contents of the section in the output file. We don't
769 // want to copy the contents of the input section to the output
770 // section; the output section contents were already written,
771 // and we waited for them in Relocate_task::is_runnable because
772 // relocs_must_follow_section_writes is set for the object.
774 // Regardless of which of the above cases is true, we have to
775 // check requires_postprocessing of the output section. If that
776 // is false, then we work with views of the output file
777 // directly. If it is true, then we work with a separate
778 // buffer, and the output section is responsible for writing the
779 // final data to the output file.
781 off_t output_section_offset
;
782 Address output_section_size
;
783 if (!os
->requires_postprocessing())
785 output_section_offset
= os
->offset();
786 output_section_size
= convert_types
<Address
, off_t
>(os
->data_size());
790 output_section_offset
= 0;
791 output_section_size
=
792 convert_types
<Address
, off_t
>(os
->postprocessing_buffer_size());
796 section_size_type view_size
;
797 bool must_decompress
= false;
798 if (output_offset
!= invalid_address
)
800 view_start
= output_section_offset
+ output_offset
;
801 view_size
= convert_to_section_size_type(shdr
.get_sh_size());
802 section_size_type uncompressed_size
;
803 if (this->section_is_compressed(i
, &uncompressed_size
))
805 view_size
= uncompressed_size
;
806 must_decompress
= true;
811 view_start
= output_section_offset
;
812 view_size
= convert_to_section_size_type(output_section_size
);
818 gold_assert(output_offset
== invalid_address
819 || output_offset
+ view_size
<= output_section_size
);
822 if (os
->requires_postprocessing())
824 unsigned char* buffer
= os
->postprocessing_buffer();
825 view
= buffer
+ view_start
;
826 if (output_offset
!= invalid_address
&& !must_decompress
)
828 off_t sh_offset
= shdr
.get_sh_offset();
829 if (!rm
.empty() && rm
.back().file_offset
> sh_offset
)
831 rm
.push_back(File_read::Read_multiple_entry(sh_offset
,
837 if (output_offset
== invalid_address
)
838 view
= of
->get_input_output_view(view_start
, view_size
);
841 view
= of
->get_output_view(view_start
, view_size
);
842 if (!must_decompress
)
844 off_t sh_offset
= shdr
.get_sh_offset();
845 if (!rm
.empty() && rm
.back().file_offset
> sh_offset
)
847 rm
.push_back(File_read::Read_multiple_entry(sh_offset
,
855 // Read and decompress the section.
856 section_size_type len
;
857 const unsigned char* p
= this->section_contents(i
, &len
, false);
858 if (!decompress_input_section(p
, len
, view
, view_size
))
859 this->error(_("could not decompress section %s"),
860 this->section_name(i
).c_str());
864 pvs
->address
= os
->address();
865 if (output_offset
!= invalid_address
)
866 pvs
->address
+= output_offset
;
867 pvs
->offset
= view_start
;
868 pvs
->view_size
= view_size
;
869 pvs
->is_input_output_view
= output_offset
== invalid_address
;
870 pvs
->is_postprocessing_view
= os
->requires_postprocessing();
873 // Actually read the data.
877 std::sort(rm
.begin(), rm
.end(), Read_multiple_compare());
878 this->read_multiple(rm
);
882 // Relocate section data. VIEWS points to the section data as views
883 // in the output file.
885 template<int size
, bool big_endian
>
887 Sized_relobj
<size
, big_endian
>::do_relocate_sections(
888 const Symbol_table
* symtab
,
889 const Layout
* layout
,
890 const unsigned char* pshdrs
,
894 unsigned int shnum
= this->shnum();
895 Sized_target
<size
, big_endian
>* target
=
896 parameters
->sized_target
<size
, big_endian
>();
898 const Output_sections
& out_sections(this->output_sections());
899 const std::vector
<Address
>& out_offsets(this->section_offsets_
);
901 Relocate_info
<size
, big_endian
> relinfo
;
902 relinfo
.symtab
= symtab
;
903 relinfo
.layout
= layout
;
904 relinfo
.object
= this;
906 const unsigned char* p
= pshdrs
+ This::shdr_size
;
907 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
909 typename
This::Shdr
shdr(p
);
911 unsigned int sh_type
= shdr
.get_sh_type();
912 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
915 off_t sh_size
= shdr
.get_sh_size();
919 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
920 if (index
>= this->shnum())
922 this->error(_("relocation section %u has bad info %u"),
927 Output_section
* os
= out_sections
[index
];
930 // This relocation section is against a section which we
934 Address output_offset
= out_offsets
[index
];
936 gold_assert((*pviews
)[index
].view
!= NULL
);
937 if (parameters
->options().relocatable())
938 gold_assert((*pviews
)[i
].view
!= NULL
);
940 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx_
)
942 gold_error(_("relocation section %u uses unexpected "
944 i
, this->adjust_shndx(shdr
.get_sh_link()));
948 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
949 sh_size
, true, false);
951 unsigned int reloc_size
;
952 if (sh_type
== elfcpp::SHT_REL
)
953 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
955 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
957 if (reloc_size
!= shdr
.get_sh_entsize())
959 gold_error(_("unexpected entsize for reloc section %u: %lu != %u"),
960 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
965 size_t reloc_count
= sh_size
/ reloc_size
;
966 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
968 gold_error(_("reloc section %u size %lu uneven"),
969 i
, static_cast<unsigned long>(sh_size
));
973 gold_assert(output_offset
!= invalid_address
974 || this->relocs_must_follow_section_writes());
976 relinfo
.reloc_shndx
= i
;
977 relinfo
.reloc_shdr
= p
;
978 relinfo
.data_shndx
= index
;
979 relinfo
.data_shdr
= pshdrs
+ index
* This::shdr_size
;
980 unsigned char* view
= (*pviews
)[index
].view
;
981 Address address
= (*pviews
)[index
].address
;
982 section_size_type view_size
= (*pviews
)[index
].view_size
;
984 Reloc_symbol_changes
* reloc_map
= NULL
;
985 if (this->uses_split_stack() && output_offset
!= invalid_address
)
987 typename
This::Shdr
data_shdr(pshdrs
+ index
* This::shdr_size
);
988 if ((data_shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
989 this->split_stack_adjust(symtab
, pshdrs
, sh_type
, index
,
990 prelocs
, reloc_count
, view
, view_size
,
994 if (!parameters
->options().relocatable())
996 target
->relocate_section(&relinfo
, sh_type
, prelocs
, reloc_count
, os
,
997 output_offset
== invalid_address
,
998 view
, address
, view_size
, reloc_map
);
999 if (parameters
->options().emit_relocs())
1000 this->emit_relocs(&relinfo
, i
, sh_type
, prelocs
, reloc_count
,
1001 os
, output_offset
, view
, address
, view_size
,
1002 (*pviews
)[i
].view
, (*pviews
)[i
].view_size
);
1003 if (parameters
->options().incremental())
1004 this->incremental_relocs_write(&relinfo
, sh_type
, prelocs
,
1005 reloc_count
, os
, output_offset
, of
);
1009 Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
1010 target
->relocate_for_relocatable(&relinfo
, sh_type
, prelocs
,
1011 reloc_count
, os
, output_offset
, rr
,
1012 view
, address
, view_size
,
1014 (*pviews
)[i
].view_size
);
1019 // Emit the relocs for --emit-relocs.
1021 template<int size
, bool big_endian
>
1023 Sized_relobj
<size
, big_endian
>::emit_relocs(
1024 const Relocate_info
<size
, big_endian
>* relinfo
,
1026 unsigned int sh_type
,
1027 const unsigned char* prelocs
,
1029 Output_section
* output_section
,
1030 typename
elfcpp::Elf_types
<size
>::Elf_Addr offset_in_output_section
,
1031 unsigned char* view
,
1032 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
1033 section_size_type view_size
,
1034 unsigned char* reloc_view
,
1035 section_size_type reloc_view_size
)
1037 if (sh_type
== elfcpp::SHT_REL
)
1038 this->emit_relocs_reltype
<elfcpp::SHT_REL
>(relinfo
, i
, prelocs
,
1039 reloc_count
, output_section
,
1040 offset_in_output_section
,
1041 view
, address
, view_size
,
1042 reloc_view
, reloc_view_size
);
1045 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1046 this->emit_relocs_reltype
<elfcpp::SHT_RELA
>(relinfo
, i
, prelocs
,
1047 reloc_count
, output_section
,
1048 offset_in_output_section
,
1049 view
, address
, view_size
,
1050 reloc_view
, reloc_view_size
);
1054 // Emit the relocs for --emit-relocs, templatized on the type of the
1055 // relocation section.
1057 template<int size
, bool big_endian
>
1058 template<int sh_type
>
1060 Sized_relobj
<size
, big_endian
>::emit_relocs_reltype(
1061 const Relocate_info
<size
, big_endian
>* relinfo
,
1063 const unsigned char* prelocs
,
1065 Output_section
* output_section
,
1066 typename
elfcpp::Elf_types
<size
>::Elf_Addr offset_in_output_section
,
1067 unsigned char* view
,
1068 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
1069 section_size_type view_size
,
1070 unsigned char* reloc_view
,
1071 section_size_type reloc_view_size
)
1073 const Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
1074 relocate_for_relocatable
<size
, big_endian
, sh_type
>(
1079 offset_in_output_section
,
1088 // Write the incremental relocs.
1090 template<int size
, bool big_endian
>
1092 Sized_relobj
<size
, big_endian
>::incremental_relocs_write(
1093 const Relocate_info
<size
, big_endian
>* relinfo
,
1094 unsigned int sh_type
,
1095 const unsigned char* prelocs
,
1097 Output_section
* output_section
,
1098 Address output_offset
,
1101 if (sh_type
== elfcpp::SHT_REL
)
1102 this->incremental_relocs_write_reltype
<elfcpp::SHT_REL
>(
1111 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1112 this->incremental_relocs_write_reltype
<elfcpp::SHT_RELA
>(
1122 // Write the incremental relocs, templatized on the type of the
1123 // relocation section.
1125 template<int size
, bool big_endian
>
1126 template<int sh_type
>
1128 Sized_relobj
<size
, big_endian
>::incremental_relocs_write_reltype(
1129 const Relocate_info
<size
, big_endian
>* relinfo
,
1130 const unsigned char* prelocs
,
1132 Output_section
* output_section
,
1133 Address output_offset
,
1136 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reloc
;
1137 const unsigned int reloc_size
=
1138 Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
1139 const unsigned int sizeof_addr
= size
/ 8;
1140 const unsigned int incr_reloc_size
= 8 + 2 * sizeof_addr
;
1142 unsigned int out_shndx
= output_section
->out_shndx();
1144 // Get a view for the .gnu_incremental_relocs section.
1146 Incremental_inputs
* inputs
= relinfo
->layout
->incremental_inputs();
1147 gold_assert(inputs
!= NULL
);
1148 const off_t relocs_off
= inputs
->relocs_section()->offset();
1149 const off_t relocs_size
= inputs
->relocs_section()->data_size();
1150 unsigned char* const view
= of
->get_output_view(relocs_off
, relocs_size
);
1152 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1154 Reloc
reloc(prelocs
);
1156 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
1157 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1158 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1160 if (r_sym
< this->local_symbol_count_
)
1163 // Get the new offset--the location in the output section where
1164 // this relocation should be applied.
1166 Address offset
= reloc
.get_r_offset();
1167 if (output_offset
!= invalid_address
)
1168 offset
+= output_offset
;
1171 section_offset_type sot_offset
=
1172 convert_types
<section_offset_type
, Address
>(offset
);
1173 section_offset_type new_sot_offset
=
1174 output_section
->output_offset(relinfo
->object
,
1175 relinfo
->data_shndx
,
1177 gold_assert(new_sot_offset
!= -1);
1178 offset
+= new_sot_offset
;
1182 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
;
1183 if (sh_type
== elfcpp::SHT_RELA
)
1185 Reloc_types
<sh_type
, size
, big_endian
>::get_reloc_addend(&reloc
);
1188 // FIXME: Get the addend for SHT_REL.
1192 // Get the index of the output relocation.
1194 unsigned int reloc_index
=
1195 this->next_incremental_reloc_index(r_sym
- this->local_symbol_count_
);
1197 // Write the relocation.
1199 unsigned char* pov
= view
+ reloc_index
* incr_reloc_size
;
1200 elfcpp::Swap
<32, big_endian
>::writeval(pov
, r_type
);
1201 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, out_shndx
);
1202 elfcpp::Swap
<size
, big_endian
>::writeval(pov
+ 8, offset
);
1203 elfcpp::Swap
<size
, big_endian
>::writeval(pov
+ 8 + sizeof_addr
, addend
);
1204 of
->write_output_view(pov
- view
, incr_reloc_size
, view
);
1208 // Create merge hash tables for the local symbols. These are used to
1209 // speed up relocations.
1211 template<int size
, bool big_endian
>
1213 Sized_relobj
<size
, big_endian
>::initialize_input_to_output_maps()
1215 const unsigned int loccount
= this->local_symbol_count_
;
1216 for (unsigned int i
= 1; i
< loccount
; ++i
)
1218 Symbol_value
<size
>& lv(this->local_values_
[i
]);
1219 lv
.initialize_input_to_output_map(this);
1223 // Free merge hash tables for the local symbols.
1225 template<int size
, bool big_endian
>
1227 Sized_relobj
<size
, big_endian
>::free_input_to_output_maps()
1229 const unsigned int loccount
= this->local_symbol_count_
;
1230 for (unsigned int i
= 1; i
< loccount
; ++i
)
1232 Symbol_value
<size
>& lv(this->local_values_
[i
]);
1233 lv
.free_input_to_output_map();
1237 // If an object was compiled with -fsplit-stack, this is called to
1238 // check whether any relocations refer to functions defined in objects
1239 // which were not compiled with -fsplit-stack. If they were, then we
1240 // need to apply some target-specific adjustments to request
1241 // additional stack space.
1243 template<int size
, bool big_endian
>
1245 Sized_relobj
<size
, big_endian
>::split_stack_adjust(
1246 const Symbol_table
* symtab
,
1247 const unsigned char* pshdrs
,
1248 unsigned int sh_type
,
1250 const unsigned char* prelocs
,
1252 unsigned char* view
,
1253 section_size_type view_size
,
1254 Reloc_symbol_changes
** reloc_map
)
1256 if (sh_type
== elfcpp::SHT_REL
)
1257 this->split_stack_adjust_reltype
<elfcpp::SHT_REL
>(symtab
, pshdrs
, shndx
,
1258 prelocs
, reloc_count
,
1263 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1264 this->split_stack_adjust_reltype
<elfcpp::SHT_RELA
>(symtab
, pshdrs
, shndx
,
1265 prelocs
, reloc_count
,
1271 // Adjust for -fsplit-stack, templatized on the type of the relocation
1274 template<int size
, bool big_endian
>
1275 template<int sh_type
>
1277 Sized_relobj
<size
, big_endian
>::split_stack_adjust_reltype(
1278 const Symbol_table
* symtab
,
1279 const unsigned char* pshdrs
,
1281 const unsigned char* prelocs
,
1283 unsigned char* view
,
1284 section_size_type view_size
,
1285 Reloc_symbol_changes
** reloc_map
)
1287 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
1288 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
1290 size_t local_count
= this->local_symbol_count();
1292 std::vector
<section_offset_type
> non_split_refs
;
1294 const unsigned char* pr
= prelocs
;
1295 for (size_t i
= 0; i
< reloc_count
; ++i
, pr
+= reloc_size
)
1299 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
1300 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1301 if (r_sym
< local_count
)
1304 const Symbol
* gsym
= this->global_symbol(r_sym
);
1305 gold_assert(gsym
!= NULL
);
1306 if (gsym
->is_forwarder())
1307 gsym
= symtab
->resolve_forwards(gsym
);
1309 // See if this relocation refers to a function defined in an
1310 // object compiled without -fsplit-stack. Note that we don't
1311 // care about the type of relocation--this means that in some
1312 // cases we will ask for a large stack unnecessarily, but this
1313 // is not fatal. FIXME: Some targets have symbols which are
1314 // functions but are not type STT_FUNC, e.g., STT_ARM_TFUNC.
1315 if (!gsym
->is_undefined()
1316 && gsym
->source() == Symbol::FROM_OBJECT
1317 && !gsym
->object()->uses_split_stack())
1319 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1320 if (parameters
->target().is_call_to_non_split(gsym
, r_type
))
1322 section_offset_type offset
=
1323 convert_to_section_size_type(reloc
.get_r_offset());
1324 non_split_refs
.push_back(offset
);
1329 if (non_split_refs
.empty())
1332 // At this point, every entry in NON_SPLIT_REFS indicates a
1333 // relocation which refers to a function in an object compiled
1334 // without -fsplit-stack. We now have to convert that list into a
1335 // set of offsets to functions. First, we find all the functions.
1337 Function_offsets function_offsets
;
1338 this->find_functions(pshdrs
, shndx
, &function_offsets
);
1339 if (function_offsets
.empty())
1342 // Now get a list of the function with references to non split-stack
1345 Function_offsets calls_non_split
;
1346 for (std::vector
<section_offset_type
>::const_iterator p
1347 = non_split_refs
.begin();
1348 p
!= non_split_refs
.end();
1351 Function_offsets::const_iterator low
= function_offsets
.lower_bound(*p
);
1352 if (low
== function_offsets
.end())
1354 else if (low
->first
== *p
)
1356 else if (low
== function_offsets
.begin())
1361 calls_non_split
.insert(*low
);
1363 if (calls_non_split
.empty())
1366 // Now we have a set of functions to adjust. The adjustments are
1367 // target specific. Besides changing the output section view
1368 // however, it likes, the target may request a relocation change
1369 // from one global symbol name to another.
1371 for (Function_offsets::const_iterator p
= calls_non_split
.begin();
1372 p
!= calls_non_split
.end();
1377 parameters
->target().calls_non_split(this, shndx
, p
->first
, p
->second
,
1378 view
, view_size
, &from
, &to
);
1381 gold_assert(!to
.empty());
1382 Symbol
* tosym
= NULL
;
1384 // Find relocations in the relevant function which are for
1387 for (size_t i
= 0; i
< reloc_count
; ++i
, pr
+= reloc_size
)
1391 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
=
1393 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1394 if (r_sym
< local_count
)
1397 section_offset_type offset
=
1398 convert_to_section_size_type(reloc
.get_r_offset());
1399 if (offset
< p
->first
1402 + static_cast<section_offset_type
>(p
->second
))))
1405 const Symbol
* gsym
= this->global_symbol(r_sym
);
1406 if (from
== gsym
->name())
1410 tosym
= symtab
->lookup(to
.c_str());
1413 this->error(_("could not convert call "
1415 from
.c_str(), to
.c_str());
1420 if (*reloc_map
== NULL
)
1421 *reloc_map
= new Reloc_symbol_changes(reloc_count
);
1422 (*reloc_map
)->set(i
, tosym
);
1429 // Find all the function in this object defined in section SHNDX.
1430 // Store their offsets in the section in FUNCTION_OFFSETS.
1432 template<int size
, bool big_endian
>
1434 Sized_relobj
<size
, big_endian
>::find_functions(
1435 const unsigned char* pshdrs
,
1437 Sized_relobj
<size
, big_endian
>::Function_offsets
* function_offsets
)
1439 // We need to read the symbols to find the functions. If we wanted
1440 // to, we could cache reading the symbols across all sections in the
1442 const unsigned int symtab_shndx
= this->symtab_shndx_
;
1443 typename
This::Shdr
symtabshdr(pshdrs
+ symtab_shndx
* This::shdr_size
);
1444 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
1446 typename
elfcpp::Elf_types
<size
>::Elf_WXword sh_size
=
1447 symtabshdr
.get_sh_size();
1448 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
1449 sh_size
, true, true);
1451 const int sym_size
= This::sym_size
;
1452 const unsigned int symcount
= sh_size
/ sym_size
;
1453 for (unsigned int i
= 0; i
< symcount
; ++i
, psyms
+= sym_size
)
1455 typename
elfcpp::Sym
<size
, big_endian
> isym(psyms
);
1457 // FIXME: Some targets can have functions which do not have type
1458 // STT_FUNC, e.g., STT_ARM_TFUNC.
1459 if (isym
.get_st_type() != elfcpp::STT_FUNC
1460 || isym
.get_st_size() == 0)
1464 unsigned int sym_shndx
= this->adjust_sym_shndx(i
, isym
.get_st_shndx(),
1466 if (!is_ordinary
|| sym_shndx
!= shndx
)
1469 section_offset_type value
=
1470 convert_to_section_size_type(isym
.get_st_value());
1471 section_size_type fnsize
=
1472 convert_to_section_size_type(isym
.get_st_size());
1474 (*function_offsets
)[value
] = fnsize
;
1478 // Class Merged_symbol_value.
1482 Merged_symbol_value
<size
>::initialize_input_to_output_map(
1483 const Relobj
* object
,
1484 unsigned int input_shndx
)
1486 Object_merge_map
* map
= object
->merge_map();
1487 map
->initialize_input_to_output_map
<size
>(input_shndx
,
1488 this->output_start_address_
,
1489 &this->output_addresses_
);
1492 // Get the output value corresponding to an input offset if we
1493 // couldn't find it in the hash table.
1496 typename
elfcpp::Elf_types
<size
>::Elf_Addr
1497 Merged_symbol_value
<size
>::value_from_output_section(
1498 const Relobj
* object
,
1499 unsigned int input_shndx
,
1500 typename
elfcpp::Elf_types
<size
>::Elf_Addr input_offset
) const
1502 section_offset_type output_offset
;
1503 bool found
= object
->merge_map()->get_output_offset(NULL
, input_shndx
,
1507 // If this assertion fails, it means that some relocation was
1508 // against a portion of an input merge section which we didn't map
1509 // to the output file and we didn't explicitly discard. We should
1510 // always map all portions of input merge sections.
1513 if (output_offset
== -1)
1516 return this->output_start_address_
+ output_offset
;
1519 // Track_relocs methods.
1521 // Initialize the class to track the relocs. This gets the object,
1522 // the reloc section index, and the type of the relocs. This returns
1523 // false if something goes wrong.
1525 template<int size
, bool big_endian
>
1527 Track_relocs
<size
, big_endian
>::initialize(
1529 unsigned int reloc_shndx
,
1530 unsigned int reloc_type
)
1532 // If RELOC_SHNDX is -1U, it means there is more than one reloc
1533 // section for the .eh_frame section. We can't handle that case.
1534 if (reloc_shndx
== -1U)
1537 // If RELOC_SHNDX is 0, there is no reloc section.
1538 if (reloc_shndx
== 0)
1541 // Get the contents of the reloc section.
1542 this->prelocs_
= object
->section_contents(reloc_shndx
, &this->len_
, false);
1544 if (reloc_type
== elfcpp::SHT_REL
)
1545 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rel_size
;
1546 else if (reloc_type
== elfcpp::SHT_RELA
)
1547 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rela_size
;
1551 if (this->len_
% this->reloc_size_
!= 0)
1553 object
->error(_("reloc section size %zu is not a multiple of "
1555 static_cast<size_t>(this->len_
),
1563 // Return the offset of the next reloc, or -1 if there isn't one.
1565 template<int size
, bool big_endian
>
1567 Track_relocs
<size
, big_endian
>::next_offset() const
1569 if (this->pos_
>= this->len_
)
1572 // Rel and Rela start out the same, so we can always use Rel to find
1573 // the r_offset value.
1574 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1575 return rel
.get_r_offset();
1578 // Return the index of the symbol referenced by the next reloc, or -1U
1579 // if there aren't any more relocs.
1581 template<int size
, bool big_endian
>
1583 Track_relocs
<size
, big_endian
>::next_symndx() const
1585 if (this->pos_
>= this->len_
)
1588 // Rel and Rela start out the same, so we can use Rel to find the
1590 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1591 return elfcpp::elf_r_sym
<size
>(rel
.get_r_info());
1594 // Advance to the next reloc whose r_offset is greater than or equal
1595 // to OFFSET. Return the number of relocs we skip.
1597 template<int size
, bool big_endian
>
1599 Track_relocs
<size
, big_endian
>::advance(off_t offset
)
1602 while (this->pos_
< this->len_
)
1604 // Rel and Rela start out the same, so we can always use Rel to
1605 // find the r_offset value.
1606 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1607 if (static_cast<off_t
>(rel
.get_r_offset()) >= offset
)
1610 this->pos_
+= this->reloc_size_
;
1615 // Instantiate the templates we need.
1617 #ifdef HAVE_TARGET_32_LITTLE
1620 Sized_relobj
<32, false>::do_read_relocs(Read_relocs_data
* rd
);
1623 #ifdef HAVE_TARGET_32_BIG
1626 Sized_relobj
<32, true>::do_read_relocs(Read_relocs_data
* rd
);
1629 #ifdef HAVE_TARGET_64_LITTLE
1632 Sized_relobj
<64, false>::do_read_relocs(Read_relocs_data
* rd
);
1635 #ifdef HAVE_TARGET_64_BIG
1638 Sized_relobj
<64, true>::do_read_relocs(Read_relocs_data
* rd
);
1641 #ifdef HAVE_TARGET_32_LITTLE
1644 Sized_relobj
<32, false>::do_gc_process_relocs(Symbol_table
* symtab
,
1646 Read_relocs_data
* rd
);
1649 #ifdef HAVE_TARGET_32_BIG
1652 Sized_relobj
<32, true>::do_gc_process_relocs(Symbol_table
* symtab
,
1654 Read_relocs_data
* rd
);
1657 #ifdef HAVE_TARGET_64_LITTLE
1660 Sized_relobj
<64, false>::do_gc_process_relocs(Symbol_table
* symtab
,
1662 Read_relocs_data
* rd
);
1665 #ifdef HAVE_TARGET_64_BIG
1668 Sized_relobj
<64, true>::do_gc_process_relocs(Symbol_table
* symtab
,
1670 Read_relocs_data
* rd
);
1673 #ifdef HAVE_TARGET_32_LITTLE
1676 Sized_relobj
<32, false>::do_scan_relocs(Symbol_table
* symtab
,
1678 Read_relocs_data
* rd
);
1681 #ifdef HAVE_TARGET_32_BIG
1684 Sized_relobj
<32, true>::do_scan_relocs(Symbol_table
* symtab
,
1686 Read_relocs_data
* rd
);
1689 #ifdef HAVE_TARGET_64_LITTLE
1692 Sized_relobj
<64, false>::do_scan_relocs(Symbol_table
* symtab
,
1694 Read_relocs_data
* rd
);
1697 #ifdef HAVE_TARGET_64_BIG
1700 Sized_relobj
<64, true>::do_scan_relocs(Symbol_table
* symtab
,
1702 Read_relocs_data
* rd
);
1705 #ifdef HAVE_TARGET_32_LITTLE
1708 Sized_relobj
<32, false>::do_relocate(const Symbol_table
* symtab
,
1709 const Layout
* layout
,
1713 #ifdef HAVE_TARGET_32_BIG
1716 Sized_relobj
<32, true>::do_relocate(const Symbol_table
* symtab
,
1717 const Layout
* layout
,
1721 #ifdef HAVE_TARGET_64_LITTLE
1724 Sized_relobj
<64, false>::do_relocate(const Symbol_table
* symtab
,
1725 const Layout
* layout
,
1729 #ifdef HAVE_TARGET_64_BIG
1732 Sized_relobj
<64, true>::do_relocate(const Symbol_table
* symtab
,
1733 const Layout
* layout
,
1737 #ifdef HAVE_TARGET_32_LITTLE
1740 Sized_relobj
<32, false>::do_relocate_sections(
1741 const Symbol_table
* symtab
,
1742 const Layout
* layout
,
1743 const unsigned char* pshdrs
,
1748 #ifdef HAVE_TARGET_32_BIG
1751 Sized_relobj
<32, true>::do_relocate_sections(
1752 const Symbol_table
* symtab
,
1753 const Layout
* layout
,
1754 const unsigned char* pshdrs
,
1759 #ifdef HAVE_TARGET_64_LITTLE
1762 Sized_relobj
<64, false>::do_relocate_sections(
1763 const Symbol_table
* symtab
,
1764 const Layout
* layout
,
1765 const unsigned char* pshdrs
,
1770 #ifdef HAVE_TARGET_64_BIG
1773 Sized_relobj
<64, true>::do_relocate_sections(
1774 const Symbol_table
* symtab
,
1775 const Layout
* layout
,
1776 const unsigned char* pshdrs
,
1781 #ifdef HAVE_TARGET_32_LITTLE
1784 Sized_relobj
<32, false>::initialize_input_to_output_maps();
1788 Sized_relobj
<32, false>::free_input_to_output_maps();
1791 #ifdef HAVE_TARGET_32_BIG
1794 Sized_relobj
<32, true>::initialize_input_to_output_maps();
1798 Sized_relobj
<32, true>::free_input_to_output_maps();
1801 #ifdef HAVE_TARGET_64_LITTLE
1804 Sized_relobj
<64, false>::initialize_input_to_output_maps();
1808 Sized_relobj
<64, false>::free_input_to_output_maps();
1811 #ifdef HAVE_TARGET_64_BIG
1814 Sized_relobj
<64, true>::initialize_input_to_output_maps();
1818 Sized_relobj
<64, true>::free_input_to_output_maps();
1821 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1823 class Merged_symbol_value
<32>;
1826 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1828 class Merged_symbol_value
<64>;
1831 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1833 class Symbol_value
<32>;
1836 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1838 class Symbol_value
<64>;
1841 #ifdef HAVE_TARGET_32_LITTLE
1843 class Track_relocs
<32, false>;
1846 #ifdef HAVE_TARGET_32_BIG
1848 class Track_relocs
<32, true>;
1851 #ifdef HAVE_TARGET_64_LITTLE
1853 class Track_relocs
<64, false>;
1856 #ifdef HAVE_TARGET_64_BIG
1858 class Track_relocs
<64, true>;
1861 } // End namespace gold.