1 // reloc.cc -- relocate input files for gold.
3 // Copyright (C) 2006-2023 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 // Scan the input relocations for --emit-relocs.
506 template<int size
, bool big_endian
>
508 Sized_relobj_file
<size
, big_endian
>::emit_relocs_scan(
509 Symbol_table
* symtab
,
511 const unsigned char* plocal_syms
,
512 const Read_relocs_data::Relocs_list::iterator
& p
)
514 Sized_target
<size
, big_endian
>* target
=
515 parameters
->sized_target
<size
, big_endian
>();
517 Relocatable_relocs
* rr
= this->relocatable_relocs(p
->reloc_shndx
);
518 gold_assert(rr
!= NULL
);
519 rr
->set_reloc_count(p
->reloc_count
);
520 target
->emit_relocs_scan(
529 p
->needs_special_offset_handling
,
530 this->local_symbol_count_
,
535 // Scan the input relocations for --incremental.
537 template<int size
, bool big_endian
>
539 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_scan(
540 const Read_relocs_data::Relocs_list::iterator
& p
)
542 if (p
->sh_type
== elfcpp::SHT_REL
)
543 this->incremental_relocs_scan_reltype
<elfcpp::SHT_REL
>(p
);
546 gold_assert(p
->sh_type
== elfcpp::SHT_RELA
);
547 this->incremental_relocs_scan_reltype
<elfcpp::SHT_RELA
>(p
);
551 // Scan the input relocation for --incremental, templatized on the
552 // type of the relocation section.
554 template<int size
, bool big_endian
>
555 template<int sh_type
>
557 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_scan_reltype(
558 const Read_relocs_data::Relocs_list::iterator
& p
)
560 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
561 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
562 const unsigned char* prelocs
= p
->contents
->data();
563 size_t reloc_count
= p
->reloc_count
;
565 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
567 Reltype
reloc(prelocs
);
569 if (p
->needs_special_offset_handling
570 && !p
->output_section
->is_input_address_mapped(this, p
->data_shndx
,
571 reloc
.get_r_offset()))
574 // FIXME: Some targets have a non-standard r_info field.
575 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
576 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
578 if (r_sym
>= this->local_symbol_count_
)
579 this->count_incremental_reloc(r_sym
- this->local_symbol_count_
);
583 // Relocate the input sections and write out the local symbols.
585 template<int size
, bool big_endian
>
587 Sized_relobj_file
<size
, big_endian
>::do_relocate(const Symbol_table
* symtab
,
588 const Layout
* layout
,
591 unsigned int shnum
= this->shnum();
593 // Read the section headers.
594 const unsigned char* pshdrs
= this->get_view(this->elf_file_
.shoff(),
595 shnum
* This::shdr_size
,
601 // Make two passes over the sections. The first one copies the
602 // section data to the output file. The second one applies
605 this->write_sections(layout
, pshdrs
, of
, &views
);
607 // To speed up relocations, we set up hash tables for fast lookup of
608 // input offsets to output addresses.
609 this->initialize_input_to_output_maps();
611 // Make the views available through get_output_view() for the duration
612 // of this routine. This RAII class will reset output_views_ to NULL
613 // when the views go out of scope.
614 struct Set_output_views
616 Set_output_views(const Views
** ppviews
, const Views
* pviews
)
623 { *ppviews_
= NULL
; }
625 const Views
** ppviews_
;
627 Set_output_views
set_output_views(&this->output_views_
, &views
);
629 // Apply relocations.
631 this->relocate_sections(symtab
, layout
, pshdrs
, of
, &views
);
633 // After we've done the relocations, we release the hash tables,
634 // since we no longer need them.
635 this->free_input_to_output_maps();
637 // Write out the accumulated views.
638 for (unsigned int i
= 1; i
< shnum
; ++i
)
640 if (views
[i
].view
!= NULL
)
642 if (views
[i
].is_ctors_reverse_view
)
643 this->reverse_words(views
[i
].view
, views
[i
].view_size
);
644 if (!views
[i
].is_postprocessing_view
)
646 if (views
[i
].is_input_output_view
)
647 of
->write_input_output_view(views
[i
].offset
,
651 of
->write_output_view(views
[i
].offset
, views
[i
].view_size
,
657 // Write out the local symbols.
658 this->write_local_symbols(of
, layout
->sympool(), layout
->dynpool(),
659 layout
->symtab_xindex(), layout
->dynsym_xindex(),
660 layout
->symtab_section_offset());
663 // Sort a Read_multiple vector by file offset.
664 struct Read_multiple_compare
667 operator()(const File_read::Read_multiple_entry
& rme1
,
668 const File_read::Read_multiple_entry
& rme2
) const
669 { return rme1
.file_offset
< rme2
.file_offset
; }
672 // Write section data to the output file. PSHDRS points to the
673 // section headers. Record the views in *PVIEWS for use when
676 template<int size
, bool big_endian
>
678 Sized_relobj_file
<size
, big_endian
>::write_sections(const Layout
* layout
,
679 const unsigned char* pshdrs
,
683 unsigned int shnum
= this->shnum();
684 const Output_sections
& out_sections(this->output_sections());
685 const std::vector
<Address
>& out_offsets(this->section_offsets());
687 File_read::Read_multiple rm
;
688 bool is_sorted
= true;
690 const unsigned char* p
= pshdrs
+ This::shdr_size
;
691 for (unsigned int i
= 1; i
< shnum
; ++i
, p
+= This::shdr_size
)
693 View_size
* pvs
= &(*pviews
)[i
];
697 const Output_section
* os
= out_sections
[i
];
700 Address output_offset
= out_offsets
[i
];
702 typename
This::Shdr
shdr(p
);
704 if (shdr
.get_sh_type() == elfcpp::SHT_NOBITS
)
707 if ((parameters
->options().relocatable()
708 || parameters
->options().emit_relocs())
709 && (shdr
.get_sh_type() == elfcpp::SHT_REL
710 || shdr
.get_sh_type() == elfcpp::SHT_RELA
)
711 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) == 0)
713 // This is a reloc section in a relocatable link or when
714 // emitting relocs. We don't need to read the input file.
715 // The size and file offset are stored in the
716 // Relocatable_relocs structure.
717 Relocatable_relocs
* rr
= this->relocatable_relocs(i
);
718 gold_assert(rr
!= NULL
);
719 Output_data
* posd
= rr
->output_data();
720 gold_assert(posd
!= NULL
);
722 pvs
->offset
= posd
->offset();
723 pvs
->view_size
= posd
->data_size();
724 pvs
->view
= of
->get_output_view(pvs
->offset
, pvs
->view_size
);
725 pvs
->address
= posd
->address();
726 pvs
->is_input_output_view
= false;
727 pvs
->is_postprocessing_view
= false;
728 pvs
->is_ctors_reverse_view
= false;
733 // In the normal case, this input section is simply mapped to
734 // the output section at offset OUTPUT_OFFSET.
736 // However, if OUTPUT_OFFSET == INVALID_ADDRESS, then input data is
737 // handled specially--e.g., a .eh_frame section. The relocation
738 // routines need to check for each reloc where it should be
739 // applied. For this case, we need an input/output view for the
740 // entire contents of the section in the output file. We don't
741 // want to copy the contents of the input section to the output
742 // section; the output section contents were already written,
743 // and we waited for them in Relocate_task::is_runnable because
744 // relocs_must_follow_section_writes is set for the object.
746 // Regardless of which of the above cases is true, we have to
747 // check requires_postprocessing of the output section. If that
748 // is false, then we work with views of the output file
749 // directly. If it is true, then we work with a separate
750 // buffer, and the output section is responsible for writing the
751 // final data to the output file.
753 off_t output_section_offset
;
754 Address output_section_size
;
755 if (!os
->requires_postprocessing())
757 output_section_offset
= os
->offset();
758 output_section_size
= convert_types
<Address
, off_t
>(os
->data_size());
762 output_section_offset
= 0;
763 output_section_size
=
764 convert_types
<Address
, off_t
>(os
->postprocessing_buffer_size());
768 section_size_type view_size
;
769 bool must_decompress
= false;
770 if (output_offset
!= invalid_address
)
772 view_start
= output_section_offset
+ output_offset
;
773 view_size
= convert_to_section_size_type(shdr
.get_sh_size());
774 section_size_type uncompressed_size
;
775 if (this->section_is_compressed(i
, &uncompressed_size
))
777 view_size
= uncompressed_size
;
778 must_decompress
= true;
783 view_start
= output_section_offset
;
784 view_size
= convert_to_section_size_type(output_section_size
);
790 gold_assert(output_offset
== invalid_address
791 || output_offset
+ view_size
<= output_section_size
);
794 if (os
->requires_postprocessing())
796 unsigned char* buffer
= os
->postprocessing_buffer();
797 view
= buffer
+ view_start
;
798 if (output_offset
!= invalid_address
&& !must_decompress
)
800 off_t sh_offset
= shdr
.get_sh_offset();
801 if (!rm
.empty() && rm
.back().file_offset
> sh_offset
)
803 rm
.push_back(File_read::Read_multiple_entry(sh_offset
,
809 if (output_offset
== invalid_address
)
810 view
= of
->get_input_output_view(view_start
, view_size
);
813 view
= of
->get_output_view(view_start
, view_size
);
814 if (!must_decompress
)
816 off_t sh_offset
= shdr
.get_sh_offset();
817 if (!rm
.empty() && rm
.back().file_offset
> sh_offset
)
819 rm
.push_back(File_read::Read_multiple_entry(sh_offset
,
827 // Read and decompress the section.
828 section_size_type len
;
829 const unsigned char* p
= this->section_contents(i
, &len
, false);
830 if (!decompress_input_section(p
, len
, view
, view_size
,
832 shdr
.get_sh_flags()))
833 this->error(_("could not decompress section %s"),
834 this->section_name(i
).c_str());
838 pvs
->address
= os
->address();
839 if (output_offset
!= invalid_address
)
840 pvs
->address
+= output_offset
;
841 pvs
->offset
= view_start
;
842 pvs
->view_size
= view_size
;
843 pvs
->is_input_output_view
= output_offset
== invalid_address
;
844 pvs
->is_postprocessing_view
= os
->requires_postprocessing();
845 pvs
->is_ctors_reverse_view
=
846 (!parameters
->options().relocatable()
847 && view_size
> size
/ 8
848 && (strcmp(os
->name(), ".init_array") == 0
849 || strcmp(os
->name(), ".fini_array") == 0)
850 && layout
->is_ctors_in_init_array(this, i
));
853 // Actually read the data.
857 std::sort(rm
.begin(), rm
.end(), Read_multiple_compare());
858 this->read_multiple(rm
);
862 // Relocate section data. VIEWS points to the section data as views
863 // in the output file.
865 template<int size
, bool big_endian
>
867 Sized_relobj_file
<size
, big_endian
>::do_relocate_sections(
868 const Symbol_table
* symtab
,
869 const Layout
* layout
,
870 const unsigned char* pshdrs
,
874 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
875 1, this->shnum() - 1);
878 // Relocate section data for the range of sections START_SHNDX through
881 template<int size
, bool big_endian
>
883 Sized_relobj_file
<size
, big_endian
>::relocate_section_range(
884 const Symbol_table
* symtab
,
885 const Layout
* layout
,
886 const unsigned char* pshdrs
,
889 unsigned int start_shndx
,
890 unsigned int end_shndx
)
892 gold_assert(start_shndx
>= 1);
893 gold_assert(end_shndx
< this->shnum());
895 if (end_shndx
< start_shndx
)
898 Sized_target
<size
, big_endian
>* target
=
899 parameters
->sized_target
<size
, big_endian
>();
901 const Output_sections
& out_sections(this->output_sections());
902 const std::vector
<Address
>& out_offsets(this->section_offsets());
904 Relocate_info
<size
, big_endian
> relinfo
;
905 relinfo
.symtab
= symtab
;
906 relinfo
.layout
= layout
;
907 relinfo
.object
= this;
909 const unsigned char* p
= pshdrs
+ start_shndx
* This::shdr_size
;
910 for (unsigned int i
= start_shndx
; i
<= end_shndx
; ++i
, p
+= This::shdr_size
)
912 typename
This::Shdr
shdr(p
);
914 unsigned int sh_type
= shdr
.get_sh_type();
915 if (sh_type
!= elfcpp::SHT_REL
&& sh_type
!= elfcpp::SHT_RELA
)
918 off_t sh_size
= shdr
.get_sh_size();
922 unsigned int index
= this->adjust_shndx(shdr
.get_sh_info());
923 if (index
>= this->shnum())
925 this->error(_("relocation section %u has bad info %u"),
930 Output_section
* os
= out_sections
[index
];
933 // This relocation section is against a section which we
937 Address output_offset
= out_offsets
[index
];
939 gold_assert((*pviews
)[index
].view
!= NULL
);
940 if (parameters
->options().relocatable())
941 gold_assert((*pviews
)[i
].view
!= NULL
);
943 if (this->adjust_shndx(shdr
.get_sh_link()) != this->symtab_shndx_
)
945 gold_error(_("relocation section %u uses unexpected "
947 i
, this->adjust_shndx(shdr
.get_sh_link()));
951 const unsigned char* prelocs
= this->get_view(shdr
.get_sh_offset(),
952 sh_size
, true, false);
954 unsigned int reloc_size
;
955 if (sh_type
== elfcpp::SHT_REL
)
956 reloc_size
= elfcpp::Elf_sizes
<size
>::rel_size
;
958 reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
960 if (reloc_size
!= shdr
.get_sh_entsize())
962 gold_error(_("unexpected entsize for reloc section %u: %lu != %u"),
963 i
, static_cast<unsigned long>(shdr
.get_sh_entsize()),
968 size_t reloc_count
= sh_size
/ reloc_size
;
969 if (static_cast<off_t
>(reloc_count
* reloc_size
) != sh_size
)
971 gold_error(_("reloc section %u size %lu uneven"),
972 i
, static_cast<unsigned long>(sh_size
));
976 gold_assert(output_offset
!= invalid_address
977 || this->relocs_must_follow_section_writes());
979 relinfo
.reloc_shndx
= i
;
980 relinfo
.reloc_shdr
= p
;
981 relinfo
.data_shndx
= index
;
982 relinfo
.data_shdr
= pshdrs
+ index
* This::shdr_size
;
983 unsigned char* view
= (*pviews
)[index
].view
;
984 Address address
= (*pviews
)[index
].address
;
985 section_size_type view_size
= (*pviews
)[index
].view_size
;
987 Reloc_symbol_changes
* reloc_map
= NULL
;
988 if (this->uses_split_stack() && output_offset
!= invalid_address
)
990 typename
This::Shdr
data_shdr(pshdrs
+ index
* This::shdr_size
);
991 if ((data_shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
992 this->split_stack_adjust(symtab
, pshdrs
, sh_type
, index
,
993 prelocs
, reloc_count
, view
, view_size
,
997 Relocatable_relocs
* rr
= NULL
;
998 if (parameters
->options().emit_relocs()
999 || parameters
->options().relocatable())
1000 rr
= this->relocatable_relocs(i
);
1003 if (!parameters
->options().relocatable())
1005 target
->relocate_section(&relinfo
, sh_type
, prelocs
, reloc_count
, os
,
1006 output_offset
== invalid_address
,
1007 view
, address
, view_size
, reloc_map
);
1008 if (parameters
->options().emit_relocs())
1009 target
->relocate_relocs(&relinfo
, sh_type
, prelocs
, reloc_count
,
1011 view
, address
, view_size
,
1013 (*pviews
)[i
].view_size
);
1014 if (parameters
->incremental())
1015 this->incremental_relocs_write(&relinfo
, sh_type
, prelocs
,
1016 reloc_count
, os
, output_offset
, of
);
1019 target
->relocate_relocs(&relinfo
, sh_type
, prelocs
, reloc_count
,
1021 view
, address
, view_size
,
1023 (*pviews
)[i
].view_size
);
1027 // Return the output view for section SHNDX.
1029 template<int size
, bool big_endian
>
1031 Sized_relobj_file
<size
, big_endian
>::do_get_output_view(
1033 section_size_type
* plen
) const
1035 gold_assert(this->output_views_
!= NULL
);
1036 gold_assert(shndx
< this->output_views_
->size());
1037 const View_size
& v
= (*this->output_views_
)[shndx
];
1038 *plen
= v
.view_size
;
1042 // Write the incremental relocs.
1044 template<int size
, bool big_endian
>
1046 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_write(
1047 const Relocate_info
<size
, big_endian
>* relinfo
,
1048 unsigned int sh_type
,
1049 const unsigned char* prelocs
,
1051 Output_section
* output_section
,
1052 Address output_offset
,
1055 if (sh_type
== elfcpp::SHT_REL
)
1056 this->incremental_relocs_write_reltype
<elfcpp::SHT_REL
>(
1065 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1066 this->incremental_relocs_write_reltype
<elfcpp::SHT_RELA
>(
1076 // Write the incremental relocs, templatized on the type of the
1077 // relocation section.
1079 template<int size
, bool big_endian
>
1080 template<int sh_type
>
1082 Sized_relobj_file
<size
, big_endian
>::incremental_relocs_write_reltype(
1083 const Relocate_info
<size
, big_endian
>* relinfo
,
1084 const unsigned char* prelocs
,
1086 Output_section
* output_section
,
1087 Address output_offset
,
1090 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reloc
;
1091 const unsigned int reloc_size
=
1092 Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
1093 const unsigned int sizeof_addr
= size
/ 8;
1094 const unsigned int incr_reloc_size
=
1095 Incremental_relocs_reader
<size
, big_endian
>::reloc_size
;
1097 unsigned int out_shndx
= output_section
->out_shndx();
1099 // Get a view for the .gnu_incremental_relocs section.
1101 Incremental_inputs
* inputs
= relinfo
->layout
->incremental_inputs();
1102 gold_assert(inputs
!= NULL
);
1103 const off_t relocs_off
= inputs
->relocs_section()->offset();
1104 const off_t relocs_size
= inputs
->relocs_section()->data_size();
1105 unsigned char* const view
= of
->get_output_view(relocs_off
, relocs_size
);
1107 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1109 Reloc
reloc(prelocs
);
1111 // FIXME: Some targets have a non-standard r_info field.
1112 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
1113 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1114 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1116 if (r_sym
< this->local_symbol_count_
)
1119 // Get the new offset--the location in the output section where
1120 // this relocation should be applied.
1122 Address offset
= reloc
.get_r_offset();
1123 if (output_offset
!= invalid_address
)
1124 offset
+= output_offset
;
1127 section_offset_type sot_offset
=
1128 convert_types
<section_offset_type
, Address
>(offset
);
1129 section_offset_type new_sot_offset
=
1130 output_section
->output_offset(relinfo
->object
,
1131 relinfo
->data_shndx
,
1133 gold_assert(new_sot_offset
!= -1);
1134 offset
+= new_sot_offset
;
1138 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
;
1139 if (sh_type
== elfcpp::SHT_RELA
)
1141 Reloc_types
<sh_type
, size
, big_endian
>::get_reloc_addend(&reloc
);
1144 // FIXME: Get the addend for SHT_REL.
1148 // Get the index of the output relocation.
1150 unsigned int reloc_index
=
1151 this->next_incremental_reloc_index(r_sym
- this->local_symbol_count_
);
1153 // Write the relocation.
1155 unsigned char* pov
= view
+ reloc_index
* incr_reloc_size
;
1156 elfcpp::Swap
<32, big_endian
>::writeval(pov
, r_type
);
1157 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, out_shndx
);
1158 elfcpp::Swap
<size
, big_endian
>::writeval(pov
+ 8, offset
);
1159 elfcpp::Swap
<size
, big_endian
>::writeval(pov
+ 8 + sizeof_addr
, addend
);
1160 of
->write_output_view(pov
- view
, incr_reloc_size
, view
);
1164 // Create merge hash tables for the local symbols. These are used to
1165 // speed up relocations.
1167 template<int size
, bool big_endian
>
1169 Sized_relobj_file
<size
, big_endian
>::initialize_input_to_output_maps()
1171 const unsigned int loccount
= this->local_symbol_count_
;
1172 for (unsigned int i
= 1; i
< loccount
; ++i
)
1174 Symbol_value
<size
>& lv(this->local_values_
[i
]);
1175 lv
.initialize_input_to_output_map(this);
1179 // Free merge hash tables for the local symbols.
1181 template<int size
, bool big_endian
>
1183 Sized_relobj_file
<size
, big_endian
>::free_input_to_output_maps()
1185 const unsigned int loccount
= this->local_symbol_count_
;
1186 for (unsigned int i
= 1; i
< loccount
; ++i
)
1188 Symbol_value
<size
>& lv(this->local_values_
[i
]);
1189 lv
.free_input_to_output_map();
1193 // If an object was compiled with -fsplit-stack, this is called to
1194 // check whether any relocations refer to functions defined in objects
1195 // which were not compiled with -fsplit-stack. If they were, then we
1196 // need to apply some target-specific adjustments to request
1197 // additional stack space.
1199 template<int size
, bool big_endian
>
1201 Sized_relobj_file
<size
, big_endian
>::split_stack_adjust(
1202 const Symbol_table
* symtab
,
1203 const unsigned char* pshdrs
,
1204 unsigned int sh_type
,
1206 const unsigned char* prelocs
,
1208 unsigned char* view
,
1209 section_size_type view_size
,
1210 Reloc_symbol_changes
** reloc_map
,
1211 const Sized_target
<size
, big_endian
>* target
)
1213 if (sh_type
== elfcpp::SHT_REL
)
1214 this->split_stack_adjust_reltype
<elfcpp::SHT_REL
>(symtab
, pshdrs
, shndx
,
1215 prelocs
, reloc_count
,
1220 gold_assert(sh_type
== elfcpp::SHT_RELA
);
1221 this->split_stack_adjust_reltype
<elfcpp::SHT_RELA
>(symtab
, pshdrs
, shndx
,
1222 prelocs
, reloc_count
,
1228 // Adjust for -fsplit-stack, templatized on the type of the relocation
1231 template<int size
, bool big_endian
>
1232 template<int sh_type
>
1234 Sized_relobj_file
<size
, big_endian
>::split_stack_adjust_reltype(
1235 const Symbol_table
* symtab
,
1236 const unsigned char* pshdrs
,
1238 const unsigned char* prelocs
,
1240 unsigned char* view
,
1241 section_size_type view_size
,
1242 Reloc_symbol_changes
** reloc_map
,
1243 const Sized_target
<size
, big_endian
>* target
)
1245 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
1246 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
1248 size_t local_count
= this->local_symbol_count();
1250 std::vector
<section_offset_type
> non_split_refs
;
1252 const unsigned char* pr
= prelocs
;
1253 for (size_t i
= 0; i
< reloc_count
; ++i
, pr
+= reloc_size
)
1255 // Some supported targets have a non-standard r_info field.
1256 // If this call is too slow, we can move this routine to
1257 // target-reloc.h and templatize it on Classify_reloc.
1258 unsigned int r_sym
= target
->get_r_sym(pr
);
1259 if (r_sym
< local_count
)
1262 const Symbol
* gsym
= this->global_symbol(r_sym
);
1263 gold_assert(gsym
!= NULL
);
1264 if (gsym
->is_forwarder())
1265 gsym
= symtab
->resolve_forwards(gsym
);
1267 // See if this relocation refers to a function defined in an
1268 // object compiled without -fsplit-stack. Note that we don't
1269 // care about the type of relocation--this means that in some
1270 // cases we will ask for a large stack unnecessarily, but this
1271 // is not fatal. FIXME: Some targets have symbols which are
1272 // functions but are not type STT_FUNC, e.g., STT_ARM_TFUNC.
1273 if (!gsym
->is_undefined()
1274 && gsym
->source() == Symbol::FROM_OBJECT
1275 && !gsym
->object()->uses_split_stack())
1277 if (parameters
->target().is_call_to_non_split(gsym
, pr
, view
,
1281 section_offset_type offset
=
1282 convert_to_section_size_type(reloc
.get_r_offset());
1283 non_split_refs
.push_back(offset
);
1288 if (non_split_refs
.empty())
1291 // At this point, every entry in NON_SPLIT_REFS indicates a
1292 // relocation which refers to a function in an object compiled
1293 // without -fsplit-stack. We now have to convert that list into a
1294 // set of offsets to functions. First, we find all the functions.
1296 Function_offsets function_offsets
;
1297 this->find_functions(pshdrs
, shndx
, &function_offsets
);
1298 if (function_offsets
.empty())
1301 // Now get a list of the function with references to non split-stack
1304 Function_offsets calls_non_split
;
1305 for (std::vector
<section_offset_type
>::const_iterator p
1306 = non_split_refs
.begin();
1307 p
!= non_split_refs
.end();
1310 Function_offsets::const_iterator low
= function_offsets
.lower_bound(*p
);
1311 if (low
== function_offsets
.end())
1313 else if (low
->first
== *p
)
1315 else if (low
== function_offsets
.begin())
1320 calls_non_split
.insert(*low
);
1322 if (calls_non_split
.empty())
1325 // Now we have a set of functions to adjust. The adjustments are
1326 // target specific. Besides changing the output section view
1327 // however, it likes, the target may request a relocation change
1328 // from one global symbol name to another.
1330 for (Function_offsets::const_iterator p
= calls_non_split
.begin();
1331 p
!= calls_non_split
.end();
1336 parameters
->target().calls_non_split(this, shndx
, p
->first
, p
->second
,
1337 prelocs
, reloc_count
,
1338 view
, view_size
, &from
, &to
);
1341 gold_assert(!to
.empty());
1342 Symbol
* tosym
= NULL
;
1344 // Find relocations in the relevant function which are for
1347 for (size_t i
= 0; i
< reloc_count
; ++i
, pr
+= reloc_size
)
1351 unsigned int r_sym
= target
->get_r_sym(pr
);
1352 if (r_sym
< local_count
)
1355 section_offset_type offset
=
1356 convert_to_section_size_type(reloc
.get_r_offset());
1357 if (offset
< p
->first
1360 + static_cast<section_offset_type
>(p
->second
))))
1363 const Symbol
* gsym
= this->global_symbol(r_sym
);
1364 if (from
== gsym
->name())
1368 tosym
= symtab
->lookup(to
.c_str());
1371 this->error(_("could not convert call "
1373 from
.c_str(), to
.c_str());
1378 if (*reloc_map
== NULL
)
1379 *reloc_map
= new Reloc_symbol_changes(reloc_count
);
1380 (*reloc_map
)->set(i
, tosym
);
1387 // Find all the function in this object defined in section SHNDX.
1388 // Store their offsets in the section in FUNCTION_OFFSETS.
1390 template<int size
, bool big_endian
>
1392 Sized_relobj_file
<size
, big_endian
>::find_functions(
1393 const unsigned char* pshdrs
,
1395 Sized_relobj_file
<size
, big_endian
>::Function_offsets
* function_offsets
)
1397 // We need to read the symbols to find the functions. If we wanted
1398 // to, we could cache reading the symbols across all sections in the
1400 const unsigned int symtab_shndx
= this->symtab_shndx_
;
1401 typename
This::Shdr
symtabshdr(pshdrs
+ symtab_shndx
* This::shdr_size
);
1402 gold_assert(symtabshdr
.get_sh_type() == elfcpp::SHT_SYMTAB
);
1404 typename
elfcpp::Elf_types
<size
>::Elf_WXword sh_size
=
1405 symtabshdr
.get_sh_size();
1406 const unsigned char* psyms
= this->get_view(symtabshdr
.get_sh_offset(),
1407 sh_size
, true, true);
1409 const int sym_size
= This::sym_size
;
1410 const unsigned int symcount
= sh_size
/ sym_size
;
1411 for (unsigned int i
= 0; i
< symcount
; ++i
, psyms
+= sym_size
)
1413 typename
elfcpp::Sym
<size
, big_endian
> isym(psyms
);
1415 // FIXME: Some targets can have functions which do not have type
1416 // STT_FUNC, e.g., STT_ARM_TFUNC.
1417 if (isym
.get_st_type() != elfcpp::STT_FUNC
1418 || isym
.get_st_size() == 0)
1422 Symbol_location loc
;
1423 loc
.shndx
= this->adjust_sym_shndx(i
, isym
.get_st_shndx(),
1429 loc
.offset
= isym
.get_st_value();
1430 parameters
->target().function_location(&loc
);
1432 if (loc
.shndx
!= shndx
)
1435 section_offset_type value
=
1436 convert_to_section_size_type(loc
.offset
);
1437 section_size_type fnsize
=
1438 convert_to_section_size_type(isym
.get_st_size());
1440 (*function_offsets
)[value
] = fnsize
;
1444 // Reverse the words in a section. Used for .ctors sections mapped to
1445 // .init_array sections. See ctors_sections_in_init_array in
1448 template<int size
, bool big_endian
>
1450 Sized_relobj_file
<size
, big_endian
>::reverse_words(unsigned char* view
,
1451 section_size_type view_size
)
1453 typedef typename
elfcpp::Swap
<size
, big_endian
>::Valtype Valtype
;
1454 Valtype
* vview
= reinterpret_cast<Valtype
*>(view
);
1455 section_size_type vview_size
= view_size
/ (size
/ 8);
1456 for (section_size_type i
= 0; i
< vview_size
/ 2; ++i
)
1458 Valtype tmp
= vview
[i
];
1459 vview
[i
] = vview
[vview_size
- 1 - i
];
1460 vview
[vview_size
- 1 - i
] = tmp
;
1464 // Class Merged_symbol_value.
1468 Merged_symbol_value
<size
>::initialize_input_to_output_map(
1469 const Relobj
* object
,
1470 unsigned int input_shndx
)
1472 object
->initialize_input_to_output_map
<size
>(input_shndx
,
1473 this->output_start_address_
,
1474 &this->output_addresses_
);
1477 // Get the output value corresponding to an input offset if we
1478 // couldn't find it in the hash table.
1481 typename
elfcpp::Elf_types
<size
>::Elf_Addr
1482 Merged_symbol_value
<size
>::value_from_output_section(
1483 const Relobj
* object
,
1484 unsigned int input_shndx
,
1485 typename
elfcpp::Elf_types
<size
>::Elf_Addr input_offset
) const
1487 section_offset_type output_offset
;
1488 bool found
= object
->merge_output_offset(input_shndx
, input_offset
,
1491 // If this assertion fails, it means that some relocation was
1492 // against a portion of an input merge section which we didn't map
1493 // to the output file and we didn't explicitly discard. We should
1494 // always map all portions of input merge sections.
1497 if (output_offset
== -1)
1500 return this->output_start_address_
+ output_offset
;
1503 // Track_relocs methods.
1505 // Initialize the class to track the relocs. This gets the object,
1506 // the reloc section index, and the type of the relocs. This returns
1507 // false if something goes wrong.
1509 template<int size
, bool big_endian
>
1511 Track_relocs
<size
, big_endian
>::initialize(
1513 unsigned int reloc_shndx
,
1514 unsigned int reloc_type
)
1516 // If RELOC_SHNDX is -1U, it means there is more than one reloc
1517 // section for the .eh_frame section. We can't handle that case.
1518 if (reloc_shndx
== -1U)
1521 // If RELOC_SHNDX is 0, there is no reloc section.
1522 if (reloc_shndx
== 0)
1525 // Get the contents of the reloc section.
1526 this->prelocs_
= object
->section_contents(reloc_shndx
, &this->len_
, false);
1528 if (reloc_type
== elfcpp::SHT_REL
)
1529 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rel_size
;
1530 else if (reloc_type
== elfcpp::SHT_RELA
)
1531 this->reloc_size_
= elfcpp::Elf_sizes
<size
>::rela_size
;
1535 if (this->len_
% this->reloc_size_
!= 0)
1537 object
->error(_("reloc section size %zu is not a multiple of "
1539 static_cast<size_t>(this->len_
),
1547 // Return the offset of the next reloc, or -1 if there isn't one.
1549 template<int size
, bool big_endian
>
1551 Track_relocs
<size
, big_endian
>::next_offset() const
1553 if (this->pos_
>= this->len_
)
1556 // Rel and Rela start out the same, so we can always use Rel to find
1557 // the r_offset value.
1558 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1559 return rel
.get_r_offset();
1562 // Return the index of the symbol referenced by the next reloc, or -1U
1563 // if there aren't any more relocs.
1565 template<int size
, bool big_endian
>
1567 Track_relocs
<size
, big_endian
>::next_symndx() const
1569 if (this->pos_
>= this->len_
)
1571 Sized_target
<size
, big_endian
>* target
1572 = parameters
->sized_target
<size
, big_endian
>();
1573 return target
->get_r_sym(this->prelocs_
+ this->pos_
);
1576 // Return the addend of the next reloc, or 0 if there isn't one.
1578 template<int size
, bool big_endian
>
1580 Track_relocs
<size
, big_endian
>::next_addend() const
1582 if (this->pos_
>= this->len_
)
1584 if (this->reloc_size_
== elfcpp::Elf_sizes
<size
>::rel_size
)
1586 elfcpp::Rela
<size
, big_endian
> rela(this->prelocs_
+ this->pos_
);
1587 return rela
.get_r_addend();
1590 // Advance to the next reloc whose r_offset is greater than or equal
1591 // to OFFSET. Return the number of relocs we skip.
1593 template<int size
, bool big_endian
>
1595 Track_relocs
<size
, big_endian
>::advance(off_t offset
)
1598 while (this->pos_
< this->len_
)
1600 // Rel and Rela start out the same, so we can always use Rel to
1601 // find the r_offset value.
1602 elfcpp::Rel
<size
, big_endian
> rel(this->prelocs_
+ this->pos_
);
1603 if (static_cast<off_t
>(rel
.get_r_offset()) >= offset
)
1605 // Skip R_*_NONE relocation entries with r_sym of zero
1606 // without counting.
1607 if (rel
.get_r_info() != 0)
1609 this->pos_
+= this->reloc_size_
;
1614 // Instantiate the templates we need.
1616 #ifdef HAVE_TARGET_32_LITTLE
1619 Sized_relobj_file
<32, false>::do_read_relocs(Read_relocs_data
* rd
);
1622 #ifdef HAVE_TARGET_32_BIG
1625 Sized_relobj_file
<32, true>::do_read_relocs(Read_relocs_data
* rd
);
1628 #ifdef HAVE_TARGET_64_LITTLE
1631 Sized_relobj_file
<64, false>::do_read_relocs(Read_relocs_data
* rd
);
1634 #ifdef HAVE_TARGET_64_BIG
1637 Sized_relobj_file
<64, true>::do_read_relocs(Read_relocs_data
* rd
);
1640 #ifdef HAVE_TARGET_32_LITTLE
1643 Sized_relobj_file
<32, false>::do_gc_process_relocs(Symbol_table
* symtab
,
1645 Read_relocs_data
* rd
);
1648 #ifdef HAVE_TARGET_32_BIG
1651 Sized_relobj_file
<32, true>::do_gc_process_relocs(Symbol_table
* symtab
,
1653 Read_relocs_data
* rd
);
1656 #ifdef HAVE_TARGET_64_LITTLE
1659 Sized_relobj_file
<64, false>::do_gc_process_relocs(Symbol_table
* symtab
,
1661 Read_relocs_data
* rd
);
1664 #ifdef HAVE_TARGET_64_BIG
1667 Sized_relobj_file
<64, true>::do_gc_process_relocs(Symbol_table
* symtab
,
1669 Read_relocs_data
* rd
);
1672 #ifdef HAVE_TARGET_32_LITTLE
1675 Sized_relobj_file
<32, false>::do_scan_relocs(Symbol_table
* symtab
,
1677 Read_relocs_data
* rd
);
1680 #ifdef HAVE_TARGET_32_BIG
1683 Sized_relobj_file
<32, true>::do_scan_relocs(Symbol_table
* symtab
,
1685 Read_relocs_data
* rd
);
1688 #ifdef HAVE_TARGET_64_LITTLE
1691 Sized_relobj_file
<64, false>::do_scan_relocs(Symbol_table
* symtab
,
1693 Read_relocs_data
* rd
);
1696 #ifdef HAVE_TARGET_64_BIG
1699 Sized_relobj_file
<64, true>::do_scan_relocs(Symbol_table
* symtab
,
1701 Read_relocs_data
* rd
);
1704 #ifdef HAVE_TARGET_32_LITTLE
1707 Sized_relobj_file
<32, false>::do_relocate(const Symbol_table
* symtab
,
1708 const Layout
* layout
,
1712 #ifdef HAVE_TARGET_32_BIG
1715 Sized_relobj_file
<32, true>::do_relocate(const Symbol_table
* symtab
,
1716 const Layout
* layout
,
1720 #ifdef HAVE_TARGET_64_LITTLE
1723 Sized_relobj_file
<64, false>::do_relocate(const Symbol_table
* symtab
,
1724 const Layout
* layout
,
1728 #ifdef HAVE_TARGET_64_BIG
1731 Sized_relobj_file
<64, true>::do_relocate(const Symbol_table
* symtab
,
1732 const Layout
* layout
,
1736 #ifdef HAVE_TARGET_32_LITTLE
1739 Sized_relobj_file
<32, false>::do_relocate_sections(
1740 const Symbol_table
* symtab
,
1741 const Layout
* layout
,
1742 const unsigned char* pshdrs
,
1748 Sized_relobj_file
<32, false>::relocate_section_range(
1749 const Symbol_table
* symtab
,
1750 const Layout
* layout
,
1751 const unsigned char* pshdrs
,
1754 unsigned int start_shndx
,
1755 unsigned int end_shndx
);
1759 Sized_relobj_file
<32, false>::do_get_output_view(
1761 section_size_type
* plen
) const;
1764 #ifdef HAVE_TARGET_32_BIG
1767 Sized_relobj_file
<32, true>::do_relocate_sections(
1768 const Symbol_table
* symtab
,
1769 const Layout
* layout
,
1770 const unsigned char* pshdrs
,
1776 Sized_relobj_file
<32, true>::relocate_section_range(
1777 const Symbol_table
* symtab
,
1778 const Layout
* layout
,
1779 const unsigned char* pshdrs
,
1782 unsigned int start_shndx
,
1783 unsigned int end_shndx
);
1787 Sized_relobj_file
<32, true>::do_get_output_view(
1789 section_size_type
* plen
) const;
1792 #ifdef HAVE_TARGET_64_LITTLE
1795 Sized_relobj_file
<64, false>::do_relocate_sections(
1796 const Symbol_table
* symtab
,
1797 const Layout
* layout
,
1798 const unsigned char* pshdrs
,
1804 Sized_relobj_file
<64, false>::relocate_section_range(
1805 const Symbol_table
* symtab
,
1806 const Layout
* layout
,
1807 const unsigned char* pshdrs
,
1810 unsigned int start_shndx
,
1811 unsigned int end_shndx
);
1815 Sized_relobj_file
<64, false>::do_get_output_view(
1817 section_size_type
* plen
) const;
1820 #ifdef HAVE_TARGET_64_BIG
1823 Sized_relobj_file
<64, true>::do_relocate_sections(
1824 const Symbol_table
* symtab
,
1825 const Layout
* layout
,
1826 const unsigned char* pshdrs
,
1832 Sized_relobj_file
<64, true>::relocate_section_range(
1833 const Symbol_table
* symtab
,
1834 const Layout
* layout
,
1835 const unsigned char* pshdrs
,
1838 unsigned int start_shndx
,
1839 unsigned int end_shndx
);
1843 Sized_relobj_file
<64, true>::do_get_output_view(
1845 section_size_type
* plen
) const;
1848 #ifdef HAVE_TARGET_32_LITTLE
1851 Sized_relobj_file
<32, false>::initialize_input_to_output_maps();
1855 Sized_relobj_file
<32, false>::free_input_to_output_maps();
1858 #ifdef HAVE_TARGET_32_BIG
1861 Sized_relobj_file
<32, true>::initialize_input_to_output_maps();
1865 Sized_relobj_file
<32, true>::free_input_to_output_maps();
1868 #ifdef HAVE_TARGET_64_LITTLE
1871 Sized_relobj_file
<64, false>::initialize_input_to_output_maps();
1875 Sized_relobj_file
<64, false>::free_input_to_output_maps();
1878 #ifdef HAVE_TARGET_64_BIG
1881 Sized_relobj_file
<64, true>::initialize_input_to_output_maps();
1885 Sized_relobj_file
<64, true>::free_input_to_output_maps();
1888 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1890 class Merged_symbol_value
<32>;
1893 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1895 class Merged_symbol_value
<64>;
1898 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
1900 class Symbol_value
<32>;
1903 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
1905 class Symbol_value
<64>;
1908 #ifdef HAVE_TARGET_32_LITTLE
1910 class Track_relocs
<32, false>;
1913 #ifdef HAVE_TARGET_32_BIG
1915 class Track_relocs
<32, true>;
1918 #ifdef HAVE_TARGET_64_LITTLE
1920 class Track_relocs
<64, false>;
1923 #ifdef HAVE_TARGET_64_BIG
1925 class Track_relocs
<64, true>;
1928 } // End namespace gold.