1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2014 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_powerpc
;
53 template<int size
, bool big_endian
>
54 class Output_data_brlt_powerpc
;
56 template<int size
, bool big_endian
>
57 class Output_data_got_powerpc
;
59 template<int size
, bool big_endian
>
60 class Output_data_glink
;
62 template<int size
, bool big_endian
>
65 template<int size
, bool big_endian
>
68 struct Stub_table_owner
70 Output_section
* output_section
;
71 const Output_section::Input_section
* owner
;
75 is_branch_reloc(unsigned int r_type
);
77 template<int size
, bool big_endian
>
78 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
81 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
82 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
83 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
85 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
86 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
87 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
88 special_(0), has_small_toc_reloc_(false), opd_valid_(false),
89 opd_ent_(), access_from_map_(), has14_(), stub_table_index_(),
90 e_flags_(ehdr
.get_e_flags()), st_other_()
92 this->set_abiversion(0);
98 // Read the symbols then set up st_other vector.
100 do_read_symbols(Read_symbols_data
*);
102 // The .got2 section shndx.
107 return this->special_
;
112 // The .opd section shndx.
119 return this->special_
;
122 // Init OPD entry arrays.
124 init_opd(size_t opd_size
)
126 size_t count
= this->opd_ent_ndx(opd_size
);
127 this->opd_ent_
.resize(count
);
130 // Return section and offset of function entry for .opd + R_OFF.
132 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
134 size_t ndx
= this->opd_ent_ndx(r_off
);
135 gold_assert(ndx
< this->opd_ent_
.size());
136 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
138 *value
= this->opd_ent_
[ndx
].off
;
139 return this->opd_ent_
[ndx
].shndx
;
142 // Set section and offset of function entry for .opd + R_OFF.
144 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
146 size_t ndx
= this->opd_ent_ndx(r_off
);
147 gold_assert(ndx
< this->opd_ent_
.size());
148 this->opd_ent_
[ndx
].shndx
= shndx
;
149 this->opd_ent_
[ndx
].off
= value
;
152 // Return discard flag for .opd + R_OFF.
154 get_opd_discard(Address r_off
) const
156 size_t ndx
= this->opd_ent_ndx(r_off
);
157 gold_assert(ndx
< this->opd_ent_
.size());
158 return this->opd_ent_
[ndx
].discard
;
161 // Set discard flag for .opd + R_OFF.
163 set_opd_discard(Address r_off
)
165 size_t ndx
= this->opd_ent_ndx(r_off
);
166 gold_assert(ndx
< this->opd_ent_
.size());
167 this->opd_ent_
[ndx
].discard
= true;
172 { return this->opd_valid_
; }
176 { this->opd_valid_
= true; }
178 // Examine .rela.opd to build info about function entry points.
180 scan_opd_relocs(size_t reloc_count
,
181 const unsigned char* prelocs
,
182 const unsigned char* plocal_syms
);
184 // Perform the Sized_relobj_file method, then set up opd info from
187 do_read_relocs(Read_relocs_data
*);
190 do_find_special_sections(Read_symbols_data
* sd
);
192 // Adjust this local symbol value. Return false if the symbol
193 // should be discarded from the output file.
195 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
197 if (size
== 64 && this->opd_shndx() != 0)
200 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
202 if (this->get_opd_discard(lv
->input_value()))
210 { return &this->access_from_map_
; }
212 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
213 // section at DST_OFF.
215 add_reference(Object
* src_obj
,
216 unsigned int src_indx
,
217 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
219 Section_id
src_id(src_obj
, src_indx
);
220 this->access_from_map_
[dst_off
].insert(src_id
);
223 // Add a reference to the code section specified by the .opd entry
226 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
228 size_t ndx
= this->opd_ent_ndx(dst_off
);
229 if (ndx
>= this->opd_ent_
.size())
230 this->opd_ent_
.resize(ndx
+ 1);
231 this->opd_ent_
[ndx
].gc_mark
= true;
235 process_gc_mark(Symbol_table
* symtab
)
237 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
238 if (this->opd_ent_
[i
].gc_mark
)
240 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
241 symtab
->gc()->worklist().push(Section_id(this, shndx
));
245 // Return offset in output GOT section that this object will use
246 // as a TOC pointer. Won't be just a constant with multi-toc support.
248 toc_base_offset() const
252 set_has_small_toc_reloc()
253 { has_small_toc_reloc_
= true; }
256 has_small_toc_reloc() const
257 { return has_small_toc_reloc_
; }
260 set_has_14bit_branch(unsigned int shndx
)
262 if (shndx
>= this->has14_
.size())
263 this->has14_
.resize(shndx
+ 1);
264 this->has14_
[shndx
] = true;
268 has_14bit_branch(unsigned int shndx
) const
269 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
272 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
274 if (shndx
>= this->stub_table_index_
.size())
275 this->stub_table_index_
.resize(shndx
+ 1);
276 this->stub_table_index_
[shndx
] = stub_index
;
279 Stub_table
<size
, big_endian
>*
280 stub_table(unsigned int shndx
)
282 if (shndx
< this->stub_table_index_
.size())
284 Target_powerpc
<size
, big_endian
>* target
285 = static_cast<Target_powerpc
<size
, big_endian
>*>(
286 parameters
->sized_target
<size
, big_endian
>());
287 unsigned int indx
= this->stub_table_index_
[shndx
];
288 gold_assert(indx
< target
->stub_tables().size());
289 return target
->stub_tables()[indx
];
297 this->stub_table_index_
.clear();
302 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
304 // Set ABI version for input and output
306 set_abiversion(int ver
);
309 ppc64_local_entry_offset(const Symbol
* sym
) const
310 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
313 ppc64_local_entry_offset(unsigned int symndx
) const
314 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
325 // Return index into opd_ent_ array for .opd entry at OFF.
326 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
327 // apart when the language doesn't use the last 8-byte word, the
328 // environment pointer. Thus dividing the entry section offset by
329 // 16 will give an index into opd_ent_ that works for either layout
330 // of .opd. (It leaves some elements of the vector unused when .opd
331 // entries are spaced 24 bytes apart, but we don't know the spacing
332 // until relocations are processed, and in any case it is possible
333 // for an object to have some entries spaced 16 bytes apart and
334 // others 24 bytes apart.)
336 opd_ent_ndx(size_t off
) const
339 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
340 unsigned int special_
;
342 // For 64-bit, whether this object uses small model relocs to access
344 bool has_small_toc_reloc_
;
346 // Set at the start of gc_process_relocs, when we know opd_ent_
347 // vector is valid. The flag could be made atomic and set in
348 // do_read_relocs with memory_order_release and then tested with
349 // memory_order_acquire, potentially resulting in fewer entries in
353 // The first 8-byte word of an OPD entry gives the address of the
354 // entry point of the function. Relocatable object files have a
355 // relocation on this word. The following vector records the
356 // section and offset specified by these relocations.
357 std::vector
<Opd_ent
> opd_ent_
;
359 // References made to this object's .opd section when running
360 // gc_process_relocs for another object, before the opd_ent_ vector
361 // is valid for this object.
362 Access_from access_from_map_
;
364 // Whether input section has a 14-bit branch reloc.
365 std::vector
<bool> has14_
;
367 // The stub table to use for a given input section.
368 std::vector
<unsigned int> stub_table_index_
;
371 elfcpp::Elf_Word e_flags_
;
373 // ELF st_other field for local symbols.
374 std::vector
<unsigned char> st_other_
;
377 template<int size
, bool big_endian
>
378 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
381 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
383 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
384 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
385 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
386 opd_shndx_(0), opd_ent_(), e_flags_(ehdr
.get_e_flags())
388 this->set_abiversion(0);
394 // Call Sized_dynobj::do_read_symbols to read the symbols then
395 // read .opd from a dynamic object, filling in opd_ent_ vector,
397 do_read_symbols(Read_symbols_data
*);
399 // The .opd section shndx.
403 return this->opd_shndx_
;
406 // The .opd section address.
410 return this->opd_address_
;
413 // Init OPD entry arrays.
415 init_opd(size_t opd_size
)
417 size_t count
= this->opd_ent_ndx(opd_size
);
418 this->opd_ent_
.resize(count
);
421 // Return section and offset of function entry for .opd + R_OFF.
423 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
425 size_t ndx
= this->opd_ent_ndx(r_off
);
426 gold_assert(ndx
< this->opd_ent_
.size());
427 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
429 *value
= this->opd_ent_
[ndx
].off
;
430 return this->opd_ent_
[ndx
].shndx
;
433 // Set section and offset of function entry for .opd + R_OFF.
435 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
437 size_t ndx
= this->opd_ent_ndx(r_off
);
438 gold_assert(ndx
< this->opd_ent_
.size());
439 this->opd_ent_
[ndx
].shndx
= shndx
;
440 this->opd_ent_
[ndx
].off
= value
;
445 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
447 // Set ABI version for input and output.
449 set_abiversion(int ver
);
452 // Used to specify extent of executable sections.
455 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
456 : start(start_
), len(len_
), shndx(shndx_
)
460 operator<(const Sec_info
& that
) const
461 { return this->start
< that
.start
; }
474 // Return index into opd_ent_ array for .opd entry at OFF.
476 opd_ent_ndx(size_t off
) const
479 // For 64-bit the .opd section shndx and address.
480 unsigned int opd_shndx_
;
481 Address opd_address_
;
483 // The first 8-byte word of an OPD entry gives the address of the
484 // entry point of the function. Records the section and offset
485 // corresponding to the address. Note that in dynamic objects,
486 // offset is *not* relative to the section.
487 std::vector
<Opd_ent
> opd_ent_
;
490 elfcpp::Elf_Word e_flags_
;
493 template<int size
, bool big_endian
>
494 class Target_powerpc
: public Sized_target
<size
, big_endian
>
498 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
499 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
500 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
501 static const Address invalid_address
= static_cast<Address
>(0) - 1;
502 // Offset of tp and dtp pointers from start of TLS block.
503 static const Address tp_offset
= 0x7000;
504 static const Address dtp_offset
= 0x8000;
507 : Sized_target
<size
, big_endian
>(&powerpc_info
),
508 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
509 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(elfcpp::R_POWERPC_COPY
),
510 tlsld_got_offset_(-1U),
511 stub_tables_(), branch_lookup_table_(), branch_info_(),
512 plt_thread_safe_(false), relax_failed_(false), relax_fail_count_(0),
517 // Process the relocations to determine unreferenced sections for
518 // garbage collection.
520 gc_process_relocs(Symbol_table
* symtab
,
522 Sized_relobj_file
<size
, big_endian
>* object
,
523 unsigned int data_shndx
,
524 unsigned int sh_type
,
525 const unsigned char* prelocs
,
527 Output_section
* output_section
,
528 bool needs_special_offset_handling
,
529 size_t local_symbol_count
,
530 const unsigned char* plocal_symbols
);
532 // Scan the relocations to look for symbol adjustments.
534 scan_relocs(Symbol_table
* symtab
,
536 Sized_relobj_file
<size
, big_endian
>* object
,
537 unsigned int data_shndx
,
538 unsigned int sh_type
,
539 const unsigned char* prelocs
,
541 Output_section
* output_section
,
542 bool needs_special_offset_handling
,
543 size_t local_symbol_count
,
544 const unsigned char* plocal_symbols
);
546 // Map input .toc section to output .got section.
548 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
550 if (size
== 64 && strcmp(name
, ".toc") == 0)
558 // Provide linker defined save/restore functions.
560 define_save_restore_funcs(Layout
*, Symbol_table
*);
562 // No stubs unless a final link.
565 { return !parameters
->options().relocatable(); }
568 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
571 do_plt_fde_location(const Output_data
*, unsigned char*,
572 uint64_t*, off_t
*) const;
574 // Stash info about branches, for stub generation.
576 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
577 unsigned int data_shndx
, Address r_offset
,
578 unsigned int r_type
, unsigned int r_sym
, Address addend
)
580 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
581 this->branch_info_
.push_back(info
);
582 if (r_type
== elfcpp::R_POWERPC_REL14
583 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
584 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
585 ppc_object
->set_has_14bit_branch(data_shndx
);
589 do_define_standard_symbols(Symbol_table
*, Layout
*);
591 // Finalize the sections.
593 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
595 // Return the value to use for a dynamic which requires special
598 do_dynsym_value(const Symbol
*) const;
600 // Return the PLT address to use for a local symbol.
602 do_plt_address_for_local(const Relobj
*, unsigned int) const;
604 // Return the PLT address to use for a global symbol.
606 do_plt_address_for_global(const Symbol
*) const;
608 // Return the offset to use for the GOT_INDX'th got entry which is
609 // for a local tls symbol specified by OBJECT, SYMNDX.
611 do_tls_offset_for_local(const Relobj
* object
,
613 unsigned int got_indx
) const;
615 // Return the offset to use for the GOT_INDX'th got entry which is
616 // for global tls symbol GSYM.
618 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
621 do_function_location(Symbol_location
*) const;
624 do_can_check_for_function_pointers() const
627 // Relocate a section.
629 relocate_section(const Relocate_info
<size
, big_endian
>*,
630 unsigned int sh_type
,
631 const unsigned char* prelocs
,
633 Output_section
* output_section
,
634 bool needs_special_offset_handling
,
636 Address view_address
,
637 section_size_type view_size
,
638 const Reloc_symbol_changes
*);
640 // Scan the relocs during a relocatable link.
642 scan_relocatable_relocs(Symbol_table
* symtab
,
644 Sized_relobj_file
<size
, big_endian
>* object
,
645 unsigned int data_shndx
,
646 unsigned int sh_type
,
647 const unsigned char* prelocs
,
649 Output_section
* output_section
,
650 bool needs_special_offset_handling
,
651 size_t local_symbol_count
,
652 const unsigned char* plocal_symbols
,
653 Relocatable_relocs
*);
655 // Emit relocations for a section.
657 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
658 unsigned int sh_type
,
659 const unsigned char* prelocs
,
661 Output_section
* output_section
,
662 typename
elfcpp::Elf_types
<size
>::Elf_Off
663 offset_in_output_section
,
664 const Relocatable_relocs
*,
666 Address view_address
,
668 unsigned char* reloc_view
,
669 section_size_type reloc_view_size
);
671 // Return whether SYM is defined by the ABI.
673 do_is_defined_by_abi(const Symbol
* sym
) const
675 return strcmp(sym
->name(), "__tls_get_addr") == 0;
678 // Return the size of the GOT section.
682 gold_assert(this->got_
!= NULL
);
683 return this->got_
->data_size();
686 // Get the PLT section.
687 const Output_data_plt_powerpc
<size
, big_endian
>*
690 gold_assert(this->plt_
!= NULL
);
694 // Get the IPLT section.
695 const Output_data_plt_powerpc
<size
, big_endian
>*
698 gold_assert(this->iplt_
!= NULL
);
702 // Get the .glink section.
703 const Output_data_glink
<size
, big_endian
>*
704 glink_section() const
706 gold_assert(this->glink_
!= NULL
);
710 Output_data_glink
<size
, big_endian
>*
713 gold_assert(this->glink_
!= NULL
);
717 bool has_glink() const
718 { return this->glink_
!= NULL
; }
720 // Get the GOT section.
721 const Output_data_got_powerpc
<size
, big_endian
>*
724 gold_assert(this->got_
!= NULL
);
728 // Get the GOT section, creating it if necessary.
729 Output_data_got_powerpc
<size
, big_endian
>*
730 got_section(Symbol_table
*, Layout
*);
733 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
734 const elfcpp::Ehdr
<size
, big_endian
>&);
736 // Return the number of entries in the GOT.
738 got_entry_count() const
740 if (this->got_
== NULL
)
742 return this->got_size() / (size
/ 8);
745 // Return the number of entries in the PLT.
747 plt_entry_count() const;
749 // Return the offset of the first non-reserved PLT entry.
751 first_plt_entry_offset() const
755 if (this->abiversion() >= 2)
760 // Return the size of each PLT entry.
762 plt_entry_size() const
766 if (this->abiversion() >= 2)
771 // Add any special sections for this symbol to the gc work list.
772 // For powerpc64, this adds the code section of a function
775 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
777 // Handle target specific gc actions when adding a gc reference from
778 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
779 // and DST_OFF. For powerpc64, this adds a referenc to the code
780 // section of a function descriptor.
782 do_gc_add_reference(Symbol_table
* symtab
,
784 unsigned int src_shndx
,
786 unsigned int dst_shndx
,
787 Address dst_off
) const;
789 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
792 { return this->stub_tables_
; }
794 const Output_data_brlt_powerpc
<size
, big_endian
>*
796 { return this->brlt_section_
; }
799 add_branch_lookup_table(Address to
)
801 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
802 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
806 find_branch_lookup_table(Address to
)
808 typename
Branch_lookup_table::const_iterator p
809 = this->branch_lookup_table_
.find(to
);
810 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
814 write_branch_lookup_table(unsigned char *oview
)
816 for (typename
Branch_lookup_table::const_iterator p
817 = this->branch_lookup_table_
.begin();
818 p
!= this->branch_lookup_table_
.end();
821 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
826 plt_thread_safe() const
827 { return this->plt_thread_safe_
; }
831 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
834 set_abiversion (int ver
)
836 elfcpp::Elf_Word flags
= this->processor_specific_flags();
837 flags
&= ~elfcpp::EF_PPC64_ABI
;
838 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
839 this->set_processor_specific_flags(flags
);
842 // Offset to to save stack slot
845 { return this->abiversion() < 2 ? 40 : 24; }
861 : tls_get_addr_(NOT_EXPECTED
),
862 relinfo_(NULL
), relnum_(0), r_offset_(0)
867 if (this->tls_get_addr_
!= NOT_EXPECTED
)
874 if (this->relinfo_
!= NULL
)
875 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
876 _("missing expected __tls_get_addr call"));
880 expect_tls_get_addr_call(
881 const Relocate_info
<size
, big_endian
>* relinfo
,
885 this->tls_get_addr_
= EXPECTED
;
886 this->relinfo_
= relinfo
;
887 this->relnum_
= relnum
;
888 this->r_offset_
= r_offset
;
892 expect_tls_get_addr_call()
893 { this->tls_get_addr_
= EXPECTED
; }
896 skip_next_tls_get_addr_call()
897 {this->tls_get_addr_
= SKIP
; }
900 maybe_skip_tls_get_addr_call(unsigned int r_type
, const Symbol
* gsym
)
902 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
903 || r_type
== elfcpp::R_PPC_PLTREL24
)
905 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
906 Tls_get_addr last_tls
= this->tls_get_addr_
;
907 this->tls_get_addr_
= NOT_EXPECTED
;
908 if (is_tls_call
&& last_tls
!= EXPECTED
)
910 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
919 // What we're up to regarding calls to __tls_get_addr.
920 // On powerpc, the branch and link insn making a call to
921 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
922 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
923 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
924 // The marker relocation always comes first, and has the same
925 // symbol as the reloc on the insn setting up the __tls_get_addr
926 // argument. This ties the arg setup insn with the call insn,
927 // allowing ld to safely optimize away the call. We check that
928 // every call to __tls_get_addr has a marker relocation, and that
929 // every marker relocation is on a call to __tls_get_addr.
930 Tls_get_addr tls_get_addr_
;
931 // Info about the last reloc for error message.
932 const Relocate_info
<size
, big_endian
>* relinfo_
;
937 // The class which scans relocations.
938 class Scan
: protected Track_tls
941 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
944 : Track_tls(), issued_non_pic_error_(false)
948 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
951 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
952 Sized_relobj_file
<size
, big_endian
>* object
,
953 unsigned int data_shndx
,
954 Output_section
* output_section
,
955 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
956 const elfcpp::Sym
<size
, big_endian
>& lsym
,
960 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
961 Sized_relobj_file
<size
, big_endian
>* object
,
962 unsigned int data_shndx
,
963 Output_section
* output_section
,
964 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
968 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
970 Sized_relobj_file
<size
, big_endian
>* relobj
,
973 const elfcpp::Rela
<size
, big_endian
>& ,
975 const elfcpp::Sym
<size
, big_endian
>&)
977 // PowerPC64 .opd is not folded, so any identical function text
978 // may be folded and we'll still keep function addresses distinct.
979 // That means no reloc is of concern here.
982 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
983 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
984 if (ppcobj
->abiversion() == 1)
987 // For 32-bit and ELFv2, conservatively assume anything but calls to
988 // function code might be taking the address of the function.
989 return !is_branch_reloc(r_type
);
993 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
995 Sized_relobj_file
<size
, big_endian
>* relobj
,
998 const elfcpp::Rela
<size
, big_endian
>& ,
1005 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1006 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1007 if (ppcobj
->abiversion() == 1)
1010 return !is_branch_reloc(r_type
);
1014 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1015 Sized_relobj_file
<size
, big_endian
>* object
,
1016 unsigned int r_type
, bool report_err
);
1020 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1021 unsigned int r_type
);
1024 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1025 unsigned int r_type
, Symbol
*);
1028 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1029 Target_powerpc
* target
);
1032 check_non_pic(Relobj
*, unsigned int r_type
);
1034 // Whether we have issued an error about a non-PIC compilation.
1035 bool issued_non_pic_error_
;
1039 symval_for_branch(const Symbol_table
* symtab
,
1040 const Sized_symbol
<size
>* gsym
,
1041 Powerpc_relobj
<size
, big_endian
>* object
,
1042 Address
*value
, unsigned int *dest_shndx
);
1044 // The class which implements relocation.
1045 class Relocate
: protected Track_tls
1048 // Use 'at' branch hints when true, 'y' when false.
1049 // FIXME maybe: set this with an option.
1050 static const bool is_isa_v2
= true;
1056 // Do a relocation. Return false if the caller should not issue
1057 // any warnings about this relocation.
1059 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
1060 Output_section
*, size_t relnum
,
1061 const elfcpp::Rela
<size
, big_endian
>&,
1062 unsigned int r_type
, const Sized_symbol
<size
>*,
1063 const Symbol_value
<size
>*,
1065 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1069 class Relocate_comdat_behavior
1072 // Decide what the linker should do for relocations that refer to
1073 // discarded comdat sections.
1074 inline Comdat_behavior
1075 get(const char* name
)
1077 gold::Default_comdat_behavior default_behavior
;
1078 Comdat_behavior ret
= default_behavior
.get(name
);
1079 if (ret
== CB_WARNING
)
1082 && (strcmp(name
, ".fixup") == 0
1083 || strcmp(name
, ".got2") == 0))
1086 && (strcmp(name
, ".opd") == 0
1087 || strcmp(name
, ".toc") == 0
1088 || strcmp(name
, ".toc1") == 0))
1095 // A class which returns the size required for a relocation type,
1096 // used while scanning relocs during a relocatable link.
1097 class Relocatable_size_for_reloc
1101 get_size_for_reloc(unsigned int, Relobj
*)
1108 // Optimize the TLS relocation type based on what we know about the
1109 // symbol. IS_FINAL is true if the final address of this symbol is
1110 // known at link time.
1112 tls::Tls_optimization
1113 optimize_tls_gd(bool is_final
)
1115 // If we are generating a shared library, then we can't do anything
1117 if (parameters
->options().shared())
1118 return tls::TLSOPT_NONE
;
1121 return tls::TLSOPT_TO_IE
;
1122 return tls::TLSOPT_TO_LE
;
1125 tls::Tls_optimization
1128 if (parameters
->options().shared())
1129 return tls::TLSOPT_NONE
;
1131 return tls::TLSOPT_TO_LE
;
1134 tls::Tls_optimization
1135 optimize_tls_ie(bool is_final
)
1137 if (!is_final
|| parameters
->options().shared())
1138 return tls::TLSOPT_NONE
;
1140 return tls::TLSOPT_TO_LE
;
1145 make_glink_section(Layout
*);
1147 // Create the PLT section.
1149 make_plt_section(Symbol_table
*, Layout
*);
1152 make_iplt_section(Symbol_table
*, Layout
*);
1155 make_brlt_section(Layout
*);
1157 // Create a PLT entry for a global symbol.
1159 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1161 // Create a PLT entry for a local IFUNC symbol.
1163 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1164 Sized_relobj_file
<size
, big_endian
>*,
1168 // Create a GOT entry for local dynamic __tls_get_addr.
1170 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1171 Sized_relobj_file
<size
, big_endian
>* object
);
1174 tlsld_got_offset() const
1176 return this->tlsld_got_offset_
;
1179 // Get the dynamic reloc section, creating it if necessary.
1181 rela_dyn_section(Layout
*);
1183 // Similarly, but for ifunc symbols get the one for ifunc.
1185 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1187 // Copy a relocation against a global symbol.
1189 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1190 Sized_relobj_file
<size
, big_endian
>* object
,
1191 unsigned int shndx
, Output_section
* output_section
,
1192 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1194 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1195 symtab
->get_sized_symbol
<size
>(sym
),
1196 object
, shndx
, output_section
,
1197 reloc
, this->rela_dyn_section(layout
));
1200 // Look over all the input sections, deciding where to place stubs.
1202 group_sections(Layout
*, const Task
*, bool);
1204 // Sort output sections by address.
1205 struct Sort_sections
1208 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1209 { return sec1
->address() < sec2
->address(); }
1215 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1216 unsigned int data_shndx
,
1218 unsigned int r_type
,
1221 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1222 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
1228 // If this branch needs a plt call stub, or a long branch stub, make one.
1230 make_stub(Stub_table
<size
, big_endian
>*,
1231 Stub_table
<size
, big_endian
>*,
1232 Symbol_table
*) const;
1235 // The branch location..
1236 Powerpc_relobj
<size
, big_endian
>* object_
;
1237 unsigned int shndx_
;
1239 // ..and the branch type and destination.
1240 unsigned int r_type_
;
1241 unsigned int r_sym_
;
1245 // Information about this specific target which we pass to the
1246 // general Target structure.
1247 static Target::Target_info powerpc_info
;
1249 // The types of GOT entries needed for this platform.
1250 // These values are exposed to the ABI in an incremental link.
1251 // Do not renumber existing values without changing the version
1252 // number of the .gnu_incremental_inputs section.
1256 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1257 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1258 GOT_TYPE_TPREL
// entry for @got@tprel
1262 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1263 // The PLT section. This is a container for a table of addresses,
1264 // and their relocations. Each address in the PLT has a dynamic
1265 // relocation (R_*_JMP_SLOT) and each address will have a
1266 // corresponding entry in .glink for lazy resolution of the PLT.
1267 // ppc32 initialises the PLT to point at the .glink entry, while
1268 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1269 // linker adds a stub that loads the PLT entry into ctr then
1270 // branches to ctr. There may be more than one stub for each PLT
1271 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1272 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1273 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1274 // The IPLT section. Like plt_, this is a container for a table of
1275 // addresses and their relocations, specifically for STT_GNU_IFUNC
1276 // functions that resolve locally (STT_GNU_IFUNC functions that
1277 // don't resolve locally go in PLT). Unlike plt_, these have no
1278 // entry in .glink for lazy resolution, and the relocation section
1279 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1280 // the relocation section may contain relocations against
1281 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1282 // relocation section will appear at the end of other dynamic
1283 // relocations, so that ld.so applies these relocations after other
1284 // dynamic relocations. In a static executable, the relocation
1285 // section is emitted and marked with __rela_iplt_start and
1286 // __rela_iplt_end symbols.
1287 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1288 // Section holding long branch destinations.
1289 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1290 // The .glink section.
1291 Output_data_glink
<size
, big_endian
>* glink_
;
1292 // The dynamic reloc section.
1293 Reloc_section
* rela_dyn_
;
1294 // Relocs saved to avoid a COPY reloc.
1295 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1296 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1297 unsigned int tlsld_got_offset_
;
1299 Stub_tables stub_tables_
;
1300 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1301 Branch_lookup_table branch_lookup_table_
;
1303 typedef std::vector
<Branch_info
> Branches
;
1304 Branches branch_info_
;
1306 bool plt_thread_safe_
;
1309 int relax_fail_count_
;
1310 int32_t stub_group_size_
;
1314 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1317 true, // is_big_endian
1318 elfcpp::EM_PPC
, // machine_code
1319 false, // has_make_symbol
1320 false, // has_resolve
1321 false, // has_code_fill
1322 true, // is_default_stack_executable
1323 false, // can_icf_inline_merge_sections
1325 "/usr/lib/ld.so.1", // dynamic_linker
1326 0x10000000, // default_text_segment_address
1327 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1328 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1329 false, // isolate_execinstr
1331 elfcpp::SHN_UNDEF
, // small_common_shndx
1332 elfcpp::SHN_UNDEF
, // large_common_shndx
1333 0, // small_common_section_flags
1334 0, // large_common_section_flags
1335 NULL
, // attributes_section
1336 NULL
, // attributes_vendor
1337 "_start" // entry_symbol_name
1341 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1344 false, // is_big_endian
1345 elfcpp::EM_PPC
, // machine_code
1346 false, // has_make_symbol
1347 false, // has_resolve
1348 false, // has_code_fill
1349 true, // is_default_stack_executable
1350 false, // can_icf_inline_merge_sections
1352 "/usr/lib/ld.so.1", // dynamic_linker
1353 0x10000000, // default_text_segment_address
1354 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1355 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1356 false, // isolate_execinstr
1358 elfcpp::SHN_UNDEF
, // small_common_shndx
1359 elfcpp::SHN_UNDEF
, // large_common_shndx
1360 0, // small_common_section_flags
1361 0, // large_common_section_flags
1362 NULL
, // attributes_section
1363 NULL
, // attributes_vendor
1364 "_start" // entry_symbol_name
1368 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1371 true, // is_big_endian
1372 elfcpp::EM_PPC64
, // machine_code
1373 false, // has_make_symbol
1374 false, // has_resolve
1375 false, // has_code_fill
1376 true, // is_default_stack_executable
1377 false, // can_icf_inline_merge_sections
1379 "/usr/lib/ld.so.1", // dynamic_linker
1380 0x10000000, // default_text_segment_address
1381 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1382 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1383 false, // isolate_execinstr
1385 elfcpp::SHN_UNDEF
, // small_common_shndx
1386 elfcpp::SHN_UNDEF
, // large_common_shndx
1387 0, // small_common_section_flags
1388 0, // large_common_section_flags
1389 NULL
, // attributes_section
1390 NULL
, // attributes_vendor
1391 "_start" // entry_symbol_name
1395 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1398 false, // is_big_endian
1399 elfcpp::EM_PPC64
, // machine_code
1400 false, // has_make_symbol
1401 false, // has_resolve
1402 false, // has_code_fill
1403 true, // is_default_stack_executable
1404 false, // can_icf_inline_merge_sections
1406 "/usr/lib/ld.so.1", // dynamic_linker
1407 0x10000000, // default_text_segment_address
1408 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1409 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1410 false, // isolate_execinstr
1412 elfcpp::SHN_UNDEF
, // small_common_shndx
1413 elfcpp::SHN_UNDEF
, // large_common_shndx
1414 0, // small_common_section_flags
1415 0, // large_common_section_flags
1416 NULL
, // attributes_section
1417 NULL
, // attributes_vendor
1418 "_start" // entry_symbol_name
1422 is_branch_reloc(unsigned int r_type
)
1424 return (r_type
== elfcpp::R_POWERPC_REL24
1425 || r_type
== elfcpp::R_PPC_PLTREL24
1426 || r_type
== elfcpp::R_PPC_LOCAL24PC
1427 || r_type
== elfcpp::R_POWERPC_REL14
1428 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1429 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1430 || r_type
== elfcpp::R_POWERPC_ADDR24
1431 || r_type
== elfcpp::R_POWERPC_ADDR14
1432 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1433 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1436 // If INSN is an opcode that may be used with an @tls operand, return
1437 // the transformed insn for TLS optimisation, otherwise return 0. If
1438 // REG is non-zero only match an insn with RB or RA equal to REG.
1440 at_tls_transform(uint32_t insn
, unsigned int reg
)
1442 if ((insn
& (0x3f << 26)) != 31 << 26)
1446 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1447 rtra
= insn
& ((1 << 26) - (1 << 16));
1448 else if (((insn
>> 16) & 0x1f) == reg
)
1449 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1453 if ((insn
& (0x3ff << 1)) == 266 << 1)
1456 else if ((insn
& (0x1f << 1)) == 23 << 1
1457 && ((insn
& (0x1f << 6)) < 14 << 6
1458 || ((insn
& (0x1f << 6)) >= 16 << 6
1459 && (insn
& (0x1f << 6)) < 24 << 6)))
1460 // load and store indexed -> dform
1461 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1462 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1463 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1464 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1465 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1467 insn
= (58 << 26) | 2;
1475 template<int size
, bool big_endian
>
1476 class Powerpc_relocate_functions
1496 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1497 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1499 template<int valsize
>
1501 has_overflow_signed(Address value
)
1503 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1504 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1505 limit
<<= ((valsize
- 1) >> 1);
1506 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1507 return value
+ limit
> (limit
<< 1) - 1;
1510 template<int valsize
>
1512 has_overflow_unsigned(Address value
)
1514 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1515 limit
<<= ((valsize
- 1) >> 1);
1516 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1517 return value
> (limit
<< 1) - 1;
1520 template<int valsize
>
1522 has_overflow_bitfield(Address value
)
1524 return (has_overflow_unsigned
<valsize
>(value
)
1525 && has_overflow_signed
<valsize
>(value
));
1528 template<int valsize
>
1529 static inline Status
1530 overflowed(Address value
, Overflow_check overflow
)
1532 if (overflow
== CHECK_SIGNED
)
1534 if (has_overflow_signed
<valsize
>(value
))
1535 return STATUS_OVERFLOW
;
1537 else if (overflow
== CHECK_UNSIGNED
)
1539 if (has_overflow_unsigned
<valsize
>(value
))
1540 return STATUS_OVERFLOW
;
1542 else if (overflow
== CHECK_BITFIELD
)
1544 if (has_overflow_bitfield
<valsize
>(value
))
1545 return STATUS_OVERFLOW
;
1550 // Do a simple RELA relocation
1551 template<int fieldsize
, int valsize
>
1552 static inline Status
1553 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1555 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1556 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1557 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1558 return overflowed
<valsize
>(value
, overflow
);
1561 template<int fieldsize
, int valsize
>
1562 static inline Status
1563 rela(unsigned char* view
,
1564 unsigned int right_shift
,
1565 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1567 Overflow_check overflow
)
1569 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1570 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1571 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1572 Valtype reloc
= value
>> right_shift
;
1575 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1576 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1579 // Do a simple RELA relocation, unaligned.
1580 template<int fieldsize
, int valsize
>
1581 static inline Status
1582 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1584 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
1585 return overflowed
<valsize
>(value
, overflow
);
1588 template<int fieldsize
, int valsize
>
1589 static inline Status
1590 rela_ua(unsigned char* view
,
1591 unsigned int right_shift
,
1592 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1594 Overflow_check overflow
)
1596 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
1598 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
1599 Valtype reloc
= value
>> right_shift
;
1602 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
1603 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1607 // R_PPC64_ADDR64: (Symbol + Addend)
1609 addr64(unsigned char* view
, Address value
)
1610 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
1612 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1614 addr64_u(unsigned char* view
, Address value
)
1615 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
1617 // R_POWERPC_ADDR32: (Symbol + Addend)
1618 static inline Status
1619 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1620 { return This::template rela
<32,32>(view
, value
, overflow
); }
1622 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1623 static inline Status
1624 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1625 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
1627 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1628 static inline Status
1629 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1631 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
1633 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1634 stat
= STATUS_OVERFLOW
;
1638 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1639 static inline Status
1640 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1641 { return This::template rela
<16,16>(view
, value
, overflow
); }
1643 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1644 static inline Status
1645 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1646 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
1648 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1649 static inline Status
1650 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1652 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
1653 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1654 stat
= STATUS_OVERFLOW
;
1658 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1660 addr16_hi(unsigned char* view
, Address value
)
1661 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1663 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1665 addr16_ha(unsigned char* view
, Address value
)
1666 { This::addr16_hi(view
, value
+ 0x8000); }
1668 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1670 addr16_hi2(unsigned char* view
, Address value
)
1671 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1673 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1675 addr16_ha2(unsigned char* view
, Address value
)
1676 { This::addr16_hi2(view
, value
+ 0x8000); }
1678 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1680 addr16_hi3(unsigned char* view
, Address value
)
1681 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1683 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1685 addr16_ha3(unsigned char* view
, Address value
)
1686 { This::addr16_hi3(view
, value
+ 0x8000); }
1688 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1689 static inline Status
1690 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1692 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
1693 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1694 stat
= STATUS_OVERFLOW
;
1699 // Set ABI version for input and output.
1701 template<int size
, bool big_endian
>
1703 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
1705 this->e_flags_
|= ver
;
1706 if (this->abiversion() != 0)
1708 Target_powerpc
<size
, big_endian
>* target
=
1709 static_cast<Target_powerpc
<size
, big_endian
>*>(
1710 parameters
->sized_target
<size
, big_endian
>());
1711 if (target
->abiversion() == 0)
1712 target
->set_abiversion(this->abiversion());
1713 else if (target
->abiversion() != this->abiversion())
1714 gold_error(_("%s: ABI version %d is not compatible "
1715 "with ABI version %d output"),
1716 this->name().c_str(),
1717 this->abiversion(), target
->abiversion());
1722 // Stash away the index of .got2 or .opd in a relocatable object, if
1723 // such a section exists.
1725 template<int size
, bool big_endian
>
1727 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1728 Read_symbols_data
* sd
)
1730 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1731 const unsigned char* namesu
= sd
->section_names
->data();
1732 const char* names
= reinterpret_cast<const char*>(namesu
);
1733 section_size_type names_size
= sd
->section_names_size
;
1734 const unsigned char* s
;
1736 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
1737 size
== 32 ? ".got2" : ".opd",
1738 names
, names_size
, NULL
);
1741 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1742 this->special_
= ndx
;
1745 if (this->abiversion() == 0)
1746 this->set_abiversion(1);
1747 else if (this->abiversion() > 1)
1748 gold_error(_("%s: .opd invalid in abiv%d"),
1749 this->name().c_str(), this->abiversion());
1752 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1755 // Examine .rela.opd to build info about function entry points.
1757 template<int size
, bool big_endian
>
1759 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1761 const unsigned char* prelocs
,
1762 const unsigned char* plocal_syms
)
1766 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1768 const int reloc_size
1769 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1770 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1771 Address expected_off
= 0;
1772 bool regular
= true;
1773 unsigned int opd_ent_size
= 0;
1775 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1777 Reltype
reloc(prelocs
);
1778 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1779 = reloc
.get_r_info();
1780 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1781 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1783 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1784 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1787 if (r_sym
< this->local_symbol_count())
1789 typename
elfcpp::Sym
<size
, big_endian
>
1790 lsym(plocal_syms
+ r_sym
* sym_size
);
1791 shndx
= lsym
.get_st_shndx();
1792 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1793 value
= lsym
.get_st_value();
1796 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1798 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1799 value
+ reloc
.get_r_addend());
1802 expected_off
= reloc
.get_r_offset();
1803 opd_ent_size
= expected_off
;
1805 else if (expected_off
!= reloc
.get_r_offset())
1807 expected_off
+= opd_ent_size
;
1809 else if (r_type
== elfcpp::R_PPC64_TOC
)
1811 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1816 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1817 this->name().c_str(), r_type
);
1821 if (reloc_count
<= 2)
1822 opd_ent_size
= this->section_size(this->opd_shndx());
1823 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1827 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1828 this->name().c_str());
1834 template<int size
, bool big_endian
>
1836 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1838 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1841 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1842 p
!= rd
->relocs
.end();
1845 if (p
->data_shndx
== this->opd_shndx())
1847 uint64_t opd_size
= this->section_size(this->opd_shndx());
1848 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1851 this->init_opd(opd_size
);
1852 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1853 rd
->local_symbols
->data());
1861 // Read the symbols then set up st_other vector.
1863 template<int size
, bool big_endian
>
1865 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1867 this->base_read_symbols(sd
);
1870 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1871 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1872 const unsigned int loccount
= this->do_local_symbol_count();
1875 this->st_other_
.resize(loccount
);
1876 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1877 off_t locsize
= loccount
* sym_size
;
1878 const unsigned int symtab_shndx
= this->symtab_shndx();
1879 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
1880 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
1881 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
1882 locsize
, true, false);
1884 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
1886 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
1887 unsigned char st_other
= sym
.get_st_other();
1888 this->st_other_
[i
] = st_other
;
1889 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1891 if (this->abiversion() == 0)
1892 this->set_abiversion(2);
1893 else if (this->abiversion() < 2)
1894 gold_error(_("%s: local symbol %d has invalid st_other"
1895 " for ABI version 1"),
1896 this->name().c_str(), i
);
1903 template<int size
, bool big_endian
>
1905 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
1907 this->e_flags_
|= ver
;
1908 if (this->abiversion() != 0)
1910 Target_powerpc
<size
, big_endian
>* target
=
1911 static_cast<Target_powerpc
<size
, big_endian
>*>(
1912 parameters
->sized_target
<size
, big_endian
>());
1913 if (target
->abiversion() == 0)
1914 target
->set_abiversion(this->abiversion());
1915 else if (target
->abiversion() != this->abiversion())
1916 gold_error(_("%s: ABI version %d is not compatible "
1917 "with ABI version %d output"),
1918 this->name().c_str(),
1919 this->abiversion(), target
->abiversion());
1924 // Call Sized_dynobj::base_read_symbols to read the symbols then
1925 // read .opd from a dynamic object, filling in opd_ent_ vector,
1927 template<int size
, bool big_endian
>
1929 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1931 this->base_read_symbols(sd
);
1934 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1935 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1936 const unsigned char* namesu
= sd
->section_names
->data();
1937 const char* names
= reinterpret_cast<const char*>(namesu
);
1938 const unsigned char* s
= NULL
;
1939 const unsigned char* opd
;
1940 section_size_type opd_size
;
1942 // Find and read .opd section.
1945 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
1946 sd
->section_names_size
,
1951 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1952 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1953 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
1955 if (this->abiversion() == 0)
1956 this->set_abiversion(1);
1957 else if (this->abiversion() > 1)
1958 gold_error(_("%s: .opd invalid in abiv%d"),
1959 this->name().c_str(), this->abiversion());
1961 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
1962 this->opd_address_
= shdr
.get_sh_addr();
1963 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
1964 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
1970 // Build set of executable sections.
1971 // Using a set is probably overkill. There is likely to be only
1972 // a few executable sections, typically .init, .text and .fini,
1973 // and they are generally grouped together.
1974 typedef std::set
<Sec_info
> Exec_sections
;
1975 Exec_sections exec_sections
;
1977 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
1979 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1980 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1981 && ((shdr
.get_sh_flags()
1982 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
1983 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
1984 && shdr
.get_sh_size() != 0)
1986 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
1987 shdr
.get_sh_size(), i
));
1990 if (exec_sections
.empty())
1993 // Look over the OPD entries. This is complicated by the fact
1994 // that some binaries will use two-word entries while others
1995 // will use the standard three-word entries. In most cases
1996 // the third word (the environment pointer for languages like
1997 // Pascal) is unused and will be zero. If the third word is
1998 // used it should not be pointing into executable sections,
2000 this->init_opd(opd_size
);
2001 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2003 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2004 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2005 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2007 // Chances are that this is the third word of an OPD entry.
2009 typename
Exec_sections::const_iterator e
2010 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2011 if (e
!= exec_sections
.begin())
2014 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2016 // We have an address in an executable section.
2017 // VAL ought to be the function entry, set it up.
2018 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2019 // Skip second word of OPD entry, the TOC pointer.
2023 // If we didn't match any executable sections, we likely
2024 // have a non-zero third word in the OPD entry.
2029 // Set up some symbols.
2031 template<int size
, bool big_endian
>
2033 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2034 Symbol_table
* symtab
,
2039 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2040 // undefined when scanning relocs (and thus requires
2041 // non-relative dynamic relocs). The proper value will be
2043 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2044 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2046 Target_powerpc
<size
, big_endian
>* target
=
2047 static_cast<Target_powerpc
<size
, big_endian
>*>(
2048 parameters
->sized_target
<size
, big_endian
>());
2049 Output_data_got_powerpc
<size
, big_endian
>* got
2050 = target
->got_section(symtab
, layout
);
2051 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2052 Symbol_table::PREDEFINED
,
2056 elfcpp::STV_HIDDEN
, 0,
2060 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2061 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2062 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2064 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2066 = layout
->add_output_section_data(".sdata", 0,
2068 | elfcpp::SHF_WRITE
,
2069 sdata
, ORDER_SMALL_DATA
, false);
2070 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2071 Symbol_table::PREDEFINED
,
2072 os
, 32768, 0, elfcpp::STT_OBJECT
,
2073 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2079 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2080 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2081 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2083 Target_powerpc
<size
, big_endian
>* target
=
2084 static_cast<Target_powerpc
<size
, big_endian
>*>(
2085 parameters
->sized_target
<size
, big_endian
>());
2086 Output_data_got_powerpc
<size
, big_endian
>* got
2087 = target
->got_section(symtab
, layout
);
2088 symtab
->define_in_output_data(".TOC.", NULL
,
2089 Symbol_table::PREDEFINED
,
2093 elfcpp::STV_HIDDEN
, 0,
2099 // Set up PowerPC target specific relobj.
2101 template<int size
, bool big_endian
>
2103 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2104 const std::string
& name
,
2105 Input_file
* input_file
,
2106 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2108 int et
= ehdr
.get_e_type();
2109 // ET_EXEC files are valid input for --just-symbols/-R,
2110 // and we treat them as relocatable objects.
2111 if (et
== elfcpp::ET_REL
2112 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2114 Powerpc_relobj
<size
, big_endian
>* obj
=
2115 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2119 else if (et
== elfcpp::ET_DYN
)
2121 Powerpc_dynobj
<size
, big_endian
>* obj
=
2122 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2128 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2133 template<int size
, bool big_endian
>
2134 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2137 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2138 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2140 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2141 : Output_data_got
<size
, big_endian
>(),
2142 symtab_(symtab
), layout_(layout
),
2143 header_ent_cnt_(size
== 32 ? 3 : 1),
2144 header_index_(size
== 32 ? 0x2000 : 0)
2147 // Override all the Output_data_got methods we use so as to first call
2150 add_global(Symbol
* gsym
, unsigned int got_type
)
2152 this->reserve_ent();
2153 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2157 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2159 this->reserve_ent();
2160 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2164 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2165 { return this->add_global_plt(gsym
, got_type
); }
2168 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2169 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2171 this->reserve_ent();
2172 Output_data_got
<size
, big_endian
>::
2173 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2177 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2178 Output_data_reloc_generic
* rel_dyn
,
2179 unsigned int r_type_1
, unsigned int r_type_2
)
2181 this->reserve_ent(2);
2182 Output_data_got
<size
, big_endian
>::
2183 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2187 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2189 this->reserve_ent();
2190 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2195 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2197 this->reserve_ent();
2198 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2203 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2204 { return this->add_local_plt(object
, sym_index
, got_type
); }
2207 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2208 unsigned int got_type
,
2209 Output_data_reloc_generic
* rel_dyn
,
2210 unsigned int r_type
)
2212 this->reserve_ent(2);
2213 Output_data_got
<size
, big_endian
>::
2214 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2218 add_constant(Valtype constant
)
2220 this->reserve_ent();
2221 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2225 add_constant_pair(Valtype c1
, Valtype c2
)
2227 this->reserve_ent(2);
2228 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2231 // Offset of _GLOBAL_OFFSET_TABLE_.
2235 return this->got_offset(this->header_index_
);
2238 // Offset of base used to access the GOT/TOC.
2239 // The got/toc pointer reg will be set to this value.
2241 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2244 return this->g_o_t();
2246 return (this->output_section()->address()
2247 + object
->toc_base_offset()
2251 // Ensure our GOT has a header.
2253 set_final_data_size()
2255 if (this->header_ent_cnt_
!= 0)
2256 this->make_header();
2257 Output_data_got
<size
, big_endian
>::set_final_data_size();
2260 // First word of GOT header needs some values that are not
2261 // handled by Output_data_got so poke them in here.
2262 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2264 do_write(Output_file
* of
)
2267 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2268 val
= this->layout_
->dynamic_section()->address();
2270 val
= this->output_section()->address() + 0x8000;
2271 this->replace_constant(this->header_index_
, val
);
2272 Output_data_got
<size
, big_endian
>::do_write(of
);
2277 reserve_ent(unsigned int cnt
= 1)
2279 if (this->header_ent_cnt_
== 0)
2281 if (this->num_entries() + cnt
> this->header_index_
)
2282 this->make_header();
2288 this->header_ent_cnt_
= 0;
2289 this->header_index_
= this->num_entries();
2292 Output_data_got
<size
, big_endian
>::add_constant(0);
2293 Output_data_got
<size
, big_endian
>::add_constant(0);
2294 Output_data_got
<size
, big_endian
>::add_constant(0);
2296 // Define _GLOBAL_OFFSET_TABLE_ at the header
2297 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2300 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2301 sym
->set_value(this->g_o_t());
2304 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2305 Symbol_table::PREDEFINED
,
2306 this, this->g_o_t(), 0,
2309 elfcpp::STV_HIDDEN
, 0,
2313 Output_data_got
<size
, big_endian
>::add_constant(0);
2316 // Stashed pointers.
2317 Symbol_table
* symtab_
;
2321 unsigned int header_ent_cnt_
;
2322 // GOT header index.
2323 unsigned int header_index_
;
2326 // Get the GOT section, creating it if necessary.
2328 template<int size
, bool big_endian
>
2329 Output_data_got_powerpc
<size
, big_endian
>*
2330 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2333 if (this->got_
== NULL
)
2335 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2338 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2340 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2341 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2342 this->got_
, ORDER_DATA
, false);
2348 // Get the dynamic reloc section, creating it if necessary.
2350 template<int size
, bool big_endian
>
2351 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2352 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2354 if (this->rela_dyn_
== NULL
)
2356 gold_assert(layout
!= NULL
);
2357 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2358 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2359 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2360 ORDER_DYNAMIC_RELOCS
, false);
2362 return this->rela_dyn_
;
2365 // Similarly, but for ifunc symbols get the one for ifunc.
2367 template<int size
, bool big_endian
>
2368 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2369 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
2374 return this->rela_dyn_section(layout
);
2376 if (this->iplt_
== NULL
)
2377 this->make_iplt_section(symtab
, layout
);
2378 return this->iplt_
->rel_plt();
2384 // Determine the stub group size. The group size is the absolute
2385 // value of the parameter --stub-group-size. If --stub-group-size
2386 // is passed a negative value, we restrict stubs to be always before
2387 // the stubbed branches.
2388 Stub_control(int32_t size
, bool no_size_errors
)
2389 : state_(NO_GROUP
), stub_group_size_(abs(size
)),
2390 stub14_group_size_(abs(size
) >> 10),
2391 stubs_always_before_branch_(size
< 0),
2392 suppress_size_errors_(no_size_errors
),
2393 group_end_addr_(0), owner_(NULL
), output_section_(NULL
)
2397 // Return true iff input section can be handled by current stub
2400 can_add_to_stub_group(Output_section
* o
,
2401 const Output_section::Input_section
* i
,
2404 const Output_section::Input_section
*
2410 { return output_section_
; }
2413 set_output_and_owner(Output_section
* o
,
2414 const Output_section::Input_section
* i
)
2416 this->output_section_
= o
;
2424 FINDING_STUB_SECTION
,
2429 uint32_t stub_group_size_
;
2430 uint32_t stub14_group_size_
;
2431 bool stubs_always_before_branch_
;
2432 bool suppress_size_errors_
;
2433 uint64_t group_end_addr_
;
2434 const Output_section::Input_section
* owner_
;
2435 Output_section
* output_section_
;
2438 // Return true iff input section can be handled by current stub
2442 Stub_control::can_add_to_stub_group(Output_section
* o
,
2443 const Output_section::Input_section
* i
,
2447 = has14
? this->stub14_group_size_
: this->stub_group_size_
;
2448 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2450 uint64_t start_addr
= o
->address();
2453 // .init and .fini sections are pasted together to form a single
2454 // function. We can't be adding stubs in the middle of the function.
2455 this_size
= o
->data_size();
2458 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2459 this_size
= i
->data_size();
2461 uint64_t end_addr
= start_addr
+ this_size
;
2462 bool toobig
= this_size
> group_size
;
2464 if (toobig
&& !this->suppress_size_errors_
)
2465 gold_warning(_("%s:%s exceeds group size"),
2466 i
->relobj()->name().c_str(),
2467 i
->relobj()->section_name(i
->shndx()).c_str());
2469 if (this->state_
!= HAS_STUB_SECTION
2470 && (!whole_sec
|| this->output_section_
!= o
)
2471 && (this->state_
== NO_GROUP
2472 || this->group_end_addr_
- end_addr
< group_size
))
2475 this->output_section_
= o
;
2478 if (this->state_
== NO_GROUP
)
2480 this->state_
= FINDING_STUB_SECTION
;
2481 this->group_end_addr_
= end_addr
;
2483 else if (this->group_end_addr_
- start_addr
< group_size
)
2485 // Adding this section would make the group larger than GROUP_SIZE.
2486 else if (this->state_
== FINDING_STUB_SECTION
2487 && !this->stubs_always_before_branch_
2490 // But wait, there's more! Input sections up to GROUP_SIZE
2491 // bytes before the stub table can be handled by it too.
2492 this->state_
= HAS_STUB_SECTION
;
2493 this->group_end_addr_
= end_addr
;
2497 this->state_
= NO_GROUP
;
2503 // Look over all the input sections, deciding where to place stubs.
2505 template<int size
, bool big_endian
>
2507 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
2509 bool no_size_errors
)
2511 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
);
2513 // Group input sections and insert stub table
2514 Stub_table_owner
* table_owner
= NULL
;
2515 std::vector
<Stub_table_owner
*> tables
;
2516 Layout::Section_list section_list
;
2517 layout
->get_executable_sections(§ion_list
);
2518 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
2519 for (Layout::Section_list::reverse_iterator o
= section_list
.rbegin();
2520 o
!= section_list
.rend();
2523 typedef Output_section::Input_section_list Input_section_list
;
2524 for (Input_section_list::const_reverse_iterator i
2525 = (*o
)->input_sections().rbegin();
2526 i
!= (*o
)->input_sections().rend();
2529 if (i
->is_input_section()
2530 || i
->is_relaxed_input_section())
2532 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2533 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2534 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
2535 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
2537 table_owner
->output_section
= stub_control
.output_section();
2538 table_owner
->owner
= stub_control
.owner();
2539 stub_control
.set_output_and_owner(*o
, &*i
);
2542 if (table_owner
== NULL
)
2544 table_owner
= new Stub_table_owner
;
2545 tables
.push_back(table_owner
);
2547 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2551 if (table_owner
!= NULL
)
2553 const Output_section::Input_section
* i
= stub_control
.owner();
2555 if (tables
.size() >= 2 && tables
[tables
.size() - 2]->owner
== i
)
2557 // Corner case. A new stub group was made for the first
2558 // section (last one looked at here) for some reason, but
2559 // the first section is already being used as the owner for
2560 // a stub table for following sections. Force it into that
2564 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2565 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2566 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2570 table_owner
->output_section
= stub_control
.output_section();
2571 table_owner
->owner
= i
;
2574 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
2578 Stub_table
<size
, big_endian
>* stub_table
;
2580 if ((*t
)->owner
->is_input_section())
2581 stub_table
= new Stub_table
<size
, big_endian
>(this,
2582 (*t
)->output_section
,
2584 else if ((*t
)->owner
->is_relaxed_input_section())
2585 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
2586 (*t
)->owner
->relaxed_input_section());
2589 this->stub_tables_
.push_back(stub_table
);
2594 static unsigned long
2595 max_branch_delta (unsigned int r_type
)
2597 if (r_type
== elfcpp::R_POWERPC_REL14
2598 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
2599 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2601 if (r_type
== elfcpp::R_POWERPC_REL24
2602 || r_type
== elfcpp::R_PPC_PLTREL24
2603 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
2608 // If this branch needs a plt call stub, or a long branch stub, make one.
2610 template<int size
, bool big_endian
>
2612 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
2613 Stub_table
<size
, big_endian
>* stub_table
,
2614 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
2615 Symbol_table
* symtab
) const
2617 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
2618 if (sym
!= NULL
&& sym
->is_forwarder())
2619 sym
= symtab
->resolve_forwards(sym
);
2620 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
2621 Target_powerpc
<size
, big_endian
>* target
=
2622 static_cast<Target_powerpc
<size
, big_endian
>*>(
2623 parameters
->sized_target
<size
, big_endian
>());
2625 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
2626 : this->object_
->local_has_plt_offset(this->r_sym_
))
2630 && target
->abiversion() >= 2
2631 && !parameters
->options().output_is_position_independent()
2632 && !is_branch_reloc(this->r_type_
))
2633 target
->glink_section()->add_global_entry(gsym
);
2636 if (stub_table
== NULL
)
2637 stub_table
= this->object_
->stub_table(this->shndx_
);
2638 if (stub_table
== NULL
)
2640 // This is a ref from a data section to an ifunc symbol.
2641 stub_table
= ifunc_stub_table
;
2643 gold_assert(stub_table
!= NULL
);
2644 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2645 if (from
!= invalid_address
)
2646 from
+= (this->object_
->output_section(this->shndx_
)->address()
2649 return stub_table
->add_plt_call_entry(from
,
2650 this->object_
, gsym
,
2651 this->r_type_
, this->addend_
);
2653 return stub_table
->add_plt_call_entry(from
,
2654 this->object_
, this->r_sym_
,
2655 this->r_type_
, this->addend_
);
2660 Address max_branch_offset
= max_branch_delta(this->r_type_
);
2661 if (max_branch_offset
== 0)
2663 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2664 gold_assert(from
!= invalid_address
);
2665 from
+= (this->object_
->output_section(this->shndx_
)->address()
2670 switch (gsym
->source())
2672 case Symbol::FROM_OBJECT
:
2674 Object
* symobj
= gsym
->object();
2675 if (symobj
->is_dynamic()
2676 || symobj
->pluginobj() != NULL
)
2679 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2680 if (shndx
== elfcpp::SHN_UNDEF
)
2685 case Symbol::IS_UNDEFINED
:
2691 Symbol_table::Compute_final_value_status status
;
2692 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2693 if (status
!= Symbol_table::CFVS_OK
)
2696 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
2700 const Symbol_value
<size
>* psymval
2701 = this->object_
->local_symbol(this->r_sym_
);
2702 Symbol_value
<size
> symval
;
2703 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2704 typename
ObjType::Compute_final_local_value_status status
2705 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2707 if (status
!= ObjType::CFLV_OK
2708 || !symval
.has_output_value())
2710 to
= symval
.value(this->object_
, 0);
2712 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
2714 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
2715 to
+= this->addend_
;
2716 if (stub_table
== NULL
)
2717 stub_table
= this->object_
->stub_table(this->shndx_
);
2718 if (size
== 64 && target
->abiversion() < 2)
2720 unsigned int dest_shndx
;
2721 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
2725 Address delta
= to
- from
;
2726 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2728 if (stub_table
== NULL
)
2730 gold_warning(_("%s:%s: branch in non-executable section,"
2731 " no long branch stub for you"),
2732 this->object_
->name().c_str(),
2733 this->object_
->section_name(this->shndx_
).c_str());
2736 return stub_table
->add_long_branch_entry(this->object_
,
2737 this->r_type_
, from
, to
);
2743 // Relaxation hook. This is where we do stub generation.
2745 template<int size
, bool big_endian
>
2747 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2748 const Input_objects
*,
2749 Symbol_table
* symtab
,
2753 unsigned int prev_brlt_size
= 0;
2757 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
2759 && this->abiversion() < 2
2761 && !parameters
->options().user_set_plt_thread_safe())
2763 static const char* const thread_starter
[] =
2767 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2769 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2770 "mq_notify", "create_timer",
2775 "GOMP_parallel_start",
2776 "GOMP_parallel_loop_static",
2777 "GOMP_parallel_loop_static_start",
2778 "GOMP_parallel_loop_dynamic",
2779 "GOMP_parallel_loop_dynamic_start",
2780 "GOMP_parallel_loop_guided",
2781 "GOMP_parallel_loop_guided_start",
2782 "GOMP_parallel_loop_runtime",
2783 "GOMP_parallel_loop_runtime_start",
2784 "GOMP_parallel_sections",
2785 "GOMP_parallel_sections_start",
2790 if (parameters
->options().shared())
2794 for (unsigned int i
= 0;
2795 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2798 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2799 thread_safe
= (sym
!= NULL
2801 && sym
->in_real_elf());
2807 this->plt_thread_safe_
= thread_safe
;
2812 this->stub_group_size_
= parameters
->options().stub_group_size();
2813 bool no_size_errors
= true;
2814 if (this->stub_group_size_
== 1)
2815 this->stub_group_size_
= 0x1c00000;
2816 else if (this->stub_group_size_
== -1)
2817 this->stub_group_size_
= -0x1e00000;
2819 no_size_errors
= false;
2820 this->group_sections(layout
, task
, no_size_errors
);
2822 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
2824 this->branch_lookup_table_
.clear();
2825 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2826 p
!= this->stub_tables_
.end();
2829 (*p
)->clear_stubs(true);
2831 this->stub_tables_
.clear();
2832 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
2833 gold_info(_("%s: stub group size is too large; retrying with %d"),
2834 program_name
, this->stub_group_size_
);
2835 this->group_sections(layout
, task
, true);
2838 // We need address of stub tables valid for make_stub.
2839 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2840 p
!= this->stub_tables_
.end();
2843 const Powerpc_relobj
<size
, big_endian
>* object
2844 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2845 Address off
= object
->get_output_section_offset((*p
)->shndx());
2846 gold_assert(off
!= invalid_address
);
2847 Output_section
* os
= (*p
)->output_section();
2848 (*p
)->set_address_and_size(os
, off
);
2853 // Clear plt call stubs, long branch stubs and branch lookup table.
2854 prev_brlt_size
= this->branch_lookup_table_
.size();
2855 this->branch_lookup_table_
.clear();
2856 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2857 p
!= this->stub_tables_
.end();
2860 (*p
)->clear_stubs(false);
2864 // Build all the stubs.
2865 this->relax_failed_
= false;
2866 Stub_table
<size
, big_endian
>* ifunc_stub_table
2867 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2868 Stub_table
<size
, big_endian
>* one_stub_table
2869 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2870 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2871 b
!= this->branch_info_
.end();
2874 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
2875 && !this->relax_failed_
)
2877 this->relax_failed_
= true;
2878 this->relax_fail_count_
++;
2879 if (this->relax_fail_count_
< 3)
2884 // Did anything change size?
2885 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2886 bool again
= num_huge_branches
!= prev_brlt_size
;
2887 if (size
== 64 && num_huge_branches
!= 0)
2888 this->make_brlt_section(layout
);
2889 if (size
== 64 && again
)
2890 this->brlt_section_
->set_current_size(num_huge_branches
);
2892 typedef Unordered_set
<Output_section
*> Output_sections
;
2893 Output_sections os_need_update
;
2894 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2895 p
!= this->stub_tables_
.end();
2898 if ((*p
)->size_update())
2901 (*p
)->add_eh_frame(layout
);
2902 os_need_update
.insert((*p
)->output_section());
2906 // Set output section offsets for all input sections in an output
2907 // section that just changed size. Anything past the stubs will
2909 for (typename
Output_sections::iterator p
= os_need_update
.begin();
2910 p
!= os_need_update
.end();
2913 Output_section
* os
= *p
;
2915 typedef Output_section::Input_section_list Input_section_list
;
2916 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
2917 i
!= os
->input_sections().end();
2920 off
= align_address(off
, i
->addralign());
2921 if (i
->is_input_section() || i
->is_relaxed_input_section())
2922 i
->relobj()->set_section_offset(i
->shndx(), off
);
2923 if (i
->is_relaxed_input_section())
2925 Stub_table
<size
, big_endian
>* stub_table
2926 = static_cast<Stub_table
<size
, big_endian
>*>(
2927 i
->relaxed_input_section());
2928 off
+= stub_table
->set_address_and_size(os
, off
);
2931 off
+= i
->data_size();
2933 // If .branch_lt is part of this output section, then we have
2934 // just done the offset adjustment.
2935 os
->clear_section_offsets_need_adjustment();
2940 && num_huge_branches
!= 0
2941 && parameters
->options().output_is_position_independent())
2943 // Fill in the BRLT relocs.
2944 this->brlt_section_
->reset_brlt_sizes();
2945 for (typename
Branch_lookup_table::const_iterator p
2946 = this->branch_lookup_table_
.begin();
2947 p
!= this->branch_lookup_table_
.end();
2950 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
2952 this->brlt_section_
->finalize_brlt_sizes();
2957 template<int size
, bool big_endian
>
2959 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
2960 unsigned char* oview
,
2964 uint64_t address
= plt
->address();
2965 off_t len
= plt
->data_size();
2967 if (plt
== this->glink_
)
2969 // See Output_data_glink::do_write() for glink contents.
2972 gold_assert(parameters
->doing_static_link());
2973 // Static linking may need stubs, to support ifunc and long
2974 // branches. We need to create an output section for
2975 // .eh_frame early in the link process, to have a place to
2976 // attach stub .eh_frame info. We also need to have
2977 // registered a CIE that matches the stub CIE. Both of
2978 // these requirements are satisfied by creating an FDE and
2979 // CIE for .glink, even though static linking will leave
2980 // .glink zero length.
2981 // ??? Hopefully generating an FDE with a zero address range
2982 // won't confuse anything that consumes .eh_frame info.
2984 else if (size
== 64)
2986 // There is one word before __glink_PLTresolve
2990 else if (parameters
->options().output_is_position_independent())
2992 // There are two FDEs for a position independent glink.
2993 // The first covers the branch table, the second
2994 // __glink_PLTresolve at the end of glink.
2995 off_t resolve_size
= this->glink_
->pltresolve_size
;
2996 if (oview
[9] == elfcpp::DW_CFA_nop
)
2997 len
-= resolve_size
;
3000 address
+= len
- resolve_size
;
3007 // Must be a stub table.
3008 const Stub_table
<size
, big_endian
>* stub_table
3009 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3010 uint64_t stub_address
= stub_table
->stub_address();
3011 len
-= stub_address
- address
;
3012 address
= stub_address
;
3015 *paddress
= address
;
3019 // A class to handle the PLT data.
3021 template<int size
, bool big_endian
>
3022 class Output_data_plt_powerpc
: public Output_section_data_build
3025 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3026 size
, big_endian
> Reloc_section
;
3028 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3029 Reloc_section
* plt_rel
,
3031 : Output_section_data_build(size
== 32 ? 4 : 8),
3037 // Add an entry to the PLT.
3042 add_ifunc_entry(Symbol
*);
3045 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3047 // Return the .rela.plt section data.
3054 // Return the number of PLT entries.
3058 if (this->current_data_size() == 0)
3060 return ((this->current_data_size() - this->first_plt_entry_offset())
3061 / this->plt_entry_size());
3066 do_adjust_output_section(Output_section
* os
)
3071 // Write to a map file.
3073 do_print_to_mapfile(Mapfile
* mapfile
) const
3074 { mapfile
->print_output_data(this, this->name_
); }
3077 // Return the offset of the first non-reserved PLT entry.
3079 first_plt_entry_offset() const
3081 // IPLT has no reserved entry.
3082 if (this->name_
[3] == 'I')
3084 return this->targ_
->first_plt_entry_offset();
3087 // Return the size of each PLT entry.
3089 plt_entry_size() const
3091 return this->targ_
->plt_entry_size();
3094 // Write out the PLT data.
3096 do_write(Output_file
*);
3098 // The reloc section.
3099 Reloc_section
* rel_
;
3100 // Allows access to .glink for do_write.
3101 Target_powerpc
<size
, big_endian
>* targ_
;
3102 // What to report in map file.
3106 // Add an entry to the PLT.
3108 template<int size
, bool big_endian
>
3110 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3112 if (!gsym
->has_plt_offset())
3114 section_size_type off
= this->current_data_size();
3116 off
+= this->first_plt_entry_offset();
3117 gsym
->set_plt_offset(off
);
3118 gsym
->set_needs_dynsym_entry();
3119 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3120 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3121 off
+= this->plt_entry_size();
3122 this->set_current_data_size(off
);
3126 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3128 template<int size
, bool big_endian
>
3130 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3132 if (!gsym
->has_plt_offset())
3134 section_size_type off
= this->current_data_size();
3135 gsym
->set_plt_offset(off
);
3136 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3137 if (size
== 64 && this->targ_
->abiversion() < 2)
3138 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3139 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3140 off
+= this->plt_entry_size();
3141 this->set_current_data_size(off
);
3145 // Add an entry for a local ifunc symbol to the IPLT.
3147 template<int size
, bool big_endian
>
3149 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
3150 Sized_relobj_file
<size
, big_endian
>* relobj
,
3151 unsigned int local_sym_index
)
3153 if (!relobj
->local_has_plt_offset(local_sym_index
))
3155 section_size_type off
= this->current_data_size();
3156 relobj
->set_local_plt_offset(local_sym_index
, off
);
3157 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3158 if (size
== 64 && this->targ_
->abiversion() < 2)
3159 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3160 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
3162 off
+= this->plt_entry_size();
3163 this->set_current_data_size(off
);
3167 static const uint32_t add_0_11_11
= 0x7c0b5a14;
3168 static const uint32_t add_2_2_11
= 0x7c425a14;
3169 static const uint32_t add_3_3_2
= 0x7c631214;
3170 static const uint32_t add_3_3_13
= 0x7c636a14;
3171 static const uint32_t add_11_0_11
= 0x7d605a14;
3172 static const uint32_t add_11_2_11
= 0x7d625a14;
3173 static const uint32_t add_11_11_2
= 0x7d6b1214;
3174 static const uint32_t addi_0_12
= 0x380c0000;
3175 static const uint32_t addi_2_2
= 0x38420000;
3176 static const uint32_t addi_3_3
= 0x38630000;
3177 static const uint32_t addi_11_11
= 0x396b0000;
3178 static const uint32_t addi_12_12
= 0x398c0000;
3179 static const uint32_t addis_0_2
= 0x3c020000;
3180 static const uint32_t addis_0_13
= 0x3c0d0000;
3181 static const uint32_t addis_3_2
= 0x3c620000;
3182 static const uint32_t addis_3_13
= 0x3c6d0000;
3183 static const uint32_t addis_11_2
= 0x3d620000;
3184 static const uint32_t addis_11_11
= 0x3d6b0000;
3185 static const uint32_t addis_11_30
= 0x3d7e0000;
3186 static const uint32_t addis_12_2
= 0x3d820000;
3187 static const uint32_t addis_12_12
= 0x3d8c0000;
3188 static const uint32_t b
= 0x48000000;
3189 static const uint32_t bcl_20_31
= 0x429f0005;
3190 static const uint32_t bctr
= 0x4e800420;
3191 static const uint32_t blr
= 0x4e800020;
3192 static const uint32_t bnectr_p4
= 0x4ce20420;
3193 static const uint32_t cmpldi_2_0
= 0x28220000;
3194 static const uint32_t cror_15_15_15
= 0x4def7b82;
3195 static const uint32_t cror_31_31_31
= 0x4ffffb82;
3196 static const uint32_t ld_0_1
= 0xe8010000;
3197 static const uint32_t ld_0_12
= 0xe80c0000;
3198 static const uint32_t ld_2_1
= 0xe8410000;
3199 static const uint32_t ld_2_2
= 0xe8420000;
3200 static const uint32_t ld_2_11
= 0xe84b0000;
3201 static const uint32_t ld_11_2
= 0xe9620000;
3202 static const uint32_t ld_11_11
= 0xe96b0000;
3203 static const uint32_t ld_12_2
= 0xe9820000;
3204 static const uint32_t ld_12_11
= 0xe98b0000;
3205 static const uint32_t ld_12_12
= 0xe98c0000;
3206 static const uint32_t lfd_0_1
= 0xc8010000;
3207 static const uint32_t li_0_0
= 0x38000000;
3208 static const uint32_t li_12_0
= 0x39800000;
3209 static const uint32_t lis_0_0
= 0x3c000000;
3210 static const uint32_t lis_11
= 0x3d600000;
3211 static const uint32_t lis_12
= 0x3d800000;
3212 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
3213 static const uint32_t lwz_0_12
= 0x800c0000;
3214 static const uint32_t lwz_11_11
= 0x816b0000;
3215 static const uint32_t lwz_11_30
= 0x817e0000;
3216 static const uint32_t lwz_12_12
= 0x818c0000;
3217 static const uint32_t lwzu_0_12
= 0x840c0000;
3218 static const uint32_t mflr_0
= 0x7c0802a6;
3219 static const uint32_t mflr_11
= 0x7d6802a6;
3220 static const uint32_t mflr_12
= 0x7d8802a6;
3221 static const uint32_t mtctr_0
= 0x7c0903a6;
3222 static const uint32_t mtctr_11
= 0x7d6903a6;
3223 static const uint32_t mtctr_12
= 0x7d8903a6;
3224 static const uint32_t mtlr_0
= 0x7c0803a6;
3225 static const uint32_t mtlr_12
= 0x7d8803a6;
3226 static const uint32_t nop
= 0x60000000;
3227 static const uint32_t ori_0_0_0
= 0x60000000;
3228 static const uint32_t srdi_0_0_2
= 0x7800f082;
3229 static const uint32_t std_0_1
= 0xf8010000;
3230 static const uint32_t std_0_12
= 0xf80c0000;
3231 static const uint32_t std_2_1
= 0xf8410000;
3232 static const uint32_t stfd_0_1
= 0xd8010000;
3233 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
3234 static const uint32_t sub_11_11_12
= 0x7d6c5850;
3235 static const uint32_t sub_12_12_11
= 0x7d8b6050;
3236 static const uint32_t xor_2_12_12
= 0x7d826278;
3237 static const uint32_t xor_11_12_12
= 0x7d8b6278;
3239 // Write out the PLT.
3241 template<int size
, bool big_endian
>
3243 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3245 if (size
== 32 && this->name_
[3] != 'I')
3247 const section_size_type offset
= this->offset();
3248 const section_size_type oview_size
3249 = convert_to_section_size_type(this->data_size());
3250 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3251 unsigned char* pov
= oview
;
3252 unsigned char* endpov
= oview
+ oview_size
;
3254 // The address of the .glink branch table
3255 const Output_data_glink
<size
, big_endian
>* glink
3256 = this->targ_
->glink_section();
3257 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
3259 while (pov
< endpov
)
3261 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
3266 of
->write_output_view(offset
, oview_size
, oview
);
3270 // Create the PLT section.
3272 template<int size
, bool big_endian
>
3274 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
3277 if (this->plt_
== NULL
)
3279 if (this->got_
== NULL
)
3280 this->got_section(symtab
, layout
);
3282 if (this->glink_
== NULL
)
3283 make_glink_section(layout
);
3285 // Ensure that .rela.dyn always appears before .rela.plt This is
3286 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3287 // needs to include .rela.plt in its range.
3288 this->rela_dyn_section(layout
);
3290 Reloc_section
* plt_rel
= new Reloc_section(false);
3291 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
3292 elfcpp::SHF_ALLOC
, plt_rel
,
3293 ORDER_DYNAMIC_PLT_RELOCS
, false);
3295 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
3297 layout
->add_output_section_data(".plt",
3299 ? elfcpp::SHT_PROGBITS
3300 : elfcpp::SHT_NOBITS
),
3301 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3310 // Create the IPLT section.
3312 template<int size
, bool big_endian
>
3314 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
3317 if (this->iplt_
== NULL
)
3319 this->make_plt_section(symtab
, layout
);
3321 Reloc_section
* iplt_rel
= new Reloc_section(false);
3322 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
3324 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
3326 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
3330 // A section for huge long branch addresses, similar to plt section.
3332 template<int size
, bool big_endian
>
3333 class Output_data_brlt_powerpc
: public Output_section_data_build
3336 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3337 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3338 size
, big_endian
> Reloc_section
;
3340 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3341 Reloc_section
* brlt_rel
)
3342 : Output_section_data_build(size
== 32 ? 4 : 8),
3350 this->reset_data_size();
3351 this->rel_
->reset_data_size();
3355 finalize_brlt_sizes()
3357 this->finalize_data_size();
3358 this->rel_
->finalize_data_size();
3361 // Add a reloc for an entry in the BRLT.
3363 add_reloc(Address to
, unsigned int off
)
3364 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
3366 // Update section and reloc section size.
3368 set_current_size(unsigned int num_branches
)
3370 this->reset_address_and_file_offset();
3371 this->set_current_data_size(num_branches
* 16);
3372 this->finalize_data_size();
3373 Output_section
* os
= this->output_section();
3374 os
->set_section_offsets_need_adjustment();
3375 if (this->rel_
!= NULL
)
3377 unsigned int reloc_size
3378 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
3379 this->rel_
->reset_address_and_file_offset();
3380 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
3381 this->rel_
->finalize_data_size();
3382 Output_section
* os
= this->rel_
->output_section();
3383 os
->set_section_offsets_need_adjustment();
3389 do_adjust_output_section(Output_section
* os
)
3394 // Write to a map file.
3396 do_print_to_mapfile(Mapfile
* mapfile
) const
3397 { mapfile
->print_output_data(this, "** BRLT"); }
3400 // Write out the BRLT data.
3402 do_write(Output_file
*);
3404 // The reloc section.
3405 Reloc_section
* rel_
;
3406 Target_powerpc
<size
, big_endian
>* targ_
;
3409 // Make the branch lookup table section.
3411 template<int size
, bool big_endian
>
3413 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
3415 if (size
== 64 && this->brlt_section_
== NULL
)
3417 Reloc_section
* brlt_rel
= NULL
;
3418 bool is_pic
= parameters
->options().output_is_position_independent();
3421 // When PIC we can't fill in .branch_lt (like .plt it can be
3422 // a bss style section) but must initialise at runtime via
3423 // dynamic relocats.
3424 this->rela_dyn_section(layout
);
3425 brlt_rel
= new Reloc_section(false);
3426 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
3429 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
3430 if (this->plt_
&& is_pic
)
3431 this->plt_
->output_section()
3432 ->add_output_section_data(this->brlt_section_
);
3434 layout
->add_output_section_data(".branch_lt",
3435 (is_pic
? elfcpp::SHT_NOBITS
3436 : elfcpp::SHT_PROGBITS
),
3437 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3438 this->brlt_section_
,
3439 (is_pic
? ORDER_SMALL_BSS
3440 : ORDER_SMALL_DATA
),
3445 // Write out .branch_lt when non-PIC.
3447 template<int size
, bool big_endian
>
3449 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3451 if (size
== 64 && !parameters
->options().output_is_position_independent())
3453 const section_size_type offset
= this->offset();
3454 const section_size_type oview_size
3455 = convert_to_section_size_type(this->data_size());
3456 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3458 this->targ_
->write_branch_lookup_table(oview
);
3459 of
->write_output_view(offset
, oview_size
, oview
);
3463 static inline uint32_t
3469 static inline uint32_t
3475 static inline uint32_t
3478 return hi(a
+ 0x8000);
3484 static const unsigned char eh_frame_cie
[12];
3488 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
3491 'z', 'R', 0, // Augmentation string.
3492 4, // Code alignment.
3493 0x80 - size
/ 8 , // Data alignment.
3495 1, // Augmentation size.
3496 (elfcpp::DW_EH_PE_pcrel
3497 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
3498 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
3501 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
3502 static const unsigned char glink_eh_frame_fde_64v1
[] =
3504 0, 0, 0, 0, // Replaced with offset to .glink.
3505 0, 0, 0, 0, // Replaced with size of .glink.
3506 0, // Augmentation size.
3507 elfcpp::DW_CFA_advance_loc
+ 1,
3508 elfcpp::DW_CFA_register
, 65, 12,
3509 elfcpp::DW_CFA_advance_loc
+ 4,
3510 elfcpp::DW_CFA_restore_extended
, 65
3513 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
3514 static const unsigned char glink_eh_frame_fde_64v2
[] =
3516 0, 0, 0, 0, // Replaced with offset to .glink.
3517 0, 0, 0, 0, // Replaced with size of .glink.
3518 0, // Augmentation size.
3519 elfcpp::DW_CFA_advance_loc
+ 1,
3520 elfcpp::DW_CFA_register
, 65, 0,
3521 elfcpp::DW_CFA_advance_loc
+ 4,
3522 elfcpp::DW_CFA_restore_extended
, 65
3525 // Describe __glink_PLTresolve use of LR, 32-bit version.
3526 static const unsigned char glink_eh_frame_fde_32
[] =
3528 0, 0, 0, 0, // Replaced with offset to .glink.
3529 0, 0, 0, 0, // Replaced with size of .glink.
3530 0, // Augmentation size.
3531 elfcpp::DW_CFA_advance_loc
+ 2,
3532 elfcpp::DW_CFA_register
, 65, 0,
3533 elfcpp::DW_CFA_advance_loc
+ 4,
3534 elfcpp::DW_CFA_restore_extended
, 65
3537 static const unsigned char default_fde
[] =
3539 0, 0, 0, 0, // Replaced with offset to stubs.
3540 0, 0, 0, 0, // Replaced with size of stubs.
3541 0, // Augmentation size.
3542 elfcpp::DW_CFA_nop
, // Pad.
3547 template<bool big_endian
>
3549 write_insn(unsigned char* p
, uint32_t v
)
3551 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
3554 // Stub_table holds information about plt and long branch stubs.
3555 // Stubs are built in an area following some input section determined
3556 // by group_sections(). This input section is converted to a relaxed
3557 // input section allowing it to be resized to accommodate the stubs
3559 template<int size
, bool big_endian
>
3560 class Stub_table
: public Output_relaxed_input_section
3563 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3564 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3566 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
3567 Output_section
* output_section
,
3568 const Output_section::Input_section
* owner
)
3569 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
3571 ->section_addralign(owner
->shndx())),
3572 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
3573 orig_data_size_(owner
->current_data_size()),
3574 plt_size_(0), last_plt_size_(0),
3575 branch_size_(0), last_branch_size_(0), eh_frame_added_(false)
3577 this->set_output_section(output_section
);
3579 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3580 new_relaxed
.push_back(this);
3581 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3584 // Add a plt call stub.
3586 add_plt_call_entry(Address
,
3587 const Sized_relobj_file
<size
, big_endian
>*,
3593 add_plt_call_entry(Address
,
3594 const Sized_relobj_file
<size
, big_endian
>*,
3599 // Find a given plt call stub.
3601 find_plt_call_entry(const Symbol
*) const;
3604 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3605 unsigned int) const;
3608 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3614 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3619 // Add a long branch stub.
3621 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3622 unsigned int, Address
, Address
);
3625 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3629 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
3631 Address max_branch_offset
= max_branch_delta(r_type
);
3632 if (max_branch_offset
== 0)
3634 gold_assert(from
!= invalid_address
);
3635 Address loc
= off
+ this->stub_address();
3636 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
3640 clear_stubs(bool all
)
3642 this->plt_call_stubs_
.clear();
3643 this->plt_size_
= 0;
3644 this->long_branch_stubs_
.clear();
3645 this->branch_size_
= 0;
3648 this->last_plt_size_
= 0;
3649 this->last_branch_size_
= 0;
3654 set_address_and_size(const Output_section
* os
, Address off
)
3656 Address start_off
= off
;
3657 off
+= this->orig_data_size_
;
3658 Address my_size
= this->plt_size_
+ this->branch_size_
;
3660 off
= align_address(off
, this->stub_align());
3661 // Include original section size and alignment padding in size
3662 my_size
+= off
- start_off
;
3663 this->reset_address_and_file_offset();
3664 this->set_current_data_size(my_size
);
3665 this->set_address_and_file_offset(os
->address() + start_off
,
3666 os
->offset() + start_off
);
3671 stub_address() const
3673 return align_address(this->address() + this->orig_data_size_
,
3674 this->stub_align());
3680 return align_address(this->offset() + this->orig_data_size_
,
3681 this->stub_align());
3686 { return this->plt_size_
; }
3691 Output_section
* os
= this->output_section();
3692 if (os
->addralign() < this->stub_align())
3694 os
->set_addralign(this->stub_align());
3695 // FIXME: get rid of the insane checkpointing.
3696 // We can't increase alignment of the input section to which
3697 // stubs are attached; The input section may be .init which
3698 // is pasted together with other .init sections to form a
3699 // function. Aligning might insert zero padding resulting in
3700 // sigill. However we do need to increase alignment of the
3701 // output section so that the align_address() on offset in
3702 // set_address_and_size() adds the same padding as the
3703 // align_address() on address in stub_address().
3704 // What's more, we need this alignment for the layout done in
3705 // relaxation_loop_body() so that the output section starts at
3706 // a suitably aligned address.
3707 os
->checkpoint_set_addralign(this->stub_align());
3709 if (this->last_plt_size_
!= this->plt_size_
3710 || this->last_branch_size_
!= this->branch_size_
)
3712 this->last_plt_size_
= this->plt_size_
;
3713 this->last_branch_size_
= this->branch_size_
;
3719 // Add .eh_frame info for this stub section. Unlike other linker
3720 // generated .eh_frame this is added late in the link, because we
3721 // only want the .eh_frame info if this particular stub section is
3724 add_eh_frame(Layout
* layout
)
3726 if (!this->eh_frame_added_
)
3728 if (!parameters
->options().ld_generated_unwind_info())
3731 // Since we add stub .eh_frame info late, it must be placed
3732 // after all other linker generated .eh_frame info so that
3733 // merge mapping need not be updated for input sections.
3734 // There is no provision to use a different CIE to that used
3736 if (!this->targ_
->has_glink())
3739 layout
->add_eh_frame_for_plt(this,
3740 Eh_cie
<size
>::eh_frame_cie
,
3741 sizeof (Eh_cie
<size
>::eh_frame_cie
),
3743 sizeof (default_fde
));
3744 this->eh_frame_added_
= true;
3748 Target_powerpc
<size
, big_endian
>*
3754 class Plt_stub_ent_hash
;
3755 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
3756 Plt_stub_ent_hash
> Plt_stub_entries
;
3758 // Alignment of stub section.
3764 unsigned int min_align
= 32;
3765 unsigned int user_align
= 1 << parameters
->options().plt_align();
3766 return std::max(user_align
, min_align
);
3769 // Return the plt offset for the given call stub.
3771 plt_off(typename
Plt_stub_entries::const_iterator p
, bool* is_iplt
) const
3773 const Symbol
* gsym
= p
->first
.sym_
;
3776 *is_iplt
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3777 && gsym
->can_use_relative_reloc(false));
3778 return gsym
->plt_offset();
3783 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
3784 unsigned int local_sym_index
= p
->first
.locsym_
;
3785 return relobj
->local_plt_offset(local_sym_index
);
3789 // Size of a given plt call stub.
3791 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
3797 Address plt_addr
= this->plt_off(p
, &is_iplt
);
3799 plt_addr
+= this->targ_
->iplt_section()->address();
3801 plt_addr
+= this->targ_
->plt_section()->address();
3802 Address got_addr
= this->targ_
->got_section()->output_section()->address();
3803 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3804 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
3805 got_addr
+= ppcobj
->toc_base_offset();
3806 Address off
= plt_addr
- got_addr
;
3807 unsigned int bytes
= 4 * 4 + 4 * (ha(off
) != 0);
3808 if (this->targ_
->abiversion() < 2)
3810 bool static_chain
= parameters
->options().plt_static_chain();
3811 bool thread_safe
= this->targ_
->plt_thread_safe();
3815 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
3817 unsigned int align
= 1 << parameters
->options().plt_align();
3819 bytes
= (bytes
+ align
- 1) & -align
;
3823 // Return long branch stub size.
3825 branch_stub_size(Address to
)
3828 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
3829 if (to
- loc
+ (1 << 25) < 2 << 25)
3831 if (size
== 64 || !parameters
->options().output_is_position_independent())
3838 do_write(Output_file
*);
3840 // Plt call stub keys.
3844 Plt_stub_ent(const Symbol
* sym
)
3845 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3848 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3849 unsigned int locsym_index
)
3850 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3853 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3855 unsigned int r_type
,
3857 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3860 this->addend_
= addend
;
3861 else if (parameters
->options().output_is_position_independent()
3862 && r_type
== elfcpp::R_PPC_PLTREL24
)
3864 this->addend_
= addend
;
3865 if (this->addend_
>= 32768)
3866 this->object_
= object
;
3870 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3871 unsigned int locsym_index
,
3872 unsigned int r_type
,
3874 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3877 this->addend_
= addend
;
3878 else if (parameters
->options().output_is_position_independent()
3879 && r_type
== elfcpp::R_PPC_PLTREL24
)
3880 this->addend_
= addend
;
3883 bool operator==(const Plt_stub_ent
& that
) const
3885 return (this->sym_
== that
.sym_
3886 && this->object_
== that
.object_
3887 && this->addend_
== that
.addend_
3888 && this->locsym_
== that
.locsym_
);
3892 const Sized_relobj_file
<size
, big_endian
>* object_
;
3893 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
3894 unsigned int locsym_
;
3897 class Plt_stub_ent_hash
3900 size_t operator()(const Plt_stub_ent
& ent
) const
3902 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
3903 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
3909 // Long branch stub keys.
3910 class Branch_stub_ent
3913 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
3914 : dest_(to
), toc_base_off_(0)
3917 toc_base_off_
= obj
->toc_base_offset();
3920 bool operator==(const Branch_stub_ent
& that
) const
3922 return (this->dest_
== that
.dest_
3924 || this->toc_base_off_
== that
.toc_base_off_
));
3928 unsigned int toc_base_off_
;
3931 class Branch_stub_ent_hash
3934 size_t operator()(const Branch_stub_ent
& ent
) const
3935 { return ent
.dest_
^ ent
.toc_base_off_
; }
3938 // In a sane world this would be a global.
3939 Target_powerpc
<size
, big_endian
>* targ_
;
3940 // Map sym/object/addend to stub offset.
3941 Plt_stub_entries plt_call_stubs_
;
3942 // Map destination address to stub offset.
3943 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
3944 Branch_stub_ent_hash
> Branch_stub_entries
;
3945 Branch_stub_entries long_branch_stubs_
;
3946 // size of input section
3947 section_size_type orig_data_size_
;
3949 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
3950 // Whether .eh_frame info has been created for this stub section.
3951 bool eh_frame_added_
;
3954 // Add a plt call stub, if we do not already have one for this
3955 // sym/object/addend combo.
3957 template<int size
, bool big_endian
>
3959 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3961 const Sized_relobj_file
<size
, big_endian
>* object
,
3963 unsigned int r_type
,
3966 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3967 unsigned int off
= this->plt_size_
;
3968 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3969 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3971 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3972 return this->can_reach_stub(from
, off
, r_type
);
3975 template<int size
, bool big_endian
>
3977 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3979 const Sized_relobj_file
<size
, big_endian
>* object
,
3980 unsigned int locsym_index
,
3981 unsigned int r_type
,
3984 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3985 unsigned int off
= this->plt_size_
;
3986 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3987 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3989 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3990 return this->can_reach_stub(from
, off
, r_type
);
3993 // Find a plt call stub.
3995 template<int size
, bool big_endian
>
3996 typename Stub_table
<size
, big_endian
>::Address
3997 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3998 const Sized_relobj_file
<size
, big_endian
>* object
,
4000 unsigned int r_type
,
4001 Address addend
) const
4003 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4004 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4005 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4008 template<int size
, bool big_endian
>
4009 typename Stub_table
<size
, big_endian
>::Address
4010 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
4012 Plt_stub_ent
ent(gsym
);
4013 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4014 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4017 template<int size
, bool big_endian
>
4018 typename Stub_table
<size
, big_endian
>::Address
4019 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4020 const Sized_relobj_file
<size
, big_endian
>* object
,
4021 unsigned int locsym_index
,
4022 unsigned int r_type
,
4023 Address addend
) const
4025 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4026 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4027 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4030 template<int size
, bool big_endian
>
4031 typename Stub_table
<size
, big_endian
>::Address
4032 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4033 const Sized_relobj_file
<size
, big_endian
>* object
,
4034 unsigned int locsym_index
) const
4036 Plt_stub_ent
ent(object
, locsym_index
);
4037 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4038 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4041 // Add a long branch stub if we don't already have one to given
4044 template<int size
, bool big_endian
>
4046 Stub_table
<size
, big_endian
>::add_long_branch_entry(
4047 const Powerpc_relobj
<size
, big_endian
>* object
,
4048 unsigned int r_type
,
4052 Branch_stub_ent
ent(object
, to
);
4053 Address off
= this->branch_size_
;
4054 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
4056 unsigned int stub_size
= this->branch_stub_size(to
);
4057 this->branch_size_
= off
+ stub_size
;
4058 if (size
== 64 && stub_size
!= 4)
4059 this->targ_
->add_branch_lookup_table(to
);
4061 return this->can_reach_stub(from
, off
, r_type
);
4064 // Find long branch stub.
4066 template<int size
, bool big_endian
>
4067 typename Stub_table
<size
, big_endian
>::Address
4068 Stub_table
<size
, big_endian
>::find_long_branch_entry(
4069 const Powerpc_relobj
<size
, big_endian
>* object
,
4072 Branch_stub_ent
ent(object
, to
);
4073 typename
Branch_stub_entries::const_iterator p
4074 = this->long_branch_stubs_
.find(ent
);
4075 return p
== this->long_branch_stubs_
.end() ? invalid_address
: p
->second
;
4078 // A class to handle .glink.
4080 template<int size
, bool big_endian
>
4081 class Output_data_glink
: public Output_section_data
4084 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4085 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4086 static const int pltresolve_size
= 16*4;
4088 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
4089 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
4090 end_branch_table_(), ge_size_(0)
4094 add_eh_frame(Layout
* layout
);
4097 add_global_entry(const Symbol
*);
4100 find_global_entry(const Symbol
*) const;
4103 global_entry_address() const
4105 gold_assert(this->is_data_size_valid());
4106 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4107 return this->address() + global_entry_off
;
4111 // Write to a map file.
4113 do_print_to_mapfile(Mapfile
* mapfile
) const
4114 { mapfile
->print_output_data(this, _("** glink")); }
4118 set_final_data_size();
4122 do_write(Output_file
*);
4124 // Allows access to .got and .plt for do_write.
4125 Target_powerpc
<size
, big_endian
>* targ_
;
4127 // Map sym to stub offset.
4128 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
4129 Global_entry_stub_entries global_entry_stubs_
;
4131 unsigned int end_branch_table_
, ge_size_
;
4134 template<int size
, bool big_endian
>
4136 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4138 if (!parameters
->options().ld_generated_unwind_info())
4143 if (this->targ_
->abiversion() < 2)
4144 layout
->add_eh_frame_for_plt(this,
4145 Eh_cie
<64>::eh_frame_cie
,
4146 sizeof (Eh_cie
<64>::eh_frame_cie
),
4147 glink_eh_frame_fde_64v1
,
4148 sizeof (glink_eh_frame_fde_64v1
));
4150 layout
->add_eh_frame_for_plt(this,
4151 Eh_cie
<64>::eh_frame_cie
,
4152 sizeof (Eh_cie
<64>::eh_frame_cie
),
4153 glink_eh_frame_fde_64v2
,
4154 sizeof (glink_eh_frame_fde_64v2
));
4158 // 32-bit .glink can use the default since the CIE return
4159 // address reg, LR, is valid.
4160 layout
->add_eh_frame_for_plt(this,
4161 Eh_cie
<32>::eh_frame_cie
,
4162 sizeof (Eh_cie
<32>::eh_frame_cie
),
4164 sizeof (default_fde
));
4165 // Except where LR is used in a PIC __glink_PLTresolve.
4166 if (parameters
->options().output_is_position_independent())
4167 layout
->add_eh_frame_for_plt(this,
4168 Eh_cie
<32>::eh_frame_cie
,
4169 sizeof (Eh_cie
<32>::eh_frame_cie
),
4170 glink_eh_frame_fde_32
,
4171 sizeof (glink_eh_frame_fde_32
));
4175 template<int size
, bool big_endian
>
4177 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
4179 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
4180 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, this->ge_size_
));
4182 this->ge_size_
+= 16;
4185 template<int size
, bool big_endian
>
4186 typename Output_data_glink
<size
, big_endian
>::Address
4187 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
4189 typename
Global_entry_stub_entries::const_iterator p
4190 = this->global_entry_stubs_
.find(gsym
);
4191 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
4194 template<int size
, bool big_endian
>
4196 Output_data_glink
<size
, big_endian
>::set_final_data_size()
4198 unsigned int count
= this->targ_
->plt_entry_count();
4199 section_size_type total
= 0;
4205 // space for branch table
4206 total
+= 4 * (count
- 1);
4208 total
+= -total
& 15;
4209 total
+= this->pltresolve_size
;
4213 total
+= this->pltresolve_size
;
4215 // space for branch table
4217 if (this->targ_
->abiversion() < 2)
4221 total
+= 4 * (count
- 0x8000);
4225 this->end_branch_table_
= total
;
4226 total
= (total
+ 15) & -16;
4227 total
+= this->ge_size_
;
4229 this->set_data_size(total
);
4232 // Write out plt and long branch stub code.
4234 template<int size
, bool big_endian
>
4236 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
4238 if (this->plt_call_stubs_
.empty()
4239 && this->long_branch_stubs_
.empty())
4242 const section_size_type start_off
= this->offset();
4243 const section_size_type off
= this->stub_offset();
4244 const section_size_type oview_size
=
4245 convert_to_section_size_type(this->data_size() - (off
- start_off
));
4246 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4251 const Output_data_got_powerpc
<size
, big_endian
>* got
4252 = this->targ_
->got_section();
4253 Address got_os_addr
= got
->output_section()->address();
4255 if (!this->plt_call_stubs_
.empty())
4257 // The base address of the .plt section.
4258 Address plt_base
= this->targ_
->plt_section()->address();
4259 Address iplt_base
= invalid_address
;
4261 // Write out plt call stubs.
4262 typename
Plt_stub_entries::const_iterator cs
;
4263 for (cs
= this->plt_call_stubs_
.begin();
4264 cs
!= this->plt_call_stubs_
.end();
4268 Address pltoff
= this->plt_off(cs
, &is_iplt
);
4269 Address plt_addr
= pltoff
;
4272 if (iplt_base
== invalid_address
)
4273 iplt_base
= this->targ_
->iplt_section()->address();
4274 plt_addr
+= iplt_base
;
4277 plt_addr
+= plt_base
;
4278 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
4279 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
4280 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
4281 Address off
= plt_addr
- got_addr
;
4283 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
4284 gold_error(_("%s: linkage table error against `%s'"),
4285 cs
->first
.object_
->name().c_str(),
4286 cs
->first
.sym_
->demangled_name().c_str());
4288 bool plt_load_toc
= this->targ_
->abiversion() < 2;
4290 = plt_load_toc
&& parameters
->options().plt_static_chain();
4292 = plt_load_toc
&& this->targ_
->plt_thread_safe();
4293 bool use_fake_dep
= false;
4294 Address cmp_branch_off
= 0;
4297 unsigned int pltindex
4298 = ((pltoff
- this->targ_
->first_plt_entry_offset())
4299 / this->targ_
->plt_entry_size());
4301 = (this->targ_
->glink_section()->pltresolve_size
4303 if (pltindex
> 32768)
4304 glinkoff
+= (pltindex
- 32768) * 4;
4306 = this->targ_
->glink_section()->address() + glinkoff
;
4308 = (this->stub_address() + cs
->second
+ 24
4309 + 4 * (ha(off
) != 0)
4310 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4311 + 4 * static_chain
);
4312 cmp_branch_off
= to
- from
;
4313 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
4316 p
= oview
+ cs
->second
;
4319 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4323 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
4325 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
4330 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
4332 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
4336 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4338 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
4342 write_insn
<big_endian
>(p
, mtctr_12
);
4348 write_insn
<big_endian
>(p
, xor_2_12_12
);
4350 write_insn
<big_endian
>(p
, add_11_11_2
);
4353 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
4357 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
4364 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4366 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
4369 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4371 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
4375 write_insn
<big_endian
>(p
, mtctr_12
);
4381 write_insn
<big_endian
>(p
, xor_11_12_12
);
4383 write_insn
<big_endian
>(p
, add_2_2_11
);
4388 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
4391 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
4395 if (thread_safe
&& !use_fake_dep
)
4397 write_insn
<big_endian
>(p
, cmpldi_2_0
);
4399 write_insn
<big_endian
>(p
, bnectr_p4
);
4401 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
4404 write_insn
<big_endian
>(p
, bctr
);
4408 // Write out long branch stubs.
4409 typename
Branch_stub_entries::const_iterator bs
;
4410 for (bs
= this->long_branch_stubs_
.begin();
4411 bs
!= this->long_branch_stubs_
.end();
4414 p
= oview
+ this->plt_size_
+ bs
->second
;
4415 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4416 Address delta
= bs
->first
.dest_
- loc
;
4417 if (delta
+ (1 << 25) < 2 << 25)
4418 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4422 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
4423 gold_assert(brlt_addr
!= invalid_address
);
4424 brlt_addr
+= this->targ_
->brlt_section()->address();
4425 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
4426 Address brltoff
= brlt_addr
- got_addr
;
4427 if (ha(brltoff
) == 0)
4429 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
)), p
+= 4;
4433 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
4434 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
)), p
+= 4;
4436 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4437 write_insn
<big_endian
>(p
, bctr
);
4443 if (!this->plt_call_stubs_
.empty())
4445 // The base address of the .plt section.
4446 Address plt_base
= this->targ_
->plt_section()->address();
4447 Address iplt_base
= invalid_address
;
4448 // The address of _GLOBAL_OFFSET_TABLE_.
4449 Address g_o_t
= invalid_address
;
4451 // Write out plt call stubs.
4452 typename
Plt_stub_entries::const_iterator cs
;
4453 for (cs
= this->plt_call_stubs_
.begin();
4454 cs
!= this->plt_call_stubs_
.end();
4458 Address plt_addr
= this->plt_off(cs
, &is_iplt
);
4461 if (iplt_base
== invalid_address
)
4462 iplt_base
= this->targ_
->iplt_section()->address();
4463 plt_addr
+= iplt_base
;
4466 plt_addr
+= plt_base
;
4468 p
= oview
+ cs
->second
;
4469 if (parameters
->options().output_is_position_independent())
4472 const Powerpc_relobj
<size
, big_endian
>* ppcobj
4473 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
4474 (cs
->first
.object_
));
4475 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
4477 unsigned int got2
= ppcobj
->got2_shndx();
4478 got_addr
= ppcobj
->get_output_section_offset(got2
);
4479 gold_assert(got_addr
!= invalid_address
);
4480 got_addr
+= (ppcobj
->output_section(got2
)->address()
4481 + cs
->first
.addend_
);
4485 if (g_o_t
== invalid_address
)
4487 const Output_data_got_powerpc
<size
, big_endian
>* got
4488 = this->targ_
->got_section();
4489 g_o_t
= got
->address() + got
->g_o_t();
4494 Address off
= plt_addr
- got_addr
;
4497 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
4498 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
4499 write_insn
<big_endian
>(p
+ 8, bctr
);
4503 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
4504 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
4505 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4506 write_insn
<big_endian
>(p
+ 12, bctr
);
4511 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
4512 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
4513 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4514 write_insn
<big_endian
>(p
+ 12, bctr
);
4519 // Write out long branch stubs.
4520 typename
Branch_stub_entries::const_iterator bs
;
4521 for (bs
= this->long_branch_stubs_
.begin();
4522 bs
!= this->long_branch_stubs_
.end();
4525 p
= oview
+ this->plt_size_
+ bs
->second
;
4526 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4527 Address delta
= bs
->first
.dest_
- loc
;
4528 if (delta
+ (1 << 25) < 2 << 25)
4529 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4530 else if (!parameters
->options().output_is_position_independent())
4532 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
4533 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
4534 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
4535 write_insn
<big_endian
>(p
+ 12, bctr
);
4540 write_insn
<big_endian
>(p
+ 0, mflr_0
);
4541 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
4542 write_insn
<big_endian
>(p
+ 8, mflr_12
);
4543 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
4544 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
4545 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4546 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
4547 write_insn
<big_endian
>(p
+ 28, bctr
);
4553 // Write out .glink.
4555 template<int size
, bool big_endian
>
4557 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
4559 const section_size_type off
= this->offset();
4560 const section_size_type oview_size
=
4561 convert_to_section_size_type(this->data_size());
4562 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4565 // The base address of the .plt section.
4566 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4567 Address plt_base
= this->targ_
->plt_section()->address();
4571 if (this->end_branch_table_
!= 0)
4573 // Write pltresolve stub.
4575 Address after_bcl
= this->address() + 16;
4576 Address pltoff
= plt_base
- after_bcl
;
4578 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
4580 if (this->targ_
->abiversion() < 2)
4582 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
4583 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4584 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4585 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4586 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
4587 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4588 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4589 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
4590 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4591 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
4595 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
4596 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4597 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4598 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4599 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
4600 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
4601 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4602 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
4603 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4604 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
4605 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4606 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
4608 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
4609 while (p
< oview
+ this->pltresolve_size
)
4610 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4612 // Write lazy link call stubs.
4614 while (p
< oview
+ this->end_branch_table_
)
4616 if (this->targ_
->abiversion() < 2)
4620 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
4624 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
4625 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
4628 uint32_t branch_off
= 8 - (p
- oview
);
4629 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
4634 Address plt_base
= this->targ_
->plt_section()->address();
4635 Address iplt_base
= invalid_address
;
4636 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4637 Address global_entry_base
= this->address() + global_entry_off
;
4638 typename
Global_entry_stub_entries::const_iterator ge
;
4639 for (ge
= this->global_entry_stubs_
.begin();
4640 ge
!= this->global_entry_stubs_
.end();
4643 p
= oview
+ global_entry_off
+ ge
->second
;
4644 Address plt_addr
= ge
->first
->plt_offset();
4645 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
4646 && ge
->first
->can_use_relative_reloc(false))
4648 if (iplt_base
== invalid_address
)
4649 iplt_base
= this->targ_
->iplt_section()->address();
4650 plt_addr
+= iplt_base
;
4653 plt_addr
+= plt_base
;
4654 Address my_addr
= global_entry_base
+ ge
->second
;
4655 Address off
= plt_addr
- my_addr
;
4657 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
4658 gold_error(_("%s: linkage table error against `%s'"),
4659 ge
->first
->object()->name().c_str(),
4660 ge
->first
->demangled_name().c_str());
4662 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
4663 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
4664 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4665 write_insn
<big_endian
>(p
, bctr
);
4670 const Output_data_got_powerpc
<size
, big_endian
>* got
4671 = this->targ_
->got_section();
4672 // The address of _GLOBAL_OFFSET_TABLE_.
4673 Address g_o_t
= got
->address() + got
->g_o_t();
4675 // Write out pltresolve branch table.
4677 unsigned int the_end
= oview_size
- this->pltresolve_size
;
4678 unsigned char* end_p
= oview
+ the_end
;
4679 while (p
< end_p
- 8 * 4)
4680 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
4682 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4684 // Write out pltresolve call stub.
4685 if (parameters
->options().output_is_position_independent())
4687 Address res0_off
= 0;
4688 Address after_bcl_off
= the_end
+ 12;
4689 Address bcl_res0
= after_bcl_off
- res0_off
;
4691 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
4692 write_insn
<big_endian
>(p
+ 4, mflr_0
);
4693 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
4694 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
4695 write_insn
<big_endian
>(p
+ 16, mflr_12
);
4696 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4697 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
4699 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
4701 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
4702 if (ha(got_bcl
) == ha(got_bcl
+ 4))
4704 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
4705 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
4709 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
4710 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
4712 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
4713 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
4714 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
4715 write_insn
<big_endian
>(p
+ 52, bctr
);
4716 write_insn
<big_endian
>(p
+ 56, nop
);
4717 write_insn
<big_endian
>(p
+ 60, nop
);
4721 Address res0
= this->address();
4723 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
4724 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
4725 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4726 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
4728 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
4729 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
4730 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
4731 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
4732 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4733 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
4735 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
4736 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
4737 write_insn
<big_endian
>(p
+ 32, bctr
);
4738 write_insn
<big_endian
>(p
+ 36, nop
);
4739 write_insn
<big_endian
>(p
+ 40, nop
);
4740 write_insn
<big_endian
>(p
+ 44, nop
);
4741 write_insn
<big_endian
>(p
+ 48, nop
);
4742 write_insn
<big_endian
>(p
+ 52, nop
);
4743 write_insn
<big_endian
>(p
+ 56, nop
);
4744 write_insn
<big_endian
>(p
+ 60, nop
);
4749 of
->write_output_view(off
, oview_size
, oview
);
4753 // A class to handle linker generated save/restore functions.
4755 template<int size
, bool big_endian
>
4756 class Output_data_save_res
: public Output_section_data_build
4759 Output_data_save_res(Symbol_table
* symtab
);
4762 // Write to a map file.
4764 do_print_to_mapfile(Mapfile
* mapfile
) const
4765 { mapfile
->print_output_data(this, _("** save/restore")); }
4768 do_write(Output_file
*);
4771 // The maximum size of save/restore contents.
4772 static const unsigned int savres_max
= 218*4;
4775 savres_define(Symbol_table
* symtab
,
4777 unsigned int lo
, unsigned int hi
,
4778 unsigned char* write_ent(unsigned char*, int),
4779 unsigned char* write_tail(unsigned char*, int));
4781 unsigned char *contents_
;
4784 template<bool big_endian
>
4785 static unsigned char*
4786 savegpr0(unsigned char* p
, int r
)
4788 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4789 write_insn
<big_endian
>(p
, insn
);
4793 template<bool big_endian
>
4794 static unsigned char*
4795 savegpr0_tail(unsigned char* p
, int r
)
4797 p
= savegpr0
<big_endian
>(p
, r
);
4798 uint32_t insn
= std_0_1
+ 16;
4799 write_insn
<big_endian
>(p
, insn
);
4801 write_insn
<big_endian
>(p
, blr
);
4805 template<bool big_endian
>
4806 static unsigned char*
4807 restgpr0(unsigned char* p
, int r
)
4809 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4810 write_insn
<big_endian
>(p
, insn
);
4814 template<bool big_endian
>
4815 static unsigned char*
4816 restgpr0_tail(unsigned char* p
, int r
)
4818 uint32_t insn
= ld_0_1
+ 16;
4819 write_insn
<big_endian
>(p
, insn
);
4821 p
= restgpr0
<big_endian
>(p
, r
);
4822 write_insn
<big_endian
>(p
, mtlr_0
);
4826 p
= restgpr0
<big_endian
>(p
, 30);
4827 p
= restgpr0
<big_endian
>(p
, 31);
4829 write_insn
<big_endian
>(p
, blr
);
4833 template<bool big_endian
>
4834 static unsigned char*
4835 savegpr1(unsigned char* p
, int r
)
4837 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4838 write_insn
<big_endian
>(p
, insn
);
4842 template<bool big_endian
>
4843 static unsigned char*
4844 savegpr1_tail(unsigned char* p
, int r
)
4846 p
= savegpr1
<big_endian
>(p
, r
);
4847 write_insn
<big_endian
>(p
, blr
);
4851 template<bool big_endian
>
4852 static unsigned char*
4853 restgpr1(unsigned char* p
, int r
)
4855 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4856 write_insn
<big_endian
>(p
, insn
);
4860 template<bool big_endian
>
4861 static unsigned char*
4862 restgpr1_tail(unsigned char* p
, int r
)
4864 p
= restgpr1
<big_endian
>(p
, r
);
4865 write_insn
<big_endian
>(p
, blr
);
4869 template<bool big_endian
>
4870 static unsigned char*
4871 savefpr(unsigned char* p
, int r
)
4873 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4874 write_insn
<big_endian
>(p
, insn
);
4878 template<bool big_endian
>
4879 static unsigned char*
4880 savefpr0_tail(unsigned char* p
, int r
)
4882 p
= savefpr
<big_endian
>(p
, r
);
4883 write_insn
<big_endian
>(p
, std_0_1
+ 16);
4885 write_insn
<big_endian
>(p
, blr
);
4889 template<bool big_endian
>
4890 static unsigned char*
4891 restfpr(unsigned char* p
, int r
)
4893 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4894 write_insn
<big_endian
>(p
, insn
);
4898 template<bool big_endian
>
4899 static unsigned char*
4900 restfpr0_tail(unsigned char* p
, int r
)
4902 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
4904 p
= restfpr
<big_endian
>(p
, r
);
4905 write_insn
<big_endian
>(p
, mtlr_0
);
4909 p
= restfpr
<big_endian
>(p
, 30);
4910 p
= restfpr
<big_endian
>(p
, 31);
4912 write_insn
<big_endian
>(p
, blr
);
4916 template<bool big_endian
>
4917 static unsigned char*
4918 savefpr1_tail(unsigned char* p
, int r
)
4920 p
= savefpr
<big_endian
>(p
, r
);
4921 write_insn
<big_endian
>(p
, blr
);
4925 template<bool big_endian
>
4926 static unsigned char*
4927 restfpr1_tail(unsigned char* p
, int r
)
4929 p
= restfpr
<big_endian
>(p
, r
);
4930 write_insn
<big_endian
>(p
, blr
);
4934 template<bool big_endian
>
4935 static unsigned char*
4936 savevr(unsigned char* p
, int r
)
4938 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4939 write_insn
<big_endian
>(p
, insn
);
4941 insn
= stvx_0_12_0
+ (r
<< 21);
4942 write_insn
<big_endian
>(p
, insn
);
4946 template<bool big_endian
>
4947 static unsigned char*
4948 savevr_tail(unsigned char* p
, int r
)
4950 p
= savevr
<big_endian
>(p
, r
);
4951 write_insn
<big_endian
>(p
, blr
);
4955 template<bool big_endian
>
4956 static unsigned char*
4957 restvr(unsigned char* p
, int r
)
4959 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4960 write_insn
<big_endian
>(p
, insn
);
4962 insn
= lvx_0_12_0
+ (r
<< 21);
4963 write_insn
<big_endian
>(p
, insn
);
4967 template<bool big_endian
>
4968 static unsigned char*
4969 restvr_tail(unsigned char* p
, int r
)
4971 p
= restvr
<big_endian
>(p
, r
);
4972 write_insn
<big_endian
>(p
, blr
);
4977 template<int size
, bool big_endian
>
4978 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
4979 Symbol_table
* symtab
)
4980 : Output_section_data_build(4),
4983 this->savres_define(symtab
,
4984 "_savegpr0_", 14, 31,
4985 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
4986 this->savres_define(symtab
,
4987 "_restgpr0_", 14, 29,
4988 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
4989 this->savres_define(symtab
,
4990 "_restgpr0_", 30, 31,
4991 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
4992 this->savres_define(symtab
,
4993 "_savegpr1_", 14, 31,
4994 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
4995 this->savres_define(symtab
,
4996 "_restgpr1_", 14, 31,
4997 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
4998 this->savres_define(symtab
,
4999 "_savefpr_", 14, 31,
5000 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
5001 this->savres_define(symtab
,
5002 "_restfpr_", 14, 29,
5003 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5004 this->savres_define(symtab
,
5005 "_restfpr_", 30, 31,
5006 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5007 this->savres_define(symtab
,
5009 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
5010 this->savres_define(symtab
,
5012 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
5013 this->savres_define(symtab
,
5015 savevr
<big_endian
>, savevr_tail
<big_endian
>);
5016 this->savres_define(symtab
,
5018 restvr
<big_endian
>, restvr_tail
<big_endian
>);
5021 template<int size
, bool big_endian
>
5023 Output_data_save_res
<size
, big_endian
>::savres_define(
5024 Symbol_table
* symtab
,
5026 unsigned int lo
, unsigned int hi
,
5027 unsigned char* write_ent(unsigned char*, int),
5028 unsigned char* write_tail(unsigned char*, int))
5030 size_t len
= strlen(name
);
5031 bool writing
= false;
5034 memcpy(sym
, name
, len
);
5037 for (unsigned int i
= lo
; i
<= hi
; i
++)
5039 sym
[len
+ 0] = i
/ 10 + '0';
5040 sym
[len
+ 1] = i
% 10 + '0';
5041 Symbol
* gsym
= symtab
->lookup(sym
);
5042 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
5043 writing
= writing
|| refd
;
5046 if (this->contents_
== NULL
)
5047 this->contents_
= new unsigned char[this->savres_max
];
5049 section_size_type value
= this->current_data_size();
5050 unsigned char* p
= this->contents_
+ value
;
5052 p
= write_ent(p
, i
);
5054 p
= write_tail(p
, i
);
5055 section_size_type cur_size
= p
- this->contents_
;
5056 this->set_current_data_size(cur_size
);
5058 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
5059 this, value
, cur_size
- value
,
5060 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
5061 elfcpp::STV_HIDDEN
, 0, false, false);
5066 // Write out save/restore.
5068 template<int size
, bool big_endian
>
5070 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
5072 const section_size_type off
= this->offset();
5073 const section_size_type oview_size
=
5074 convert_to_section_size_type(this->data_size());
5075 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5076 memcpy(oview
, this->contents_
, oview_size
);
5077 of
->write_output_view(off
, oview_size
, oview
);
5081 // Create the glink section.
5083 template<int size
, bool big_endian
>
5085 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
5087 if (this->glink_
== NULL
)
5089 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
5090 this->glink_
->add_eh_frame(layout
);
5091 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
5092 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
5093 this->glink_
, ORDER_TEXT
, false);
5097 // Create a PLT entry for a global symbol.
5099 template<int size
, bool big_endian
>
5101 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
5105 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
5106 && gsym
->can_use_relative_reloc(false))
5108 if (this->iplt_
== NULL
)
5109 this->make_iplt_section(symtab
, layout
);
5110 this->iplt_
->add_ifunc_entry(gsym
);
5114 if (this->plt_
== NULL
)
5115 this->make_plt_section(symtab
, layout
);
5116 this->plt_
->add_entry(gsym
);
5120 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
5122 template<int size
, bool big_endian
>
5124 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
5125 Symbol_table
* symtab
,
5127 Sized_relobj_file
<size
, big_endian
>* relobj
,
5130 if (this->iplt_
== NULL
)
5131 this->make_iplt_section(symtab
, layout
);
5132 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
5135 // Return the number of entries in the PLT.
5137 template<int size
, bool big_endian
>
5139 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
5141 if (this->plt_
== NULL
)
5143 return this->plt_
->entry_count();
5146 // Create a GOT entry for local dynamic __tls_get_addr calls.
5148 template<int size
, bool big_endian
>
5150 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
5151 Symbol_table
* symtab
,
5153 Sized_relobj_file
<size
, big_endian
>* object
)
5155 if (this->tlsld_got_offset_
== -1U)
5157 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
5158 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
5159 Output_data_got_powerpc
<size
, big_endian
>* got
5160 = this->got_section(symtab
, layout
);
5161 unsigned int got_offset
= got
->add_constant_pair(0, 0);
5162 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
5164 this->tlsld_got_offset_
= got_offset
;
5166 return this->tlsld_got_offset_
;
5169 // Get the Reference_flags for a particular relocation.
5171 template<int size
, bool big_endian
>
5173 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
5174 unsigned int r_type
,
5175 const Target_powerpc
* target
)
5181 case elfcpp::R_POWERPC_NONE
:
5182 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5183 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5184 case elfcpp::R_PPC64_TOC
:
5185 // No symbol reference.
5188 case elfcpp::R_PPC64_ADDR64
:
5189 case elfcpp::R_PPC64_UADDR64
:
5190 case elfcpp::R_POWERPC_ADDR32
:
5191 case elfcpp::R_POWERPC_UADDR32
:
5192 case elfcpp::R_POWERPC_ADDR16
:
5193 case elfcpp::R_POWERPC_UADDR16
:
5194 case elfcpp::R_POWERPC_ADDR16_LO
:
5195 case elfcpp::R_POWERPC_ADDR16_HI
:
5196 case elfcpp::R_POWERPC_ADDR16_HA
:
5197 ref
= Symbol::ABSOLUTE_REF
;
5200 case elfcpp::R_POWERPC_ADDR24
:
5201 case elfcpp::R_POWERPC_ADDR14
:
5202 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5203 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5204 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
5207 case elfcpp::R_PPC64_REL64
:
5208 case elfcpp::R_POWERPC_REL32
:
5209 case elfcpp::R_PPC_LOCAL24PC
:
5210 case elfcpp::R_POWERPC_REL16
:
5211 case elfcpp::R_POWERPC_REL16_LO
:
5212 case elfcpp::R_POWERPC_REL16_HI
:
5213 case elfcpp::R_POWERPC_REL16_HA
:
5214 ref
= Symbol::RELATIVE_REF
;
5217 case elfcpp::R_POWERPC_REL24
:
5218 case elfcpp::R_PPC_PLTREL24
:
5219 case elfcpp::R_POWERPC_REL14
:
5220 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5221 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5222 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
5225 case elfcpp::R_POWERPC_GOT16
:
5226 case elfcpp::R_POWERPC_GOT16_LO
:
5227 case elfcpp::R_POWERPC_GOT16_HI
:
5228 case elfcpp::R_POWERPC_GOT16_HA
:
5229 case elfcpp::R_PPC64_GOT16_DS
:
5230 case elfcpp::R_PPC64_GOT16_LO_DS
:
5231 case elfcpp::R_PPC64_TOC16
:
5232 case elfcpp::R_PPC64_TOC16_LO
:
5233 case elfcpp::R_PPC64_TOC16_HI
:
5234 case elfcpp::R_PPC64_TOC16_HA
:
5235 case elfcpp::R_PPC64_TOC16_DS
:
5236 case elfcpp::R_PPC64_TOC16_LO_DS
:
5238 ref
= Symbol::ABSOLUTE_REF
;
5241 case elfcpp::R_POWERPC_GOT_TPREL16
:
5242 case elfcpp::R_POWERPC_TLS
:
5243 ref
= Symbol::TLS_REF
;
5246 case elfcpp::R_POWERPC_COPY
:
5247 case elfcpp::R_POWERPC_GLOB_DAT
:
5248 case elfcpp::R_POWERPC_JMP_SLOT
:
5249 case elfcpp::R_POWERPC_RELATIVE
:
5250 case elfcpp::R_POWERPC_DTPMOD
:
5252 // Not expected. We will give an error later.
5256 if (size
== 64 && target
->abiversion() < 2)
5257 ref
|= Symbol::FUNC_DESC_ABI
;
5261 // Report an unsupported relocation against a local symbol.
5263 template<int size
, bool big_endian
>
5265 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
5266 Sized_relobj_file
<size
, big_endian
>* object
,
5267 unsigned int r_type
)
5269 gold_error(_("%s: unsupported reloc %u against local symbol"),
5270 object
->name().c_str(), r_type
);
5273 // We are about to emit a dynamic relocation of type R_TYPE. If the
5274 // dynamic linker does not support it, issue an error.
5276 template<int size
, bool big_endian
>
5278 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
5279 unsigned int r_type
)
5281 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
5283 // These are the relocation types supported by glibc for both 32-bit
5284 // and 64-bit powerpc.
5287 case elfcpp::R_POWERPC_NONE
:
5288 case elfcpp::R_POWERPC_RELATIVE
:
5289 case elfcpp::R_POWERPC_GLOB_DAT
:
5290 case elfcpp::R_POWERPC_DTPMOD
:
5291 case elfcpp::R_POWERPC_DTPREL
:
5292 case elfcpp::R_POWERPC_TPREL
:
5293 case elfcpp::R_POWERPC_JMP_SLOT
:
5294 case elfcpp::R_POWERPC_COPY
:
5295 case elfcpp::R_POWERPC_IRELATIVE
:
5296 case elfcpp::R_POWERPC_ADDR32
:
5297 case elfcpp::R_POWERPC_UADDR32
:
5298 case elfcpp::R_POWERPC_ADDR24
:
5299 case elfcpp::R_POWERPC_ADDR16
:
5300 case elfcpp::R_POWERPC_UADDR16
:
5301 case elfcpp::R_POWERPC_ADDR16_LO
:
5302 case elfcpp::R_POWERPC_ADDR16_HI
:
5303 case elfcpp::R_POWERPC_ADDR16_HA
:
5304 case elfcpp::R_POWERPC_ADDR14
:
5305 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5306 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5307 case elfcpp::R_POWERPC_REL32
:
5308 case elfcpp::R_POWERPC_REL24
:
5309 case elfcpp::R_POWERPC_TPREL16
:
5310 case elfcpp::R_POWERPC_TPREL16_LO
:
5311 case elfcpp::R_POWERPC_TPREL16_HI
:
5312 case elfcpp::R_POWERPC_TPREL16_HA
:
5323 // These are the relocation types supported only on 64-bit.
5324 case elfcpp::R_PPC64_ADDR64
:
5325 case elfcpp::R_PPC64_UADDR64
:
5326 case elfcpp::R_PPC64_JMP_IREL
:
5327 case elfcpp::R_PPC64_ADDR16_DS
:
5328 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5329 case elfcpp::R_PPC64_ADDR16_HIGH
:
5330 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5331 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5332 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5333 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5334 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5335 case elfcpp::R_PPC64_REL64
:
5336 case elfcpp::R_POWERPC_ADDR30
:
5337 case elfcpp::R_PPC64_TPREL16_DS
:
5338 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5339 case elfcpp::R_PPC64_TPREL16_HIGH
:
5340 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5341 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5342 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5343 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5344 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5355 // These are the relocation types supported only on 32-bit.
5356 // ??? glibc ld.so doesn't need to support these.
5357 case elfcpp::R_POWERPC_DTPREL16
:
5358 case elfcpp::R_POWERPC_DTPREL16_LO
:
5359 case elfcpp::R_POWERPC_DTPREL16_HI
:
5360 case elfcpp::R_POWERPC_DTPREL16_HA
:
5368 // This prevents us from issuing more than one error per reloc
5369 // section. But we can still wind up issuing more than one
5370 // error per object file.
5371 if (this->issued_non_pic_error_
)
5373 gold_assert(parameters
->options().output_is_position_independent());
5374 object
->error(_("requires unsupported dynamic reloc; "
5375 "recompile with -fPIC"));
5376 this->issued_non_pic_error_
= true;
5380 // Return whether we need to make a PLT entry for a relocation of the
5381 // given type against a STT_GNU_IFUNC symbol.
5383 template<int size
, bool big_endian
>
5385 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
5386 Target_powerpc
<size
, big_endian
>* target
,
5387 Sized_relobj_file
<size
, big_endian
>* object
,
5388 unsigned int r_type
,
5391 // In non-pic code any reference will resolve to the plt call stub
5392 // for the ifunc symbol.
5393 if ((size
== 32 || target
->abiversion() >= 2)
5394 && !parameters
->options().output_is_position_independent())
5399 // Word size refs from data sections are OK, but don't need a PLT entry.
5400 case elfcpp::R_POWERPC_ADDR32
:
5401 case elfcpp::R_POWERPC_UADDR32
:
5406 case elfcpp::R_PPC64_ADDR64
:
5407 case elfcpp::R_PPC64_UADDR64
:
5412 // GOT refs are good, but also don't need a PLT entry.
5413 case elfcpp::R_POWERPC_GOT16
:
5414 case elfcpp::R_POWERPC_GOT16_LO
:
5415 case elfcpp::R_POWERPC_GOT16_HI
:
5416 case elfcpp::R_POWERPC_GOT16_HA
:
5417 case elfcpp::R_PPC64_GOT16_DS
:
5418 case elfcpp::R_PPC64_GOT16_LO_DS
:
5421 // Function calls are good, and these do need a PLT entry.
5422 case elfcpp::R_POWERPC_ADDR24
:
5423 case elfcpp::R_POWERPC_ADDR14
:
5424 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5425 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5426 case elfcpp::R_POWERPC_REL24
:
5427 case elfcpp::R_PPC_PLTREL24
:
5428 case elfcpp::R_POWERPC_REL14
:
5429 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5430 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5437 // Anything else is a problem.
5438 // If we are building a static executable, the libc startup function
5439 // responsible for applying indirect function relocations is going
5440 // to complain about the reloc type.
5441 // If we are building a dynamic executable, we will have a text
5442 // relocation. The dynamic loader will set the text segment
5443 // writable and non-executable to apply text relocations. So we'll
5444 // segfault when trying to run the indirection function to resolve
5447 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
5448 object
->name().c_str(), r_type
);
5452 // Scan a relocation for a local symbol.
5454 template<int size
, bool big_endian
>
5456 Target_powerpc
<size
, big_endian
>::Scan::local(
5457 Symbol_table
* symtab
,
5459 Target_powerpc
<size
, big_endian
>* target
,
5460 Sized_relobj_file
<size
, big_endian
>* object
,
5461 unsigned int data_shndx
,
5462 Output_section
* output_section
,
5463 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5464 unsigned int r_type
,
5465 const elfcpp::Sym
<size
, big_endian
>& lsym
,
5468 this->maybe_skip_tls_get_addr_call(r_type
, NULL
);
5470 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5471 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5473 this->expect_tls_get_addr_call();
5474 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5475 if (tls_type
!= tls::TLSOPT_NONE
)
5476 this->skip_next_tls_get_addr_call();
5478 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5479 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5481 this->expect_tls_get_addr_call();
5482 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5483 if (tls_type
!= tls::TLSOPT_NONE
)
5484 this->skip_next_tls_get_addr_call();
5487 Powerpc_relobj
<size
, big_endian
>* ppc_object
5488 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5493 && data_shndx
== ppc_object
->opd_shndx()
5494 && r_type
== elfcpp::R_PPC64_ADDR64
)
5495 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5499 // A local STT_GNU_IFUNC symbol may require a PLT entry.
5500 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
5501 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5503 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5504 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5505 r_type
, r_sym
, reloc
.get_r_addend());
5506 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
5511 case elfcpp::R_POWERPC_NONE
:
5512 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5513 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5514 case elfcpp::R_PPC64_TOCSAVE
:
5515 case elfcpp::R_POWERPC_TLS
:
5518 case elfcpp::R_PPC64_TOC
:
5520 Output_data_got_powerpc
<size
, big_endian
>* got
5521 = target
->got_section(symtab
, layout
);
5522 if (parameters
->options().output_is_position_independent())
5524 Address off
= reloc
.get_r_offset();
5526 && target
->abiversion() < 2
5527 && data_shndx
== ppc_object
->opd_shndx()
5528 && ppc_object
->get_opd_discard(off
- 8))
5531 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5532 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5533 rela_dyn
->add_output_section_relative(got
->output_section(),
5534 elfcpp::R_POWERPC_RELATIVE
,
5536 object
, data_shndx
, off
,
5537 symobj
->toc_base_offset());
5542 case elfcpp::R_PPC64_ADDR64
:
5543 case elfcpp::R_PPC64_UADDR64
:
5544 case elfcpp::R_POWERPC_ADDR32
:
5545 case elfcpp::R_POWERPC_UADDR32
:
5546 case elfcpp::R_POWERPC_ADDR24
:
5547 case elfcpp::R_POWERPC_ADDR16
:
5548 case elfcpp::R_POWERPC_ADDR16_LO
:
5549 case elfcpp::R_POWERPC_ADDR16_HI
:
5550 case elfcpp::R_POWERPC_ADDR16_HA
:
5551 case elfcpp::R_POWERPC_UADDR16
:
5552 case elfcpp::R_PPC64_ADDR16_HIGH
:
5553 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5554 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5555 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5556 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5557 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5558 case elfcpp::R_PPC64_ADDR16_DS
:
5559 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5560 case elfcpp::R_POWERPC_ADDR14
:
5561 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5562 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5563 // If building a shared library (or a position-independent
5564 // executable), we need to create a dynamic relocation for
5566 if (parameters
->options().output_is_position_independent()
5567 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5569 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5571 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5572 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5573 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
5575 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5576 : elfcpp::R_POWERPC_RELATIVE
);
5577 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5578 output_section
, data_shndx
,
5579 reloc
.get_r_offset(),
5580 reloc
.get_r_addend(), false);
5582 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
5584 check_non_pic(object
, r_type
);
5585 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
5586 data_shndx
, reloc
.get_r_offset(),
5587 reloc
.get_r_addend());
5591 gold_assert(lsym
.get_st_value() == 0);
5592 unsigned int shndx
= lsym
.get_st_shndx();
5594 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
5597 object
->error(_("section symbol %u has bad shndx %u"),
5600 rela_dyn
->add_local_section(object
, shndx
, r_type
,
5601 output_section
, data_shndx
,
5602 reloc
.get_r_offset());
5607 case elfcpp::R_POWERPC_REL24
:
5608 case elfcpp::R_PPC_PLTREL24
:
5609 case elfcpp::R_PPC_LOCAL24PC
:
5610 case elfcpp::R_POWERPC_REL14
:
5611 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5612 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5614 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5615 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5616 reloc
.get_r_addend());
5619 case elfcpp::R_PPC64_REL64
:
5620 case elfcpp::R_POWERPC_REL32
:
5621 case elfcpp::R_POWERPC_REL16
:
5622 case elfcpp::R_POWERPC_REL16_LO
:
5623 case elfcpp::R_POWERPC_REL16_HI
:
5624 case elfcpp::R_POWERPC_REL16_HA
:
5625 case elfcpp::R_POWERPC_SECTOFF
:
5626 case elfcpp::R_POWERPC_SECTOFF_LO
:
5627 case elfcpp::R_POWERPC_SECTOFF_HI
:
5628 case elfcpp::R_POWERPC_SECTOFF_HA
:
5629 case elfcpp::R_PPC64_SECTOFF_DS
:
5630 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5631 case elfcpp::R_POWERPC_TPREL16
:
5632 case elfcpp::R_POWERPC_TPREL16_LO
:
5633 case elfcpp::R_POWERPC_TPREL16_HI
:
5634 case elfcpp::R_POWERPC_TPREL16_HA
:
5635 case elfcpp::R_PPC64_TPREL16_DS
:
5636 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5637 case elfcpp::R_PPC64_TPREL16_HIGH
:
5638 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5639 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5640 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5641 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5642 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5643 case elfcpp::R_POWERPC_DTPREL16
:
5644 case elfcpp::R_POWERPC_DTPREL16_LO
:
5645 case elfcpp::R_POWERPC_DTPREL16_HI
:
5646 case elfcpp::R_POWERPC_DTPREL16_HA
:
5647 case elfcpp::R_PPC64_DTPREL16_DS
:
5648 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5649 case elfcpp::R_PPC64_DTPREL16_HIGH
:
5650 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
5651 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5652 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5653 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5654 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5655 case elfcpp::R_PPC64_TLSGD
:
5656 case elfcpp::R_PPC64_TLSLD
:
5657 case elfcpp::R_PPC64_ADDR64_LOCAL
:
5660 case elfcpp::R_POWERPC_GOT16
:
5661 case elfcpp::R_POWERPC_GOT16_LO
:
5662 case elfcpp::R_POWERPC_GOT16_HI
:
5663 case elfcpp::R_POWERPC_GOT16_HA
:
5664 case elfcpp::R_PPC64_GOT16_DS
:
5665 case elfcpp::R_PPC64_GOT16_LO_DS
:
5667 // The symbol requires a GOT entry.
5668 Output_data_got_powerpc
<size
, big_endian
>* got
5669 = target
->got_section(symtab
, layout
);
5670 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5672 if (!parameters
->options().output_is_position_independent())
5674 if ((size
== 32 && is_ifunc
)
5675 || (size
== 64 && target
->abiversion() >= 2))
5676 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
5678 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
5680 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
5682 // If we are generating a shared object or a pie, this
5683 // symbol's GOT entry will be set by a dynamic relocation.
5685 off
= got
->add_constant(0);
5686 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
5688 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5690 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5691 : elfcpp::R_POWERPC_RELATIVE
);
5692 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5693 got
, off
, 0, false);
5698 case elfcpp::R_PPC64_TOC16
:
5699 case elfcpp::R_PPC64_TOC16_LO
:
5700 case elfcpp::R_PPC64_TOC16_HI
:
5701 case elfcpp::R_PPC64_TOC16_HA
:
5702 case elfcpp::R_PPC64_TOC16_DS
:
5703 case elfcpp::R_PPC64_TOC16_LO_DS
:
5704 // We need a GOT section.
5705 target
->got_section(symtab
, layout
);
5708 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5709 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5710 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5711 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5713 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5714 if (tls_type
== tls::TLSOPT_NONE
)
5716 Output_data_got_powerpc
<size
, big_endian
>* got
5717 = target
->got_section(symtab
, layout
);
5718 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5719 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5720 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
5721 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
5723 else if (tls_type
== tls::TLSOPT_TO_LE
)
5725 // no GOT relocs needed for Local Exec.
5732 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5733 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5734 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5735 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5737 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5738 if (tls_type
== tls::TLSOPT_NONE
)
5739 target
->tlsld_got_offset(symtab
, layout
, object
);
5740 else if (tls_type
== tls::TLSOPT_TO_LE
)
5742 // no GOT relocs needed for Local Exec.
5743 if (parameters
->options().emit_relocs())
5745 Output_section
* os
= layout
->tls_segment()->first_section();
5746 gold_assert(os
!= NULL
);
5747 os
->set_needs_symtab_index();
5755 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5756 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5757 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5758 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5760 Output_data_got_powerpc
<size
, big_endian
>* got
5761 = target
->got_section(symtab
, layout
);
5762 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5763 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
5767 case elfcpp::R_POWERPC_GOT_TPREL16
:
5768 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5769 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5770 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5772 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
5773 if (tls_type
== tls::TLSOPT_NONE
)
5775 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5776 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
5778 Output_data_got_powerpc
<size
, big_endian
>* got
5779 = target
->got_section(symtab
, layout
);
5780 unsigned int off
= got
->add_constant(0);
5781 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
5783 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5784 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
5785 elfcpp::R_POWERPC_TPREL
,
5789 else if (tls_type
== tls::TLSOPT_TO_LE
)
5791 // no GOT relocs needed for Local Exec.
5799 unsupported_reloc_local(object
, r_type
);
5805 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5806 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5807 case elfcpp::R_POWERPC_GOT_TPREL16
:
5808 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5809 case elfcpp::R_POWERPC_GOT16
:
5810 case elfcpp::R_PPC64_GOT16_DS
:
5811 case elfcpp::R_PPC64_TOC16
:
5812 case elfcpp::R_PPC64_TOC16_DS
:
5813 ppc_object
->set_has_small_toc_reloc();
5819 // Report an unsupported relocation against a global symbol.
5821 template<int size
, bool big_endian
>
5823 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
5824 Sized_relobj_file
<size
, big_endian
>* object
,
5825 unsigned int r_type
,
5828 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5829 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
5832 // Scan a relocation for a global symbol.
5834 template<int size
, bool big_endian
>
5836 Target_powerpc
<size
, big_endian
>::Scan::global(
5837 Symbol_table
* symtab
,
5839 Target_powerpc
<size
, big_endian
>* target
,
5840 Sized_relobj_file
<size
, big_endian
>* object
,
5841 unsigned int data_shndx
,
5842 Output_section
* output_section
,
5843 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5844 unsigned int r_type
,
5847 if (this->maybe_skip_tls_get_addr_call(r_type
, gsym
) == Track_tls::SKIP
)
5850 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5851 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5853 this->expect_tls_get_addr_call();
5854 const bool final
= gsym
->final_value_is_known();
5855 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5856 if (tls_type
!= tls::TLSOPT_NONE
)
5857 this->skip_next_tls_get_addr_call();
5859 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5860 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5862 this->expect_tls_get_addr_call();
5863 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5864 if (tls_type
!= tls::TLSOPT_NONE
)
5865 this->skip_next_tls_get_addr_call();
5868 Powerpc_relobj
<size
, big_endian
>* ppc_object
5869 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5871 // A STT_GNU_IFUNC symbol may require a PLT entry.
5872 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
5873 bool pushed_ifunc
= false;
5874 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5876 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5877 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5878 reloc
.get_r_addend());
5879 target
->make_plt_entry(symtab
, layout
, gsym
);
5880 pushed_ifunc
= true;
5885 case elfcpp::R_POWERPC_NONE
:
5886 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5887 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5888 case elfcpp::R_PPC_LOCAL24PC
:
5889 case elfcpp::R_POWERPC_TLS
:
5892 case elfcpp::R_PPC64_TOC
:
5894 Output_data_got_powerpc
<size
, big_endian
>* got
5895 = target
->got_section(symtab
, layout
);
5896 if (parameters
->options().output_is_position_independent())
5898 Address off
= reloc
.get_r_offset();
5900 && data_shndx
== ppc_object
->opd_shndx()
5901 && ppc_object
->get_opd_discard(off
- 8))
5904 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5905 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5906 if (data_shndx
!= ppc_object
->opd_shndx())
5907 symobj
= static_cast
5908 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
5909 rela_dyn
->add_output_section_relative(got
->output_section(),
5910 elfcpp::R_POWERPC_RELATIVE
,
5912 object
, data_shndx
, off
,
5913 symobj
->toc_base_offset());
5918 case elfcpp::R_PPC64_ADDR64
:
5920 && target
->abiversion() < 2
5921 && data_shndx
== ppc_object
->opd_shndx()
5922 && (gsym
->is_defined_in_discarded_section()
5923 || gsym
->object() != object
))
5925 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5929 case elfcpp::R_PPC64_UADDR64
:
5930 case elfcpp::R_POWERPC_ADDR32
:
5931 case elfcpp::R_POWERPC_UADDR32
:
5932 case elfcpp::R_POWERPC_ADDR24
:
5933 case elfcpp::R_POWERPC_ADDR16
:
5934 case elfcpp::R_POWERPC_ADDR16_LO
:
5935 case elfcpp::R_POWERPC_ADDR16_HI
:
5936 case elfcpp::R_POWERPC_ADDR16_HA
:
5937 case elfcpp::R_POWERPC_UADDR16
:
5938 case elfcpp::R_PPC64_ADDR16_HIGH
:
5939 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5940 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5941 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5942 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5943 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5944 case elfcpp::R_PPC64_ADDR16_DS
:
5945 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5946 case elfcpp::R_POWERPC_ADDR14
:
5947 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5948 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5950 // Make a PLT entry if necessary.
5951 if (gsym
->needs_plt_entry())
5953 // Since this is not a PC-relative relocation, we may be
5954 // taking the address of a function. In that case we need to
5955 // set the entry in the dynamic symbol table to the address of
5956 // the PLT call stub.
5957 bool need_ifunc_plt
= false;
5958 if ((size
== 32 || target
->abiversion() >= 2)
5959 && gsym
->is_from_dynobj()
5960 && !parameters
->options().output_is_position_independent())
5962 gsym
->set_needs_dynsym_value();
5963 need_ifunc_plt
= true;
5965 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
5967 target
->push_branch(ppc_object
, data_shndx
,
5968 reloc
.get_r_offset(), r_type
,
5969 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5970 reloc
.get_r_addend());
5971 target
->make_plt_entry(symtab
, layout
, gsym
);
5974 // Make a dynamic relocation if necessary.
5975 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
5976 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5978 if (!parameters
->options().output_is_position_independent()
5979 && gsym
->may_need_copy_reloc())
5981 target
->copy_reloc(symtab
, layout
, object
,
5982 data_shndx
, output_section
, gsym
, reloc
);
5984 else if ((((size
== 32
5985 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5987 && r_type
== elfcpp::R_PPC64_ADDR64
5988 && target
->abiversion() >= 2))
5989 && gsym
->can_use_relative_reloc(false)
5990 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
5991 && parameters
->options().shared()))
5993 && r_type
== elfcpp::R_PPC64_ADDR64
5994 && target
->abiversion() < 2
5995 && (gsym
->can_use_relative_reloc(false)
5996 || data_shndx
== ppc_object
->opd_shndx())))
5998 Reloc_section
* rela_dyn
5999 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6000 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6001 : elfcpp::R_POWERPC_RELATIVE
);
6002 rela_dyn
->add_symbolless_global_addend(
6003 gsym
, dynrel
, output_section
, object
, data_shndx
,
6004 reloc
.get_r_offset(), reloc
.get_r_addend());
6008 Reloc_section
* rela_dyn
6009 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6010 check_non_pic(object
, r_type
);
6011 rela_dyn
->add_global(gsym
, r_type
, output_section
,
6013 reloc
.get_r_offset(),
6014 reloc
.get_r_addend());
6020 case elfcpp::R_PPC_PLTREL24
:
6021 case elfcpp::R_POWERPC_REL24
:
6024 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6026 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6027 reloc
.get_r_addend());
6028 if (gsym
->needs_plt_entry()
6029 || (!gsym
->final_value_is_known()
6030 && (gsym
->is_undefined()
6031 || gsym
->is_from_dynobj()
6032 || gsym
->is_preemptible())))
6033 target
->make_plt_entry(symtab
, layout
, gsym
);
6037 case elfcpp::R_PPC64_REL64
:
6038 case elfcpp::R_POWERPC_REL32
:
6039 // Make a dynamic relocation if necessary.
6040 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
6042 if (!parameters
->options().output_is_position_independent()
6043 && gsym
->may_need_copy_reloc())
6045 target
->copy_reloc(symtab
, layout
, object
,
6046 data_shndx
, output_section
, gsym
,
6051 Reloc_section
* rela_dyn
6052 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6053 check_non_pic(object
, r_type
);
6054 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
6055 data_shndx
, reloc
.get_r_offset(),
6056 reloc
.get_r_addend());
6061 case elfcpp::R_POWERPC_REL14
:
6062 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6063 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6065 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6066 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6067 reloc
.get_r_addend());
6070 case elfcpp::R_POWERPC_REL16
:
6071 case elfcpp::R_POWERPC_REL16_LO
:
6072 case elfcpp::R_POWERPC_REL16_HI
:
6073 case elfcpp::R_POWERPC_REL16_HA
:
6074 case elfcpp::R_POWERPC_SECTOFF
:
6075 case elfcpp::R_POWERPC_SECTOFF_LO
:
6076 case elfcpp::R_POWERPC_SECTOFF_HI
:
6077 case elfcpp::R_POWERPC_SECTOFF_HA
:
6078 case elfcpp::R_PPC64_SECTOFF_DS
:
6079 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6080 case elfcpp::R_POWERPC_TPREL16
:
6081 case elfcpp::R_POWERPC_TPREL16_LO
:
6082 case elfcpp::R_POWERPC_TPREL16_HI
:
6083 case elfcpp::R_POWERPC_TPREL16_HA
:
6084 case elfcpp::R_PPC64_TPREL16_DS
:
6085 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6086 case elfcpp::R_PPC64_TPREL16_HIGH
:
6087 case elfcpp::R_PPC64_TPREL16_HIGHA
:
6088 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6089 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6090 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6091 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6092 case elfcpp::R_POWERPC_DTPREL16
:
6093 case elfcpp::R_POWERPC_DTPREL16_LO
:
6094 case elfcpp::R_POWERPC_DTPREL16_HI
:
6095 case elfcpp::R_POWERPC_DTPREL16_HA
:
6096 case elfcpp::R_PPC64_DTPREL16_DS
:
6097 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6098 case elfcpp::R_PPC64_DTPREL16_HIGH
:
6099 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
6100 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6101 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6102 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6103 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6104 case elfcpp::R_PPC64_TLSGD
:
6105 case elfcpp::R_PPC64_TLSLD
:
6106 case elfcpp::R_PPC64_ADDR64_LOCAL
:
6109 case elfcpp::R_POWERPC_GOT16
:
6110 case elfcpp::R_POWERPC_GOT16_LO
:
6111 case elfcpp::R_POWERPC_GOT16_HI
:
6112 case elfcpp::R_POWERPC_GOT16_HA
:
6113 case elfcpp::R_PPC64_GOT16_DS
:
6114 case elfcpp::R_PPC64_GOT16_LO_DS
:
6116 // The symbol requires a GOT entry.
6117 Output_data_got_powerpc
<size
, big_endian
>* got
;
6119 got
= target
->got_section(symtab
, layout
);
6120 if (gsym
->final_value_is_known())
6122 if ((size
== 32 && is_ifunc
)
6123 || (size
== 64 && target
->abiversion() >= 2))
6124 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
6126 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
6128 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
6130 // If we are generating a shared object or a pie, this
6131 // symbol's GOT entry will be set by a dynamic relocation.
6132 unsigned int off
= got
->add_constant(0);
6133 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
6135 Reloc_section
* rela_dyn
6136 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6138 if (gsym
->can_use_relative_reloc(false)
6140 || target
->abiversion() >= 2)
6141 && gsym
->visibility() == elfcpp::STV_PROTECTED
6142 && parameters
->options().shared()))
6144 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6145 : elfcpp::R_POWERPC_RELATIVE
);
6146 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
6150 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
6151 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
6157 case elfcpp::R_PPC64_TOC16
:
6158 case elfcpp::R_PPC64_TOC16_LO
:
6159 case elfcpp::R_PPC64_TOC16_HI
:
6160 case elfcpp::R_PPC64_TOC16_HA
:
6161 case elfcpp::R_PPC64_TOC16_DS
:
6162 case elfcpp::R_PPC64_TOC16_LO_DS
:
6163 // We need a GOT section.
6164 target
->got_section(symtab
, layout
);
6167 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6168 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6169 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6170 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6172 const bool final
= gsym
->final_value_is_known();
6173 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6174 if (tls_type
== tls::TLSOPT_NONE
)
6176 Output_data_got_powerpc
<size
, big_endian
>* got
6177 = target
->got_section(symtab
, layout
);
6178 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6179 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
6180 elfcpp::R_POWERPC_DTPMOD
,
6181 elfcpp::R_POWERPC_DTPREL
);
6183 else if (tls_type
== tls::TLSOPT_TO_IE
)
6185 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6187 Output_data_got_powerpc
<size
, big_endian
>* got
6188 = target
->got_section(symtab
, layout
);
6189 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6190 if (gsym
->is_undefined()
6191 || gsym
->is_from_dynobj())
6193 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6194 elfcpp::R_POWERPC_TPREL
);
6198 unsigned int off
= got
->add_constant(0);
6199 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6200 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6201 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6206 else if (tls_type
== tls::TLSOPT_TO_LE
)
6208 // no GOT relocs needed for Local Exec.
6215 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6216 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6217 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6218 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6220 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6221 if (tls_type
== tls::TLSOPT_NONE
)
6222 target
->tlsld_got_offset(symtab
, layout
, object
);
6223 else if (tls_type
== tls::TLSOPT_TO_LE
)
6225 // no GOT relocs needed for Local Exec.
6226 if (parameters
->options().emit_relocs())
6228 Output_section
* os
= layout
->tls_segment()->first_section();
6229 gold_assert(os
!= NULL
);
6230 os
->set_needs_symtab_index();
6238 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6239 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6240 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6241 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6243 Output_data_got_powerpc
<size
, big_endian
>* got
6244 = target
->got_section(symtab
, layout
);
6245 if (!gsym
->final_value_is_known()
6246 && (gsym
->is_from_dynobj()
6247 || gsym
->is_undefined()
6248 || gsym
->is_preemptible()))
6249 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
6250 target
->rela_dyn_section(layout
),
6251 elfcpp::R_POWERPC_DTPREL
);
6253 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
6257 case elfcpp::R_POWERPC_GOT_TPREL16
:
6258 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6259 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6260 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6262 const bool final
= gsym
->final_value_is_known();
6263 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6264 if (tls_type
== tls::TLSOPT_NONE
)
6266 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6268 Output_data_got_powerpc
<size
, big_endian
>* got
6269 = target
->got_section(symtab
, layout
);
6270 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6271 if (gsym
->is_undefined()
6272 || gsym
->is_from_dynobj())
6274 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6275 elfcpp::R_POWERPC_TPREL
);
6279 unsigned int off
= got
->add_constant(0);
6280 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6281 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6282 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6287 else if (tls_type
== tls::TLSOPT_TO_LE
)
6289 // no GOT relocs needed for Local Exec.
6297 unsupported_reloc_global(object
, r_type
, gsym
);
6303 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6304 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6305 case elfcpp::R_POWERPC_GOT_TPREL16
:
6306 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6307 case elfcpp::R_POWERPC_GOT16
:
6308 case elfcpp::R_PPC64_GOT16_DS
:
6309 case elfcpp::R_PPC64_TOC16
:
6310 case elfcpp::R_PPC64_TOC16_DS
:
6311 ppc_object
->set_has_small_toc_reloc();
6317 // Process relocations for gc.
6319 template<int size
, bool big_endian
>
6321 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
6322 Symbol_table
* symtab
,
6324 Sized_relobj_file
<size
, big_endian
>* object
,
6325 unsigned int data_shndx
,
6327 const unsigned char* prelocs
,
6329 Output_section
* output_section
,
6330 bool needs_special_offset_handling
,
6331 size_t local_symbol_count
,
6332 const unsigned char* plocal_symbols
)
6334 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6335 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
6336 Powerpc_relobj
<size
, big_endian
>* ppc_object
6337 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6339 ppc_object
->set_opd_valid();
6340 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
6342 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
6343 for (p
= ppc_object
->access_from_map()->begin();
6344 p
!= ppc_object
->access_from_map()->end();
6347 Address dst_off
= p
->first
;
6348 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6349 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
6350 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
6352 Object
* src_obj
= s
->first
;
6353 unsigned int src_indx
= s
->second
;
6354 symtab
->gc()->add_reference(src_obj
, src_indx
,
6355 ppc_object
, dst_indx
);
6359 ppc_object
->access_from_map()->clear();
6360 ppc_object
->process_gc_mark(symtab
);
6361 // Don't look at .opd relocs as .opd will reference everything.
6365 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
6366 typename
Target_powerpc::Relocatable_size_for_reloc
>(
6375 needs_special_offset_handling
,
6380 // Handle target specific gc actions when adding a gc reference from
6381 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
6382 // and DST_OFF. For powerpc64, this adds a referenc to the code
6383 // section of a function descriptor.
6385 template<int size
, bool big_endian
>
6387 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
6388 Symbol_table
* symtab
,
6390 unsigned int src_shndx
,
6392 unsigned int dst_shndx
,
6393 Address dst_off
) const
6395 if (size
!= 64 || dst_obj
->is_dynamic())
6398 Powerpc_relobj
<size
, big_endian
>* ppc_object
6399 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
6400 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
6402 if (ppc_object
->opd_valid())
6404 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
6405 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
6409 // If we haven't run scan_opd_relocs, we must delay
6410 // processing this function descriptor reference.
6411 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
6416 // Add any special sections for this symbol to the gc work list.
6417 // For powerpc64, this adds the code section of a function
6420 template<int size
, bool big_endian
>
6422 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
6423 Symbol_table
* symtab
,
6428 Powerpc_relobj
<size
, big_endian
>* ppc_object
6429 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
6431 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6432 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
6434 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
6435 Address dst_off
= gsym
->value();
6436 if (ppc_object
->opd_valid())
6438 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6439 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
6442 ppc_object
->add_gc_mark(dst_off
);
6447 // For a symbol location in .opd, set LOC to the location of the
6450 template<int size
, bool big_endian
>
6452 Target_powerpc
<size
, big_endian
>::do_function_location(
6453 Symbol_location
* loc
) const
6455 if (size
== 64 && loc
->shndx
!= 0)
6457 if (loc
->object
->is_dynamic())
6459 Powerpc_dynobj
<size
, big_endian
>* ppc_object
6460 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
6461 if (loc
->shndx
== ppc_object
->opd_shndx())
6464 Address off
= loc
->offset
- ppc_object
->opd_address();
6465 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
6466 loc
->offset
= dest_off
;
6471 const Powerpc_relobj
<size
, big_endian
>* ppc_object
6472 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
6473 if (loc
->shndx
== ppc_object
->opd_shndx())
6476 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
6477 loc
->offset
= dest_off
;
6483 // Scan relocations for a section.
6485 template<int size
, bool big_endian
>
6487 Target_powerpc
<size
, big_endian
>::scan_relocs(
6488 Symbol_table
* symtab
,
6490 Sized_relobj_file
<size
, big_endian
>* object
,
6491 unsigned int data_shndx
,
6492 unsigned int sh_type
,
6493 const unsigned char* prelocs
,
6495 Output_section
* output_section
,
6496 bool needs_special_offset_handling
,
6497 size_t local_symbol_count
,
6498 const unsigned char* plocal_symbols
)
6500 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6501 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
6503 if (sh_type
== elfcpp::SHT_REL
)
6505 gold_error(_("%s: unsupported REL reloc section"),
6506 object
->name().c_str());
6510 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
6519 needs_special_offset_handling
,
6524 // Functor class for processing the global symbol table.
6525 // Removes symbols defined on discarded opd entries.
6527 template<bool big_endian
>
6528 class Global_symbol_visitor_opd
6531 Global_symbol_visitor_opd()
6535 operator()(Sized_symbol
<64>* sym
)
6537 if (sym
->has_symtab_index()
6538 || sym
->source() != Symbol::FROM_OBJECT
6539 || !sym
->in_real_elf())
6542 if (sym
->object()->is_dynamic())
6545 Powerpc_relobj
<64, big_endian
>* symobj
6546 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
6547 if (symobj
->opd_shndx() == 0)
6551 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6552 if (shndx
== symobj
->opd_shndx()
6553 && symobj
->get_opd_discard(sym
->value()))
6555 sym
->set_undefined();
6556 sym
->set_is_defined_in_discarded_section();
6557 sym
->set_symtab_index(-1U);
6562 template<int size
, bool big_endian
>
6564 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
6566 Symbol_table
* symtab
)
6570 Output_data_save_res
<64, big_endian
>* savres
6571 = new Output_data_save_res
<64, big_endian
>(symtab
);
6572 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6573 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6574 savres
, ORDER_TEXT
, false);
6578 // Sort linker created .got section first (for the header), then input
6579 // sections belonging to files using small model code.
6581 template<bool big_endian
>
6582 class Sort_toc_sections
6586 operator()(const Output_section::Input_section
& is1
,
6587 const Output_section::Input_section
& is2
) const
6589 if (!is1
.is_input_section() && is2
.is_input_section())
6592 = (is1
.is_input_section()
6593 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
6594 ->has_small_toc_reloc()));
6596 = (is2
.is_input_section()
6597 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
6598 ->has_small_toc_reloc()));
6599 return small1
&& !small2
;
6603 // Finalize the sections.
6605 template<int size
, bool big_endian
>
6607 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
6609 const Input_objects
*,
6610 Symbol_table
* symtab
)
6612 if (parameters
->doing_static_link())
6614 // At least some versions of glibc elf-init.o have a strong
6615 // reference to __rela_iplt marker syms. A weak ref would be
6617 if (this->iplt_
!= NULL
)
6619 Reloc_section
* rel
= this->iplt_
->rel_plt();
6620 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
6621 Symbol_table::PREDEFINED
, rel
, 0, 0,
6622 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6623 elfcpp::STV_HIDDEN
, 0, false, true);
6624 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
6625 Symbol_table::PREDEFINED
, rel
, 0, 0,
6626 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6627 elfcpp::STV_HIDDEN
, 0, true, true);
6631 symtab
->define_as_constant("__rela_iplt_start", NULL
,
6632 Symbol_table::PREDEFINED
, 0, 0,
6633 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6634 elfcpp::STV_HIDDEN
, 0, true, false);
6635 symtab
->define_as_constant("__rela_iplt_end", NULL
,
6636 Symbol_table::PREDEFINED
, 0, 0,
6637 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6638 elfcpp::STV_HIDDEN
, 0, true, false);
6644 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
6645 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
6647 if (!parameters
->options().relocatable())
6649 this->define_save_restore_funcs(layout
, symtab
);
6651 // Annoyingly, we need to make these sections now whether or
6652 // not we need them. If we delay until do_relax then we
6653 // need to mess with the relaxation machinery checkpointing.
6654 this->got_section(symtab
, layout
);
6655 this->make_brlt_section(layout
);
6657 if (parameters
->options().toc_sort())
6659 Output_section
* os
= this->got_
->output_section();
6660 if (os
!= NULL
&& os
->input_sections().size() > 1)
6661 std::stable_sort(os
->input_sections().begin(),
6662 os
->input_sections().end(),
6663 Sort_toc_sections
<big_endian
>());
6668 // Fill in some more dynamic tags.
6669 Output_data_dynamic
* odyn
= layout
->dynamic_data();
6672 const Reloc_section
* rel_plt
= (this->plt_
== NULL
6674 : this->plt_
->rel_plt());
6675 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
6676 this->rela_dyn_
, true, size
== 32);
6680 if (this->got_
!= NULL
)
6682 this->got_
->finalize_data_size();
6683 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
6684 this->got_
, this->got_
->g_o_t());
6689 if (this->glink_
!= NULL
)
6691 this->glink_
->finalize_data_size();
6692 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
6694 (this->glink_
->pltresolve_size
6700 // Emit any relocs we saved in an attempt to avoid generating COPY
6702 if (this->copy_relocs_
.any_saved_relocs())
6703 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
6706 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6710 ok_lo_toc_insn(uint32_t insn
)
6712 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6713 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6714 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6715 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6716 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6717 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6718 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6719 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6720 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6721 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6722 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6723 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6724 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6725 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6726 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6728 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6729 && ((insn
& 3) == 0 || (insn
& 3) == 3))
6730 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
6733 // Return the value to use for a branch relocation.
6735 template<int size
, bool big_endian
>
6737 Target_powerpc
<size
, big_endian
>::symval_for_branch(
6738 const Symbol_table
* symtab
,
6739 const Sized_symbol
<size
>* gsym
,
6740 Powerpc_relobj
<size
, big_endian
>* object
,
6742 unsigned int *dest_shndx
)
6744 if (size
== 32 || this->abiversion() >= 2)
6748 // If the symbol is defined in an opd section, ie. is a function
6749 // descriptor, use the function descriptor code entry address
6750 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
6752 && gsym
->source() != Symbol::FROM_OBJECT
)
6755 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6756 unsigned int shndx
= symobj
->opd_shndx();
6759 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
6760 if (opd_addr
== invalid_address
)
6762 opd_addr
+= symobj
->output_section_address(shndx
);
6763 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
6766 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
6767 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
6770 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
6771 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
6772 *dest_shndx
= folded
.second
;
6774 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
6775 if (sec_addr
== invalid_address
)
6778 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
6779 *value
= sec_addr
+ sec_off
;
6784 // Perform a relocation.
6786 template<int size
, bool big_endian
>
6788 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
6789 const Relocate_info
<size
, big_endian
>* relinfo
,
6790 Target_powerpc
* target
,
6793 const elfcpp::Rela
<size
, big_endian
>& rela
,
6794 unsigned int r_type
,
6795 const Sized_symbol
<size
>* gsym
,
6796 const Symbol_value
<size
>* psymval
,
6797 unsigned char* view
,
6799 section_size_type view_size
)
6804 switch (this->maybe_skip_tls_get_addr_call(r_type
, gsym
))
6806 case Track_tls::NOT_EXPECTED
:
6807 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6808 _("__tls_get_addr call lacks marker reloc"));
6810 case Track_tls::EXPECTED
:
6811 // We have already complained.
6813 case Track_tls::SKIP
:
6815 case Track_tls::NORMAL
:
6819 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
6820 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
6821 Powerpc_relobj
<size
, big_endian
>* const object
6822 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
6824 bool has_stub_value
= false;
6825 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6827 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
6828 : object
->local_has_plt_offset(r_sym
))
6829 && (!psymval
->is_ifunc_symbol()
6830 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
6834 && target
->abiversion() >= 2
6835 && !parameters
->options().output_is_position_independent()
6836 && !is_branch_reloc(r_type
))
6838 unsigned int off
= target
->glink_section()->find_global_entry(gsym
);
6839 gold_assert(off
!= (unsigned int)-1);
6840 value
= target
->glink_section()->global_entry_address() + off
;
6844 Stub_table
<size
, big_endian
>* stub_table
6845 = object
->stub_table(relinfo
->data_shndx
);
6846 if (stub_table
== NULL
)
6848 // This is a ref from a data section to an ifunc symbol.
6849 if (target
->stub_tables().size() != 0)
6850 stub_table
= target
->stub_tables()[0];
6852 gold_assert(stub_table
!= NULL
);
6855 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
6856 rela
.get_r_addend());
6858 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
6859 rela
.get_r_addend());
6860 gold_assert(off
!= invalid_address
);
6861 value
= stub_table
->stub_address() + off
;
6863 has_stub_value
= true;
6866 if (r_type
== elfcpp::R_POWERPC_GOT16
6867 || r_type
== elfcpp::R_POWERPC_GOT16_LO
6868 || r_type
== elfcpp::R_POWERPC_GOT16_HI
6869 || r_type
== elfcpp::R_POWERPC_GOT16_HA
6870 || r_type
== elfcpp::R_PPC64_GOT16_DS
6871 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
6875 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
6876 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
6880 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6881 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
6882 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
6884 value
-= target
->got_section()->got_base_offset(object
);
6886 else if (r_type
== elfcpp::R_PPC64_TOC
)
6888 value
= (target
->got_section()->output_section()->address()
6889 + object
->toc_base_offset());
6891 else if (gsym
!= NULL
6892 && (r_type
== elfcpp::R_POWERPC_REL24
6893 || r_type
== elfcpp::R_PPC_PLTREL24
)
6898 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
6899 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
6900 bool can_plt_call
= false;
6901 if (rela
.get_r_offset() + 8 <= view_size
)
6903 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
6904 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
6907 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
6909 elfcpp::Swap
<32, big_endian
>::
6910 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
6911 can_plt_call
= true;
6916 // If we don't have a branch and link followed by a nop,
6917 // we can't go via the plt because there is no place to
6918 // put a toc restoring instruction.
6919 // Unless we know we won't be returning.
6920 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
6921 can_plt_call
= true;
6925 // g++ as of 20130507 emits self-calls without a
6926 // following nop. This is arguably wrong since we have
6927 // conflicting information. On the one hand a global
6928 // symbol and on the other a local call sequence, but
6929 // don't error for this special case.
6930 // It isn't possible to cheaply verify we have exactly
6931 // such a call. Allow all calls to the same section.
6933 Address code
= value
;
6934 if (gsym
->source() == Symbol::FROM_OBJECT
6935 && gsym
->object() == object
)
6937 unsigned int dest_shndx
= 0;
6938 if (target
->abiversion() < 2)
6940 Address addend
= rela
.get_r_addend();
6941 code
= psymval
->value(object
, addend
);
6942 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
6943 &code
, &dest_shndx
);
6946 if (dest_shndx
== 0)
6947 dest_shndx
= gsym
->shndx(&is_ordinary
);
6948 ok
= dest_shndx
== relinfo
->data_shndx
;
6952 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6953 _("call lacks nop, can't restore toc; "
6954 "recompile with -fPIC"));
6960 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6961 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
6962 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
6963 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
6965 // First instruction of a global dynamic sequence, arg setup insn.
6966 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6967 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6968 enum Got_type got_type
= GOT_TYPE_STANDARD
;
6969 if (tls_type
== tls::TLSOPT_NONE
)
6970 got_type
= GOT_TYPE_TLSGD
;
6971 else if (tls_type
== tls::TLSOPT_TO_IE
)
6972 got_type
= GOT_TYPE_TPREL
;
6973 if (got_type
!= GOT_TYPE_STANDARD
)
6977 gold_assert(gsym
->has_got_offset(got_type
));
6978 value
= gsym
->got_offset(got_type
);
6982 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6983 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
6984 value
= object
->local_got_offset(r_sym
, got_type
);
6986 value
-= target
->got_section()->got_base_offset(object
);
6988 if (tls_type
== tls::TLSOPT_TO_IE
)
6990 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6991 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
6993 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6994 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6995 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
6997 insn
|= 32 << 26; // lwz
6999 insn
|= 58 << 26; // ld
7000 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7002 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
7003 - elfcpp::R_POWERPC_GOT_TLSGD16
);
7005 else if (tls_type
== tls::TLSOPT_TO_LE
)
7007 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7008 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7010 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7011 Insn insn
= addis_3_13
;
7014 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7015 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7016 value
= psymval
->value(object
, rela
.get_r_addend());
7020 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7022 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7023 r_type
= elfcpp::R_POWERPC_NONE
;
7027 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7028 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
7029 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
7030 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
7032 // First instruction of a local dynamic sequence, arg setup insn.
7033 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7034 if (tls_type
== tls::TLSOPT_NONE
)
7036 value
= target
->tlsld_got_offset();
7037 value
-= target
->got_section()->got_base_offset(object
);
7041 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7042 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7043 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
7045 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7046 Insn insn
= addis_3_13
;
7049 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7050 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7055 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7057 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7058 r_type
= elfcpp::R_POWERPC_NONE
;
7062 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
7063 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
7064 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
7065 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
7067 // Accesses relative to a local dynamic sequence address,
7068 // no optimisation here.
7071 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
7072 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
7076 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7077 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
7078 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
7080 value
-= target
->got_section()->got_base_offset(object
);
7082 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7083 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
7084 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
7085 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
7087 // First instruction of initial exec sequence.
7088 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7089 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7090 if (tls_type
== tls::TLSOPT_NONE
)
7094 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
7095 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
7099 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7100 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
7101 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
7103 value
-= target
->got_section()->got_base_offset(object
);
7107 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7108 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7109 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
7111 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7112 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7113 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
7118 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7119 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7120 value
= psymval
->value(object
, rela
.get_r_addend());
7124 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7126 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7127 r_type
= elfcpp::R_POWERPC_NONE
;
7131 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7132 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7134 // Second instruction of a global dynamic sequence,
7135 // the __tls_get_addr call
7136 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7137 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7138 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7139 if (tls_type
!= tls::TLSOPT_NONE
)
7141 if (tls_type
== tls::TLSOPT_TO_IE
)
7143 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7144 Insn insn
= add_3_3_13
;
7147 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7148 r_type
= elfcpp::R_POWERPC_NONE
;
7152 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7153 Insn insn
= addi_3_3
;
7154 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7155 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7156 view
+= 2 * big_endian
;
7157 value
= psymval
->value(object
, rela
.get_r_addend());
7159 this->skip_next_tls_get_addr_call();
7162 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7163 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7165 // Second instruction of a local dynamic sequence,
7166 // the __tls_get_addr call
7167 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7168 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7169 if (tls_type
== tls::TLSOPT_TO_LE
)
7171 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7172 Insn insn
= addi_3_3
;
7173 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7174 this->skip_next_tls_get_addr_call();
7175 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7176 view
+= 2 * big_endian
;
7180 else if (r_type
== elfcpp::R_POWERPC_TLS
)
7182 // Second instruction of an initial exec sequence
7183 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7184 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7185 if (tls_type
== tls::TLSOPT_TO_LE
)
7187 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7188 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7189 unsigned int reg
= size
== 32 ? 2 : 13;
7190 insn
= at_tls_transform(insn
, reg
);
7191 gold_assert(insn
!= 0);
7192 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7193 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7194 view
+= 2 * big_endian
;
7195 value
= psymval
->value(object
, rela
.get_r_addend());
7198 else if (!has_stub_value
)
7201 if (!(size
== 32 && r_type
== elfcpp::R_PPC_PLTREL24
))
7202 addend
= rela
.get_r_addend();
7203 value
= psymval
->value(object
, addend
);
7204 if (size
== 64 && is_branch_reloc(r_type
))
7206 if (target
->abiversion() >= 2)
7209 value
+= object
->ppc64_local_entry_offset(gsym
);
7211 value
+= object
->ppc64_local_entry_offset(r_sym
);
7215 unsigned int dest_shndx
;
7216 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7217 &value
, &dest_shndx
);
7220 Address max_branch_offset
= max_branch_delta(r_type
);
7221 if (max_branch_offset
!= 0
7222 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
7224 Stub_table
<size
, big_endian
>* stub_table
7225 = object
->stub_table(relinfo
->data_shndx
);
7226 if (stub_table
!= NULL
)
7228 Address off
= stub_table
->find_long_branch_entry(object
, value
);
7229 if (off
!= invalid_address
)
7231 value
= (stub_table
->stub_address() + stub_table
->plt_size()
7233 has_stub_value
= true;
7241 case elfcpp::R_PPC64_REL64
:
7242 case elfcpp::R_POWERPC_REL32
:
7243 case elfcpp::R_POWERPC_REL24
:
7244 case elfcpp::R_PPC_PLTREL24
:
7245 case elfcpp::R_PPC_LOCAL24PC
:
7246 case elfcpp::R_POWERPC_REL16
:
7247 case elfcpp::R_POWERPC_REL16_LO
:
7248 case elfcpp::R_POWERPC_REL16_HI
:
7249 case elfcpp::R_POWERPC_REL16_HA
:
7250 case elfcpp::R_POWERPC_REL14
:
7251 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7252 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7256 case elfcpp::R_PPC64_TOC16
:
7257 case elfcpp::R_PPC64_TOC16_LO
:
7258 case elfcpp::R_PPC64_TOC16_HI
:
7259 case elfcpp::R_PPC64_TOC16_HA
:
7260 case elfcpp::R_PPC64_TOC16_DS
:
7261 case elfcpp::R_PPC64_TOC16_LO_DS
:
7262 // Subtract the TOC base address.
7263 value
-= (target
->got_section()->output_section()->address()
7264 + object
->toc_base_offset());
7267 case elfcpp::R_POWERPC_SECTOFF
:
7268 case elfcpp::R_POWERPC_SECTOFF_LO
:
7269 case elfcpp::R_POWERPC_SECTOFF_HI
:
7270 case elfcpp::R_POWERPC_SECTOFF_HA
:
7271 case elfcpp::R_PPC64_SECTOFF_DS
:
7272 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7274 value
-= os
->address();
7277 case elfcpp::R_PPC64_TPREL16_DS
:
7278 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7279 case elfcpp::R_PPC64_TPREL16_HIGH
:
7280 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7282 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
7284 case elfcpp::R_POWERPC_TPREL16
:
7285 case elfcpp::R_POWERPC_TPREL16_LO
:
7286 case elfcpp::R_POWERPC_TPREL16_HI
:
7287 case elfcpp::R_POWERPC_TPREL16_HA
:
7288 case elfcpp::R_POWERPC_TPREL
:
7289 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7290 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7291 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7292 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7293 // tls symbol values are relative to tls_segment()->vaddr()
7297 case elfcpp::R_PPC64_DTPREL16_DS
:
7298 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7299 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7300 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7301 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7302 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7304 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
7305 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
7307 case elfcpp::R_POWERPC_DTPREL16
:
7308 case elfcpp::R_POWERPC_DTPREL16_LO
:
7309 case elfcpp::R_POWERPC_DTPREL16_HI
:
7310 case elfcpp::R_POWERPC_DTPREL16_HA
:
7311 case elfcpp::R_POWERPC_DTPREL
:
7312 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7313 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7314 // tls symbol values are relative to tls_segment()->vaddr()
7315 value
-= dtp_offset
;
7318 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7320 value
+= object
->ppc64_local_entry_offset(gsym
);
7322 value
+= object
->ppc64_local_entry_offset(r_sym
);
7329 Insn branch_bit
= 0;
7332 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7333 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7334 branch_bit
= 1 << 21;
7335 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7336 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7338 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7339 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7342 if (this->is_isa_v2
)
7344 // Set 'a' bit. This is 0b00010 in BO field for branch
7345 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
7346 // for branch on CTR insns (BO == 1a00t or 1a01t).
7347 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7349 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7356 // Invert 'y' bit if not the default.
7357 if (static_cast<Signed_address
>(value
) < 0)
7360 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7370 // Multi-instruction sequences that access the TOC can be
7371 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
7372 // to nop; addi rb,r2,x;
7378 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7379 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7380 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7381 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7382 case elfcpp::R_POWERPC_GOT16_HA
:
7383 case elfcpp::R_PPC64_TOC16_HA
:
7384 if (parameters
->options().toc_optimize())
7386 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7387 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7388 if ((insn
& ((0x3f << 26) | 0x1f << 16))
7389 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
7390 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7391 _("toc optimization is not supported "
7392 "for %#08x instruction"), insn
);
7393 else if (value
+ 0x8000 < 0x10000)
7395 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
7401 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7402 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7403 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7404 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7405 case elfcpp::R_POWERPC_GOT16_LO
:
7406 case elfcpp::R_PPC64_GOT16_LO_DS
:
7407 case elfcpp::R_PPC64_TOC16_LO
:
7408 case elfcpp::R_PPC64_TOC16_LO_DS
:
7409 if (parameters
->options().toc_optimize())
7411 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7412 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7413 if (!ok_lo_toc_insn(insn
))
7414 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7415 _("toc optimization is not supported "
7416 "for %#08x instruction"), insn
);
7417 else if (value
+ 0x8000 < 0x10000)
7419 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
7421 // Transform addic to addi when we change reg.
7422 insn
&= ~((0x3f << 26) | (0x1f << 16));
7423 insn
|= (14u << 26) | (2 << 16);
7427 insn
&= ~(0x1f << 16);
7430 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7437 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
7438 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
7441 case elfcpp::R_POWERPC_ADDR32
:
7442 case elfcpp::R_POWERPC_UADDR32
:
7444 overflow
= Reloc::CHECK_BITFIELD
;
7447 case elfcpp::R_POWERPC_REL32
:
7449 overflow
= Reloc::CHECK_SIGNED
;
7452 case elfcpp::R_POWERPC_UADDR16
:
7453 overflow
= Reloc::CHECK_BITFIELD
;
7456 case elfcpp::R_POWERPC_ADDR16
:
7457 // We really should have three separate relocations,
7458 // one for 16-bit data, one for insns with 16-bit signed fields,
7459 // and one for insns with 16-bit unsigned fields.
7460 overflow
= Reloc::CHECK_BITFIELD
;
7461 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
7462 overflow
= Reloc::CHECK_LOW_INSN
;
7465 case elfcpp::R_POWERPC_ADDR16_HI
:
7466 case elfcpp::R_POWERPC_ADDR16_HA
:
7467 case elfcpp::R_POWERPC_GOT16_HI
:
7468 case elfcpp::R_POWERPC_GOT16_HA
:
7469 case elfcpp::R_POWERPC_PLT16_HI
:
7470 case elfcpp::R_POWERPC_PLT16_HA
:
7471 case elfcpp::R_POWERPC_SECTOFF_HI
:
7472 case elfcpp::R_POWERPC_SECTOFF_HA
:
7473 case elfcpp::R_PPC64_TOC16_HI
:
7474 case elfcpp::R_PPC64_TOC16_HA
:
7475 case elfcpp::R_PPC64_PLTGOT16_HI
:
7476 case elfcpp::R_PPC64_PLTGOT16_HA
:
7477 case elfcpp::R_POWERPC_TPREL16_HI
:
7478 case elfcpp::R_POWERPC_TPREL16_HA
:
7479 case elfcpp::R_POWERPC_DTPREL16_HI
:
7480 case elfcpp::R_POWERPC_DTPREL16_HA
:
7481 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7482 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7483 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7484 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7485 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7486 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7487 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7488 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7489 case elfcpp::R_POWERPC_REL16_HI
:
7490 case elfcpp::R_POWERPC_REL16_HA
:
7492 overflow
= Reloc::CHECK_HIGH_INSN
;
7495 case elfcpp::R_POWERPC_REL16
:
7496 case elfcpp::R_PPC64_TOC16
:
7497 case elfcpp::R_POWERPC_GOT16
:
7498 case elfcpp::R_POWERPC_SECTOFF
:
7499 case elfcpp::R_POWERPC_TPREL16
:
7500 case elfcpp::R_POWERPC_DTPREL16
:
7501 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7502 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7503 case elfcpp::R_POWERPC_GOT_TPREL16
:
7504 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7505 overflow
= Reloc::CHECK_LOW_INSN
;
7508 case elfcpp::R_POWERPC_ADDR24
:
7509 case elfcpp::R_POWERPC_ADDR14
:
7510 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7511 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7512 case elfcpp::R_PPC64_ADDR16_DS
:
7513 case elfcpp::R_POWERPC_REL24
:
7514 case elfcpp::R_PPC_PLTREL24
:
7515 case elfcpp::R_PPC_LOCAL24PC
:
7516 case elfcpp::R_PPC64_TPREL16_DS
:
7517 case elfcpp::R_PPC64_DTPREL16_DS
:
7518 case elfcpp::R_PPC64_TOC16_DS
:
7519 case elfcpp::R_PPC64_GOT16_DS
:
7520 case elfcpp::R_PPC64_SECTOFF_DS
:
7521 case elfcpp::R_POWERPC_REL14
:
7522 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7523 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7524 overflow
= Reloc::CHECK_SIGNED
;
7528 if (overflow
== Reloc::CHECK_LOW_INSN
7529 || overflow
== Reloc::CHECK_HIGH_INSN
)
7531 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7532 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7534 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
7535 overflow
= Reloc::CHECK_BITFIELD
;
7536 else if (overflow
== Reloc::CHECK_LOW_INSN
7537 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
7538 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
7539 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
7540 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
7541 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
7542 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
7543 overflow
= Reloc::CHECK_UNSIGNED
;
7545 overflow
= Reloc::CHECK_SIGNED
;
7548 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
7549 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
7552 case elfcpp::R_POWERPC_NONE
:
7553 case elfcpp::R_POWERPC_TLS
:
7554 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7555 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7558 case elfcpp::R_PPC64_ADDR64
:
7559 case elfcpp::R_PPC64_REL64
:
7560 case elfcpp::R_PPC64_TOC
:
7561 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7562 Reloc::addr64(view
, value
);
7565 case elfcpp::R_POWERPC_TPREL
:
7566 case elfcpp::R_POWERPC_DTPREL
:
7568 Reloc::addr64(view
, value
);
7570 status
= Reloc::addr32(view
, value
, overflow
);
7573 case elfcpp::R_PPC64_UADDR64
:
7574 Reloc::addr64_u(view
, value
);
7577 case elfcpp::R_POWERPC_ADDR32
:
7578 status
= Reloc::addr32(view
, value
, overflow
);
7581 case elfcpp::R_POWERPC_REL32
:
7582 case elfcpp::R_POWERPC_UADDR32
:
7583 status
= Reloc::addr32_u(view
, value
, overflow
);
7586 case elfcpp::R_POWERPC_ADDR24
:
7587 case elfcpp::R_POWERPC_REL24
:
7588 case elfcpp::R_PPC_PLTREL24
:
7589 case elfcpp::R_PPC_LOCAL24PC
:
7590 status
= Reloc::addr24(view
, value
, overflow
);
7593 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7594 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7597 status
= Reloc::addr16_ds(view
, value
, overflow
);
7600 case elfcpp::R_POWERPC_ADDR16
:
7601 case elfcpp::R_POWERPC_REL16
:
7602 case elfcpp::R_PPC64_TOC16
:
7603 case elfcpp::R_POWERPC_GOT16
:
7604 case elfcpp::R_POWERPC_SECTOFF
:
7605 case elfcpp::R_POWERPC_TPREL16
:
7606 case elfcpp::R_POWERPC_DTPREL16
:
7607 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7608 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7609 case elfcpp::R_POWERPC_GOT_TPREL16
:
7610 case elfcpp::R_POWERPC_ADDR16_LO
:
7611 case elfcpp::R_POWERPC_REL16_LO
:
7612 case elfcpp::R_PPC64_TOC16_LO
:
7613 case elfcpp::R_POWERPC_GOT16_LO
:
7614 case elfcpp::R_POWERPC_SECTOFF_LO
:
7615 case elfcpp::R_POWERPC_TPREL16_LO
:
7616 case elfcpp::R_POWERPC_DTPREL16_LO
:
7617 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7618 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7619 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7620 status
= Reloc::addr16(view
, value
, overflow
);
7623 case elfcpp::R_POWERPC_UADDR16
:
7624 status
= Reloc::addr16_u(view
, value
, overflow
);
7627 case elfcpp::R_PPC64_ADDR16_HIGH
:
7628 case elfcpp::R_PPC64_TPREL16_HIGH
:
7629 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7631 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
7633 case elfcpp::R_POWERPC_ADDR16_HI
:
7634 case elfcpp::R_POWERPC_REL16_HI
:
7635 case elfcpp::R_PPC64_TOC16_HI
:
7636 case elfcpp::R_POWERPC_GOT16_HI
:
7637 case elfcpp::R_POWERPC_SECTOFF_HI
:
7638 case elfcpp::R_POWERPC_TPREL16_HI
:
7639 case elfcpp::R_POWERPC_DTPREL16_HI
:
7640 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7641 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7642 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7643 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7644 Reloc::addr16_hi(view
, value
);
7647 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7648 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7649 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7651 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
7653 case elfcpp::R_POWERPC_ADDR16_HA
:
7654 case elfcpp::R_POWERPC_REL16_HA
:
7655 case elfcpp::R_PPC64_TOC16_HA
:
7656 case elfcpp::R_POWERPC_GOT16_HA
:
7657 case elfcpp::R_POWERPC_SECTOFF_HA
:
7658 case elfcpp::R_POWERPC_TPREL16_HA
:
7659 case elfcpp::R_POWERPC_DTPREL16_HA
:
7660 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7661 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7662 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7663 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7664 Reloc::addr16_ha(view
, value
);
7667 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7669 // R_PPC_EMB_NADDR16_LO
7671 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7672 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7673 Reloc::addr16_hi2(view
, value
);
7676 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7678 // R_PPC_EMB_NADDR16_HI
7680 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7681 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7682 Reloc::addr16_ha2(view
, value
);
7685 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7687 // R_PPC_EMB_NADDR16_HA
7689 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7690 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7691 Reloc::addr16_hi3(view
, value
);
7694 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7698 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7699 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7700 Reloc::addr16_ha3(view
, value
);
7703 case elfcpp::R_PPC64_DTPREL16_DS
:
7704 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7706 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
7708 case elfcpp::R_PPC64_TPREL16_DS
:
7709 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7711 // R_PPC_TLSGD, R_PPC_TLSLD
7713 case elfcpp::R_PPC64_ADDR16_DS
:
7714 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7715 case elfcpp::R_PPC64_TOC16_DS
:
7716 case elfcpp::R_PPC64_TOC16_LO_DS
:
7717 case elfcpp::R_PPC64_GOT16_DS
:
7718 case elfcpp::R_PPC64_GOT16_LO_DS
:
7719 case elfcpp::R_PPC64_SECTOFF_DS
:
7720 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7721 status
= Reloc::addr16_ds(view
, value
, overflow
);
7724 case elfcpp::R_POWERPC_ADDR14
:
7725 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7726 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7727 case elfcpp::R_POWERPC_REL14
:
7728 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7729 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7730 status
= Reloc::addr14(view
, value
, overflow
);
7733 case elfcpp::R_POWERPC_COPY
:
7734 case elfcpp::R_POWERPC_GLOB_DAT
:
7735 case elfcpp::R_POWERPC_JMP_SLOT
:
7736 case elfcpp::R_POWERPC_RELATIVE
:
7737 case elfcpp::R_POWERPC_DTPMOD
:
7738 case elfcpp::R_PPC64_JMP_IREL
:
7739 case elfcpp::R_POWERPC_IRELATIVE
:
7740 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7741 _("unexpected reloc %u in object file"),
7745 case elfcpp::R_PPC_EMB_SDA21
:
7750 // R_PPC64_TOCSAVE. For the time being this can be ignored.
7754 case elfcpp::R_PPC_EMB_SDA2I16
:
7755 case elfcpp::R_PPC_EMB_SDA2REL
:
7758 // R_PPC64_TLSGD, R_PPC64_TLSLD
7761 case elfcpp::R_POWERPC_PLT32
:
7762 case elfcpp::R_POWERPC_PLTREL32
:
7763 case elfcpp::R_POWERPC_PLT16_LO
:
7764 case elfcpp::R_POWERPC_PLT16_HI
:
7765 case elfcpp::R_POWERPC_PLT16_HA
:
7766 case elfcpp::R_PPC_SDAREL16
:
7767 case elfcpp::R_POWERPC_ADDR30
:
7768 case elfcpp::R_PPC64_PLT64
:
7769 case elfcpp::R_PPC64_PLTREL64
:
7770 case elfcpp::R_PPC64_PLTGOT16
:
7771 case elfcpp::R_PPC64_PLTGOT16_LO
:
7772 case elfcpp::R_PPC64_PLTGOT16_HI
:
7773 case elfcpp::R_PPC64_PLTGOT16_HA
:
7774 case elfcpp::R_PPC64_PLT16_LO_DS
:
7775 case elfcpp::R_PPC64_PLTGOT16_DS
:
7776 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
7777 case elfcpp::R_PPC_EMB_RELSDA
:
7778 case elfcpp::R_PPC_TOC16
:
7781 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7782 _("unsupported reloc %u"),
7786 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
7789 && gsym
->is_weak_undefined()
7790 && is_branch_reloc(r_type
))))
7792 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7793 _("relocation overflow"));
7795 gold_info(_("try relinking with a smaller --stub-group-size"));
7801 // Relocate section data.
7803 template<int size
, bool big_endian
>
7805 Target_powerpc
<size
, big_endian
>::relocate_section(
7806 const Relocate_info
<size
, big_endian
>* relinfo
,
7807 unsigned int sh_type
,
7808 const unsigned char* prelocs
,
7810 Output_section
* output_section
,
7811 bool needs_special_offset_handling
,
7812 unsigned char* view
,
7814 section_size_type view_size
,
7815 const Reloc_symbol_changes
* reloc_symbol_changes
)
7817 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
7818 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
7819 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
7820 Powerpc_comdat_behavior
;
7822 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7824 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
7825 Powerpc_relocate
, Powerpc_comdat_behavior
>(
7831 needs_special_offset_handling
,
7835 reloc_symbol_changes
);
7838 class Powerpc_scan_relocatable_reloc
7841 // Return the strategy to use for a local symbol which is not a
7842 // section symbol, given the relocation type.
7843 inline Relocatable_relocs::Reloc_strategy
7844 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
7846 if (r_type
== 0 && r_sym
== 0)
7847 return Relocatable_relocs::RELOC_DISCARD
;
7848 return Relocatable_relocs::RELOC_COPY
;
7851 // Return the strategy to use for a local symbol which is a section
7852 // symbol, given the relocation type.
7853 inline Relocatable_relocs::Reloc_strategy
7854 local_section_strategy(unsigned int, Relobj
*)
7856 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
7859 // Return the strategy to use for a global symbol, given the
7860 // relocation type, the object, and the symbol index.
7861 inline Relocatable_relocs::Reloc_strategy
7862 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
7864 if (r_type
== elfcpp::R_PPC_PLTREL24
)
7865 return Relocatable_relocs::RELOC_SPECIAL
;
7866 return Relocatable_relocs::RELOC_COPY
;
7870 // Scan the relocs during a relocatable link.
7872 template<int size
, bool big_endian
>
7874 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
7875 Symbol_table
* symtab
,
7877 Sized_relobj_file
<size
, big_endian
>* object
,
7878 unsigned int data_shndx
,
7879 unsigned int sh_type
,
7880 const unsigned char* prelocs
,
7882 Output_section
* output_section
,
7883 bool needs_special_offset_handling
,
7884 size_t local_symbol_count
,
7885 const unsigned char* plocal_symbols
,
7886 Relocatable_relocs
* rr
)
7888 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7890 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
7891 Powerpc_scan_relocatable_reloc
>(
7899 needs_special_offset_handling
,
7905 // Emit relocations for a section.
7906 // This is a modified version of the function by the same name in
7907 // target-reloc.h. Using relocate_special_relocatable for
7908 // R_PPC_PLTREL24 would require duplication of the entire body of the
7909 // loop, so we may as well duplicate the whole thing.
7911 template<int size
, bool big_endian
>
7913 Target_powerpc
<size
, big_endian
>::relocate_relocs(
7914 const Relocate_info
<size
, big_endian
>* relinfo
,
7915 unsigned int sh_type
,
7916 const unsigned char* prelocs
,
7918 Output_section
* output_section
,
7919 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
7920 const Relocatable_relocs
* rr
,
7922 Address view_address
,
7924 unsigned char* reloc_view
,
7925 section_size_type reloc_view_size
)
7927 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7929 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
7931 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
7933 const int reloc_size
7934 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
7936 Powerpc_relobj
<size
, big_endian
>* const object
7937 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
7938 const unsigned int local_count
= object
->local_symbol_count();
7939 unsigned int got2_shndx
= object
->got2_shndx();
7940 Address got2_addend
= 0;
7941 if (got2_shndx
!= 0)
7943 got2_addend
= object
->get_output_section_offset(got2_shndx
);
7944 gold_assert(got2_addend
!= invalid_address
);
7947 unsigned char* pwrite
= reloc_view
;
7948 bool zap_next
= false;
7949 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
7951 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
7952 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
7955 Reltype
reloc(prelocs
);
7956 Reltype_write
reloc_write(pwrite
);
7958 Address offset
= reloc
.get_r_offset();
7959 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
7960 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
7961 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
7962 const unsigned int orig_r_sym
= r_sym
;
7963 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
7964 = reloc
.get_r_addend();
7965 const Symbol
* gsym
= NULL
;
7969 // We could arrange to discard these and other relocs for
7970 // tls optimised sequences in the strategy methods, but for
7971 // now do as BFD ld does.
7972 r_type
= elfcpp::R_POWERPC_NONE
;
7976 // Get the new symbol index.
7977 if (r_sym
< local_count
)
7981 case Relocatable_relocs::RELOC_COPY
:
7982 case Relocatable_relocs::RELOC_SPECIAL
:
7985 r_sym
= object
->symtab_index(r_sym
);
7986 gold_assert(r_sym
!= -1U);
7990 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
7992 // We are adjusting a section symbol. We need to find
7993 // the symbol table index of the section symbol for
7994 // the output section corresponding to input section
7995 // in which this symbol is defined.
7996 gold_assert(r_sym
< local_count
);
7998 unsigned int shndx
=
7999 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
8000 gold_assert(is_ordinary
);
8001 Output_section
* os
= object
->output_section(shndx
);
8002 gold_assert(os
!= NULL
);
8003 gold_assert(os
->needs_symtab_index());
8004 r_sym
= os
->symtab_index();
8014 gsym
= object
->global_symbol(r_sym
);
8015 gold_assert(gsym
!= NULL
);
8016 if (gsym
->is_forwarder())
8017 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
8019 gold_assert(gsym
->has_symtab_index());
8020 r_sym
= gsym
->symtab_index();
8023 // Get the new offset--the location in the output section where
8024 // this relocation should be applied.
8025 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8026 offset
+= offset_in_output_section
;
8029 section_offset_type sot_offset
=
8030 convert_types
<section_offset_type
, Address
>(offset
);
8031 section_offset_type new_sot_offset
=
8032 output_section
->output_offset(object
, relinfo
->data_shndx
,
8034 gold_assert(new_sot_offset
!= -1);
8035 offset
= new_sot_offset
;
8038 // In an object file, r_offset is an offset within the section.
8039 // In an executable or dynamic object, generated by
8040 // --emit-relocs, r_offset is an absolute address.
8041 if (!parameters
->options().relocatable())
8043 offset
+= view_address
;
8044 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8045 offset
-= offset_in_output_section
;
8048 // Handle the reloc addend based on the strategy.
8049 if (strategy
== Relocatable_relocs::RELOC_COPY
)
8051 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
8053 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
8054 addend
= psymval
->value(object
, addend
);
8056 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
8058 if (addend
>= 32768)
8059 addend
+= got2_addend
;
8064 if (!parameters
->options().relocatable())
8066 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8067 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
8068 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
8069 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
8071 // First instruction of a global dynamic sequence,
8073 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8074 switch (this->optimize_tls_gd(final
))
8076 case tls::TLSOPT_TO_IE
:
8077 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
8078 - elfcpp::R_POWERPC_GOT_TLSGD16
);
8080 case tls::TLSOPT_TO_LE
:
8081 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8082 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
8083 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8086 r_type
= elfcpp::R_POWERPC_NONE
;
8087 offset
-= 2 * big_endian
;
8094 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8095 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
8096 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
8097 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
8099 // First instruction of a local dynamic sequence,
8101 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8103 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8104 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
8106 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8107 const Output_section
* os
= relinfo
->layout
->tls_segment()
8109 gold_assert(os
!= NULL
);
8110 gold_assert(os
->needs_symtab_index());
8111 r_sym
= os
->symtab_index();
8112 addend
= dtp_offset
;
8116 r_type
= elfcpp::R_POWERPC_NONE
;
8117 offset
-= 2 * big_endian
;
8121 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8122 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
8123 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
8124 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
8126 // First instruction of initial exec sequence.
8127 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8128 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8130 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8131 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
8132 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8135 r_type
= elfcpp::R_POWERPC_NONE
;
8136 offset
-= 2 * big_endian
;
8140 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8141 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8143 // Second instruction of a global dynamic sequence,
8144 // the __tls_get_addr call
8145 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8146 switch (this->optimize_tls_gd(final
))
8148 case tls::TLSOPT_TO_IE
:
8149 r_type
= elfcpp::R_POWERPC_NONE
;
8152 case tls::TLSOPT_TO_LE
:
8153 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8154 offset
+= 2 * big_endian
;
8161 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8162 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8164 // Second instruction of a local dynamic sequence,
8165 // the __tls_get_addr call
8166 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8168 const Output_section
* os
= relinfo
->layout
->tls_segment()
8170 gold_assert(os
!= NULL
);
8171 gold_assert(os
->needs_symtab_index());
8172 r_sym
= os
->symtab_index();
8173 addend
= dtp_offset
;
8174 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8175 offset
+= 2 * big_endian
;
8179 else if (r_type
== elfcpp::R_POWERPC_TLS
)
8181 // Second instruction of an initial exec sequence
8182 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8183 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8185 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8186 offset
+= 2 * big_endian
;
8191 reloc_write
.put_r_offset(offset
);
8192 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
8193 reloc_write
.put_r_addend(addend
);
8195 pwrite
+= reloc_size
;
8198 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
8199 == reloc_view_size
);
8202 // Return the value to use for a dynamic symbol which requires special
8203 // treatment. This is how we support equality comparisons of function
8204 // pointers across shared library boundaries, as described in the
8205 // processor specific ABI supplement.
8207 template<int size
, bool big_endian
>
8209 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8213 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
8214 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8215 p
!= this->stub_tables_
.end();
8218 Address off
= (*p
)->find_plt_call_entry(gsym
);
8219 if (off
!= invalid_address
)
8220 return (*p
)->stub_address() + off
;
8223 else if (this->abiversion() >= 2)
8225 unsigned int off
= this->glink_section()->find_global_entry(gsym
);
8226 if (off
!= (unsigned int)-1)
8227 return this->glink_section()->global_entry_address() + off
;
8232 // Return the PLT address to use for a local symbol.
8233 template<int size
, bool big_endian
>
8235 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
8236 const Relobj
* object
,
8237 unsigned int symndx
) const
8241 const Sized_relobj
<size
, big_endian
>* relobj
8242 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
8243 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8244 p
!= this->stub_tables_
.end();
8247 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
8249 if (off
!= invalid_address
)
8250 return (*p
)->stub_address() + off
;
8256 // Return the PLT address to use for a global symbol.
8257 template<int size
, bool big_endian
>
8259 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
8260 const Symbol
* gsym
) const
8264 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8265 p
!= this->stub_tables_
.end();
8268 Address off
= (*p
)->find_plt_call_entry(gsym
);
8269 if (off
!= invalid_address
)
8270 return (*p
)->stub_address() + off
;
8273 else if (this->abiversion() >= 2)
8275 unsigned int off
= this->glink_section()->find_global_entry(gsym
);
8276 if (off
!= (unsigned int)-1)
8277 return this->glink_section()->global_entry_address() + off
;
8282 // Return the offset to use for the GOT_INDX'th got entry which is
8283 // for a local tls symbol specified by OBJECT, SYMNDX.
8284 template<int size
, bool big_endian
>
8286 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
8287 const Relobj
* object
,
8288 unsigned int symndx
,
8289 unsigned int got_indx
) const
8291 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8292 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
8293 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
8295 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8296 got_type
<= GOT_TYPE_TPREL
;
8297 got_type
= Got_type(got_type
+ 1))
8298 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
8300 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
8301 if (got_type
== GOT_TYPE_TLSGD
)
8303 if (off
== got_indx
* (size
/ 8))
8305 if (got_type
== GOT_TYPE_TPREL
)
8315 // Return the offset to use for the GOT_INDX'th got entry which is
8316 // for global tls symbol GSYM.
8317 template<int size
, bool big_endian
>
8319 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
8321 unsigned int got_indx
) const
8323 if (gsym
->type() == elfcpp::STT_TLS
)
8325 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8326 got_type
<= GOT_TYPE_TPREL
;
8327 got_type
= Got_type(got_type
+ 1))
8328 if (gsym
->has_got_offset(got_type
))
8330 unsigned int off
= gsym
->got_offset(got_type
);
8331 if (got_type
== GOT_TYPE_TLSGD
)
8333 if (off
== got_indx
* (size
/ 8))
8335 if (got_type
== GOT_TYPE_TPREL
)
8345 // The selector for powerpc object files.
8347 template<int size
, bool big_endian
>
8348 class Target_selector_powerpc
: public Target_selector
8351 Target_selector_powerpc()
8352 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
8355 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
8356 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
8358 ? (big_endian
? "elf64ppc" : "elf64lppc")
8359 : (big_endian
? "elf32ppc" : "elf32lppc")))
8363 do_instantiate_target()
8364 { return new Target_powerpc
<size
, big_endian
>(); }
8367 Target_selector_powerpc
<32, true> target_selector_ppc32
;
8368 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
8369 Target_selector_powerpc
<64, true> target_selector_ppc64
;
8370 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
8372 // Instantiate these constants for -O0
8373 template<int size
, bool big_endian
>
8374 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
8375 template<int size
, bool big_endian
>
8376 const typename Output_data_glink
<size
, big_endian
>::Address
8377 Output_data_glink
<size
, big_endian
>::invalid_address
;
8378 template<int size
, bool big_endian
>
8379 const typename Stub_table
<size
, big_endian
>::Address
8380 Stub_table
<size
, big_endian
>::invalid_address
;
8381 template<int size
, bool big_endian
>
8382 const typename Target_powerpc
<size
, big_endian
>::Address
8383 Target_powerpc
<size
, big_endian
>::invalid_address
;
8385 } // End anonymous namespace.