1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2023 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"
44 #include "attributes.h"
51 template<int size
, bool big_endian
>
52 class Output_data_plt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_brlt_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_got_powerpc
;
60 template<int size
, bool big_endian
>
61 class Output_data_glink
;
63 template<int size
, bool big_endian
>
66 template<int size
, bool big_endian
>
67 class Output_data_save_res
;
69 template<int size
, bool big_endian
>
72 struct Stub_table_owner
75 : output_section(NULL
), owner(NULL
)
78 Output_section
* output_section
;
79 const Output_section::Input_section
* owner
;
83 inline bool is_branch_reloc(unsigned int);
86 inline bool is_plt16_reloc(unsigned int);
88 // Counter incremented on every Powerpc_relobj constructed.
89 static uint32_t object_id
= 0;
91 template<int size
, bool big_endian
>
92 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
95 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
96 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
97 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
99 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
100 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
101 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
102 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
103 has_small_toc_reloc_(false), opd_valid_(false),
104 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
105 access_from_map_(), has14_(), stub_table_index_(), st_other_(),
106 attributes_section_data_(NULL
)
108 this->set_abiversion(0);
112 { delete this->attributes_section_data_
; }
114 // Read the symbols then set up st_other vector.
116 do_read_symbols(Read_symbols_data
*);
118 // Arrange to always relocate .toc first.
120 do_relocate_sections(
121 const Symbol_table
* symtab
, const Layout
* layout
,
122 const unsigned char* pshdrs
, Output_file
* of
,
123 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
125 // The .toc section index.
132 // Mark .toc entry at OFF as not optimizable.
134 set_no_toc_opt(Address off
)
136 if (this->no_toc_opt_
.empty())
137 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
140 if (off
< this->no_toc_opt_
.size())
141 this->no_toc_opt_
[off
] = true;
144 // Mark the entire .toc as not optimizable.
148 this->no_toc_opt_
.resize(1);
149 this->no_toc_opt_
[0] = true;
152 // Return true if code using the .toc entry at OFF should not be edited.
154 no_toc_opt(Address off
) const
156 if (this->no_toc_opt_
.empty())
159 if (off
>= this->no_toc_opt_
.size())
161 return this->no_toc_opt_
[off
];
164 // The .got2 section shndx.
169 return this->special_
;
174 // The .opd section shndx.
181 return this->special_
;
184 // Init OPD entry arrays.
186 init_opd(size_t opd_size
)
188 size_t count
= this->opd_ent_ndx(opd_size
);
189 this->opd_ent_
.resize(count
);
192 // Return section and offset of function entry for .opd + R_OFF.
194 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
196 size_t ndx
= this->opd_ent_ndx(r_off
);
197 gold_assert(ndx
< this->opd_ent_
.size());
198 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
200 *value
= this->opd_ent_
[ndx
].off
;
201 return this->opd_ent_
[ndx
].shndx
;
204 // Set section and offset of function entry for .opd + R_OFF.
206 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
208 size_t ndx
= this->opd_ent_ndx(r_off
);
209 gold_assert(ndx
< this->opd_ent_
.size());
210 this->opd_ent_
[ndx
].shndx
= shndx
;
211 this->opd_ent_
[ndx
].off
= value
;
214 // Return discard flag for .opd + R_OFF.
216 get_opd_discard(Address r_off
) const
218 size_t ndx
= this->opd_ent_ndx(r_off
);
219 gold_assert(ndx
< this->opd_ent_
.size());
220 return this->opd_ent_
[ndx
].discard
;
223 // Set discard flag for .opd + R_OFF.
225 set_opd_discard(Address r_off
)
227 size_t ndx
= this->opd_ent_ndx(r_off
);
228 gold_assert(ndx
< this->opd_ent_
.size());
229 this->opd_ent_
[ndx
].discard
= true;
234 { return this->opd_valid_
; }
238 { this->opd_valid_
= true; }
240 // Examine .rela.opd to build info about function entry points.
242 scan_opd_relocs(size_t reloc_count
,
243 const unsigned char* prelocs
,
244 const unsigned char* plocal_syms
);
246 // Returns true if a code sequence loading a TOC entry can be
247 // converted into code calculating a TOC pointer relative offset.
249 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
253 make_got_relative(Target_powerpc
<size
, big_endian
>* target
,
254 const Symbol_value
<size
>* psymval
,
258 // Perform the Sized_relobj_file method, then set up opd info from
261 do_read_relocs(Read_relocs_data
*);
264 do_find_special_sections(Read_symbols_data
* sd
);
266 // Adjust this local symbol value. Return false if the symbol
267 // should be discarded from the output file.
269 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
271 if (size
== 64 && this->opd_shndx() != 0)
274 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
276 if (this->get_opd_discard(lv
->input_value()))
284 { return &this->access_from_map_
; }
286 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
287 // section at DST_OFF.
289 add_reference(Relobj
* src_obj
,
290 unsigned int src_indx
,
291 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
293 Section_id
src_id(src_obj
, src_indx
);
294 this->access_from_map_
[dst_off
].insert(src_id
);
297 // Add a reference to the code section specified by the .opd entry
300 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
302 size_t ndx
= this->opd_ent_ndx(dst_off
);
303 if (ndx
>= this->opd_ent_
.size())
304 this->opd_ent_
.resize(ndx
+ 1);
305 this->opd_ent_
[ndx
].gc_mark
= true;
309 process_gc_mark(Symbol_table
* symtab
)
311 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
312 if (this->opd_ent_
[i
].gc_mark
)
314 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
315 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
320 set_has_small_toc_reloc()
321 { has_small_toc_reloc_
= true; }
324 has_small_toc_reloc() const
325 { return has_small_toc_reloc_
; }
328 set_has_14bit_branch(unsigned int shndx
)
330 if (shndx
>= this->has14_
.size())
331 this->has14_
.resize(shndx
+ 1);
332 this->has14_
[shndx
] = true;
336 has_14bit_branch(unsigned int shndx
) const
337 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
340 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
342 if (shndx
>= this->stub_table_index_
.size())
343 this->stub_table_index_
.resize(shndx
+ 1, -1);
344 this->stub_table_index_
[shndx
] = stub_index
;
347 Stub_table
<size
, big_endian
>*
348 stub_table(unsigned int shndx
)
350 if (shndx
< this->stub_table_index_
.size())
352 Target_powerpc
<size
, big_endian
>* target
353 = static_cast<Target_powerpc
<size
, big_endian
>*>(
354 parameters
->sized_target
<size
, big_endian
>());
355 unsigned int indx
= this->stub_table_index_
[shndx
];
356 if (indx
< target
->stub_tables().size())
357 return target
->stub_tables()[indx
];
365 this->stub_table_index_
.clear();
370 { return this->uniq_
; }
374 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
376 // Set ABI version for input and output
378 set_abiversion(int ver
);
381 st_other (unsigned int symndx
) const
383 return this->st_other_
[symndx
];
387 ppc64_local_entry_offset(const Symbol
* sym
) const
388 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
391 ppc64_local_entry_offset(unsigned int symndx
) const
392 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
395 ppc64_needs_toc(const Symbol
* sym
) const
396 { return sym
->nonvis() > 1 << 3; }
399 ppc64_needs_toc(unsigned int symndx
) const
400 { return this->st_other_
[symndx
] > 1 << 5; }
402 // The contents of the .gnu.attributes section if there is one.
403 const Attributes_section_data
*
404 attributes_section_data() const
405 { return this->attributes_section_data_
; }
416 // Return index into opd_ent_ array for .opd entry at OFF.
417 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
418 // apart when the language doesn't use the last 8-byte word, the
419 // environment pointer. Thus dividing the entry section offset by
420 // 16 will give an index into opd_ent_ that works for either layout
421 // of .opd. (It leaves some elements of the vector unused when .opd
422 // entries are spaced 24 bytes apart, but we don't know the spacing
423 // until relocations are processed, and in any case it is possible
424 // for an object to have some entries spaced 16 bytes apart and
425 // others 24 bytes apart.)
427 opd_ent_ndx(size_t off
) const
430 // Per object unique identifier
433 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
434 unsigned int special_
;
436 // For 64-bit the .rela.toc and .toc section shdnx.
437 unsigned int relatoc_
;
440 // For 64-bit, whether this object uses small model relocs to access
442 bool has_small_toc_reloc_
;
444 // Set at the start of gc_process_relocs, when we know opd_ent_
445 // vector is valid. The flag could be made atomic and set in
446 // do_read_relocs with memory_order_release and then tested with
447 // memory_order_acquire, potentially resulting in fewer entries in
452 elfcpp::Elf_Word e_flags_
;
454 // For 64-bit, an array with one entry per 64-bit word in the .toc
455 // section, set if accesses using that word cannot be optimised.
456 std::vector
<bool> no_toc_opt_
;
458 // The first 8-byte word of an OPD entry gives the address of the
459 // entry point of the function. Relocatable object files have a
460 // relocation on this word. The following vector records the
461 // section and offset specified by these relocations.
462 std::vector
<Opd_ent
> opd_ent_
;
464 // References made to this object's .opd section when running
465 // gc_process_relocs for another object, before the opd_ent_ vector
466 // is valid for this object.
467 Access_from access_from_map_
;
469 // Whether input section has a 14-bit branch reloc.
470 std::vector
<bool> has14_
;
472 // The stub table to use for a given input section.
473 std::vector
<unsigned int> stub_table_index_
;
475 // ELF st_other field for local symbols.
476 std::vector
<unsigned char> st_other_
;
478 // Object attributes if there is a .gnu.attributes section.
479 Attributes_section_data
* attributes_section_data_
;
482 template<int size
, bool big_endian
>
483 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
486 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
488 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
489 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
490 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
491 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
492 attributes_section_data_(NULL
)
494 this->set_abiversion(0);
498 { delete this->attributes_section_data_
; }
500 // Call Sized_dynobj::do_read_symbols to read the symbols then
501 // read .opd from a dynamic object, filling in opd_ent_ vector,
503 do_read_symbols(Read_symbols_data
*);
505 // The .opd section shndx.
509 return this->opd_shndx_
;
512 // The .opd section address.
516 return this->opd_address_
;
519 // Init OPD entry arrays.
521 init_opd(size_t opd_size
)
523 size_t count
= this->opd_ent_ndx(opd_size
);
524 this->opd_ent_
.resize(count
);
527 // Return section and offset of function entry for .opd + R_OFF.
529 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
531 size_t ndx
= this->opd_ent_ndx(r_off
);
532 gold_assert(ndx
< this->opd_ent_
.size());
533 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
535 *value
= this->opd_ent_
[ndx
].off
;
536 return this->opd_ent_
[ndx
].shndx
;
539 // Set section and offset of function entry for .opd + R_OFF.
541 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
543 size_t ndx
= this->opd_ent_ndx(r_off
);
544 gold_assert(ndx
< this->opd_ent_
.size());
545 this->opd_ent_
[ndx
].shndx
= shndx
;
546 this->opd_ent_
[ndx
].off
= value
;
551 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
553 // Set ABI version for input and output.
555 set_abiversion(int ver
);
557 // The contents of the .gnu.attributes section if there is one.
558 const Attributes_section_data
*
559 attributes_section_data() const
560 { return this->attributes_section_data_
; }
563 // Used to specify extent of executable sections.
566 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
567 : start(start_
), len(len_
), shndx(shndx_
)
571 operator<(const Sec_info
& that
) const
572 { return this->start
< that
.start
; }
585 // Return index into opd_ent_ array for .opd entry at OFF.
587 opd_ent_ndx(size_t off
) const
590 // For 64-bit the .opd section shndx and address.
591 unsigned int opd_shndx_
;
592 Address opd_address_
;
595 elfcpp::Elf_Word e_flags_
;
597 // The first 8-byte word of an OPD entry gives the address of the
598 // entry point of the function. Records the section and offset
599 // corresponding to the address. Note that in dynamic objects,
600 // offset is *not* relative to the section.
601 std::vector
<Opd_ent
> opd_ent_
;
603 // Object attributes if there is a .gnu.attributes section.
604 Attributes_section_data
* attributes_section_data_
;
607 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
608 // base class will emit.
610 template<int sh_type
, int size
, bool big_endian
>
611 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
614 Powerpc_copy_relocs()
615 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
618 // Emit any saved relocations which turn out to be needed. This is
619 // called after all the relocs have been scanned.
621 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
624 // The types of GOT entries needed for this platform.
625 // These values are exposed to the ABI in an incremental link, but
626 // powerpc does not support incremental linking as yet.
629 GOT_TYPE_STANDARD
= 0,
630 GOT_TYPE_TLSGD
= 1, // double entry for @got@tlsgd
631 GOT_TYPE_DTPREL
= 2, // entry for @got@dtprel
632 GOT_TYPE_TPREL
= 3, // entry for @got@tprel
634 GOT_TYPE_SMALL_TLSGD
= 5,
635 GOT_TYPE_SMALL_DTPREL
= 6,
636 GOT_TYPE_SMALL_TPREL
= 7
639 // gsym->needs_plt_entry purpose is to decide whether a non-branch
640 // reloc should reference a plt entry. It can't be used to decide
641 // whether branches need a plt entry. In fact the call to
642 // needs_plt_entry here is not needed; All cases where it might
643 // return true ought to be covered already. However, since this
644 // function is used to decide between plt_ and lplt_ sections in
645 // plt_off, make certain that every case where make_plt_entry puts
646 // entries in plt_ is covered here.
648 branch_needs_plt_entry(const Symbol
* gsym
)
650 return (((!gsym
->is_defined()
651 || gsym
->is_from_dynobj()
652 || gsym
->is_preemptible())
653 && !gsym
->final_value_is_known())
654 || gsym
->needs_plt_entry());
657 template<int size
, bool big_endian
>
658 class Target_powerpc
: public Sized_target
<size
, big_endian
>
662 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
663 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
664 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
665 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
666 static const Address invalid_address
= static_cast<Address
>(0) - 1;
667 // Offset of tp and dtp pointers from start of TLS block.
668 static const Address tp_offset
= 0x7000;
669 static const Address dtp_offset
= 0x8000;
672 : Sized_target
<size
, big_endian
>(&powerpc_info
),
673 got_(NULL
), biggot_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
),
674 brlt_section_(NULL
), glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
675 tlsld_got_offset_(-1U),
676 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
677 power10_relocs_(false), plt_thread_safe_(false), plt_localentry0_(false),
678 plt_localentry0_init_(false), has_localentry0_(false),
679 has_tls_get_addr_opt_(false), no_tprel_opt_(false),
680 relax_failed_(false), relax_fail_count_(0),
681 stub_group_size_(0), savres_section_(0),
682 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
683 attributes_section_data_(NULL
),
684 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
688 // Process the relocations to determine unreferenced sections for
689 // garbage collection.
691 gc_process_relocs(Symbol_table
* symtab
,
693 Sized_relobj_file
<size
, big_endian
>* object
,
694 unsigned int data_shndx
,
695 unsigned int sh_type
,
696 const unsigned char* prelocs
,
698 Output_section
* output_section
,
699 bool needs_special_offset_handling
,
700 size_t local_symbol_count
,
701 const unsigned char* plocal_symbols
);
703 // Scan the relocations to look for symbol adjustments.
705 scan_relocs(Symbol_table
* symtab
,
707 Sized_relobj_file
<size
, big_endian
>* object
,
708 unsigned int data_shndx
,
709 unsigned int sh_type
,
710 const unsigned char* prelocs
,
712 Output_section
* output_section
,
713 bool needs_special_offset_handling
,
714 size_t local_symbol_count
,
715 const unsigned char* plocal_symbols
);
717 // Map input .toc section to output .got section.
719 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
721 if (size
== 64 && strcmp(name
, ".toc") == 0)
729 // Provide linker defined save/restore functions.
731 define_save_restore_funcs(Layout
*, Symbol_table
*);
733 // No stubs unless a final link.
736 { return !parameters
->options().relocatable(); }
739 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
742 do_plt_fde_location(const Output_data
*, unsigned char*,
743 uint64_t*, off_t
*) const;
745 // Stash info about branches, for stub generation.
747 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
748 unsigned int data_shndx
, Address r_offset
,
749 unsigned int r_type
, unsigned int r_sym
, Address addend
)
751 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
752 this->branch_info_
.push_back(info
);
753 if (r_type
== elfcpp::R_POWERPC_REL14
754 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
755 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
756 ppc_object
->set_has_14bit_branch(data_shndx
);
759 // Return whether the last branch is a plt call, and if so, mark the
760 // branch as having an R_PPC64_TOCSAVE.
762 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
763 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
766 && !this->branch_info_
.empty()
767 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
768 r_offset
, this, symtab
));
771 // Say the given location, that of a nop in a function prologue with
772 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
773 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
775 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
776 unsigned int shndx
, Address offset
)
779 loc
.object
= ppc_object
;
782 this->tocsave_loc_
.insert(loc
);
789 return &this->tocsave_loc_
;
793 do_define_standard_symbols(Symbol_table
*, Layout
*);
795 // Finalize the sections.
797 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
799 // Get the custom dynamic tag value.
801 do_dynamic_tag_custom_value(elfcpp::DT
) const;
803 // Return the value to use for a dynamic which requires special
806 do_dynsym_value(const Symbol
*) const;
808 // Return the PLT address to use for a local symbol.
810 do_plt_address_for_local(const Relobj
*, unsigned int) const;
812 // Return the PLT address to use for a global symbol.
814 do_plt_address_for_global(const Symbol
*) const;
816 // Return the offset to use for the GOT_INDX'th got entry which is
817 // for a local tls symbol specified by OBJECT, SYMNDX.
819 do_tls_offset_for_local(const Relobj
* object
,
821 Output_data_got_base
* got
,
822 unsigned int got_indx
,
823 uint64_t addend
) const;
825 // Return the offset to use for the GOT_INDX'th got entry which is
826 // for global tls symbol GSYM.
828 do_tls_offset_for_global(Symbol
* gsym
,
829 Output_data_got_base
* got
, unsigned int got_indx
,
830 uint64_t addend
) const;
833 do_function_location(Symbol_location
*) const;
836 do_can_check_for_function_pointers() const
839 // Adjust -fsplit-stack code which calls non-split-stack code.
841 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
842 section_offset_type fnoffset
, section_size_type fnsize
,
843 const unsigned char* prelocs
, size_t reloc_count
,
844 unsigned char* view
, section_size_type view_size
,
845 std::string
* from
, std::string
* to
) const;
847 // Relocate a section.
849 relocate_section(const Relocate_info
<size
, big_endian
>*,
850 unsigned int sh_type
,
851 const unsigned char* prelocs
,
853 Output_section
* output_section
,
854 bool needs_special_offset_handling
,
856 Address view_address
,
857 section_size_type view_size
,
858 const Reloc_symbol_changes
*);
860 // Scan the relocs during a relocatable link.
862 scan_relocatable_relocs(Symbol_table
* symtab
,
864 Sized_relobj_file
<size
, big_endian
>* object
,
865 unsigned int data_shndx
,
866 unsigned int sh_type
,
867 const unsigned char* prelocs
,
869 Output_section
* output_section
,
870 bool needs_special_offset_handling
,
871 size_t local_symbol_count
,
872 const unsigned char* plocal_symbols
,
873 Relocatable_relocs
*);
875 // Scan the relocs for --emit-relocs.
877 emit_relocs_scan(Symbol_table
* symtab
,
879 Sized_relobj_file
<size
, big_endian
>* object
,
880 unsigned int data_shndx
,
881 unsigned int sh_type
,
882 const unsigned char* prelocs
,
884 Output_section
* output_section
,
885 bool needs_special_offset_handling
,
886 size_t local_symbol_count
,
887 const unsigned char* plocal_syms
,
888 Relocatable_relocs
* rr
);
890 // Emit relocations for a section.
892 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
893 unsigned int sh_type
,
894 const unsigned char* prelocs
,
896 Output_section
* output_section
,
897 typename
elfcpp::Elf_types
<size
>::Elf_Off
898 offset_in_output_section
,
900 Address view_address
,
902 unsigned char* reloc_view
,
903 section_size_type reloc_view_size
);
905 // Return whether SYM is defined by the ABI.
907 do_is_defined_by_abi(const Symbol
* sym
) const
909 return strcmp(sym
->name(), "__tls_get_addr") == 0;
912 // Return the size of the GOT section, for incremental linking
916 gold_assert(this->got_
!= NULL
);
917 return this->got_
->data_size() + (this->biggot_
918 ? this->biggot_
->data_size() : 0);
921 // Get the PLT section.
922 const Output_data_plt_powerpc
<size
, big_endian
>*
925 gold_assert(this->plt_
!= NULL
);
929 // Get the IPLT section.
930 const Output_data_plt_powerpc
<size
, big_endian
>*
933 gold_assert(this->iplt_
!= NULL
);
937 // Get the LPLT section.
938 const Output_data_plt_powerpc
<size
, big_endian
>*
944 // Return the plt offset and section for the given global sym.
946 plt_off(const Symbol
* gsym
,
947 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
949 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
950 && gsym
->can_use_relative_reloc(false))
951 *sec
= this->iplt_section();
952 else if (branch_needs_plt_entry(gsym
))
953 *sec
= this->plt_section();
955 *sec
= this->lplt_section();
956 return gsym
->plt_offset();
959 // Return the plt offset and section for the given local sym.
961 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
962 unsigned int local_sym_index
,
963 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
965 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
966 if (lsym
->is_ifunc_symbol())
967 *sec
= this->iplt_section();
969 *sec
= this->lplt_section();
970 return relobj
->local_plt_offset(local_sym_index
);
973 // Get the .glink section.
974 const Output_data_glink
<size
, big_endian
>*
975 glink_section() const
977 gold_assert(this->glink_
!= NULL
);
981 Output_data_glink
<size
, big_endian
>*
984 gold_assert(this->glink_
!= NULL
);
988 bool has_glink() const
989 { return this->glink_
!= NULL
; }
991 // Get the GOT section.
992 const Output_data_got_powerpc
<size
, big_endian
>*
993 got_section(Got_type got_type
) const
995 gold_assert(this->got_
!= NULL
);
996 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
998 gold_assert(this->biggot_
!= NULL
);
999 return this->biggot_
;
1002 // Get the GOT section, creating it if necessary.
1003 Output_data_got_powerpc
<size
, big_endian
>*
1004 got_section(Symbol_table
*, Layout
*, Got_type
);
1006 // The toc/got pointer reg will be set to this value.
1010 return this->got_
->address() + this->got_
->g_o_t();
1013 // Offset of base used to access the GOT/TOC relative to the GOT section.
1015 got_base_offset(Got_type got_type
) const
1017 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
1018 return this->got_
->g_o_t();
1019 return this->toc_pointer() - this->biggot_
->address();
1023 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1024 const elfcpp::Ehdr
<size
, big_endian
>&);
1026 // Return the number of entries in the GOT.
1028 got_entry_count() const
1030 if (this->got_
== NULL
)
1032 return this->got_size() / (size
/ 8);
1035 // Return the number of entries in the PLT.
1037 plt_entry_count() const;
1039 // Return the offset of the first non-reserved PLT entry.
1041 first_plt_entry_offset() const
1045 if (this->abiversion() >= 2)
1050 // Return the size of each PLT entry.
1052 plt_entry_size() const
1056 if (this->abiversion() >= 2)
1061 Output_data_save_res
<size
, big_endian
>*
1062 savres_section() const
1064 return this->savres_section_
;
1067 // Add any special sections for this symbol to the gc work list.
1068 // For powerpc64, this adds the code section of a function
1071 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1073 // Handle target specific gc actions when adding a gc reference from
1074 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1075 // and DST_OFF. For powerpc64, this adds a referenc to the code
1076 // section of a function descriptor.
1078 do_gc_add_reference(Symbol_table
* symtab
,
1080 unsigned int src_shndx
,
1082 unsigned int dst_shndx
,
1083 Address dst_off
) const;
1085 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1088 { return this->stub_tables_
; }
1090 const Output_data_brlt_powerpc
<size
, big_endian
>*
1091 brlt_section() const
1092 { return this->brlt_section_
; }
1095 add_branch_lookup_table(Address to
)
1097 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1098 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1102 find_branch_lookup_table(Address to
)
1104 typename
Branch_lookup_table::const_iterator p
1105 = this->branch_lookup_table_
.find(to
);
1106 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1110 write_branch_lookup_table(unsigned char *oview
)
1112 for (typename
Branch_lookup_table::const_iterator p
1113 = this->branch_lookup_table_
.begin();
1114 p
!= this->branch_lookup_table_
.end();
1117 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1121 // Wrapper used after relax to define a local symbol in output data,
1122 // from the end if value < 0.
1124 define_local(Symbol_table
* symtab
, const char* name
,
1125 Output_data
* od
, Address value
, unsigned int symsize
)
1128 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1129 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1130 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1131 static_cast<Signed_address
>(value
) < 0,
1133 // We are creating this symbol late, so need to fix up things
1134 // done early in Layout::finalize.
1135 sym
->set_dynsym_index(-1U);
1139 set_power10_relocs()
1141 this->power10_relocs_
= true;
1145 power10_stubs() const
1147 return (this->power10_relocs_
1148 && (parameters
->options().power10_stubs_enum()
1149 != General_options::POWER10_STUBS_NO
));
1153 power10_stubs_auto() const
1155 return (parameters
->options().power10_stubs_enum()
1156 == General_options::POWER10_STUBS_AUTO
);
1160 plt_thread_safe() const
1161 { return this->plt_thread_safe_
; }
1164 plt_localentry0() const
1165 { return this->plt_localentry0_
; }
1168 has_localentry0() const
1169 { return this->has_localentry0_
; }
1172 set_has_localentry0()
1174 this->has_localentry0_
= true;
1178 is_elfv2_localentry0(const Symbol
* gsym
) const
1181 && this->abiversion() >= 2
1182 && this->plt_localentry0()
1183 && gsym
->type() == elfcpp::STT_FUNC
1184 && gsym
->is_defined()
1185 && gsym
->nonvis() >> 3 == 0
1186 && !gsym
->non_zero_localentry());
1190 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1191 unsigned int r_sym
) const
1193 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1194 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1197 && this->abiversion() >= 2
1198 && this->plt_localentry0()
1199 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1201 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1203 if (!psymval
->is_ifunc_symbol()
1204 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1213 { return !this->no_tprel_opt_
&& parameters
->options().tls_optimize(); }
1217 { this->no_tprel_opt_
= true; }
1219 // Remember any symbols seen with non-zero localentry, even those
1220 // not providing a definition
1222 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1227 unsigned char st_other
= sym
.get_st_other();
1228 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1229 to
->set_non_zero_localentry();
1231 // We haven't resolved anything, continue normal processing.
1237 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1240 set_abiversion(int ver
)
1242 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1243 flags
&= ~elfcpp::EF_PPC64_ABI
;
1244 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1245 this->set_processor_specific_flags(flags
);
1249 tls_get_addr_opt() const
1250 { return this->tls_get_addr_opt_
; }
1253 tls_get_addr() const
1254 { return this->tls_get_addr_
; }
1256 // If optimizing __tls_get_addr calls, whether this is the
1257 // "__tls_get_addr" symbol.
1259 is_tls_get_addr_opt(const Symbol
* gsym
) const
1261 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1262 || gsym
== this->tls_get_addr_opt_
);
1266 replace_tls_get_addr(const Symbol
* gsym
) const
1267 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1270 set_has_tls_get_addr_opt()
1271 { this->has_tls_get_addr_opt_
= true; }
1273 // Offset to toc save stack slot
1276 { return this->abiversion() < 2 ? 40 : 24; }
1278 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1279 // so use the CR save slot. Used only by __tls_get_addr call stub,
1280 // relying on __tls_get_addr not saving CR itself.
1283 { return this->abiversion() < 2 ? 32 : 8; }
1285 // Merge object attributes from input object with those in the output.
1287 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1290 symval_for_branch(const Symbol_table
* symtab
,
1291 const Sized_symbol
<size
>* gsym
,
1292 Powerpc_relobj
<size
, big_endian
>* object
,
1293 Address
*value
, unsigned int *dest_shndx
);
1309 : tls_get_addr_state_(NOT_EXPECTED
),
1310 relinfo_(NULL
), relnum_(0), r_offset_(0)
1315 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1322 if (this->relinfo_
!= NULL
)
1323 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1324 _("missing expected __tls_get_addr call"));
1328 expect_tls_get_addr_call(
1329 const Relocate_info
<size
, big_endian
>* relinfo
,
1333 this->tls_get_addr_state_
= EXPECTED
;
1334 this->relinfo_
= relinfo
;
1335 this->relnum_
= relnum
;
1336 this->r_offset_
= r_offset
;
1340 expect_tls_get_addr_call()
1341 { this->tls_get_addr_state_
= EXPECTED
; }
1344 skip_next_tls_get_addr_call()
1345 {this->tls_get_addr_state_
= SKIP
; }
1348 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1349 unsigned int r_type
, const Symbol
* gsym
)
1352 = ((r_type
== elfcpp::R_POWERPC_REL24
1353 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1354 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
1355 || r_type
== elfcpp::R_PPC_PLTREL24
1356 || is_plt16_reloc
<size
>(r_type
)
1357 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1358 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1359 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1360 || r_type
== elfcpp::R_POWERPC_PLTCALL
1361 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1362 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1364 && (gsym
== target
->tls_get_addr()
1365 || gsym
== target
->tls_get_addr_opt()));
1366 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1367 this->tls_get_addr_state_
= NOT_EXPECTED
;
1368 if (is_tls_call
&& last_tls
!= EXPECTED
)
1370 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1379 // What we're up to regarding calls to __tls_get_addr.
1380 // On powerpc, the branch and link insn making a call to
1381 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1382 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1383 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1384 // The marker relocation always comes first, and has the same
1385 // symbol as the reloc on the insn setting up the __tls_get_addr
1386 // argument. This ties the arg setup insn with the call insn,
1387 // allowing ld to safely optimize away the call. We check that
1388 // every call to __tls_get_addr has a marker relocation, and that
1389 // every marker relocation is on a call to __tls_get_addr.
1390 Tls_get_addr tls_get_addr_state_
;
1391 // Info about the last reloc for error message.
1392 const Relocate_info
<size
, big_endian
>* relinfo_
;
1397 // The class which scans relocations.
1398 class Scan
: protected Track_tls
1401 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1404 : Track_tls(), issued_non_pic_error_(false)
1408 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1411 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1412 Sized_relobj_file
<size
, big_endian
>* object
,
1413 unsigned int data_shndx
,
1414 Output_section
* output_section
,
1415 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1416 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1420 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1421 Sized_relobj_file
<size
, big_endian
>* object
,
1422 unsigned int data_shndx
,
1423 Output_section
* output_section
,
1424 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1428 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1430 Sized_relobj_file
<size
, big_endian
>* relobj
,
1433 const elfcpp::Rela
<size
, big_endian
>& ,
1434 unsigned int r_type
,
1435 const elfcpp::Sym
<size
, big_endian
>&)
1437 // PowerPC64 .opd is not folded, so any identical function text
1438 // may be folded and we'll still keep function addresses distinct.
1439 // That means no reloc is of concern here.
1442 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1443 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1444 if (ppcobj
->abiversion() == 1)
1447 // For 32-bit and ELFv2, conservatively assume anything but calls to
1448 // function code might be taking the address of the function.
1449 return !is_branch_reloc
<size
>(r_type
);
1453 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1455 Sized_relobj_file
<size
, big_endian
>* relobj
,
1458 const elfcpp::Rela
<size
, big_endian
>& ,
1459 unsigned int r_type
,
1465 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1466 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1467 if (ppcobj
->abiversion() == 1)
1470 return !is_branch_reloc
<size
>(r_type
);
1474 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1475 Sized_relobj_file
<size
, big_endian
>* object
,
1476 unsigned int r_type
, bool report_err
);
1480 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1481 unsigned int r_type
);
1484 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1485 unsigned int r_type
, Symbol
*);
1488 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1489 Target_powerpc
* target
);
1492 check_non_pic(Relobj
*, unsigned int r_type
);
1494 // Whether we have issued an error about a non-PIC compilation.
1495 bool issued_non_pic_error_
;
1498 // The class which implements relocation.
1499 class Relocate
: protected Track_tls
1502 // Use 'at' branch hints when true, 'y' when false.
1503 // FIXME maybe: set this with an option.
1504 static const bool is_isa_v2
= true;
1510 // Do a relocation. Return false if the caller should not issue
1511 // any warnings about this relocation.
1513 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1514 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1515 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1516 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1520 class Relocate_comdat_behavior
1523 // Decide what the linker should do for relocations that refer to
1524 // discarded comdat sections.
1525 inline Comdat_behavior
1526 get(const char* name
)
1528 gold::Default_comdat_behavior default_behavior
;
1529 Comdat_behavior ret
= default_behavior
.get(name
);
1530 if (ret
== CB_ERROR
)
1533 && (strcmp(name
, ".fixup") == 0
1534 || strcmp(name
, ".got2") == 0))
1537 && (strcmp(name
, ".opd") == 0
1538 || strcmp(name
, ".toc") == 0
1539 || strcmp(name
, ".toc1") == 0))
1546 // Optimize the TLS relocation type based on what we know about the
1547 // symbol. IS_FINAL is true if the final address of this symbol is
1548 // known at link time.
1550 tls::Tls_optimization
1551 optimize_tls_gd(bool is_final
)
1553 // If we are generating a shared library, then we can't do anything
1555 if (parameters
->options().shared()
1556 || !parameters
->options().tls_optimize())
1557 return tls::TLSOPT_NONE
;
1560 return tls::TLSOPT_TO_IE
;
1561 return tls::TLSOPT_TO_LE
;
1564 tls::Tls_optimization
1567 if (parameters
->options().shared()
1568 || !parameters
->options().tls_optimize())
1569 return tls::TLSOPT_NONE
;
1571 return tls::TLSOPT_TO_LE
;
1574 tls::Tls_optimization
1575 optimize_tls_ie(bool is_final
)
1578 || parameters
->options().shared()
1579 || !parameters
->options().tls_optimize())
1580 return tls::TLSOPT_NONE
;
1582 return tls::TLSOPT_TO_LE
;
1587 make_glink_section(Layout
*);
1589 // Create the PLT section.
1591 make_plt_section(Symbol_table
*, Layout
*);
1594 make_iplt_section(Symbol_table
*, Layout
*);
1597 make_lplt_section(Symbol_table
*, Layout
*);
1600 make_brlt_section(Layout
*);
1602 // Create a PLT entry for a global symbol.
1604 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1606 // Create a PLT entry for a local IFUNC symbol.
1608 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1609 Sized_relobj_file
<size
, big_endian
>*,
1612 // Create a PLT entry for a local non-IFUNC symbol.
1614 make_local_plt_entry(Symbol_table
*, Layout
*,
1615 Sized_relobj_file
<size
, big_endian
>*,
1619 make_local_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1621 // Create a GOT entry for local dynamic __tls_get_addr.
1623 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1624 Sized_relobj_file
<size
, big_endian
>* object
);
1627 tlsld_got_offset() const
1629 return this->tlsld_got_offset_
;
1632 // Get the dynamic reloc section, creating it if necessary.
1634 rela_dyn_section(Layout
*);
1636 // Similarly, but for ifunc symbols get the one for ifunc.
1638 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1640 // Copy a relocation against a global symbol.
1642 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1643 Sized_relobj_file
<size
, big_endian
>* object
,
1644 unsigned int shndx
, Output_section
* output_section
,
1645 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1647 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1648 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1649 symtab
->get_sized_symbol
<size
>(sym
),
1650 object
, shndx
, output_section
,
1651 r_type
, reloc
.get_r_offset(),
1652 reloc
.get_r_addend(),
1653 this->rela_dyn_section(layout
));
1656 // Look over all the input sections, deciding where to place stubs.
1658 group_sections(Layout
*, const Task
*, bool);
1660 // Sort output sections by address.
1661 struct Sort_sections
1664 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1665 { return sec1
->address() < sec2
->address(); }
1671 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1672 unsigned int data_shndx
,
1674 unsigned int r_type
,
1677 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1678 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1684 // Return whether this branch is going via a plt call stub, and if
1685 // so, mark it as having an R_PPC64_TOCSAVE.
1687 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1688 unsigned int shndx
, Address offset
,
1689 Target_powerpc
* target
, Symbol_table
* symtab
);
1691 // If this branch needs a plt call stub, or a long branch stub, make one.
1693 make_stub(Stub_table
<size
, big_endian
>*,
1694 Stub_table
<size
, big_endian
>*,
1695 Symbol_table
*) const;
1698 // The branch location..
1699 Powerpc_relobj
<size
, big_endian
>* object_
;
1700 unsigned int shndx_
;
1702 // ..and the branch type and destination.
1703 unsigned int r_type_
: 31;
1704 unsigned int tocsave_
: 1;
1705 unsigned int r_sym_
;
1709 // Information about this specific target which we pass to the
1710 // general Target structure.
1711 static Target::Target_info powerpc_info
;
1713 // The small GOT section used by ppc32, and by ppc64 for entries that
1714 // must be addresseed +/-32k from the got pointer.
1715 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1716 // Another GOT section used for entries that can be addressed +/- 2G
1717 // from the got pointer.
1718 Output_data_got_powerpc
<size
, big_endian
>* biggot_
;
1720 // The PLT section. This is a container for a table of addresses,
1721 // and their relocations. Each address in the PLT has a dynamic
1722 // relocation (R_*_JMP_SLOT) and each address will have a
1723 // corresponding entry in .glink for lazy resolution of the PLT.
1724 // ppc32 initialises the PLT to point at the .glink entry, while
1725 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1726 // linker adds a stub that loads the PLT entry into ctr then
1727 // branches to ctr. There may be more than one stub for each PLT
1728 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1729 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1730 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1731 // The IPLT section. Like plt_, this is a container for a table of
1732 // addresses and their relocations, specifically for STT_GNU_IFUNC
1733 // functions that resolve locally (STT_GNU_IFUNC functions that
1734 // don't resolve locally go in PLT). Unlike plt_, these have no
1735 // entry in .glink for lazy resolution, and the relocation section
1736 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1737 // the relocation section may contain relocations against
1738 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1739 // relocation section will appear at the end of other dynamic
1740 // relocations, so that ld.so applies these relocations after other
1741 // dynamic relocations. In a static executable, the relocation
1742 // section is emitted and marked with __rela_iplt_start and
1743 // __rela_iplt_end symbols.
1744 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1745 // A PLT style section for local, non-ifunc symbols
1746 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1747 // Section holding long branch destinations.
1748 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1749 // The .glink section.
1750 Output_data_glink
<size
, big_endian
>* glink_
;
1751 // The dynamic reloc section.
1752 Reloc_section
* rela_dyn_
;
1753 // Relocs saved to avoid a COPY reloc.
1754 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1755 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1756 unsigned int tlsld_got_offset_
;
1758 Stub_tables stub_tables_
;
1759 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1760 Branch_lookup_table branch_lookup_table_
;
1762 typedef std::vector
<Branch_info
> Branches
;
1763 Branches branch_info_
;
1764 Tocsave_loc tocsave_loc_
;
1766 off_t rela_dyn_size_
;
1768 bool power10_relocs_
;
1769 bool plt_thread_safe_
;
1770 bool plt_localentry0_
;
1771 bool plt_localentry0_init_
;
1772 bool has_localentry0_
;
1773 bool has_tls_get_addr_opt_
;
1777 int relax_fail_count_
;
1778 int32_t stub_group_size_
;
1780 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1782 // The "__tls_get_addr" symbol, if present
1783 Symbol
* tls_get_addr_
;
1784 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1785 Symbol
* tls_get_addr_opt_
;
1787 // Attributes in output.
1788 Attributes_section_data
* attributes_section_data_
;
1790 // Last input file to change various attribute tags
1791 const char* last_fp_
;
1792 const char* last_ld_
;
1793 const char* last_vec_
;
1794 const char* last_struct_
;
1798 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1801 true, // is_big_endian
1802 elfcpp::EM_PPC
, // machine_code
1803 false, // has_make_symbol
1804 false, // has_resolve
1805 false, // has_code_fill
1806 true, // is_default_stack_executable
1807 false, // can_icf_inline_merge_sections
1809 "/usr/lib/ld.so.1", // dynamic_linker
1810 0x10000000, // default_text_segment_address
1811 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1812 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1813 false, // isolate_execinstr
1815 elfcpp::SHN_UNDEF
, // small_common_shndx
1816 elfcpp::SHN_UNDEF
, // large_common_shndx
1817 0, // small_common_section_flags
1818 0, // large_common_section_flags
1819 NULL
, // attributes_section
1820 NULL
, // attributes_vendor
1821 "_start", // entry_symbol_name
1822 32, // hash_entry_size
1823 elfcpp::SHT_PROGBITS
, // unwind_section_type
1827 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1830 false, // is_big_endian
1831 elfcpp::EM_PPC
, // machine_code
1832 false, // has_make_symbol
1833 false, // has_resolve
1834 false, // has_code_fill
1835 true, // is_default_stack_executable
1836 false, // can_icf_inline_merge_sections
1838 "/usr/lib/ld.so.1", // dynamic_linker
1839 0x10000000, // default_text_segment_address
1840 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1841 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1842 false, // isolate_execinstr
1844 elfcpp::SHN_UNDEF
, // small_common_shndx
1845 elfcpp::SHN_UNDEF
, // large_common_shndx
1846 0, // small_common_section_flags
1847 0, // large_common_section_flags
1848 NULL
, // attributes_section
1849 NULL
, // attributes_vendor
1850 "_start", // entry_symbol_name
1851 32, // hash_entry_size
1852 elfcpp::SHT_PROGBITS
, // unwind_section_type
1856 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1859 true, // is_big_endian
1860 elfcpp::EM_PPC64
, // machine_code
1861 false, // has_make_symbol
1862 true, // has_resolve
1863 false, // has_code_fill
1864 false, // is_default_stack_executable
1865 false, // can_icf_inline_merge_sections
1867 "/usr/lib/ld.so.1", // dynamic_linker
1868 0x10000000, // default_text_segment_address
1869 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1870 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1871 false, // isolate_execinstr
1873 elfcpp::SHN_UNDEF
, // small_common_shndx
1874 elfcpp::SHN_UNDEF
, // large_common_shndx
1875 0, // small_common_section_flags
1876 0, // large_common_section_flags
1877 NULL
, // attributes_section
1878 NULL
, // attributes_vendor
1879 "_start", // entry_symbol_name
1880 32, // hash_entry_size
1881 elfcpp::SHT_PROGBITS
, // unwind_section_type
1885 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1888 false, // is_big_endian
1889 elfcpp::EM_PPC64
, // machine_code
1890 false, // has_make_symbol
1891 true, // has_resolve
1892 false, // has_code_fill
1893 false, // is_default_stack_executable
1894 false, // can_icf_inline_merge_sections
1896 "/usr/lib/ld.so.1", // dynamic_linker
1897 0x10000000, // default_text_segment_address
1898 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1899 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1900 false, // isolate_execinstr
1902 elfcpp::SHN_UNDEF
, // small_common_shndx
1903 elfcpp::SHN_UNDEF
, // large_common_shndx
1904 0, // small_common_section_flags
1905 0, // large_common_section_flags
1906 NULL
, // attributes_section
1907 NULL
, // attributes_vendor
1908 "_start", // entry_symbol_name
1909 32, // hash_entry_size
1910 elfcpp::SHT_PROGBITS
, // unwind_section_type
1915 is_branch_reloc(unsigned int r_type
)
1917 return (r_type
== elfcpp::R_POWERPC_REL24
1918 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1919 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
1920 || r_type
== elfcpp::R_PPC_PLTREL24
1921 || r_type
== elfcpp::R_PPC_LOCAL24PC
1922 || r_type
== elfcpp::R_POWERPC_REL14
1923 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1924 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1925 || r_type
== elfcpp::R_POWERPC_ADDR24
1926 || r_type
== elfcpp::R_POWERPC_ADDR14
1927 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1928 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1931 // Reloc resolves to plt entry.
1934 is_plt16_reloc(unsigned int r_type
)
1936 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1937 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1938 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1939 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1942 // GOT_TYPE_STANDARD or GOT_TYPE_SMALL (ie. not TLS) GOT relocs
1944 is_got_reloc(unsigned int r_type
)
1946 return (r_type
== elfcpp::R_POWERPC_GOT16
1947 || r_type
== elfcpp::R_POWERPC_GOT16_LO
1948 || r_type
== elfcpp::R_POWERPC_GOT16_HI
1949 || r_type
== elfcpp::R_POWERPC_GOT16_HA
1950 || r_type
== elfcpp::R_PPC64_GOT16_DS
1951 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
1952 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
);
1955 // If INSN is an opcode that may be used with an @tls operand, return
1956 // the transformed insn for TLS optimisation, otherwise return 0. If
1957 // REG is non-zero only match an insn with RB or RA equal to REG.
1959 at_tls_transform(uint32_t insn
, unsigned int reg
)
1961 if ((insn
& (0x3f << 26)) != 31 << 26)
1965 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1966 rtra
= insn
& ((1 << 26) - (1 << 16));
1967 else if (((insn
>> 16) & 0x1f) == reg
)
1968 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1972 if ((insn
& (0x3ff << 1)) == 266 << 1)
1975 else if ((insn
& (0x1f << 1)) == 23 << 1
1976 && ((insn
& (0x1f << 6)) < 14 << 6
1977 || ((insn
& (0x1f << 6)) >= 16 << 6
1978 && (insn
& (0x1f << 6)) < 24 << 6)))
1979 // load and store indexed -> dform
1980 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1981 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1982 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1983 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1984 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1986 insn
= (58 << 26) | 2;
1994 template<int size
, bool big_endian
>
1995 class Powerpc_relocate_functions
2015 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
2016 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2017 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
2019 template<int valsize
>
2021 has_overflow_signed(Address value
)
2023 // limit = 1 << (valsize - 1) without shift count exceeding size of type
2024 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2025 limit
<<= ((valsize
- 1) >> 1);
2026 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2027 return value
+ limit
> (limit
<< 1) - 1;
2030 template<int valsize
>
2032 has_overflow_unsigned(Address value
)
2034 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2035 limit
<<= ((valsize
- 1) >> 1);
2036 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2037 return value
> (limit
<< 1) - 1;
2040 template<int valsize
>
2042 has_overflow_bitfield(Address value
)
2044 return (has_overflow_unsigned
<valsize
>(value
)
2045 && has_overflow_signed
<valsize
>(value
));
2048 template<int valsize
>
2049 static inline Status
2050 overflowed(Address value
, Overflow_check overflow
)
2052 if (overflow
== CHECK_SIGNED
)
2054 if (has_overflow_signed
<valsize
>(value
))
2055 return STATUS_OVERFLOW
;
2057 else if (overflow
== CHECK_UNSIGNED
)
2059 if (has_overflow_unsigned
<valsize
>(value
))
2060 return STATUS_OVERFLOW
;
2062 else if (overflow
== CHECK_BITFIELD
)
2064 if (has_overflow_bitfield
<valsize
>(value
))
2065 return STATUS_OVERFLOW
;
2070 // Do a simple RELA relocation
2071 template<int fieldsize
, int valsize
>
2072 static inline Status
2073 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2075 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2076 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2077 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2078 return overflowed
<valsize
>(value
, overflow
);
2081 template<int fieldsize
, int valsize
>
2082 static inline Status
2083 rela(unsigned char* view
,
2084 unsigned int right_shift
,
2085 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2087 Overflow_check overflow
)
2089 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2090 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2091 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2092 if (overflow
== CHECK_SIGNED
)
2093 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2095 value
= value
>> right_shift
;
2096 Valtype reloc
= value
;
2099 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2100 return overflowed
<valsize
>(value
, overflow
);
2103 // Do a simple RELA relocation, unaligned.
2104 template<int fieldsize
, int valsize
>
2105 static inline Status
2106 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2108 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2109 return overflowed
<valsize
>(value
, overflow
);
2112 template<int fieldsize
, int valsize
>
2113 static inline Status
2114 rela_ua(unsigned char* view
,
2115 unsigned int right_shift
,
2116 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2118 Overflow_check overflow
)
2120 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2122 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2123 if (overflow
== CHECK_SIGNED
)
2124 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2126 value
= value
>> right_shift
;
2127 Valtype reloc
= value
;
2130 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2131 return overflowed
<valsize
>(value
, overflow
);
2135 // R_PPC64_ADDR64: (Symbol + Addend)
2137 addr64(unsigned char* view
, Address value
)
2138 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2140 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2142 addr64_u(unsigned char* view
, Address value
)
2143 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2145 // R_POWERPC_ADDR32: (Symbol + Addend)
2146 static inline Status
2147 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2148 { return This::template rela
<32,32>(view
, value
, overflow
); }
2150 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2151 static inline Status
2152 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2153 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2155 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2156 static inline Status
2157 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2159 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2161 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2162 stat
= STATUS_OVERFLOW
;
2166 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2167 static inline Status
2168 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2169 { return This::template rela
<16,16>(view
, value
, overflow
); }
2171 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2172 static inline Status
2173 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2174 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2176 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2177 static inline Status
2178 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2180 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2181 if ((value
& 3) != 0)
2182 stat
= STATUS_OVERFLOW
;
2186 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2187 static inline Status
2188 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2190 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2191 if ((value
& 15) != 0)
2192 stat
= STATUS_OVERFLOW
;
2196 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2198 addr16_hi(unsigned char* view
, Address value
)
2199 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2201 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2203 addr16_ha(unsigned char* view
, Address value
)
2204 { This::addr16_hi(view
, value
+ 0x8000); }
2206 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2208 addr16_hi2(unsigned char* view
, Address value
)
2209 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2211 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2213 addr16_ha2(unsigned char* view
, Address value
)
2214 { This::addr16_hi2(view
, value
+ 0x8000); }
2216 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2218 addr16_hi3(unsigned char* view
, Address value
)
2219 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2221 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2223 addr16_ha3(unsigned char* view
, Address value
)
2224 { This::addr16_hi3(view
, value
+ 0x8000); }
2226 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2227 static inline Status
2228 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2230 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2231 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2232 stat
= STATUS_OVERFLOW
;
2236 // R_POWERPC_REL16DX_HA
2237 static inline Status
2238 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2240 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2241 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2242 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2244 value
= static_cast<SignedAddress
>(value
) >> 16;
2245 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2246 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2247 return overflowed
<16>(value
, overflow
);
2251 static inline Status
2252 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2254 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2256 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2262 addr34_hi(unsigned char *view
, uint64_t value
)
2263 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2267 addr34_ha(unsigned char *view
, uint64_t value
)
2268 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2271 static inline Status
2272 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2274 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2276 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2280 // R_PPC64_ADDR16_HIGHER34
2282 addr16_higher34(unsigned char* view
, uint64_t value
)
2283 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2285 // R_PPC64_ADDR16_HIGHERA34
2287 addr16_highera34(unsigned char* view
, uint64_t value
)
2288 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2290 // R_PPC64_ADDR16_HIGHEST34
2292 addr16_highest34(unsigned char* view
, uint64_t value
)
2293 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2295 // R_PPC64_ADDR16_HIGHESTA34
2297 addr16_highesta34(unsigned char* view
, uint64_t value
)
2298 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2301 // Set ABI version for input and output.
2303 template<int size
, bool big_endian
>
2305 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2307 this->e_flags_
|= ver
;
2308 if (this->abiversion() != 0)
2310 Target_powerpc
<size
, big_endian
>* target
=
2311 static_cast<Target_powerpc
<size
, big_endian
>*>(
2312 parameters
->sized_target
<size
, big_endian
>());
2313 if (target
->abiversion() == 0)
2314 target
->set_abiversion(this->abiversion());
2315 else if (target
->abiversion() != this->abiversion())
2316 gold_error(_("%s: ABI version %d is not compatible "
2317 "with ABI version %d output"),
2318 this->name().c_str(),
2319 this->abiversion(), target
->abiversion());
2324 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2325 // relocatable object, if such sections exists.
2327 template<int size
, bool big_endian
>
2329 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2330 Read_symbols_data
* sd
)
2332 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2333 const unsigned char* namesu
= sd
->section_names
->data();
2334 const char* names
= reinterpret_cast<const char*>(namesu
);
2335 section_size_type names_size
= sd
->section_names_size
;
2336 const unsigned char* s
;
2338 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2339 size
== 32 ? ".got2" : ".opd",
2340 names
, names_size
, NULL
);
2343 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2344 this->special_
= ndx
;
2347 if (this->abiversion() == 0)
2348 this->set_abiversion(1);
2349 else if (this->abiversion() > 1)
2350 gold_error(_("%s: .opd invalid in abiv%d"),
2351 this->name().c_str(), this->abiversion());
2356 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2357 names
, names_size
, NULL
);
2360 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2361 this->relatoc_
= ndx
;
2362 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2363 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2366 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2369 // Examine .rela.opd to build info about function entry points.
2371 template<int size
, bool big_endian
>
2373 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2375 const unsigned char* prelocs
,
2376 const unsigned char* plocal_syms
)
2380 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2381 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2382 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2383 Address expected_off
= 0;
2384 bool regular
= true;
2385 unsigned int opd_ent_size
= 0;
2387 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2389 Reltype
reloc(prelocs
);
2390 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2391 = reloc
.get_r_info();
2392 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2393 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2395 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2396 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2399 if (r_sym
< this->local_symbol_count())
2401 typename
elfcpp::Sym
<size
, big_endian
>
2402 lsym(plocal_syms
+ r_sym
* sym_size
);
2403 shndx
= lsym
.get_st_shndx();
2404 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2405 value
= lsym
.get_st_value();
2408 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2410 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2411 value
+ reloc
.get_r_addend());
2414 expected_off
= reloc
.get_r_offset();
2415 opd_ent_size
= expected_off
;
2417 else if (expected_off
!= reloc
.get_r_offset())
2419 expected_off
+= opd_ent_size
;
2421 else if (r_type
== elfcpp::R_PPC64_TOC
)
2423 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2428 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2429 this->name().c_str(), r_type
);
2433 if (reloc_count
<= 2)
2434 opd_ent_size
= this->section_size(this->opd_shndx());
2435 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2439 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2440 this->name().c_str());
2446 // Returns true if a code sequence loading the TOC entry at VALUE
2447 // relative to the TOC pointer can be converted into code calculating
2448 // a TOC pointer relative offset.
2449 // If so, the TOC pointer relative offset is stored to VALUE.
2451 template<int size
, bool big_endian
>
2453 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2454 Target_powerpc
<size
, big_endian
>* target
,
2460 // With -mcmodel=medium code it is quite possible to have
2461 // toc-relative relocs referring to objects outside the TOC.
2462 // Don't try to look at a non-existent TOC.
2463 if (this->toc_shndx() == 0
2464 || this->output_section(this->toc_shndx()) == 0)
2467 // Convert VALUE back to an address by adding got_base (see below),
2468 // then to an offset in the TOC by subtracting the TOC output
2469 // section address and the TOC output offset.
2470 Address off
= (*value
+ target
->toc_pointer()
2471 - this->output_section(this->toc_shndx())->address()
2472 - this->output_section_offset(this->toc_shndx()));
2473 // Is this offset in the TOC? -mcmodel=medium code may be using
2474 // TOC relative access to variables outside the TOC. Those of
2475 // course can't be optimized. We also don't try to optimize code
2476 // that is using a different object's TOC.
2477 if (off
>= this->section_size(this->toc_shndx()))
2480 if (this->no_toc_opt(off
))
2483 section_size_type vlen
;
2484 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2485 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2487 Address got_base
= target
->toc_pointer();
2489 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2496 template<int size
, bool big_endian
>
2498 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2499 Target_powerpc
<size
, big_endian
>* target
,
2500 const Symbol_value
<size
>* psymval
,
2504 Address addr
= psymval
->value(this, addend
);
2505 Address got_base
= target
->toc_pointer();
2507 if (addr
+ 0x80008000 > 0xffffffff)
2514 // Perform the Sized_relobj_file method, then set up opd info from
2517 template<int size
, bool big_endian
>
2519 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2521 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2524 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2525 p
!= rd
->relocs
.end();
2528 if (p
->data_shndx
== this->opd_shndx())
2530 uint64_t opd_size
= this->section_size(this->opd_shndx());
2531 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2534 this->init_opd(opd_size
);
2535 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2536 rd
->local_symbols
->data());
2544 // Read the symbols then set up st_other vector.
2546 template<int size
, bool big_endian
>
2548 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2550 this->base_read_symbols(sd
);
2551 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2555 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2556 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2557 const unsigned int loccount
= this->do_local_symbol_count();
2560 this->st_other_
.resize(loccount
);
2561 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2562 off_t locsize
= loccount
* sym_size
;
2563 const unsigned int symtab_shndx
= this->symtab_shndx();
2564 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2565 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2566 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2567 locsize
, true, false);
2569 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2571 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2572 unsigned char st_other
= sym
.get_st_other();
2573 this->st_other_
[i
] = st_other
;
2574 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2576 if (this->abiversion() == 0)
2577 this->set_abiversion(2);
2578 else if (this->abiversion() < 2)
2579 gold_error(_("%s: local symbol %d has invalid st_other"
2580 " for ABI version 1"),
2581 this->name().c_str(), i
);
2587 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2588 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2589 bool merge_attributes
= false;
2590 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2592 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2593 switch (shdr
.get_sh_type())
2595 case elfcpp::SHT_GNU_ATTRIBUTES
:
2597 gold_assert(this->attributes_section_data_
== NULL
);
2598 section_offset_type section_offset
= shdr
.get_sh_offset();
2599 section_size_type section_size
=
2600 convert_to_section_size_type(shdr
.get_sh_size());
2601 const unsigned char* view
=
2602 this->get_view(section_offset
, section_size
, true, false);
2603 this->attributes_section_data_
=
2604 new Attributes_section_data(view
, section_size
);
2608 case elfcpp::SHT_SYMTAB
:
2610 // Sometimes an object has no contents except the section
2611 // name string table and an empty symbol table with the
2612 // undefined symbol. We don't want to merge
2613 // processor-specific flags from such an object.
2614 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2615 elfcpp::Elf_sizes
<size
>::sym_size
;
2616 if (shdr
.get_sh_size() > sym_size
)
2617 merge_attributes
= true;
2621 case elfcpp::SHT_STRTAB
:
2625 merge_attributes
= true;
2630 if (!merge_attributes
)
2632 // Should rarely happen.
2633 delete this->attributes_section_data_
;
2634 this->attributes_section_data_
= NULL
;
2638 template<int size
, bool big_endian
>
2640 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2642 this->e_flags_
|= ver
;
2643 if (this->abiversion() != 0)
2645 Target_powerpc
<size
, big_endian
>* target
=
2646 static_cast<Target_powerpc
<size
, big_endian
>*>(
2647 parameters
->sized_target
<size
, big_endian
>());
2648 if (target
->abiversion() == 0)
2649 target
->set_abiversion(this->abiversion());
2650 else if (target
->abiversion() != this->abiversion())
2651 gold_error(_("%s: ABI version %d is not compatible "
2652 "with ABI version %d output"),
2653 this->name().c_str(),
2654 this->abiversion(), target
->abiversion());
2659 // Call Sized_dynobj::base_read_symbols to read the symbols then
2660 // read .opd from a dynamic object, filling in opd_ent_ vector,
2662 template<int size
, bool big_endian
>
2664 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2666 this->base_read_symbols(sd
);
2667 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2668 const unsigned char* ps
=
2669 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2670 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2672 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2673 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2675 section_offset_type section_offset
= shdr
.get_sh_offset();
2676 section_size_type section_size
=
2677 convert_to_section_size_type(shdr
.get_sh_size());
2678 const unsigned char* view
=
2679 this->get_view(section_offset
, section_size
, true, false);
2680 this->attributes_section_data_
=
2681 new Attributes_section_data(view
, section_size
);
2687 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2688 const unsigned char* namesu
= sd
->section_names
->data();
2689 const char* names
= reinterpret_cast<const char*>(namesu
);
2690 const unsigned char* s
= NULL
;
2691 const unsigned char* opd
;
2692 section_size_type opd_size
;
2694 // Find and read .opd section.
2697 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2698 sd
->section_names_size
,
2703 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2704 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2705 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2707 if (this->abiversion() == 0)
2708 this->set_abiversion(1);
2709 else if (this->abiversion() > 1)
2710 gold_error(_("%s: .opd invalid in abiv%d"),
2711 this->name().c_str(), this->abiversion());
2713 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2714 this->opd_address_
= shdr
.get_sh_addr();
2715 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2716 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2722 // Build set of executable sections.
2723 // Using a set is probably overkill. There is likely to be only
2724 // a few executable sections, typically .init, .text and .fini,
2725 // and they are generally grouped together.
2726 typedef std::set
<Sec_info
> Exec_sections
;
2727 Exec_sections exec_sections
;
2729 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2731 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2732 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2733 && ((shdr
.get_sh_flags()
2734 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2735 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2736 && shdr
.get_sh_size() != 0)
2738 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2739 shdr
.get_sh_size(), i
));
2742 if (exec_sections
.empty())
2745 // Look over the OPD entries. This is complicated by the fact
2746 // that some binaries will use two-word entries while others
2747 // will use the standard three-word entries. In most cases
2748 // the third word (the environment pointer for languages like
2749 // Pascal) is unused and will be zero. If the third word is
2750 // used it should not be pointing into executable sections,
2752 this->init_opd(opd_size
);
2753 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2755 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2756 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2757 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2759 // Chances are that this is the third word of an OPD entry.
2761 typename
Exec_sections::const_iterator e
2762 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2763 if (e
!= exec_sections
.begin())
2766 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2768 // We have an address in an executable section.
2769 // VAL ought to be the function entry, set it up.
2770 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2771 // Skip second word of OPD entry, the TOC pointer.
2775 // If we didn't match any executable sections, we likely
2776 // have a non-zero third word in the OPD entry.
2781 // Relocate sections.
2783 template<int size
, bool big_endian
>
2785 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2786 const Symbol_table
* symtab
, const Layout
* layout
,
2787 const unsigned char* pshdrs
, Output_file
* of
,
2788 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2790 unsigned int start
= 1;
2792 && this->relatoc_
!= 0
2793 && !parameters
->options().relocatable())
2795 // Relocate .toc first.
2796 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2797 this->relatoc_
, this->relatoc_
);
2798 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2799 1, this->relatoc_
- 1);
2800 start
= this->relatoc_
+ 1;
2802 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2803 start
, this->shnum() - 1);
2806 // Set up some symbols.
2808 template<int size
, bool big_endian
>
2810 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2811 Symbol_table
* symtab
,
2816 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2817 // undefined when scanning relocs (and thus requires
2818 // non-relative dynamic relocs). The proper value will be
2820 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2821 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2823 Target_powerpc
<size
, big_endian
>* target
=
2824 static_cast<Target_powerpc
<size
, big_endian
>*>(
2825 parameters
->sized_target
<size
, big_endian
>());
2826 Output_data_got_powerpc
<size
, big_endian
>* got
2827 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
2828 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2829 Symbol_table::PREDEFINED
,
2833 elfcpp::STV_HIDDEN
, 0,
2837 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2838 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2839 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2841 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2843 = layout
->add_output_section_data(".sdata", 0,
2845 | elfcpp::SHF_WRITE
,
2846 sdata
, ORDER_SMALL_DATA
, false);
2847 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2848 Symbol_table::PREDEFINED
,
2849 os
, 32768, 0, elfcpp::STT_OBJECT
,
2850 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2856 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2857 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2858 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2860 Target_powerpc
<size
, big_endian
>* target
=
2861 static_cast<Target_powerpc
<size
, big_endian
>*>(
2862 parameters
->sized_target
<size
, big_endian
>());
2863 Output_data_got_powerpc
<size
, big_endian
>* got
2864 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
2865 symtab
->define_in_output_data(".TOC.", NULL
,
2866 Symbol_table::PREDEFINED
,
2870 elfcpp::STV_HIDDEN
, 0,
2875 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2876 if (parameters
->options().tls_get_addr_optimize()
2877 && this->tls_get_addr_
!= NULL
2878 && this->tls_get_addr_
->in_reg())
2879 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2880 if (this->tls_get_addr_opt_
!= NULL
)
2882 if (this->tls_get_addr_
->is_undefined()
2883 || this->tls_get_addr_
->is_from_dynobj())
2885 // Make it seem as if references to __tls_get_addr are
2886 // really to __tls_get_addr_opt, so the latter symbol is
2887 // made dynamic, not the former.
2888 this->tls_get_addr_
->clear_in_reg();
2889 this->tls_get_addr_opt_
->set_in_reg();
2891 // We have a non-dynamic definition for __tls_get_addr.
2892 // Make __tls_get_addr_opt the same, if it does not already have
2893 // a non-dynamic definition.
2894 else if (this->tls_get_addr_opt_
->is_undefined()
2895 || this->tls_get_addr_opt_
->is_from_dynobj())
2897 Sized_symbol
<size
>* from
2898 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2899 Sized_symbol
<size
>* to
2900 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2901 symtab
->clone
<size
>(to
, from
);
2906 // Set up PowerPC target specific relobj.
2908 template<int size
, bool big_endian
>
2910 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2911 const std::string
& name
,
2912 Input_file
* input_file
,
2913 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2915 int et
= ehdr
.get_e_type();
2916 // ET_EXEC files are valid input for --just-symbols/-R,
2917 // and we treat them as relocatable objects.
2918 if (et
== elfcpp::ET_REL
2919 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2921 Powerpc_relobj
<size
, big_endian
>* obj
=
2922 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2926 else if (et
== elfcpp::ET_DYN
)
2928 Powerpc_dynobj
<size
, big_endian
>* obj
=
2929 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2935 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2940 template<int size
, bool big_endian
>
2941 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2944 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2945 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2947 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
,
2949 : Output_data_got
<size
, big_endian
>(),
2950 symtab_(symtab
), layout_(layout
),
2951 header_ent_cnt_(size
== 32 ? 3 : 1),
2952 header_index_(size
== 32 ? 0x2000 : -1u)
2955 this->set_addralign(256);
2956 if (size
== 64 && (got_type
& GOT_TYPE_SMALL
))
2957 this->make_header();
2960 // Override all the Output_data_got methods we use so as to first call
2963 add_global(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2965 this->reserve_ent();
2966 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
,
2971 add_global_plt(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2973 this->reserve_ent();
2974 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
,
2979 add_global_tls(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2980 { return this->add_global_plt(gsym
, got_type
, addend
); }
2983 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2984 Output_data_reloc_generic
* rel_dyn
,
2985 unsigned int r_type
, uint64_t addend
)
2987 this->reserve_ent();
2988 Output_data_got
<size
, big_endian
>::
2989 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
, addend
);
2993 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2994 Output_data_reloc_generic
* rel_dyn
,
2995 unsigned int r_type_1
, unsigned int r_type_2
,
2998 if (gsym
->has_got_offset(got_type
))
3001 this->reserve_ent(2);
3002 Output_data_got
<size
, big_endian
>::
3003 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
,
3008 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
,
3011 this->reserve_ent();
3012 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
3017 add_local_plt(Relobj
* object
, unsigned int sym_index
,
3018 unsigned int got_type
, uint64_t addend
)
3020 this->reserve_ent();
3021 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
3026 add_local_tls(Relobj
* object
, unsigned int sym_index
,
3027 unsigned int got_type
, uint64_t addend
)
3028 { return this->add_local_plt(object
, sym_index
, got_type
, addend
); }
3031 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
3032 unsigned int got_type
,
3033 Output_data_reloc_generic
* rel_dyn
,
3034 unsigned int r_type
, uint64_t addend
)
3036 if (object
->local_has_got_offset(sym_index
, got_type
, addend
))
3039 this->reserve_ent(2);
3040 Output_data_got
<size
, big_endian
>::
3041 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
, addend
);
3045 add_constant(Valtype constant
)
3047 this->reserve_ent();
3048 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
3052 add_constant_pair(Valtype c1
, Valtype c2
)
3054 this->reserve_ent(2);
3055 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3058 // Offset of _GLOBAL_OFFSET_TABLE_ and .TOC. in this section.
3063 return this->got_offset(this->header_index_
);
3064 else if (this->header_index_
!= -1u)
3065 return this->got_offset(this->header_index_
) + 0x8000;
3070 // Ensure our GOT has a header.
3072 set_final_data_size()
3074 if (size
== 32 && this->header_ent_cnt_
!= 0)
3075 this->make_header();
3076 Output_data_got
<size
, big_endian
>::set_final_data_size();
3079 // First word of GOT header needs some values that are not
3080 // handled by Output_data_got so poke them in here.
3081 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3083 do_write(Output_file
* of
)
3085 if (this->header_index_
!= -1u)
3088 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3089 val
= this->layout_
->dynamic_section()->address();
3091 val
= this->address() + this->g_o_t();
3092 this->replace_constant(this->header_index_
, val
);
3094 Output_data_got
<size
, big_endian
>::do_write(of
);
3099 reserve_ent(unsigned int cnt
= 1)
3101 if (size
!= 32 || this->header_ent_cnt_
== 0)
3103 if (this->num_entries() + cnt
> this->header_index_
)
3104 this->make_header();
3110 this->header_ent_cnt_
= 0;
3111 this->header_index_
= this->num_entries();
3114 Output_data_got
<size
, big_endian
>::add_constant(0);
3115 Output_data_got
<size
, big_endian
>::add_constant(0);
3116 Output_data_got
<size
, big_endian
>::add_constant(0);
3118 // Define _GLOBAL_OFFSET_TABLE_ at the header
3119 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3122 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3123 sym
->set_value(this->g_o_t());
3126 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3127 Symbol_table::PREDEFINED
,
3128 this, this->g_o_t(), 0,
3131 elfcpp::STV_HIDDEN
, 0,
3135 Output_data_got
<size
, big_endian
>::add_constant(0);
3138 // Stashed pointers.
3139 Symbol_table
* symtab_
;
3143 unsigned int header_ent_cnt_
;
3144 // GOT header index.
3145 unsigned int header_index_
;
3148 // Get the GOT section, creating it if necessary.
3150 template<int size
, bool big_endian
>
3151 Output_data_got_powerpc
<size
, big_endian
>*
3152 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3156 if (this->got_
== NULL
)
3158 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3161 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
,
3164 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3165 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3166 this->got_
, ORDER_DATA
, false);
3169 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
3172 if (this->biggot_
== NULL
)
3175 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
,
3178 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3179 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3180 this->biggot_
, ORDER_DATA
, false);
3183 return this->biggot_
;
3186 // Get the dynamic reloc section, creating it if necessary.
3188 template<int size
, bool big_endian
>
3189 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3190 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3192 if (this->rela_dyn_
== NULL
)
3194 gold_assert(layout
!= NULL
);
3195 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3196 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3197 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3198 ORDER_DYNAMIC_RELOCS
, false);
3200 return this->rela_dyn_
;
3203 // Similarly, but for ifunc symbols get the one for ifunc.
3205 template<int size
, bool big_endian
>
3206 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3207 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3212 return this->rela_dyn_section(layout
);
3214 if (this->iplt_
== NULL
)
3215 this->make_iplt_section(symtab
, layout
);
3216 return this->iplt_
->rel_plt();
3222 // Determine the stub group size. The group size is the absolute
3223 // value of the parameter --stub-group-size. If --stub-group-size
3224 // is passed a negative value, we restrict stubs to be always after
3225 // the stubbed branches.
3226 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3227 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3228 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3229 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3230 owner_(NULL
), output_section_(NULL
)
3234 // Return true iff input section can be handled by current stub
3237 can_add_to_stub_group(Output_section
* o
,
3238 const Output_section::Input_section
* i
,
3241 const Output_section::Input_section
*
3247 { return output_section_
; }
3250 set_output_and_owner(Output_section
* o
,
3251 const Output_section::Input_section
* i
)
3253 this->output_section_
= o
;
3262 // Adding group sections before the stubs.
3263 FINDING_STUB_SECTION
,
3264 // Adding group sections after the stubs.
3268 uint32_t stub_group_size_
;
3269 bool stubs_always_after_branch_
;
3270 bool suppress_size_errors_
;
3271 // True if a stub group can serve multiple output sections.
3274 // Current max size of group. Starts at stub_group_size_ but is
3275 // reduced to stub_group_size_/1024 on seeing a section with
3276 // external conditional branches.
3277 uint32_t group_size_
;
3278 uint64_t group_start_addr_
;
3279 // owner_ and output_section_ specify the section to which stubs are
3280 // attached. The stubs are placed at the end of this section.
3281 const Output_section::Input_section
* owner_
;
3282 Output_section
* output_section_
;
3285 // Return true iff input section can be handled by current stub
3286 // group. Sections are presented to this function in order,
3287 // so the first section is the head of the group.
3290 Stub_control::can_add_to_stub_group(Output_section
* o
,
3291 const Output_section::Input_section
* i
,
3294 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3296 uint64_t start_addr
= o
->address();
3299 // .init and .fini sections are pasted together to form a single
3300 // function. We can't be adding stubs in the middle of the function.
3301 this_size
= o
->data_size();
3304 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3305 this_size
= i
->data_size();
3308 uint64_t end_addr
= start_addr
+ this_size
;
3309 uint32_t group_size
= this->stub_group_size_
;
3311 this->group_size_
= group_size
= group_size
>> 10;
3313 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3314 gold_warning(_("%s:%s exceeds group size"),
3315 i
->relobj()->name().c_str(),
3316 i
->relobj()->section_name(i
->shndx()).c_str());
3318 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3319 has14
? " 14bit" : "",
3320 i
->relobj()->name().c_str(),
3321 i
->relobj()->section_name(i
->shndx()).c_str(),
3322 (long long) this_size
,
3323 (this->state_
== NO_GROUP
3325 : (long long) end_addr
- this->group_start_addr_
));
3327 if (this->state_
== NO_GROUP
)
3329 // Only here on very first use of Stub_control
3331 this->output_section_
= o
;
3332 this->state_
= FINDING_STUB_SECTION
;
3333 this->group_size_
= group_size
;
3334 this->group_start_addr_
= start_addr
;
3337 else if (!this->multi_os_
&& this->output_section_
!= o
)
3339 else if (this->state_
== HAS_STUB_SECTION
)
3341 // Can we add this section, which is after the stubs, to the
3343 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3346 else if (this->state_
== FINDING_STUB_SECTION
)
3348 if ((whole_sec
&& this->output_section_
== o
)
3349 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3351 // Stubs are added at the end of "owner_".
3353 this->output_section_
= o
;
3356 // The group before the stubs has reached maximum size.
3357 // Now see about adding sections after the stubs to the
3358 // group. If the current section has a 14-bit branch and
3359 // the group before the stubs exceeds group_size_ (because
3360 // they didn't have 14-bit branches), don't add sections
3361 // after the stubs: The size of stubs for such a large
3362 // group may exceed the reach of a 14-bit branch.
3363 if (!this->stubs_always_after_branch_
3364 && this_size
<= this->group_size_
3365 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3367 gold_debug(DEBUG_TARGET
, "adding after stubs");
3368 this->state_
= HAS_STUB_SECTION
;
3369 this->group_start_addr_
= start_addr
;
3376 gold_debug(DEBUG_TARGET
,
3377 !this->multi_os_
&& this->output_section_
!= o
3378 ? "nope, new output section\n"
3379 : "nope, didn't fit\n");
3381 // The section fails to fit in the current group. Set up a few
3382 // things for the next group. owner_ and output_section_ will be
3383 // set later after we've retrieved those values for the current
3385 this->state_
= FINDING_STUB_SECTION
;
3386 this->group_size_
= group_size
;
3387 this->group_start_addr_
= start_addr
;
3391 // Look over all the input sections, deciding where to place stubs.
3393 template<int size
, bool big_endian
>
3395 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3397 bool no_size_errors
)
3399 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3400 parameters
->options().stub_group_multi());
3402 // Group input sections and insert stub table
3403 Stub_table_owner
* table_owner
= NULL
;
3404 std::vector
<Stub_table_owner
*> tables
;
3405 Layout::Section_list section_list
;
3406 layout
->get_executable_sections(§ion_list
);
3407 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3408 for (Layout::Section_list::iterator o
= section_list
.begin();
3409 o
!= section_list
.end();
3412 typedef Output_section::Input_section_list Input_section_list
;
3413 for (Input_section_list::const_iterator i
3414 = (*o
)->input_sections().begin();
3415 i
!= (*o
)->input_sections().end();
3418 if (i
->is_input_section()
3419 || i
->is_relaxed_input_section())
3421 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3422 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3423 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3424 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3426 table_owner
->output_section
= stub_control
.output_section();
3427 table_owner
->owner
= stub_control
.owner();
3428 stub_control
.set_output_and_owner(*o
, &*i
);
3431 if (table_owner
== NULL
)
3433 table_owner
= new Stub_table_owner
;
3434 tables
.push_back(table_owner
);
3436 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3440 if (table_owner
!= NULL
)
3442 table_owner
->output_section
= stub_control
.output_section();
3443 table_owner
->owner
= stub_control
.owner();;
3445 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3449 Stub_table
<size
, big_endian
>* stub_table
;
3451 if ((*t
)->owner
->is_input_section())
3452 stub_table
= new Stub_table
<size
, big_endian
>(this,
3453 (*t
)->output_section
,
3455 this->stub_tables_
.size());
3456 else if ((*t
)->owner
->is_relaxed_input_section())
3457 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3458 (*t
)->owner
->relaxed_input_section());
3461 this->stub_tables_
.push_back(stub_table
);
3467 static unsigned long
3468 max_branch_delta (unsigned int r_type
)
3470 if (r_type
== elfcpp::R_POWERPC_REL14
3471 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3472 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3474 if (r_type
== elfcpp::R_POWERPC_REL24
3475 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3476 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
3477 || r_type
== elfcpp::R_PPC_PLTREL24
3478 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3483 // Return whether this branch is going via a plt call stub.
3485 template<int size
, bool big_endian
>
3487 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3488 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3491 Target_powerpc
* target
,
3492 Symbol_table
* symtab
)
3494 if (this->object_
!= ppc_object
3495 || this->shndx_
!= shndx
3496 || this->offset_
!= offset
)
3499 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3500 if (sym
!= NULL
&& sym
->is_forwarder())
3501 sym
= symtab
->resolve_forwards(sym
);
3502 if (target
->replace_tls_get_addr(sym
))
3503 sym
= target
->tls_get_addr_opt();
3504 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3506 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3507 && !target
->is_elfv2_localentry0(gsym
))
3508 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3509 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3517 // If this branch needs a plt call stub, or a long branch stub, make one.
3519 template<int size
, bool big_endian
>
3521 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3522 Stub_table
<size
, big_endian
>* stub_table
,
3523 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3524 Symbol_table
* symtab
) const
3526 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3527 Target_powerpc
<size
, big_endian
>* target
=
3528 static_cast<Target_powerpc
<size
, big_endian
>*>(
3529 parameters
->sized_target
<size
, big_endian
>());
3530 if (sym
!= NULL
&& sym
->is_forwarder())
3531 sym
= symtab
->resolve_forwards(sym
);
3532 if (target
->replace_tls_get_addr(sym
))
3533 sym
= target
->tls_get_addr_opt();
3534 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3538 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3539 : this->object_
->local_has_plt_offset(this->r_sym_
))
3543 && target
->abiversion() >= 2
3544 && !parameters
->options().output_is_position_independent()
3545 && !is_branch_reloc
<size
>(this->r_type_
))
3546 target
->glink_section()->add_global_entry(gsym
);
3549 if (stub_table
== NULL
3552 && !parameters
->options().output_is_position_independent()
3553 && !is_branch_reloc
<size
>(this->r_type_
)))
3554 stub_table
= this->object_
->stub_table(this->shndx_
);
3555 if (stub_table
== NULL
)
3557 // This is a ref from a data section to an ifunc symbol,
3558 // or a non-branch reloc for which we always want to use
3559 // one set of stubs for resolving function addresses.
3560 stub_table
= ifunc_stub_table
;
3562 gold_assert(stub_table
!= NULL
);
3563 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3564 if (from
!= invalid_address
)
3565 from
+= (this->object_
->output_section(this->shndx_
)->address()
3568 ok
= stub_table
->add_plt_call_entry(from
,
3569 this->object_
, gsym
,
3570 this->r_type_
, this->addend_
,
3573 ok
= stub_table
->add_plt_call_entry(from
,
3574 this->object_
, this->r_sym_
,
3575 this->r_type_
, this->addend_
,
3581 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3582 if (max_branch_offset
== 0)
3584 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3585 gold_assert(from
!= invalid_address
);
3586 from
+= (this->object_
->output_section(this->shndx_
)->address()
3589 unsigned int other
= 0;
3592 switch (gsym
->source())
3594 case Symbol::FROM_OBJECT
:
3596 Object
* symobj
= gsym
->object();
3597 if (symobj
->is_dynamic()
3598 || symobj
->pluginobj() != NULL
)
3601 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3602 if (shndx
== elfcpp::SHN_UNDEF
)
3607 case Symbol::IS_UNDEFINED
:
3613 Symbol_table::Compute_final_value_status status
;
3614 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3615 if (status
!= Symbol_table::CFVS_OK
)
3618 other
= gsym
->nonvis() >> 3;
3622 const Symbol_value
<size
>* psymval
3623 = this->object_
->local_symbol(this->r_sym_
);
3624 Symbol_value
<size
> symval
;
3625 if (psymval
->is_section_symbol())
3626 symval
.set_is_section_symbol();
3627 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3628 typename
ObjType::Compute_final_local_value_status status
3629 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3631 if (status
!= ObjType::CFLV_OK
3632 || !symval
.has_output_value())
3634 to
= symval
.value(this->object_
, 0);
3636 other
= this->object_
->st_other(this->r_sym_
) >> 5;
3638 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3639 to
+= this->addend_
;
3640 if (stub_table
== NULL
)
3641 stub_table
= this->object_
->stub_table(this->shndx_
);
3642 if (size
== 64 && target
->abiversion() < 2)
3644 unsigned int dest_shndx
;
3645 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3649 unsigned int local_ent
= 0;
3651 && this->r_type_
!= elfcpp::R_PPC64_REL24_NOTOC
3652 && this->r_type_
!= elfcpp::R_PPC64_REL24_P9NOTOC
)
3653 local_ent
= elfcpp::ppc64_decode_local_entry(other
);
3654 Address delta
= to
+ local_ent
- from
;
3655 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3657 && (this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3658 || this->r_type_
== elfcpp::R_PPC64_REL24_P9NOTOC
)
3660 ? this->object_
->ppc64_needs_toc(gsym
)
3661 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3663 if (stub_table
== NULL
)
3665 gold_warning(_("%s:%s: branch in non-executable section,"
3666 " no long branch stub for you"),
3667 this->object_
->name().c_str(),
3668 this->object_
->section_name(this->shndx_
).c_str());
3671 bool save_res
= (size
== 64
3673 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3674 && gsym
->output_data() == target
->savres_section());
3675 ok
= stub_table
->add_long_branch_entry(this->r_type_
,
3676 from
, to
, other
, save_res
);
3680 gold_debug(DEBUG_TARGET
,
3681 "branch at %s:%s+%#lx\n"
3682 "can't reach stub attached to %s:%s",
3683 this->object_
->name().c_str(),
3684 this->object_
->section_name(this->shndx_
).c_str(),
3685 (unsigned long) this->offset_
,
3686 stub_table
->relobj()->name().c_str(),
3687 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3692 // Helper for do_relax, avoiding checks that size, address and offset
3693 // are not set more than once.
3696 update_current_size(Output_section_data_build
* od
, off_t cur_size
)
3698 od
->reset_address_and_file_offset();
3699 od
->set_current_data_size(cur_size
);
3700 od
->finalize_data_size();
3701 od
->output_section()->set_section_offsets_need_adjustment();
3704 // Relaxation hook. This is where we do stub generation.
3706 template<int size
, bool big_endian
>
3708 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3709 const Input_objects
*,
3710 Symbol_table
* symtab
,
3714 unsigned int prev_brlt_size
= 0;
3718 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3720 && this->abiversion() < 2
3722 && !parameters
->options().user_set_plt_thread_safe())
3724 static const char* const thread_starter
[] =
3728 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3730 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3731 "mq_notify", "create_timer",
3736 "GOMP_parallel_start",
3737 "GOMP_parallel_loop_static",
3738 "GOMP_parallel_loop_static_start",
3739 "GOMP_parallel_loop_dynamic",
3740 "GOMP_parallel_loop_dynamic_start",
3741 "GOMP_parallel_loop_guided",
3742 "GOMP_parallel_loop_guided_start",
3743 "GOMP_parallel_loop_runtime",
3744 "GOMP_parallel_loop_runtime_start",
3745 "GOMP_parallel_sections",
3746 "GOMP_parallel_sections_start",
3751 if (parameters
->options().shared())
3755 for (unsigned int i
= 0;
3756 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3759 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3760 thread_safe
= (sym
!= NULL
3762 && sym
->in_real_elf());
3768 this->plt_thread_safe_
= thread_safe
;
3770 if (parameters
->options().output_is_position_independent())
3771 this->rela_dyn_size_
3772 = this->rela_dyn_section(layout
)->current_data_size();
3774 this->stub_group_size_
= parameters
->options().stub_group_size();
3775 bool no_size_errors
= true;
3776 if (this->stub_group_size_
== 1)
3777 this->stub_group_size_
= 0x1c00000;
3778 else if (this->stub_group_size_
== -1)
3779 this->stub_group_size_
= -0x1e00000;
3781 no_size_errors
= false;
3782 this->group_sections(layout
, task
, no_size_errors
);
3784 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3786 this->branch_lookup_table_
.clear();
3787 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3788 p
!= this->stub_tables_
.end();
3791 (*p
)->clear_stubs(true);
3793 this->stub_tables_
.clear();
3794 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3795 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3796 program_name
, this->stub_group_size_
);
3797 this->group_sections(layout
, task
, true);
3800 // We need address of stub tables valid for make_stub.
3801 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3802 p
!= this->stub_tables_
.end();
3805 const Powerpc_relobj
<size
, big_endian
>* object
3806 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3807 Address off
= object
->get_output_section_offset((*p
)->shndx());
3808 gold_assert(off
!= invalid_address
);
3809 Output_section
* os
= (*p
)->output_section();
3810 (*p
)->set_address_and_size(os
, off
);
3815 // Clear plt call stubs, long branch stubs and branch lookup table.
3816 prev_brlt_size
= this->branch_lookup_table_
.size();
3817 this->branch_lookup_table_
.clear();
3818 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3819 p
!= this->stub_tables_
.end();
3822 (*p
)->clear_stubs(false);
3826 // Build all the stubs.
3827 this->relax_failed_
= false;
3828 Stub_table
<size
, big_endian
>* ifunc_stub_table
3829 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3830 Stub_table
<size
, big_endian
>* one_stub_table
3831 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3832 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3833 b
!= this->branch_info_
.end();
3836 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3837 && !this->relax_failed_
)
3839 this->relax_failed_
= true;
3840 this->relax_fail_count_
++;
3841 if (this->relax_fail_count_
< 3)
3845 bool do_resize
= false;
3846 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3847 p
!= this->stub_tables_
.end();
3849 if ((*p
)->need_resize())
3856 this->branch_lookup_table_
.clear();
3857 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3858 p
!= this->stub_tables_
.end();
3860 (*p
)->set_resizing(true);
3861 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3862 b
!= this->branch_info_
.end();
3865 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3866 && !this->relax_failed_
)
3868 this->relax_failed_
= true;
3869 this->relax_fail_count_
++;
3870 if (this->relax_fail_count_
< 3)
3874 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3875 p
!= this->stub_tables_
.end();
3877 (*p
)->set_resizing(false);
3880 // Did anything change size?
3881 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3882 bool again
= num_huge_branches
!= prev_brlt_size
;
3883 if (size
== 64 && num_huge_branches
!= 0)
3884 this->make_brlt_section(layout
);
3885 if (size
== 64 && again
)
3887 update_current_size(this->brlt_section_
, num_huge_branches
* 16);
3888 if (parameters
->options().output_is_position_independent())
3890 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
3891 off_t cur
= this->rela_dyn_size_
+ num_huge_branches
* reloc_size
;
3892 update_current_size(this->rela_dyn_
, cur
);
3896 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3897 p
!= this->stub_tables_
.rend();
3899 (*p
)->remove_eh_frame(layout
);
3901 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3902 p
!= this->stub_tables_
.end();
3904 (*p
)->add_eh_frame(layout
);
3906 typedef Unordered_set
<Output_section
*> Output_sections
;
3907 Output_sections os_need_update
;
3908 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3909 p
!= this->stub_tables_
.end();
3912 if ((*p
)->size_update())
3915 os_need_update
.insert((*p
)->output_section());
3919 // Set output section offsets for all input sections in an output
3920 // section that just changed size. Anything past the stubs will
3922 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3923 p
!= os_need_update
.end();
3926 Output_section
* os
= *p
;
3928 typedef Output_section::Input_section_list Input_section_list
;
3929 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3930 i
!= os
->input_sections().end();
3933 off
= align_address(off
, i
->addralign());
3934 if (i
->is_input_section() || i
->is_relaxed_input_section())
3935 i
->relobj()->set_section_offset(i
->shndx(), off
);
3936 if (i
->is_relaxed_input_section())
3938 Stub_table
<size
, big_endian
>* stub_table
3939 = static_cast<Stub_table
<size
, big_endian
>*>(
3940 i
->relaxed_input_section());
3941 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3942 off
+= stub_table_size
;
3943 // After a few iterations, set current stub table size
3944 // as min size threshold, so later stub tables can only
3947 stub_table
->set_min_size_threshold(stub_table_size
);
3950 off
+= i
->data_size();
3952 // If .branch_lt is part of this output section, then we have
3953 // just done the offset adjustment.
3954 os
->clear_section_offsets_need_adjustment();
3959 && num_huge_branches
!= 0
3960 && parameters
->options().output_is_position_independent())
3962 // Fill in the BRLT relocs.
3963 this->rela_dyn_
->reset_data_size();
3964 this->rela_dyn_
->set_current_data_size(this->rela_dyn_size_
);
3965 for (typename
Branch_lookup_table::const_iterator p
3966 = this->branch_lookup_table_
.begin();
3967 p
!= this->branch_lookup_table_
.end();
3970 this->rela_dyn_
->add_relative(elfcpp::R_POWERPC_RELATIVE
,
3971 this->brlt_section_
, p
->second
,
3974 this->rela_dyn_
->finalize_data_size();
3975 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
3976 gold_assert(this->rela_dyn_
->data_size()
3977 == this->rela_dyn_size_
+ num_huge_branches
* reloc_size
);
3981 && (parameters
->options().user_set_emit_stub_syms()
3982 ? parameters
->options().emit_stub_syms()
3984 || parameters
->options().output_is_position_independent()
3985 || parameters
->options().emit_relocs())))
3987 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3988 p
!= this->stub_tables_
.end();
3990 (*p
)->define_stub_syms(symtab
);
3992 if (this->glink_
!= NULL
)
3994 int stub_size
= this->glink_
->pltresolve_size();
3995 Address value
= -stub_size
;
4001 this->define_local(symtab
, "__glink_PLTresolve",
4002 this->glink_
, value
, stub_size
);
4005 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
4012 template<int size
, bool big_endian
>
4014 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
4015 unsigned char* oview
,
4019 uint64_t address
= plt
->address();
4020 off_t len
= plt
->data_size();
4022 if (plt
== this->glink_
)
4024 // See Output_data_glink::do_write() for glink contents.
4027 // Static linking may need stubs, to support ifunc and long
4028 // branches. We need to create an output section for
4029 // .eh_frame early in the link process, to have a place to
4030 // attach stub .eh_frame info. We also need to have
4031 // registered a CIE that matches the stub CIE. Both of
4032 // these requirements are satisfied by creating an FDE and
4033 // CIE for .glink, even though static linking will leave
4034 // .glink zero length.
4035 // ??? Hopefully generating an FDE with a zero address range
4036 // won't confuse anything that consumes .eh_frame info.
4038 else if (size
== 64)
4040 // There is one word before __glink_PLTresolve
4044 else if (parameters
->options().output_is_position_independent())
4046 // There are two FDEs for a position independent glink.
4047 // The first covers the branch table, the second
4048 // __glink_PLTresolve at the end of glink.
4049 off_t resolve_size
= this->glink_
->pltresolve_size();
4050 if (oview
[9] == elfcpp::DW_CFA_nop
)
4051 len
-= resolve_size
;
4054 address
+= len
- resolve_size
;
4061 // Must be a stub table.
4062 const Stub_table
<size
, big_endian
>* stub_table
4063 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
4064 uint64_t stub_address
= stub_table
->stub_address();
4065 len
-= stub_address
- address
;
4066 address
= stub_address
;
4069 *paddress
= address
;
4073 // A class to handle the PLT data.
4075 template<int size
, bool big_endian
>
4076 class Output_data_plt_powerpc
: public Output_section_data_build
4079 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4080 size
, big_endian
> Reloc_section
;
4082 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4083 Symbol_table
* symtab
,
4084 Reloc_section
* plt_rel
,
4086 : Output_section_data_build(size
== 32 ? 4 : 8),
4087 rel_(plt_rel
), targ_(targ
), symtab_(symtab
), name_(name
), sym_ents_()
4090 // Add an entry to the PLT.
4092 add_entry(Symbol
*, bool = false);
4095 add_ifunc_entry(Symbol
*);
4098 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4101 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4103 // Return the .rela.plt section data.
4110 // Return the number of PLT entries.
4114 if (this->current_data_size() == 0)
4116 return ((this->current_data_size() - this->first_plt_entry_offset())
4117 / this->plt_entry_size());
4122 do_adjust_output_section(Output_section
* os
)
4127 // Write to a map file.
4129 do_print_to_mapfile(Mapfile
* mapfile
) const
4130 { mapfile
->print_output_data(this, this->name_
); }
4133 struct Local_plt_ent
4135 Local_plt_ent(Sized_relobj_file
<size
, big_endian
>* obj
, unsigned int rsym
)
4136 { rsym_
= rsym
; u
.obj_
= obj
; }
4137 Local_plt_ent(Symbol
* sym
)
4138 { rsym_
= -1u; u
.gsym_
= sym
; }
4145 Sized_relobj_file
<size
, big_endian
>* obj_
;
4150 // Return the offset of the first non-reserved PLT entry.
4152 first_plt_entry_offset() const
4154 // IPLT and LPLT have no reserved entry.
4155 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4157 return this->targ_
->first_plt_entry_offset();
4160 // Return the size of each PLT entry.
4162 plt_entry_size() const
4164 return this->targ_
->plt_entry_size();
4167 // Write out the PLT data.
4169 do_write(Output_file
*);
4171 // The reloc section.
4172 Reloc_section
* rel_
;
4173 // Allows access to .glink for do_write.
4174 Target_powerpc
<size
, big_endian
>* targ_
;
4175 Symbol_table
* symtab_
;
4176 // What to report in map file.
4179 std::vector
<Local_plt_ent
> sym_ents_
;
4182 // Add an entry to the PLT.
4184 template<int size
, bool big_endian
>
4186 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
,
4189 if (!gsym
->has_plt_offset())
4191 section_size_type off
= this->current_data_size();
4193 off
+= this->first_plt_entry_offset();
4194 gsym
->set_plt_offset(off
);
4199 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4200 if (size
== 64 && this->targ_
->abiversion() < 2)
4201 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4202 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
,
4207 gsym
->set_needs_dynsym_entry();
4208 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4209 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4212 off
+= this->plt_entry_size();
4213 this->set_current_data_size(off
);
4216 Local_plt_ent
sym(gsym
);
4217 this->sym_ents_
.push_back(sym
);
4222 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4224 template<int size
, bool big_endian
>
4226 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4228 if (!gsym
->has_plt_offset())
4230 section_size_type off
= this->current_data_size();
4231 gsym
->set_plt_offset(off
);
4232 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4233 if (size
== 64 && this->targ_
->abiversion() < 2)
4234 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4235 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4236 off
+= this->plt_entry_size();
4237 this->set_current_data_size(off
);
4241 // Add an entry for a local symbol to the PLT.
4243 template<int size
, bool big_endian
>
4245 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4246 Sized_relobj_file
<size
, big_endian
>* relobj
,
4247 unsigned int local_sym_index
)
4249 if (!relobj
->local_has_plt_offset(local_sym_index
))
4251 section_size_type off
= this->current_data_size();
4252 relobj
->set_local_plt_offset(local_sym_index
, off
);
4255 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4256 if (size
== 64 && this->targ_
->abiversion() < 2)
4257 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4258 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4259 dynrel
, this, off
, 0);
4261 off
+= this->plt_entry_size();
4262 this->set_current_data_size(off
);
4263 Local_plt_ent
sym(relobj
, local_sym_index
);
4264 this->sym_ents_
.push_back(sym
);
4268 // Add an entry for a local ifunc symbol to the IPLT.
4270 template<int size
, bool big_endian
>
4272 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4273 Sized_relobj_file
<size
, big_endian
>* relobj
,
4274 unsigned int local_sym_index
)
4276 if (!relobj
->local_has_plt_offset(local_sym_index
))
4278 section_size_type off
= this->current_data_size();
4279 relobj
->set_local_plt_offset(local_sym_index
, off
);
4280 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4281 if (size
== 64 && this->targ_
->abiversion() < 2)
4282 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4283 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4285 off
+= this->plt_entry_size();
4286 this->set_current_data_size(off
);
4290 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4291 static const uint32_t add_2_2_11
= 0x7c425a14;
4292 static const uint32_t add_2_2_12
= 0x7c426214;
4293 static const uint32_t add_3_3_2
= 0x7c631214;
4294 static const uint32_t add_3_3_13
= 0x7c636a14;
4295 static const uint32_t add_3_12_2
= 0x7c6c1214;
4296 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4297 static const uint32_t add_11_0_11
= 0x7d605a14;
4298 static const uint32_t add_11_2_11
= 0x7d625a14;
4299 static const uint32_t add_11_11_2
= 0x7d6b1214;
4300 static const uint32_t add_12_11_12
= 0x7d8b6214;
4301 static const uint32_t addi_0_12
= 0x380c0000;
4302 static const uint32_t addi_2_2
= 0x38420000;
4303 static const uint32_t addi_3_3
= 0x38630000;
4304 static const uint32_t addi_11_11
= 0x396b0000;
4305 static const uint32_t addi_12_1
= 0x39810000;
4306 static const uint32_t addi_12_11
= 0x398b0000;
4307 static const uint32_t addi_12_12
= 0x398c0000;
4308 static const uint32_t addis_0_2
= 0x3c020000;
4309 static const uint32_t addis_0_13
= 0x3c0d0000;
4310 static const uint32_t addis_2_12
= 0x3c4c0000;
4311 static const uint32_t addis_11_2
= 0x3d620000;
4312 static const uint32_t addis_11_11
= 0x3d6b0000;
4313 static const uint32_t addis_11_30
= 0x3d7e0000;
4314 static const uint32_t addis_12_1
= 0x3d810000;
4315 static const uint32_t addis_12_2
= 0x3d820000;
4316 static const uint32_t addis_12_11
= 0x3d8b0000;
4317 static const uint32_t addis_12_12
= 0x3d8c0000;
4318 static const uint32_t b
= 0x48000000;
4319 static const uint32_t bcl_20_31
= 0x429f0005;
4320 static const uint32_t bctr
= 0x4e800420;
4321 static const uint32_t bctrl
= 0x4e800421;
4322 static const uint32_t beqlr
= 0x4d820020;
4323 static const uint32_t blr
= 0x4e800020;
4324 static const uint32_t bnectr_p4
= 0x4ce20420;
4325 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4326 static const uint32_t cmpldi_2_0
= 0x28220000;
4327 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4328 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4329 static const uint32_t cror_15_15_15
= 0x4def7b82;
4330 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4331 static const uint32_t ld_0_1
= 0xe8010000;
4332 static const uint32_t ld_0_11
= 0xe80b0000;
4333 static const uint32_t ld_0_12
= 0xe80c0000;
4334 static const uint32_t ld_2_1
= 0xe8410000;
4335 static const uint32_t ld_2_2
= 0xe8420000;
4336 static const uint32_t ld_2_11
= 0xe84b0000;
4337 static const uint32_t ld_2_12
= 0xe84c0000;
4338 static const uint32_t ld_11_1
= 0xe9610000;
4339 static const uint32_t ld_11_2
= 0xe9620000;
4340 static const uint32_t ld_11_3
= 0xe9630000;
4341 static const uint32_t ld_11_11
= 0xe96b0000;
4342 static const uint32_t ld_12_2
= 0xe9820000;
4343 static const uint32_t ld_12_3
= 0xe9830000;
4344 static const uint32_t ld_12_11
= 0xe98b0000;
4345 static const uint32_t ld_12_12
= 0xe98c0000;
4346 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4347 static const uint32_t lfd_0_1
= 0xc8010000;
4348 static const uint32_t li_0_0
= 0x38000000;
4349 static const uint32_t li_11_0
= 0x39600000;
4350 static const uint32_t li_12_0
= 0x39800000;
4351 static const uint32_t lis_0
= 0x3c000000;
4352 static const uint32_t lis_2
= 0x3c400000;
4353 static const uint32_t lis_11
= 0x3d600000;
4354 static const uint32_t lis_12
= 0x3d800000;
4355 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4356 static const uint32_t lwz_0_12
= 0x800c0000;
4357 static const uint32_t lwz_11_3
= 0x81630000;
4358 static const uint32_t lwz_11_11
= 0x816b0000;
4359 static const uint32_t lwz_11_30
= 0x817e0000;
4360 static const uint32_t lwz_12_3
= 0x81830000;
4361 static const uint32_t lwz_12_12
= 0x818c0000;
4362 static const uint32_t lwzu_0_12
= 0x840c0000;
4363 static const uint32_t mflr_0
= 0x7c0802a6;
4364 static const uint32_t mflr_11
= 0x7d6802a6;
4365 static const uint32_t mflr_12
= 0x7d8802a6;
4366 static const uint32_t mr_0_3
= 0x7c601b78;
4367 static const uint32_t mr_3_0
= 0x7c030378;
4368 static const uint32_t mtctr_0
= 0x7c0903a6;
4369 static const uint32_t mtctr_11
= 0x7d6903a6;
4370 static const uint32_t mtctr_12
= 0x7d8903a6;
4371 static const uint32_t mtlr_0
= 0x7c0803a6;
4372 static const uint32_t mtlr_11
= 0x7d6803a6;
4373 static const uint32_t mtlr_12
= 0x7d8803a6;
4374 static const uint32_t nop
= 0x60000000;
4375 static const uint32_t ori_0_0_0
= 0x60000000;
4376 static const uint32_t ori_11_11_0
= 0x616b0000;
4377 static const uint32_t ori_12_12_0
= 0x618c0000;
4378 static const uint32_t oris_12_12_0
= 0x658c0000;
4379 static const uint32_t sldi_11_11_34
= 0x796b1746;
4380 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4381 static const uint32_t srdi_0_0_2
= 0x7800f082;
4382 static const uint32_t std_0_1
= 0xf8010000;
4383 static const uint32_t std_0_12
= 0xf80c0000;
4384 static const uint32_t std_2_1
= 0xf8410000;
4385 static const uint32_t std_11_1
= 0xf9610000;
4386 static const uint32_t stfd_0_1
= 0xd8010000;
4387 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4388 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4389 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4390 static const uint32_t xor_2_12_12
= 0x7d826278;
4391 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4393 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4394 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4395 static const uint64_t pnop
= 0x0700000000000000ULL
;
4397 // Write out the PLT.
4399 template<int size
, bool big_endian
>
4401 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4403 if (!this->sym_ents_
.empty()
4404 && !parameters
->options().output_is_position_independent())
4406 const section_size_type offset
= this->offset();
4407 const section_size_type oview_size
4408 = convert_to_section_size_type(this->data_size());
4409 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4410 unsigned char* pov
= oview
;
4411 unsigned char* endpov
= oview
+ oview_size
;
4413 for (typename
std::vector
<Local_plt_ent
>::iterator e
4414 = this->sym_ents_
.begin();
4415 e
!= this->sym_ents_
.end();
4418 typename
elfcpp::Elf_types
<size
>::Elf_Addr val
;
4419 Sized_symbol
<size
>* gsym
= NULL
;
4420 Powerpc_relobj
<size
, big_endian
>* obj
= NULL
;
4421 if (e
->rsym_
== -1u)
4423 gsym
= static_cast<Sized_symbol
<size
>*>(e
->u
.gsym_
);
4424 val
= gsym
->value();
4428 obj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(e
->u
.obj_
);
4429 val
= obj
->local_symbol(e
->rsym_
)->value(obj
, 0);
4431 if (this->targ_
->abiversion() >= 2)
4433 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4439 this->targ_
->symval_for_branch(this->symtab_
, gsym
, obj
,
4441 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4443 val
= this->targ_
->toc_pointer();
4444 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4446 if (this->plt_entry_size() > 16)
4448 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, 0);
4453 gold_assert(pov
== endpov
);
4456 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4458 const section_size_type offset
= this->offset();
4459 const section_size_type oview_size
4460 = convert_to_section_size_type(this->data_size());
4461 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4462 unsigned char* pov
= oview
;
4463 unsigned char* endpov
= oview
+ oview_size
;
4465 // The address of the .glink branch table
4466 const Output_data_glink
<size
, big_endian
>* glink
4467 = this->targ_
->glink_section();
4468 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4470 while (pov
< endpov
)
4472 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4477 of
->write_output_view(offset
, oview_size
, oview
);
4481 // Create the PLT section.
4483 template<int size
, bool big_endian
>
4485 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4488 if (this->plt_
== NULL
)
4490 if (this->got_
== NULL
)
4491 this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
4493 if (this->glink_
== NULL
)
4494 make_glink_section(layout
);
4496 // Ensure that .rela.dyn always appears before .rela.plt This is
4497 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4498 // needs to include .rela.plt in its range.
4499 this->rela_dyn_section(layout
);
4501 Reloc_section
* plt_rel
= new Reloc_section(false);
4502 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4503 elfcpp::SHF_ALLOC
, plt_rel
,
4504 ORDER_DYNAMIC_PLT_RELOCS
, false);
4506 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, plt_rel
,
4508 layout
->add_output_section_data(".plt",
4510 ? elfcpp::SHT_PROGBITS
4511 : elfcpp::SHT_NOBITS
),
4512 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4519 Output_section
* rela_plt_os
= plt_rel
->output_section();
4520 rela_plt_os
->set_info_section(this->plt_
->output_section());
4524 // Create the IPLT section.
4526 template<int size
, bool big_endian
>
4528 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4531 if (this->iplt_
== NULL
)
4533 this->make_plt_section(symtab
, layout
);
4534 this->make_lplt_section(symtab
, layout
);
4536 Reloc_section
* iplt_rel
= new Reloc_section(false);
4537 if (this->rela_dyn_
->output_section())
4538 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4540 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, iplt_rel
,
4542 if (this->plt_
->output_section())
4543 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4547 // Create the LPLT section.
4549 template<int size
, bool big_endian
>
4551 Target_powerpc
<size
, big_endian
>::make_lplt_section(Symbol_table
* symtab
,
4554 if (this->lplt_
== NULL
)
4556 Reloc_section
* lplt_rel
= NULL
;
4557 if (parameters
->options().output_is_position_independent())
4558 lplt_rel
= this->rela_dyn_section(layout
);
4560 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, lplt_rel
,
4562 this->make_brlt_section(layout
);
4563 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4564 this->brlt_section_
->output_section()
4565 ->add_output_section_data(this->lplt_
);
4567 layout
->add_output_section_data(".branch_lt",
4568 elfcpp::SHT_PROGBITS
,
4569 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4576 // A section for huge long branch addresses, similar to plt section.
4578 template<int size
, bool big_endian
>
4579 class Output_data_brlt_powerpc
: public Output_section_data_build
4582 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4583 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4584 size
, big_endian
> Reloc_section
;
4586 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
)
4587 : Output_section_data_build(size
== 32 ? 4 : 8),
4593 do_adjust_output_section(Output_section
* os
)
4598 // Write to a map file.
4600 do_print_to_mapfile(Mapfile
* mapfile
) const
4601 { mapfile
->print_output_data(this, "** BRLT"); }
4604 // Write out the BRLT data.
4606 do_write(Output_file
*);
4608 Target_powerpc
<size
, big_endian
>* targ_
;
4611 // Make the branch lookup table section.
4613 template<int size
, bool big_endian
>
4615 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4617 if (size
== 64 && this->brlt_section_
== NULL
)
4619 bool is_pic
= parameters
->options().output_is_position_independent();
4622 // When PIC we can't fill in .branch_lt but must initialise at
4623 // runtime via dynamic relocations.
4624 this->rela_dyn_section(layout
);
4627 = new Output_data_brlt_powerpc
<size
, big_endian
>(this);
4628 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4629 this->plt_
->output_section()
4630 ->add_output_section_data(this->brlt_section_
);
4632 layout
->add_output_section_data(".branch_lt",
4633 elfcpp::SHT_PROGBITS
,
4634 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4635 this->brlt_section_
,
4641 // Write out .branch_lt when non-PIC.
4643 template<int size
, bool big_endian
>
4645 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4647 if (size
== 64 && !parameters
->options().output_is_position_independent())
4649 const section_size_type offset
= this->offset();
4650 const section_size_type oview_size
4651 = convert_to_section_size_type(this->data_size());
4652 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4654 this->targ_
->write_branch_lookup_table(oview
);
4655 of
->write_output_view(offset
, oview_size
, oview
);
4659 static inline uint32_t
4665 static inline uint32_t
4671 static inline uint32_t
4674 return hi(a
+ 0x8000);
4677 static inline uint64_t
4680 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4683 static inline uint64_t
4686 return (v
+ (1ULL << 33)) >> 34;
4692 static const unsigned char eh_frame_cie
[12];
4696 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4699 'z', 'R', 0, // Augmentation string.
4700 4, // Code alignment.
4701 0x80 - size
/ 8 , // Data alignment.
4703 1, // Augmentation size.
4704 (elfcpp::DW_EH_PE_pcrel
4705 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4706 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4709 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4710 static const unsigned char glink_eh_frame_fde_64v1
[] =
4712 0, 0, 0, 0, // Replaced with offset to .glink.
4713 0, 0, 0, 0, // Replaced with size of .glink.
4714 0, // Augmentation size.
4715 elfcpp::DW_CFA_advance_loc
+ 2,
4716 elfcpp::DW_CFA_register
, 65, 12,
4717 elfcpp::DW_CFA_advance_loc
+ 4,
4718 elfcpp::DW_CFA_restore_extended
, 65
4721 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4722 static const unsigned char glink_eh_frame_fde_64v2
[] =
4724 0, 0, 0, 0, // Replaced with offset to .glink.
4725 0, 0, 0, 0, // Replaced with size of .glink.
4726 0, // Augmentation size.
4727 elfcpp::DW_CFA_advance_loc
+ 2,
4728 elfcpp::DW_CFA_register
, 65, 0,
4729 elfcpp::DW_CFA_advance_loc
+ 2,
4730 elfcpp::DW_CFA_restore_extended
, 65
4733 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4735 0, 0, 0, 0, // Replaced with offset to .glink.
4736 0, 0, 0, 0, // Replaced with size of .glink.
4737 0, // Augmentation size.
4738 elfcpp::DW_CFA_advance_loc
+ 3,
4739 elfcpp::DW_CFA_register
, 65, 0,
4740 elfcpp::DW_CFA_advance_loc
+ 2,
4741 elfcpp::DW_CFA_restore_extended
, 65
4744 // Describe __glink_PLTresolve use of LR, 32-bit version.
4745 static const unsigned char glink_eh_frame_fde_32
[] =
4747 0, 0, 0, 0, // Replaced with offset to .glink.
4748 0, 0, 0, 0, // Replaced with size of .glink.
4749 0, // Augmentation size.
4750 elfcpp::DW_CFA_advance_loc
+ 2,
4751 elfcpp::DW_CFA_register
, 65, 0,
4752 elfcpp::DW_CFA_advance_loc
+ 4,
4753 elfcpp::DW_CFA_restore_extended
, 65
4756 static const unsigned char default_fde
[] =
4758 0, 0, 0, 0, // Replaced with offset to stubs.
4759 0, 0, 0, 0, // Replaced with size of stubs.
4760 0, // Augmentation size.
4761 elfcpp::DW_CFA_nop
, // Pad.
4766 template<bool big_endian
>
4768 write_insn(unsigned char* p
, uint32_t v
)
4770 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4774 static inline unsigned int
4777 if (!parameters
->options().user_set_plt_align())
4778 return size
== 64 ? 32 : 8;
4779 return 1 << parameters
->options().plt_align();
4782 // Stub_table holds information about plt and long branch stubs.
4783 // Stubs are built in an area following some input section determined
4784 // by group_sections(). This input section is converted to a relaxed
4785 // input section allowing it to be resized to accommodate the stubs
4787 template<int size
, bool big_endian
>
4788 class Stub_table
: public Output_relaxed_input_section
4793 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4794 : off_(off
), indx_(indx
), tocoff_(0), p9off_(0), tsize_ (0), iter_(0),
4795 toc_(0), notoc_(0), p9notoc_(0), r2save_(0), localentry0_(0)
4800 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4801 // toc stub, p9off_ is offset to p9notoc stub
4802 unsigned int tocoff_
: 8;
4803 unsigned int p9off_
: 8;
4804 // The size of the toc stub, used to locate blr on tls_get_addr stub.
4805 unsigned int tsize_
: 8;
4806 // Stub revision management
4807 unsigned int iter_
: 1;
4808 // The three types of stubs.
4809 unsigned int toc_
: 1;
4810 unsigned int notoc_
: 1;
4811 unsigned int p9notoc_
: 1;
4812 // Each with a possible variant saving r2 first
4813 unsigned int r2save_
: 1;
4814 // Handy cached info from symbol
4815 unsigned int localentry0_
: 1;
4817 struct Branch_stub_ent
4819 Branch_stub_ent(unsigned int off
)
4820 : off_(off
), tocoff_(0), p9off_(0), iter_(0), toc_(0), notoc_(0),
4821 p9notoc_(0), save_res_(0), other_(0)
4825 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4826 // toc stub, p9off_ is offset to p9notoc stub
4827 unsigned int tocoff_
: 8;
4828 unsigned int p9off_
: 8;
4829 // Stub revision management
4830 unsigned int iter_
: 1;
4831 // Four types of stubs.
4832 unsigned int toc_
: 1;
4833 unsigned int notoc_
: 1;
4834 unsigned int p9notoc_
: 1;
4835 unsigned int save_res_
: 1;
4836 // Handy cached info from symbol
4837 unsigned int other_
: 3;
4839 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4840 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4842 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4843 Output_section
* output_section
,
4844 const Output_section::Input_section
* owner
,
4846 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4848 ->section_addralign(owner
->shndx())),
4849 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4850 orig_data_size_(owner
->current_data_size()),
4851 plt_size_(0), last_plt_size_(0),
4852 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4853 need_save_res_(false), need_resize_(false), resizing_(false),
4856 this->set_output_section(output_section
);
4858 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4859 new_relaxed
.push_back(this);
4860 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4863 // Add a plt call stub.
4865 add_plt_call_entry(Address
,
4866 const Sized_relobj_file
<size
, big_endian
>*,
4873 add_plt_call_entry(Address
,
4874 const Sized_relobj_file
<size
, big_endian
>*,
4880 // Find a given plt call stub.
4882 find_plt_call_entry(const Symbol
*) const;
4885 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4886 unsigned int) const;
4889 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4895 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4900 // Add a long branch stub.
4902 add_long_branch_entry(unsigned int, Address
, Address
, unsigned int, bool);
4904 const Branch_stub_ent
*
4905 find_long_branch_entry(Address
) const;
4908 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4910 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4911 if (max_branch_offset
== 0)
4913 gold_assert(from
!= invalid_address
);
4914 Address loc
= off
+ this->stub_address();
4915 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4919 clear_stubs(bool all
)
4921 this->plt_call_stubs_
.clear();
4922 this->plt_size_
= 0;
4923 this->long_branch_stubs_
.clear();
4924 this->branch_size_
= 0;
4925 this->need_save_res_
= false;
4928 this->last_plt_size_
= 0;
4929 this->last_branch_size_
= 0;
4935 { return need_resize_
; }
4938 set_resizing(bool val
)
4940 this->resizing_
= val
;
4943 this->need_resize_
= false;
4944 this->plt_size_
= 0;
4945 this->branch_size_
= 0;
4946 this->need_save_res_
= false;
4951 set_address_and_size(const Output_section
* os
, Address off
)
4953 Address start_off
= off
;
4954 off
+= this->orig_data_size_
;
4955 Address my_size
= this->plt_size_
+ this->branch_size_
;
4956 if (this->need_save_res_
)
4957 my_size
+= this->targ_
->savres_section()->data_size();
4959 off
= align_address(off
, this->stub_align());
4960 // Include original section size and alignment padding in size
4961 my_size
+= off
- start_off
;
4962 // Ensure new size is always larger than min size
4963 // threshold. Alignment requirement is included in "my_size", so
4964 // increase "my_size" does not invalidate alignment.
4965 if (my_size
< this->min_size_threshold_
)
4966 my_size
= this->min_size_threshold_
;
4967 this->reset_address_and_file_offset();
4968 this->set_current_data_size(my_size
);
4969 this->set_address_and_file_offset(os
->address() + start_off
,
4970 os
->offset() + start_off
);
4975 stub_address() const
4977 return align_address(this->address() + this->orig_data_size_
,
4978 this->stub_align());
4984 return align_address(this->offset() + this->orig_data_size_
,
4985 this->stub_align());
4990 { return this->plt_size_
; }
4994 { return this->branch_size_
; }
4997 set_min_size_threshold(Address min_size
)
4998 { this->min_size_threshold_
= min_size
; }
5001 define_stub_syms(Symbol_table
*);
5006 Output_section
* os
= this->output_section();
5007 if (os
->addralign() < this->stub_align())
5009 os
->set_addralign(this->stub_align());
5010 // FIXME: get rid of the insane checkpointing.
5011 // We can't increase alignment of the input section to which
5012 // stubs are attached; The input section may be .init which
5013 // is pasted together with other .init sections to form a
5014 // function. Aligning might insert zero padding resulting in
5015 // sigill. However we do need to increase alignment of the
5016 // output section so that the align_address() on offset in
5017 // set_address_and_size() adds the same padding as the
5018 // align_address() on address in stub_address().
5019 // What's more, we need this alignment for the layout done in
5020 // relaxation_loop_body() so that the output section starts at
5021 // a suitably aligned address.
5022 os
->checkpoint_set_addralign(this->stub_align());
5024 if (this->last_plt_size_
!= this->plt_size_
5025 || this->last_branch_size_
!= this->branch_size_
)
5027 this->last_plt_size_
= this->plt_size_
;
5028 this->last_branch_size_
= this->branch_size_
;
5034 // Add .eh_frame info for this stub section.
5036 add_eh_frame(Layout
* layout
);
5038 // Remove .eh_frame info for this stub section.
5040 remove_eh_frame(Layout
* layout
);
5042 Target_powerpc
<size
, big_endian
>*
5048 class Plt_stub_key_hash
;
5049 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
5050 Plt_stub_key_hash
> Plt_stub_entries
;
5051 class Branch_stub_key
;
5052 class Branch_stub_key_hash
;
5053 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
5054 Branch_stub_key_hash
> Branch_stub_entries
;
5056 // Alignment of stub section.
5060 unsigned int min_align
= size
== 64 ? 32 : 16;
5061 unsigned int user_align
= 1 << parameters
->options().plt_align();
5062 return std::max(user_align
, min_align
);
5065 // Return the plt offset for the given call stub.
5067 plt_off(typename
Plt_stub_entries::const_iterator p
,
5068 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
5070 const Symbol
* gsym
= p
->first
.sym_
;
5072 return this->targ_
->plt_off(gsym
, sec
);
5075 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
5076 unsigned int local_sym_index
= p
->first
.locsym_
;
5077 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
5081 // Size of a given plt call stub.
5083 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
5086 plt_call_align(unsigned int bytes
) const
5088 unsigned int align
= param_plt_align
<size
>();
5089 return (bytes
+ align
- 1) & -align
;
5092 // Return long branch stub size.
5094 branch_stub_size(typename
Branch_stub_entries::iterator p
,
5098 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
5101 build_tls_opt_tail(unsigned char* p
);
5104 plt_error(const Plt_stub_key
& p
);
5108 do_write(Output_file
*);
5110 // Plt call stub keys.
5114 Plt_stub_key(const Symbol
* sym
)
5115 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5118 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5119 unsigned int locsym_index
)
5120 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5123 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5125 unsigned int r_type
,
5127 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5130 this->addend_
= addend
;
5131 else if (parameters
->options().output_is_position_independent()
5132 && (r_type
== elfcpp::R_PPC_PLTREL24
5133 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5135 this->addend_
= addend
;
5136 if (this->addend_
>= 32768)
5137 this->object_
= object
;
5141 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5142 unsigned int locsym_index
,
5143 unsigned int r_type
,
5145 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5148 this->addend_
= addend
;
5149 else if (parameters
->options().output_is_position_independent()
5150 && (r_type
== elfcpp::R_PPC_PLTREL24
5151 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5152 this->addend_
= addend
;
5155 bool operator==(const Plt_stub_key
& that
) const
5157 return (this->sym_
== that
.sym_
5158 && this->object_
== that
.object_
5159 && this->addend_
== that
.addend_
5160 && this->locsym_
== that
.locsym_
);
5164 const Sized_relobj_file
<size
, big_endian
>* object_
;
5165 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5166 unsigned int locsym_
;
5169 class Plt_stub_key_hash
5172 size_t operator()(const Plt_stub_key
& ent
) const
5174 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5175 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5181 // Long branch stub keys.
5182 class Branch_stub_key
5185 Branch_stub_key(Address to
)
5189 bool operator==(const Branch_stub_key
& that
) const
5191 return this->dest_
== that
.dest_
;
5197 class Branch_stub_key_hash
5200 size_t operator()(const Branch_stub_key
& key
) const
5201 { return key
.dest_
; }
5204 // In a sane world this would be a global.
5205 Target_powerpc
<size
, big_endian
>* targ_
;
5206 // Map sym/object/addend to stub offset.
5207 Plt_stub_entries plt_call_stubs_
;
5208 // Map destination address to stub offset.
5209 Branch_stub_entries long_branch_stubs_
;
5210 // size of input section
5211 section_size_type orig_data_size_
;
5213 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5214 // Some rare cases cause (PR/20529) fluctuation in stub table
5215 // size, which leads to an endless relax loop. This is to be fixed
5216 // by, after the first few iterations, allowing only increase of
5217 // stub table size. This variable sets the minimal possible size of
5218 // a stub table, it is zero for the first few iterations, then
5219 // increases monotonically.
5220 Address min_size_threshold_
;
5221 // Set if this stub group needs a copy of out-of-line register
5222 // save/restore functions.
5223 bool need_save_res_
;
5224 // Set when notoc_/r2save_ changes after sizing a stub
5226 // Set when resizing stubs
5228 // Per stub table unique identifier.
5232 // Add a plt call stub, if we do not already have one for this
5233 // sym/object/addend combo.
5235 template<int size
, bool big_endian
>
5237 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5239 const Sized_relobj_file
<size
, big_endian
>* object
,
5241 unsigned int r_type
,
5245 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5246 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5247 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5248 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5252 && this->targ_
->is_elfv2_localentry0(gsym
))
5254 p
.first
->second
.localentry0_
= 1;
5255 this->targ_
->set_has_localentry0();
5257 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5258 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5260 if (this->targ_
->power10_stubs()
5261 && (!this->targ_
->power10_stubs_auto()
5262 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5264 if (!p
.second
&& !p
.first
->second
.notoc_
)
5265 this->need_resize_
= true;
5266 p
.first
->second
.notoc_
= 1;
5270 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5271 this->need_resize_
= true;
5272 p
.first
->second
.p9notoc_
= 1;
5277 if (!p
.second
&& !p
.first
->second
.toc_
)
5278 this->need_resize_
= true;
5279 p
.first
->second
.toc_
= 1;
5280 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5282 if (!p
.second
&& !p
.first
->second
.r2save_
)
5283 this->need_resize_
= true;
5284 p
.first
->second
.r2save_
= 1;
5288 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5290 if (this->resizing_
)
5292 p
.first
->second
.iter_
= 1;
5293 p
.first
->second
.off_
= this->plt_size_
;
5295 this->plt_size_
+= this->plt_call_size(p
.first
);
5296 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5297 this->targ_
->set_has_tls_get_addr_opt();
5299 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5302 template<int size
, bool big_endian
>
5304 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5306 const Sized_relobj_file
<size
, big_endian
>* object
,
5307 unsigned int locsym_index
,
5308 unsigned int r_type
,
5312 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5313 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5314 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5315 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5319 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5321 p
.first
->second
.localentry0_
= 1;
5322 this->targ_
->set_has_localentry0();
5324 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5325 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5327 if (this->targ_
->power10_stubs()
5328 && (!this->targ_
->power10_stubs_auto()
5329 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5331 if (!p
.second
&& !p
.first
->second
.notoc_
)
5332 this->need_resize_
= true;
5333 p
.first
->second
.notoc_
= 1;
5337 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5338 this->need_resize_
= true;
5339 p
.first
->second
.p9notoc_
= 1;
5344 if (!p
.second
&& !p
.first
->second
.toc_
)
5345 this->need_resize_
= true;
5346 p
.first
->second
.toc_
= 1;
5347 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5349 if (!p
.second
&& !p
.first
->second
.r2save_
)
5350 this->need_resize_
= true;
5351 p
.first
->second
.r2save_
= 1;
5355 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5357 if (this->resizing_
)
5359 p
.first
->second
.iter_
= 1;
5360 p
.first
->second
.off_
= this->plt_size_
;
5362 this->plt_size_
+= this->plt_call_size(p
.first
);
5364 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5367 // Find a plt call stub.
5369 template<int size
, bool big_endian
>
5370 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5371 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5372 const Sized_relobj_file
<size
, big_endian
>* object
,
5374 unsigned int r_type
,
5375 Address addend
) const
5377 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5378 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5379 if (p
== this->plt_call_stubs_
.end())
5384 template<int size
, bool big_endian
>
5385 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5386 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5388 Plt_stub_key
key(gsym
);
5389 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5390 if (p
== this->plt_call_stubs_
.end())
5395 template<int size
, bool big_endian
>
5396 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5397 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5398 const Sized_relobj_file
<size
, big_endian
>* object
,
5399 unsigned int locsym_index
,
5400 unsigned int r_type
,
5401 Address addend
) const
5403 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5404 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5405 if (p
== this->plt_call_stubs_
.end())
5410 template<int size
, bool big_endian
>
5411 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5412 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5413 const Sized_relobj_file
<size
, big_endian
>* object
,
5414 unsigned int locsym_index
) const
5416 Plt_stub_key
key(object
, locsym_index
);
5417 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5418 if (p
== this->plt_call_stubs_
.end())
5423 // Add a long branch stub if we don't already have one to given
5426 template<int size
, bool big_endian
>
5428 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5429 unsigned int r_type
,
5435 Branch_stub_key
key(to
);
5436 Branch_stub_ent
ent(this->branch_size_
);
5437 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5438 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5441 if (!p
.second
&& !p
.first
->second
.save_res_
)
5442 this->need_resize_
= true;
5443 p
.first
->second
.save_res_
= true;
5446 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5447 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
))
5449 if (this->targ_
->power10_stubs()
5450 && (!this->targ_
->power10_stubs_auto()
5451 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5453 if (!p
.second
&& !p
.first
->second
.notoc_
)
5454 this->need_resize_
= true;
5455 p
.first
->second
.notoc_
= true;
5459 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5460 this->need_resize_
= true;
5461 p
.first
->second
.p9notoc_
= true;
5466 if (!p
.second
&& !p
.first
->second
.toc_
)
5467 this->need_resize_
= true;
5468 p
.first
->second
.toc_
= true;
5470 if (size
== 64 && p
.first
->second
.other_
== 0)
5471 p
.first
->second
.other_
= other
;
5472 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5474 if (this->resizing_
)
5476 p
.first
->second
.iter_
= 1;
5477 p
.first
->second
.off_
= this->branch_size_
;
5480 this->need_save_res_
= true;
5483 bool need_lt
= false;
5484 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5485 this->branch_size_
+= stub_size
;
5486 if (size
== 64 && need_lt
)
5487 this->targ_
->add_branch_lookup_table(to
);
5490 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5493 // Find long branch stub offset.
5495 template<int size
, bool big_endian
>
5496 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5497 Stub_table
<size
, big_endian
>::find_long_branch_entry(Address to
) const
5499 Branch_stub_key
key(to
);
5500 typename
Branch_stub_entries::const_iterator p
5501 = this->long_branch_stubs_
.find(key
);
5502 if (p
== this->long_branch_stubs_
.end())
5507 template<bool big_endian
>
5509 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5513 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5514 else if (delta
< 256)
5516 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5517 fde
.push_back(delta
);
5519 else if (delta
< 65536)
5521 fde
.resize(fde
.size() + 3);
5522 unsigned char *p
= &*fde
.end() - 3;
5523 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5524 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5528 fde
.resize(fde
.size() + 5);
5529 unsigned char *p
= &*fde
.end() - 5;
5530 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5531 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5535 template<typename T
>
5537 stub_sort(T s1
, T s2
)
5539 return s1
->second
.off_
< s2
->second
.off_
;
5542 // Add .eh_frame info for this stub section. Unlike other linker
5543 // generated .eh_frame this is added late in the link, because we
5544 // only want the .eh_frame info if this particular stub section is
5547 template<int size
, bool big_endian
>
5549 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5552 || !parameters
->options().ld_generated_unwind_info())
5555 // Since we add stub .eh_frame info late, it must be placed
5556 // after all other linker generated .eh_frame info so that
5557 // merge mapping need not be updated for input sections.
5558 // There is no provision to use a different CIE to that used
5560 if (!this->targ_
->has_glink())
5563 typedef typename
Plt_stub_entries::iterator plt_iter
;
5564 std::vector
<plt_iter
> calls
;
5565 if (!this->plt_call_stubs_
.empty())
5566 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5567 cs
!= this->plt_call_stubs_
.end();
5569 if (cs
->second
.p9notoc_
5571 && cs
->second
.r2save_
5572 && !cs
->second
.localentry0_
5573 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)))
5574 calls
.push_back(cs
);
5575 if (calls
.size() > 1)
5576 std::stable_sort(calls
.begin(), calls
.end(),
5577 stub_sort
<plt_iter
>);
5579 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5580 std::vector
<branch_iter
> branches
;
5581 if (!this->long_branch_stubs_
.empty()
5582 && !this->targ_
->power10_stubs())
5583 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5584 bs
!= this->long_branch_stubs_
.end();
5586 if (bs
->second
.notoc_
)
5587 branches
.push_back(bs
);
5588 if (branches
.size() > 1)
5589 std::stable_sort(branches
.begin(), branches
.end(),
5590 stub_sort
<branch_iter
>);
5592 if (calls
.empty() && branches
.empty())
5595 unsigned int last_eh_loc
= 0;
5596 // offset pcrel sdata4, size udata4, and augmentation size byte.
5597 std::vector
<unsigned char> fde(9, 0);
5599 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5601 plt_iter cs
= calls
[i
];
5602 unsigned int off
= cs
->second
.off_
;
5603 // The __tls_get_addr_opt call stub needs to describe where
5604 // it saves LR, to support exceptions that might be thrown
5605 // from __tls_get_addr, and to support asynchronous exceptions.
5606 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5610 && cs
->second
.r2save_
5611 && !cs
->second
.localentry0_
)
5613 off
+= cs
->second
.tocoff_
+ 2 * 4;
5614 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5615 fde
.resize(fde
.size() + 6);
5616 unsigned char* p
= &*fde
.end() - 6;
5617 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5619 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5620 unsigned int delta
= cs
->second
.tsize_
- 9 * 4 - 4;
5621 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5622 *p
++ = elfcpp::DW_CFA_restore_extended
;
5624 last_eh_loc
= off
+ delta
;
5625 off
= cs
->second
.off_
+ 7 * 4;
5628 // notoc stubs also should describe LR changes, to support
5629 // asynchronous exceptions.
5630 if (cs
->second
.p9notoc_
)
5632 off
+= cs
->second
.p9off_
;
5633 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5634 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5635 fde
.resize(fde
.size() + 6);
5636 unsigned char* p
= &*fde
.end() - 6;
5637 *p
++ = elfcpp::DW_CFA_register
;
5640 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5641 *p
++ = elfcpp::DW_CFA_restore_extended
;
5643 last_eh_loc
= off
+ 8;
5647 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5649 branch_iter bs
= branches
[i
];
5650 unsigned int off
= bs
->second
.off_
+ 8;
5651 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5652 fde
.resize(fde
.size() + 6);
5653 unsigned char* p
= &*fde
.end() - 6;
5654 *p
++ = elfcpp::DW_CFA_register
;
5657 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5658 *p
++ = elfcpp::DW_CFA_restore_extended
;
5660 last_eh_loc
= off
+ 8;
5663 layout
->add_eh_frame_for_plt(this,
5664 Eh_cie
<size
>::eh_frame_cie
,
5665 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5666 &*fde
.begin(), fde
.size());
5669 template<int size
, bool big_endian
>
5671 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5674 && parameters
->options().ld_generated_unwind_info()
5675 && this->targ_
->has_glink())
5676 layout
->remove_eh_frame_for_plt(this,
5677 Eh_cie
<size
>::eh_frame_cie
,
5678 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5681 // A class to handle .glink.
5683 template<int size
, bool big_endian
>
5684 class Output_data_glink
: public Output_section_data
5687 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5688 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5690 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5691 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5692 end_branch_table_(), ge_size_(0)
5696 add_eh_frame(Layout
* layout
);
5699 add_global_entry(const Symbol
*);
5702 find_global_entry(const Symbol
*) const;
5705 global_entry_align(unsigned int off
) const
5707 unsigned int align
= param_plt_align
<size
>();
5708 return (off
+ align
- 1) & -align
;
5712 global_entry_off() const
5714 return this->global_entry_align(this->end_branch_table_
);
5718 global_entry_address() const
5720 gold_assert(this->is_data_size_valid());
5721 return this->address() + this->global_entry_off();
5725 pltresolve_size() const
5729 + (this->targ_
->abiversion() < 2 ? 11 * 4
5730 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5735 // Write to a map file.
5737 do_print_to_mapfile(Mapfile
* mapfile
) const
5738 { mapfile
->print_output_data(this, _("** glink")); }
5742 set_final_data_size();
5746 do_write(Output_file
*);
5748 // Allows access to .got and .plt for do_write.
5749 Target_powerpc
<size
, big_endian
>* targ_
;
5751 // Map sym to stub offset.
5752 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5753 Global_entry_stub_entries global_entry_stubs_
;
5755 unsigned int end_branch_table_
, ge_size_
;
5758 template<int size
, bool big_endian
>
5760 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5762 if (!parameters
->options().ld_generated_unwind_info())
5767 if (this->targ_
->abiversion() < 2)
5768 layout
->add_eh_frame_for_plt(this,
5769 Eh_cie
<64>::eh_frame_cie
,
5770 sizeof (Eh_cie
<64>::eh_frame_cie
),
5771 glink_eh_frame_fde_64v1
,
5772 sizeof (glink_eh_frame_fde_64v1
));
5773 else if (this->targ_
->has_localentry0())
5774 layout
->add_eh_frame_for_plt(this,
5775 Eh_cie
<64>::eh_frame_cie
,
5776 sizeof (Eh_cie
<64>::eh_frame_cie
),
5777 glink_eh_frame_fde_64v2_localentry0
,
5778 sizeof (glink_eh_frame_fde_64v2
));
5780 layout
->add_eh_frame_for_plt(this,
5781 Eh_cie
<64>::eh_frame_cie
,
5782 sizeof (Eh_cie
<64>::eh_frame_cie
),
5783 glink_eh_frame_fde_64v2
,
5784 sizeof (glink_eh_frame_fde_64v2
));
5788 // 32-bit .glink can use the default since the CIE return
5789 // address reg, LR, is valid.
5790 layout
->add_eh_frame_for_plt(this,
5791 Eh_cie
<32>::eh_frame_cie
,
5792 sizeof (Eh_cie
<32>::eh_frame_cie
),
5794 sizeof (default_fde
));
5795 // Except where LR is used in a PIC __glink_PLTresolve.
5796 if (parameters
->options().output_is_position_independent())
5797 layout
->add_eh_frame_for_plt(this,
5798 Eh_cie
<32>::eh_frame_cie
,
5799 sizeof (Eh_cie
<32>::eh_frame_cie
),
5800 glink_eh_frame_fde_32
,
5801 sizeof (glink_eh_frame_fde_32
));
5805 template<int size
, bool big_endian
>
5807 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5809 unsigned int off
= this->global_entry_align(this->ge_size_
);
5810 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5811 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5813 this->ge_size_
= off
+ 16;
5816 template<int size
, bool big_endian
>
5817 typename Output_data_glink
<size
, big_endian
>::Address
5818 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5820 typename
Global_entry_stub_entries::const_iterator p
5821 = this->global_entry_stubs_
.find(gsym
);
5822 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5825 template<int size
, bool big_endian
>
5827 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5829 unsigned int count
= this->targ_
->plt_entry_count();
5830 section_size_type total
= 0;
5836 // space for branch table
5837 total
+= 4 * (count
- 1);
5839 total
+= -total
& 15;
5840 total
+= this->pltresolve_size();
5844 total
+= this->pltresolve_size();
5846 // space for branch table
5848 if (this->targ_
->abiversion() < 2)
5852 total
+= 4 * (count
- 0x8000);
5856 this->end_branch_table_
= total
;
5857 total
= this->global_entry_align(total
);
5858 total
+= this->ge_size_
;
5860 this->set_data_size(total
);
5863 // Define symbols on stubs, identifying the stub.
5865 template<int size
, bool big_endian
>
5867 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5869 if (!this->plt_call_stubs_
.empty())
5871 // The key for the plt call stub hash table includes addresses,
5872 // therefore traversal order depends on those addresses, which
5873 // can change between runs if gold is a PIE. Unfortunately the
5874 // output .symtab ordering depends on the order in which symbols
5875 // are added to the linker symtab. We want reproducible output
5876 // so must sort the call stub symbols.
5877 typedef typename
Plt_stub_entries::iterator plt_iter
;
5878 std::vector
<plt_iter
> sorted
;
5879 sorted
.resize(this->plt_call_stubs_
.size());
5881 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5882 cs
!= this->plt_call_stubs_
.end();
5884 sorted
[cs
->second
.indx_
] = cs
;
5886 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5888 plt_iter cs
= sorted
[i
];
5891 if (cs
->first
.addend_
!= 0)
5892 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5895 if (cs
->first
.object_
)
5897 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5898 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5899 sprintf(obj
, "%x:", ppcobj
->uniq());
5902 const char *symname
;
5903 if (cs
->first
.sym_
== NULL
)
5905 sprintf(localname
, "%x", cs
->first
.locsym_
);
5906 symname
= localname
;
5908 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5909 symname
= this->targ_
->tls_get_addr_opt()->name();
5911 symname
= cs
->first
.sym_
->name();
5912 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5913 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5915 = this->stub_address() - this->address() + cs
->second
.off_
;
5916 unsigned int stub_size
= this->plt_call_size(cs
);
5917 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5921 typedef typename
Branch_stub_entries::iterator branch_iter
;
5922 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5923 bs
!= this->long_branch_stubs_
.end();
5926 if (bs
->second
.save_res_
)
5929 char* name
= new char[8 + 13 + 16 + 1];
5930 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5931 static_cast<unsigned long long>(bs
->first
.dest_
));
5932 Address value
= (this->stub_address() - this->address()
5933 + this->plt_size_
+ bs
->second
.off_
);
5934 bool need_lt
= false;
5935 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5936 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5940 // Emit the start of a __tls_get_addr_opt plt call stub.
5942 template<int size
, bool big_endian
>
5944 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5947 unsigned char* p
= *pp
;
5950 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5952 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5954 write_insn
<big_endian
>(p
, mr_0_3
);
5956 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5958 write_insn
<big_endian
>(p
, add_3_12_13
);
5960 write_insn
<big_endian
>(p
, beqlr
);
5962 write_insn
<big_endian
>(p
, mr_3_0
);
5966 write_insn
<big_endian
>(p
, mflr_11
);
5968 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5974 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5976 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5978 write_insn
<big_endian
>(p
, mr_0_3
);
5980 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5982 write_insn
<big_endian
>(p
, add_3_12_2
);
5984 write_insn
<big_endian
>(p
, beqlr
);
5986 write_insn
<big_endian
>(p
, mr_3_0
);
5988 write_insn
<big_endian
>(p
, nop
);
5994 // Emit the tail of a __tls_get_addr_opt plt call stub.
5996 template<int size
, bool big_endian
>
5998 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
6000 write_insn
<big_endian
>(p
, bctrl
);
6002 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
6004 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
6006 write_insn
<big_endian
>(p
, mtlr_11
);
6008 write_insn
<big_endian
>(p
, blr
);
6011 // Emit pc-relative plt call stub code.
6013 template<bool big_endian
>
6014 static unsigned char*
6015 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
6018 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6023 write_insn
<big_endian
>(p
, nop
);
6031 write_insn
<big_endian
>(p
, insn
>> 32);
6033 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6035 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6038 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
6042 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6045 insn
= paddi_12_pc
| d34(off
);
6046 write_insn
<big_endian
>(p
, insn
>> 32);
6048 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6052 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6056 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6058 write_insn
<big_endian
>(p
, add_12_11_12
);
6063 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
6065 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
6069 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6072 insn
= paddi_12_pc
| d34(off
);
6073 write_insn
<big_endian
>(p
, insn
>> 32);
6075 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6079 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6083 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6085 write_insn
<big_endian
>(p
, add_12_11_12
);
6091 // Gets the address of a label (1:) in r11 and builds an offset in r12,
6092 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
6097 // lis %r12,xxx-1b@highest
6098 // ori %r12,%r12,xxx-1b@higher
6099 // sldi %r12,%r12,32
6100 // oris %r12,%r12,xxx-1b@high
6101 // ori %r12,%r12,xxx-1b@l
6102 // add/ldx %r12,%r11,%r12
6104 template<bool big_endian
>
6105 static unsigned char*
6106 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
6108 write_insn
<big_endian
>(p
, mflr_12
);
6110 write_insn
<big_endian
>(p
, bcl_20_31
);
6112 write_insn
<big_endian
>(p
, mflr_11
);
6114 write_insn
<big_endian
>(p
, mtlr_12
);
6116 if (off
+ 0x8000 < 0x10000)
6119 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6121 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
6123 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6125 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
6128 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6130 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
6134 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
6136 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
6141 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
6143 if (((off
>> 32) & 0xffff) != 0)
6145 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
6149 if (((off
>> 32) & 0xffffffffULL
) != 0)
6151 write_insn
<big_endian
>(p
, sldi_12_12_32
);
6156 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
6161 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6165 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6167 write_insn
<big_endian
>(p
, add_12_11_12
);
6173 // Size of a given plt call stub.
6175 template<int size
, bool big_endian
>
6177 Stub_table
<size
, big_endian
>::plt_call_size(
6178 typename
Plt_stub_entries::iterator p
) const
6182 unsigned int bytes
= 4 * 4;
6183 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6185 return this->plt_call_align(bytes
);
6188 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6189 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6190 plt_addr
+= plt
->address();
6191 if (this->targ_
->power10_stubs()
6192 && this->targ_
->power10_stubs_auto())
6194 unsigned int bytes
= 0;
6195 if (p
->second
.notoc_
)
6197 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6199 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6200 uint64_t odd
= from
& 4;
6201 uint64_t off
= plt_addr
- from
;
6202 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6203 bytes
+= odd
+ 4 * 4;
6204 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6208 bytes
= this->plt_call_align(bytes
);
6212 p
->second
.tocoff_
= bytes
;
6213 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6216 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6217 bytes
+= 2 * 4 + 4 * 4;
6219 if (p
->second
.r2save_
)
6221 uint64_t got_addr
= this->targ_
->toc_pointer();
6222 uint64_t off
= plt_addr
- got_addr
;
6223 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6224 p
->second
.tsize_
= bytes
- p
->second
.tocoff_
;
6225 bytes
= this->plt_call_align(bytes
);
6227 if (p
->second
.p9notoc_
)
6229 p
->second
.p9off_
= bytes
;
6230 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6232 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6233 uint64_t off
= plt_addr
- from
;
6234 if (off
+ 0x8000 < 0x10000)
6236 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6241 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6242 && ((off
>> 32) & 0xffff) != 0)
6244 if (((off
>> 32) & 0xffffffffULL
) != 0)
6251 bytes
= this->plt_call_align(bytes
);
6257 unsigned int bytes
= 0;
6258 unsigned int tail
= 0;
6259 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6262 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6269 if (p
->second
.r2save_
)
6272 if (this->targ_
->power10_stubs())
6274 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6275 uint64_t odd
= from
& 4;
6276 uint64_t off
= plt_addr
- from
;
6277 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6278 bytes
+= odd
+ 4 * 4;
6279 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6283 return this->plt_call_align(bytes
+ tail
);
6286 if (p
->second
.p9notoc_
)
6288 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6289 uint64_t off
= plt_addr
- from
;
6290 if (off
+ 0x8000 < 0x10000)
6292 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6297 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6298 && ((off
>> 32) & 0xffff) != 0)
6300 if (((off
>> 32) & 0xffffffffULL
) != 0)
6307 return this->plt_call_align(bytes
+ tail
);
6310 uint64_t got_addr
= this->targ_
->toc_pointer();
6311 uint64_t off
= plt_addr
- got_addr
;
6312 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6313 if (this->targ_
->abiversion() < 2)
6315 bool static_chain
= parameters
->options().plt_static_chain();
6316 bool thread_safe
= this->targ_
->plt_thread_safe();
6320 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6322 return this->plt_call_align(bytes
+ tail
);
6326 // Return long branch stub size.
6328 template<int size
, bool big_endian
>
6330 Stub_table
<size
, big_endian
>::branch_stub_size(
6331 typename
Branch_stub_entries::iterator p
,
6334 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6337 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6339 if (parameters
->options().output_is_position_independent())
6344 uint64_t off
= p
->first
.dest_
- loc
;
6345 unsigned int bytes
= 0;
6346 if (p
->second
.notoc_
)
6348 if (this->targ_
->power10_stubs())
6350 Address odd
= loc
& 4;
6351 if (off
+ (1 << 25) < 2 << 25)
6353 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6355 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6359 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6361 p
->second
.tocoff_
= bytes
;
6366 if (off
+ 0x8000 < 0x10000)
6368 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6370 if (off
+ 24 + (1 << 25) < 2 << 25)
6376 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6377 && ((off
>> 32) & 0xffff) != 0)
6379 if (((off
>> 32) & 0xffffffffULL
) != 0)
6389 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6390 if (off
+ (1 << 25) < 2 << 25)
6392 if (!this->targ_
->power10_stubs()
6393 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6398 template<int size
, bool big_endian
>
6400 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6403 gold_error(_("linkage table error against `%s'"),
6404 p
.sym_
->demangled_name().c_str());
6406 gold_error(_("linkage table error against `%s:[local %u]'"),
6407 p
.object_
->name().c_str(),
6411 // Write out plt and long branch stub code.
6413 template<int size
, bool big_endian
>
6415 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6417 if (this->plt_call_stubs_
.empty()
6418 && this->long_branch_stubs_
.empty())
6421 const section_size_type start_off
= this->offset();
6422 const section_size_type off
= this->stub_offset();
6423 const section_size_type oview_size
=
6424 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6425 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6429 && this->targ_
->power10_stubs())
6431 if (!this->plt_call_stubs_
.empty())
6433 // Write out plt call stubs.
6434 typename
Plt_stub_entries::const_iterator cs
;
6435 for (cs
= this->plt_call_stubs_
.begin();
6436 cs
!= this->plt_call_stubs_
.end();
6439 p
= oview
+ cs
->second
.off_
;
6440 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6441 Address pltoff
= this->plt_off(cs
, &plt
);
6442 Address plt_addr
= pltoff
+ plt
->address();
6443 if (this->targ_
->power10_stubs_auto())
6445 if (cs
->second
.notoc_
)
6447 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6448 this->build_tls_opt_head(&p
, false);
6449 Address from
= this->stub_address() + (p
- oview
);
6450 Address delta
= plt_addr
- from
;
6451 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6453 write_insn
<big_endian
>(p
, mtctr_12
);
6455 write_insn
<big_endian
>(p
, bctr
);
6457 p
= oview
+ this->plt_call_align(p
- oview
);
6459 if (cs
->second
.toc_
)
6461 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6464 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6465 this->build_tls_opt_head(&p
, save_lr
);
6467 Address got_addr
= this->targ_
->toc_pointer();
6468 Address off
= plt_addr
- got_addr
;
6470 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6471 this->plt_error(cs
->first
);
6473 if (cs
->second
.r2save_
)
6475 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6480 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6482 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6487 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6490 write_insn
<big_endian
>(p
, mtctr_12
);
6492 if (cs
->second
.r2save_
6493 && !cs
->second
.localentry0_
6494 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6495 this->build_tls_opt_tail(p
);
6497 write_insn
<big_endian
>(p
, bctr
);
6499 if (cs
->second
.p9notoc_
)
6501 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6502 this->build_tls_opt_head(&p
, false);
6503 Address from
= this->stub_address() + (p
- oview
);
6504 Address delta
= plt_addr
- from
;
6505 p
= build_notoc_offset
<big_endian
>(p
, delta
, true);
6506 write_insn
<big_endian
>(p
, mtctr_12
);
6508 write_insn
<big_endian
>(p
, bctr
);
6510 p
= oview
+ this->plt_call_align(p
- oview
);
6515 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6518 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6519 this->build_tls_opt_head(&p
, save_lr
);
6521 if (cs
->second
.r2save_
)
6523 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6526 Address from
= this->stub_address() + (p
- oview
);
6527 Address delta
= plt_addr
- from
;
6528 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6529 write_insn
<big_endian
>(p
, mtctr_12
);
6531 if (cs
->second
.r2save_
6532 && !cs
->second
.localentry0_
6533 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6534 this->build_tls_opt_tail(p
);
6536 write_insn
<big_endian
>(p
, bctr
);
6541 // Write out long branch stubs.
6542 typename
Branch_stub_entries::const_iterator bs
;
6543 for (bs
= this->long_branch_stubs_
.begin();
6544 bs
!= this->long_branch_stubs_
.end();
6547 if (bs
->second
.save_res_
)
6549 Address off
= this->plt_size_
+ bs
->second
.off_
;
6551 Address loc
= this->stub_address() + off
;
6552 Address delta
= bs
->first
.dest_
- loc
;
6553 if (this->targ_
->power10_stubs_auto())
6555 if (bs
->second
.notoc_
)
6557 unsigned char* startp
= p
;
6558 p
= build_power10_offset
<big_endian
>(p
, delta
,
6560 delta
-= p
- startp
;
6562 if (delta
+ (1 << 25) < 2 << 25)
6563 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6566 write_insn
<big_endian
>(p
, mtctr_12
);
6568 write_insn
<big_endian
>(p
, bctr
);
6571 delta
-= p
- startp
;
6573 if (bs
->second
.toc_
)
6575 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6576 if (delta
+ (1 << 25) >= 2 << 25)
6579 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6580 gold_assert(brlt_addr
!= invalid_address
);
6581 brlt_addr
+= this->targ_
->brlt_section()->address();
6582 Address got_addr
= this->targ_
->toc_pointer();
6583 Address brltoff
= brlt_addr
- got_addr
;
6584 if (ha(brltoff
) == 0)
6586 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6591 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6593 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6597 if (delta
+ (1 << 25) < 2 << 25)
6598 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6601 write_insn
<big_endian
>(p
, mtctr_12
);
6603 write_insn
<big_endian
>(p
, bctr
);
6606 if (bs
->second
.p9notoc_
)
6608 unsigned char* startp
= p
;
6609 p
= build_notoc_offset
<big_endian
>(p
, delta
, false);
6610 delta
-= p
- startp
;
6612 if (delta
+ (1 << 25) < 2 << 25)
6613 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6616 write_insn
<big_endian
>(p
, mtctr_12
);
6618 write_insn
<big_endian
>(p
, bctr
);
6621 delta
-= p
- startp
;
6626 if (!bs
->second
.notoc_
)
6627 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6628 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6630 unsigned char* startp
= p
;
6631 p
= build_power10_offset
<big_endian
>(p
, delta
,
6633 delta
-= p
- startp
;
6635 if (delta
+ (1 << 25) < 2 << 25)
6636 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6639 write_insn
<big_endian
>(p
, mtctr_12
);
6641 write_insn
<big_endian
>(p
, bctr
);
6646 else if (size
== 64)
6649 if (!this->plt_call_stubs_
.empty()
6650 && this->targ_
->abiversion() >= 2)
6652 // Write out plt call stubs for ELFv2.
6653 typename
Plt_stub_entries::const_iterator cs
;
6654 for (cs
= this->plt_call_stubs_
.begin();
6655 cs
!= this->plt_call_stubs_
.end();
6658 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6659 Address pltoff
= this->plt_off(cs
, &plt
);
6660 Address plt_addr
= pltoff
+ plt
->address();
6662 p
= oview
+ cs
->second
.off_
;
6663 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6665 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6666 this->build_tls_opt_head(&p
, save_lr
);
6668 if (cs
->second
.r2save_
)
6670 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6673 if (cs
->second
.p9notoc_
)
6675 Address from
= this->stub_address() + (p
- oview
) + 8;
6676 Address off
= plt_addr
- from
;
6677 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6681 Address got_addr
= this->targ_
->toc_pointer();
6682 Address off
= plt_addr
- got_addr
;
6684 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6685 this->plt_error(cs
->first
);
6689 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6691 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6696 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6700 write_insn
<big_endian
>(p
, mtctr_12
);
6702 if (cs
->second
.r2save_
6703 && !cs
->second
.localentry0_
6704 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6705 this->build_tls_opt_tail(p
);
6707 write_insn
<big_endian
>(p
, bctr
);
6710 else if (!this->plt_call_stubs_
.empty())
6712 // Write out plt call stubs for ELFv1.
6713 typename
Plt_stub_entries::const_iterator cs
;
6714 for (cs
= this->plt_call_stubs_
.begin();
6715 cs
!= this->plt_call_stubs_
.end();
6718 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6719 Address pltoff
= this->plt_off(cs
, &plt
);
6720 Address plt_addr
= pltoff
+ plt
->address();
6721 Address got_addr
= this->targ_
->toc_pointer();
6722 Address off
= plt_addr
- got_addr
;
6724 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6725 || cs
->second
.notoc_
)
6726 this->plt_error(cs
->first
);
6728 bool static_chain
= parameters
->options().plt_static_chain();
6729 bool thread_safe
= this->targ_
->plt_thread_safe();
6730 bool use_fake_dep
= false;
6731 Address cmp_branch_off
= 0;
6734 unsigned int pltindex
6735 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6736 / this->targ_
->plt_entry_size());
6738 = (this->targ_
->glink_section()->pltresolve_size()
6740 if (pltindex
> 32768)
6741 glinkoff
+= (pltindex
- 32768) * 4;
6743 = this->targ_
->glink_section()->address() + glinkoff
;
6745 = (this->stub_address() + cs
->second
.off_
+ 20
6746 + 4 * cs
->second
.r2save_
6747 + 4 * (ha(off
) != 0)
6748 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6749 + 4 * static_chain
);
6750 cmp_branch_off
= to
- from
;
6751 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6754 p
= oview
+ cs
->second
.off_
;
6755 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6757 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6758 this->build_tls_opt_head(&p
, save_lr
);
6759 use_fake_dep
= thread_safe
;
6761 if (cs
->second
.r2save_
)
6763 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6768 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6770 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6772 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6774 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6778 write_insn
<big_endian
>(p
, mtctr_12
);
6782 write_insn
<big_endian
>(p
, xor_2_12_12
);
6784 write_insn
<big_endian
>(p
, add_11_11_2
);
6787 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6791 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6797 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6799 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6801 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6805 write_insn
<big_endian
>(p
, mtctr_12
);
6809 write_insn
<big_endian
>(p
, xor_11_12_12
);
6811 write_insn
<big_endian
>(p
, add_2_2_11
);
6816 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6819 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6822 if (cs
->second
.r2save_
6823 && !cs
->second
.localentry0_
6824 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6825 this->build_tls_opt_tail(p
);
6826 else if (thread_safe
&& !use_fake_dep
)
6828 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6830 write_insn
<big_endian
>(p
, bnectr_p4
);
6832 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6835 write_insn
<big_endian
>(p
, bctr
);
6839 // Write out long branch stubs.
6840 typename
Branch_stub_entries::const_iterator bs
;
6841 for (bs
= this->long_branch_stubs_
.begin();
6842 bs
!= this->long_branch_stubs_
.end();
6845 if (bs
->second
.save_res_
)
6847 Address off
= this->plt_size_
+ bs
->second
.off_
;
6849 Address loc
= this->stub_address() + off
;
6850 Address delta
= bs
->first
.dest_
- loc
;
6851 if (!bs
->second
.p9notoc_
)
6852 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6853 if (bs
->second
.p9notoc_
)
6855 unsigned char* startp
= p
;
6856 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6857 delta
-= p
- startp
;
6859 else if (delta
+ (1 << 25) >= 2 << 25)
6862 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6863 gold_assert(brlt_addr
!= invalid_address
);
6864 brlt_addr
+= this->targ_
->brlt_section()->address();
6865 Address got_addr
= this->targ_
->toc_pointer();
6866 Address brltoff
= brlt_addr
- got_addr
;
6867 if (ha(brltoff
) == 0)
6869 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6874 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6876 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6880 if (delta
+ (1 << 25) < 2 << 25)
6881 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6884 write_insn
<big_endian
>(p
, mtctr_12
);
6886 write_insn
<big_endian
>(p
, bctr
);
6892 if (!this->plt_call_stubs_
.empty())
6894 // The address of _GLOBAL_OFFSET_TABLE_.
6895 Address g_o_t
= invalid_address
;
6897 // Write out plt call stubs.
6898 typename
Plt_stub_entries::const_iterator cs
;
6899 for (cs
= this->plt_call_stubs_
.begin();
6900 cs
!= this->plt_call_stubs_
.end();
6903 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6904 Address plt_addr
= this->plt_off(cs
, &plt
);
6905 plt_addr
+= plt
->address();
6907 p
= oview
+ cs
->second
.off_
;
6908 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6909 this->build_tls_opt_head(&p
, false);
6910 if (parameters
->options().output_is_position_independent())
6913 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6914 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6915 (cs
->first
.object_
));
6916 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6918 unsigned int got2
= ppcobj
->got2_shndx();
6919 got_addr
= ppcobj
->get_output_section_offset(got2
);
6920 gold_assert(got_addr
!= invalid_address
);
6921 got_addr
+= (ppcobj
->output_section(got2
)->address()
6922 + cs
->first
.addend_
);
6926 if (g_o_t
== invalid_address
)
6927 g_o_t
= this->targ_
->toc_pointer();
6931 Address off
= plt_addr
- got_addr
;
6933 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6936 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6938 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6943 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6945 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6948 write_insn
<big_endian
>(p
, mtctr_11
);
6950 write_insn
<big_endian
>(p
, bctr
);
6954 // Write out long branch stubs.
6955 typename
Branch_stub_entries::const_iterator bs
;
6956 for (bs
= this->long_branch_stubs_
.begin();
6957 bs
!= this->long_branch_stubs_
.end();
6960 if (bs
->second
.save_res_
)
6962 Address off
= this->plt_size_
+ bs
->second
.off_
;
6964 Address loc
= this->stub_address() + off
;
6965 Address delta
= bs
->first
.dest_
- loc
;
6966 if (delta
+ (1 << 25) < 2 << 25)
6967 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6968 else if (!parameters
->options().output_is_position_independent())
6970 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6972 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6977 write_insn
<big_endian
>(p
, mflr_0
);
6979 write_insn
<big_endian
>(p
, bcl_20_31
);
6981 write_insn
<big_endian
>(p
, mflr_12
);
6983 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6985 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6987 write_insn
<big_endian
>(p
, mtlr_0
);
6990 write_insn
<big_endian
>(p
, mtctr_12
);
6992 write_insn
<big_endian
>(p
, bctr
);
6995 if (this->need_save_res_
)
6997 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6998 memcpy (p
, this->targ_
->savres_section()->contents(),
6999 this->targ_
->savres_section()->data_size());
7003 // Write out .glink.
7005 template<int size
, bool big_endian
>
7007 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
7009 const section_size_type off
= this->offset();
7010 const section_size_type oview_size
=
7011 convert_to_section_size_type(this->data_size());
7012 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7015 // The base address of the .plt section.
7016 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
7017 Address plt_base
= this->targ_
->plt_section()->address();
7021 if (this->end_branch_table_
!= 0)
7023 // Write pltresolve stub.
7025 Address after_bcl
= this->address() + 16;
7026 Address pltoff
= plt_base
- after_bcl
;
7028 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
7030 if (this->targ_
->abiversion() < 2)
7032 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
7033 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7034 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7035 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
7036 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
7037 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
7038 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7039 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
7040 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7041 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
7045 if (this->targ_
->has_localentry0())
7047 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
7049 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
7050 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7051 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7052 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
7053 if (this->targ_
->has_localentry0())
7055 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
7059 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
7061 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
7062 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
7063 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
7064 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7065 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
7066 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7067 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
7069 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
7070 gold_assert(p
== oview
+ this->pltresolve_size());
7072 // Write lazy link call stubs.
7074 while (p
< oview
+ this->end_branch_table_
)
7076 if (this->targ_
->abiversion() < 2)
7080 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
7084 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
7085 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
7088 uint32_t branch_off
= 8 - (p
- oview
);
7089 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
7094 Address plt_base
= this->targ_
->plt_section()->address();
7095 Address iplt_base
= invalid_address
;
7096 unsigned int global_entry_off
= this->global_entry_off();
7097 Address global_entry_base
= this->address() + global_entry_off
;
7098 typename
Global_entry_stub_entries::const_iterator ge
;
7099 for (ge
= this->global_entry_stubs_
.begin();
7100 ge
!= this->global_entry_stubs_
.end();
7103 p
= oview
+ global_entry_off
+ ge
->second
;
7104 Address plt_addr
= ge
->first
->plt_offset();
7105 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
7106 && ge
->first
->can_use_relative_reloc(false))
7108 if (iplt_base
== invalid_address
)
7109 iplt_base
= this->targ_
->iplt_section()->address();
7110 plt_addr
+= iplt_base
;
7113 plt_addr
+= plt_base
;
7114 Address my_addr
= global_entry_base
+ ge
->second
;
7115 Address off
= plt_addr
- my_addr
;
7117 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
7118 gold_error(_("linkage table error against `%s'"),
7119 ge
->first
->demangled_name().c_str());
7121 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
7122 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
7123 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7124 write_insn
<big_endian
>(p
, bctr
);
7129 // The address of _GLOBAL_OFFSET_TABLE_.
7130 Address g_o_t
= this->targ_
->toc_pointer();
7132 // Write out pltresolve branch table.
7134 unsigned int the_end
= oview_size
- this->pltresolve_size();
7135 unsigned char* end_p
= oview
+ the_end
;
7136 while (p
< end_p
- 8 * 4)
7137 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
7139 write_insn
<big_endian
>(p
, nop
), p
+= 4;
7141 // Write out pltresolve call stub.
7142 end_p
= oview
+ oview_size
;
7143 if (parameters
->options().output_is_position_independent())
7145 Address res0_off
= 0;
7146 Address after_bcl_off
= the_end
+ 12;
7147 Address bcl_res0
= after_bcl_off
- res0_off
;
7149 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
7151 write_insn
<big_endian
>(p
, mflr_0
);
7153 write_insn
<big_endian
>(p
, bcl_20_31
);
7155 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
7157 write_insn
<big_endian
>(p
, mflr_12
);
7159 write_insn
<big_endian
>(p
, mtlr_0
);
7161 write_insn
<big_endian
>(p
, sub_11_11_12
);
7164 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
7166 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
7168 if (ha(got_bcl
) == ha(got_bcl
+ 4))
7170 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
7172 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
7176 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
7178 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7181 write_insn
<big_endian
>(p
, mtctr_0
);
7183 write_insn
<big_endian
>(p
, add_0_11_11
);
7185 write_insn
<big_endian
>(p
, add_11_0_11
);
7189 Address res0
= this->address();
7191 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7193 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7195 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7196 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7198 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7200 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7202 write_insn
<big_endian
>(p
, mtctr_0
);
7204 write_insn
<big_endian
>(p
, add_0_11_11
);
7206 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7207 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7209 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7211 write_insn
<big_endian
>(p
, add_11_0_11
);
7214 write_insn
<big_endian
>(p
, bctr
);
7218 write_insn
<big_endian
>(p
, nop
);
7223 of
->write_output_view(off
, oview_size
, oview
);
7227 // A class to handle linker generated save/restore functions.
7229 template<int size
, bool big_endian
>
7230 class Output_data_save_res
: public Output_section_data_build
7233 Output_data_save_res(Symbol_table
* symtab
);
7235 const unsigned char*
7242 // Write to a map file.
7244 do_print_to_mapfile(Mapfile
* mapfile
) const
7245 { mapfile
->print_output_data(this, _("** save/restore")); }
7248 do_write(Output_file
*);
7251 // The maximum size of save/restore contents.
7252 static const unsigned int savres_max
= 218*4;
7255 savres_define(Symbol_table
* symtab
,
7257 unsigned int lo
, unsigned int hi
,
7258 unsigned char* write_ent(unsigned char*, int),
7259 unsigned char* write_tail(unsigned char*, int));
7261 unsigned char *contents_
;
7264 template<bool big_endian
>
7265 static unsigned char*
7266 savegpr0(unsigned char* p
, int r
)
7268 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7269 write_insn
<big_endian
>(p
, insn
);
7273 template<bool big_endian
>
7274 static unsigned char*
7275 savegpr0_tail(unsigned char* p
, int r
)
7277 p
= savegpr0
<big_endian
>(p
, r
);
7278 uint32_t insn
= std_0_1
+ 16;
7279 write_insn
<big_endian
>(p
, insn
);
7281 write_insn
<big_endian
>(p
, blr
);
7285 template<bool big_endian
>
7286 static unsigned char*
7287 restgpr0(unsigned char* p
, int r
)
7289 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7290 write_insn
<big_endian
>(p
, insn
);
7294 template<bool big_endian
>
7295 static unsigned char*
7296 restgpr0_tail(unsigned char* p
, int r
)
7298 uint32_t insn
= ld_0_1
+ 16;
7299 write_insn
<big_endian
>(p
, insn
);
7301 p
= restgpr0
<big_endian
>(p
, r
);
7302 write_insn
<big_endian
>(p
, mtlr_0
);
7306 p
= restgpr0
<big_endian
>(p
, 30);
7307 p
= restgpr0
<big_endian
>(p
, 31);
7309 write_insn
<big_endian
>(p
, blr
);
7313 template<bool big_endian
>
7314 static unsigned char*
7315 savegpr1(unsigned char* p
, int r
)
7317 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7318 write_insn
<big_endian
>(p
, insn
);
7322 template<bool big_endian
>
7323 static unsigned char*
7324 savegpr1_tail(unsigned char* p
, int r
)
7326 p
= savegpr1
<big_endian
>(p
, r
);
7327 write_insn
<big_endian
>(p
, blr
);
7331 template<bool big_endian
>
7332 static unsigned char*
7333 restgpr1(unsigned char* p
, int r
)
7335 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7336 write_insn
<big_endian
>(p
, insn
);
7340 template<bool big_endian
>
7341 static unsigned char*
7342 restgpr1_tail(unsigned char* p
, int r
)
7344 p
= restgpr1
<big_endian
>(p
, r
);
7345 write_insn
<big_endian
>(p
, blr
);
7349 template<bool big_endian
>
7350 static unsigned char*
7351 savefpr(unsigned char* p
, int r
)
7353 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7354 write_insn
<big_endian
>(p
, insn
);
7358 template<bool big_endian
>
7359 static unsigned char*
7360 savefpr0_tail(unsigned char* p
, int r
)
7362 p
= savefpr
<big_endian
>(p
, r
);
7363 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7365 write_insn
<big_endian
>(p
, blr
);
7369 template<bool big_endian
>
7370 static unsigned char*
7371 restfpr(unsigned char* p
, int r
)
7373 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7374 write_insn
<big_endian
>(p
, insn
);
7378 template<bool big_endian
>
7379 static unsigned char*
7380 restfpr0_tail(unsigned char* p
, int r
)
7382 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7384 p
= restfpr
<big_endian
>(p
, r
);
7385 write_insn
<big_endian
>(p
, mtlr_0
);
7389 p
= restfpr
<big_endian
>(p
, 30);
7390 p
= restfpr
<big_endian
>(p
, 31);
7392 write_insn
<big_endian
>(p
, blr
);
7396 template<bool big_endian
>
7397 static unsigned char*
7398 savefpr1_tail(unsigned char* p
, int r
)
7400 p
= savefpr
<big_endian
>(p
, r
);
7401 write_insn
<big_endian
>(p
, blr
);
7405 template<bool big_endian
>
7406 static unsigned char*
7407 restfpr1_tail(unsigned char* p
, int r
)
7409 p
= restfpr
<big_endian
>(p
, r
);
7410 write_insn
<big_endian
>(p
, blr
);
7414 template<bool big_endian
>
7415 static unsigned char*
7416 savevr(unsigned char* p
, int r
)
7418 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7419 write_insn
<big_endian
>(p
, insn
);
7421 insn
= stvx_0_12_0
+ (r
<< 21);
7422 write_insn
<big_endian
>(p
, insn
);
7426 template<bool big_endian
>
7427 static unsigned char*
7428 savevr_tail(unsigned char* p
, int r
)
7430 p
= savevr
<big_endian
>(p
, r
);
7431 write_insn
<big_endian
>(p
, blr
);
7435 template<bool big_endian
>
7436 static unsigned char*
7437 restvr(unsigned char* p
, int r
)
7439 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7440 write_insn
<big_endian
>(p
, insn
);
7442 insn
= lvx_0_12_0
+ (r
<< 21);
7443 write_insn
<big_endian
>(p
, insn
);
7447 template<bool big_endian
>
7448 static unsigned char*
7449 restvr_tail(unsigned char* p
, int r
)
7451 p
= restvr
<big_endian
>(p
, r
);
7452 write_insn
<big_endian
>(p
, blr
);
7457 template<int size
, bool big_endian
>
7458 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7459 Symbol_table
* symtab
)
7460 : Output_section_data_build(4),
7463 this->savres_define(symtab
,
7464 "_savegpr0_", 14, 31,
7465 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7466 this->savres_define(symtab
,
7467 "_restgpr0_", 14, 29,
7468 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7469 this->savres_define(symtab
,
7470 "_restgpr0_", 30, 31,
7471 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7472 this->savres_define(symtab
,
7473 "_savegpr1_", 14, 31,
7474 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7475 this->savres_define(symtab
,
7476 "_restgpr1_", 14, 31,
7477 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7478 this->savres_define(symtab
,
7479 "_savefpr_", 14, 31,
7480 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7481 this->savres_define(symtab
,
7482 "_restfpr_", 14, 29,
7483 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7484 this->savres_define(symtab
,
7485 "_restfpr_", 30, 31,
7486 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7487 this->savres_define(symtab
,
7489 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7490 this->savres_define(symtab
,
7492 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7493 this->savres_define(symtab
,
7495 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7496 this->savres_define(symtab
,
7498 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7501 template<int size
, bool big_endian
>
7503 Output_data_save_res
<size
, big_endian
>::savres_define(
7504 Symbol_table
* symtab
,
7506 unsigned int lo
, unsigned int hi
,
7507 unsigned char* write_ent(unsigned char*, int),
7508 unsigned char* write_tail(unsigned char*, int))
7510 size_t len
= strlen(name
);
7511 bool writing
= false;
7514 memcpy(sym
, name
, len
);
7517 for (unsigned int i
= lo
; i
<= hi
; i
++)
7519 sym
[len
+ 0] = i
/ 10 + '0';
7520 sym
[len
+ 1] = i
% 10 + '0';
7521 Symbol
* gsym
= symtab
->lookup(sym
);
7522 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7523 writing
= writing
|| refd
;
7526 if (this->contents_
== NULL
)
7527 this->contents_
= new unsigned char[this->savres_max
];
7529 section_size_type value
= this->current_data_size();
7530 unsigned char* p
= this->contents_
+ value
;
7532 p
= write_ent(p
, i
);
7534 p
= write_tail(p
, i
);
7535 section_size_type cur_size
= p
- this->contents_
;
7536 this->set_current_data_size(cur_size
);
7538 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7539 this, value
, cur_size
- value
,
7540 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7541 elfcpp::STV_HIDDEN
, 0, false, false);
7546 // Write out save/restore.
7548 template<int size
, bool big_endian
>
7550 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7552 const section_size_type off
= this->offset();
7553 const section_size_type oview_size
=
7554 convert_to_section_size_type(this->data_size());
7555 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7556 memcpy(oview
, this->contents_
, oview_size
);
7557 of
->write_output_view(off
, oview_size
, oview
);
7561 // Create the glink section.
7563 template<int size
, bool big_endian
>
7565 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7567 if (this->glink_
== NULL
)
7569 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7570 this->glink_
->add_eh_frame(layout
);
7571 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7572 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7573 this->glink_
, ORDER_TEXT
, false);
7577 // Create a PLT entry for a global symbol.
7579 template<int size
, bool big_endian
>
7581 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7585 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7586 && gsym
->can_use_relative_reloc(false))
7588 if (this->iplt_
== NULL
)
7589 this->make_iplt_section(symtab
, layout
);
7590 this->iplt_
->add_ifunc_entry(gsym
);
7594 if (this->plt_
== NULL
)
7595 this->make_plt_section(symtab
, layout
);
7596 this->plt_
->add_entry(gsym
);
7600 // Make a PLT entry for a local symbol.
7602 template<int size
, bool big_endian
>
7604 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7605 Symbol_table
* symtab
,
7607 Sized_relobj_file
<size
, big_endian
>* relobj
,
7610 if (this->lplt_
== NULL
)
7611 this->make_lplt_section(symtab
, layout
);
7612 this->lplt_
->add_local_entry(relobj
, r_sym
);
7615 template<int size
, bool big_endian
>
7617 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(Symbol_table
* symtab
,
7621 if (this->lplt_
== NULL
)
7622 this->make_lplt_section(symtab
, layout
);
7623 this->lplt_
->add_entry(gsym
, true);
7626 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7628 template<int size
, bool big_endian
>
7630 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7631 Symbol_table
* symtab
,
7633 Sized_relobj_file
<size
, big_endian
>* relobj
,
7636 if (this->iplt_
== NULL
)
7637 this->make_iplt_section(symtab
, layout
);
7638 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7641 // Return the number of entries in the PLT.
7643 template<int size
, bool big_endian
>
7645 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7647 if (this->plt_
== NULL
)
7649 return this->plt_
->entry_count();
7652 // Create a GOT entry for local dynamic __tls_get_addr calls.
7654 template<int size
, bool big_endian
>
7656 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7657 Symbol_table
* symtab
,
7659 Sized_relobj_file
<size
, big_endian
>* object
)
7661 if (this->tlsld_got_offset_
== -1U)
7663 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7664 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7665 Output_data_got_powerpc
<size
, big_endian
>* got
7666 = this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
7667 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7668 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7670 this->tlsld_got_offset_
= got_offset
;
7672 return this->tlsld_got_offset_
;
7675 // Get the Reference_flags for a particular relocation.
7677 template<int size
, bool big_endian
>
7679 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7680 unsigned int r_type
,
7681 const Target_powerpc
* target
)
7687 case elfcpp::R_PPC64_TOC
:
7691 case elfcpp::R_POWERPC_NONE
:
7692 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7693 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7694 // No symbol reference.
7697 case elfcpp::R_PPC64_ADDR64
:
7698 case elfcpp::R_PPC64_UADDR64
:
7699 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7700 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7701 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7702 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7703 case elfcpp::R_PPC64_D34
:
7704 case elfcpp::R_PPC64_D34_LO
:
7705 case elfcpp::R_PPC64_D34_HI30
:
7706 case elfcpp::R_PPC64_D34_HA30
:
7707 case elfcpp::R_PPC64_D28
:
7711 case elfcpp::R_POWERPC_ADDR32
:
7712 case elfcpp::R_POWERPC_UADDR32
:
7713 case elfcpp::R_POWERPC_ADDR16
:
7714 case elfcpp::R_POWERPC_UADDR16
:
7715 case elfcpp::R_POWERPC_ADDR16_LO
:
7716 case elfcpp::R_POWERPC_ADDR16_HI
:
7717 case elfcpp::R_POWERPC_ADDR16_HA
:
7718 ref
= Symbol::ABSOLUTE_REF
;
7721 case elfcpp::R_POWERPC_ADDR24
:
7722 case elfcpp::R_POWERPC_ADDR14
:
7723 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7724 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7725 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7728 case elfcpp::R_PPC_LOCAL24PC
:
7732 ref
= Symbol::RELATIVE_REF
;
7735 case elfcpp::R_PPC64_REL64
:
7736 case elfcpp::R_PPC64_REL16_HIGH
:
7737 case elfcpp::R_PPC64_REL16_HIGHA
:
7738 case elfcpp::R_PPC64_REL16_HIGHER
:
7739 case elfcpp::R_PPC64_REL16_HIGHERA
:
7740 case elfcpp::R_PPC64_REL16_HIGHEST
:
7741 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7742 case elfcpp::R_PPC64_PCREL34
:
7743 case elfcpp::R_PPC64_REL16_HIGHER34
:
7744 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7745 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7746 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7747 case elfcpp::R_PPC64_PCREL28
:
7751 case elfcpp::R_POWERPC_REL32
:
7752 case elfcpp::R_POWERPC_REL16
:
7753 case elfcpp::R_POWERPC_REL16_LO
:
7754 case elfcpp::R_POWERPC_REL16_HI
:
7755 case elfcpp::R_POWERPC_REL16_HA
:
7756 ref
= Symbol::RELATIVE_REF
;
7759 case elfcpp::R_PPC_PLTREL24
:
7762 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7765 case elfcpp::R_PPC64_REL24_NOTOC
:
7766 case elfcpp::R_PPC64_REL24_P9NOTOC
:
7767 case elfcpp::R_PPC64_PLT16_LO_DS
:
7768 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7769 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7770 case elfcpp::R_PPC64_PLT_PCREL34
:
7771 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7775 case elfcpp::R_POWERPC_REL24
:
7776 case elfcpp::R_POWERPC_REL14
:
7777 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7778 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7779 case elfcpp::R_POWERPC_PLT16_LO
:
7780 case elfcpp::R_POWERPC_PLT16_HI
:
7781 case elfcpp::R_POWERPC_PLT16_HA
:
7782 case elfcpp::R_POWERPC_PLTSEQ
:
7783 case elfcpp::R_POWERPC_PLTCALL
:
7784 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7787 case elfcpp::R_PPC64_GOT16_DS
:
7788 case elfcpp::R_PPC64_GOT16_LO_DS
:
7789 case elfcpp::R_PPC64_GOT_PCREL34
:
7790 case elfcpp::R_PPC64_TOC16
:
7791 case elfcpp::R_PPC64_TOC16_LO
:
7792 case elfcpp::R_PPC64_TOC16_HI
:
7793 case elfcpp::R_PPC64_TOC16_HA
:
7794 case elfcpp::R_PPC64_TOC16_DS
:
7795 case elfcpp::R_PPC64_TOC16_LO_DS
:
7799 case elfcpp::R_POWERPC_GOT16
:
7800 case elfcpp::R_POWERPC_GOT16_LO
:
7801 case elfcpp::R_POWERPC_GOT16_HI
:
7802 case elfcpp::R_POWERPC_GOT16_HA
:
7803 ref
= Symbol::RELATIVE_REF
;
7806 case elfcpp::R_PPC64_TLSGD
:
7807 case elfcpp::R_PPC64_TLSLD
:
7808 case elfcpp::R_PPC64_TPREL34
:
7809 case elfcpp::R_PPC64_DTPREL34
:
7810 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7811 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7812 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7813 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7817 case elfcpp::R_POWERPC_GOT_TPREL16
:
7818 case elfcpp::R_POWERPC_TLS
:
7819 ref
= Symbol::TLS_REF
;
7822 case elfcpp::R_POWERPC_COPY
:
7823 case elfcpp::R_POWERPC_GLOB_DAT
:
7824 case elfcpp::R_POWERPC_JMP_SLOT
:
7825 case elfcpp::R_POWERPC_RELATIVE
:
7826 case elfcpp::R_POWERPC_DTPMOD
:
7828 // Not expected. We will give an error later.
7832 if (size
== 64 && target
->abiversion() < 2)
7833 ref
|= Symbol::FUNC_DESC_ABI
;
7837 // Report an unsupported relocation against a local symbol.
7839 template<int size
, bool big_endian
>
7841 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7842 Sized_relobj_file
<size
, big_endian
>* object
,
7843 unsigned int r_type
)
7845 gold_error(_("%s: unsupported reloc %u against local symbol"),
7846 object
->name().c_str(), r_type
);
7849 // We are about to emit a dynamic relocation of type R_TYPE. If the
7850 // dynamic linker does not support it, issue an error.
7852 template<int size
, bool big_endian
>
7854 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7855 unsigned int r_type
)
7857 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7859 // These are the relocation types supported by glibc for both 32-bit
7860 // and 64-bit powerpc.
7863 case elfcpp::R_POWERPC_NONE
:
7864 case elfcpp::R_POWERPC_RELATIVE
:
7865 case elfcpp::R_POWERPC_GLOB_DAT
:
7866 case elfcpp::R_POWERPC_DTPMOD
:
7867 case elfcpp::R_POWERPC_DTPREL
:
7868 case elfcpp::R_POWERPC_TPREL
:
7869 case elfcpp::R_POWERPC_JMP_SLOT
:
7870 case elfcpp::R_POWERPC_COPY
:
7871 case elfcpp::R_POWERPC_IRELATIVE
:
7872 case elfcpp::R_POWERPC_ADDR32
:
7873 case elfcpp::R_POWERPC_UADDR32
:
7874 case elfcpp::R_POWERPC_ADDR24
:
7875 case elfcpp::R_POWERPC_ADDR16
:
7876 case elfcpp::R_POWERPC_UADDR16
:
7877 case elfcpp::R_POWERPC_ADDR16_LO
:
7878 case elfcpp::R_POWERPC_ADDR16_HI
:
7879 case elfcpp::R_POWERPC_ADDR16_HA
:
7880 case elfcpp::R_POWERPC_ADDR14
:
7881 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7882 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7883 case elfcpp::R_POWERPC_REL32
:
7884 case elfcpp::R_POWERPC_TPREL16
:
7885 case elfcpp::R_POWERPC_TPREL16_LO
:
7886 case elfcpp::R_POWERPC_TPREL16_HI
:
7887 case elfcpp::R_POWERPC_TPREL16_HA
:
7898 // These are the relocation types supported only on 64-bit.
7899 case elfcpp::R_PPC64_ADDR64
:
7900 case elfcpp::R_PPC64_UADDR64
:
7901 case elfcpp::R_PPC64_JMP_IREL
:
7902 case elfcpp::R_PPC64_ADDR16_DS
:
7903 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7904 case elfcpp::R_PPC64_ADDR16_HIGH
:
7905 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7906 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7907 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7908 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7909 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7910 case elfcpp::R_PPC64_REL64
:
7911 case elfcpp::R_POWERPC_ADDR30
:
7912 case elfcpp::R_PPC64_TPREL16_DS
:
7913 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7914 case elfcpp::R_PPC64_TPREL16_HIGH
:
7915 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7916 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7917 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7918 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7919 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7930 // These are the relocation types supported only on 32-bit.
7931 // ??? glibc ld.so doesn't need to support these.
7932 case elfcpp::R_POWERPC_REL24
:
7933 case elfcpp::R_POWERPC_DTPREL16
:
7934 case elfcpp::R_POWERPC_DTPREL16_LO
:
7935 case elfcpp::R_POWERPC_DTPREL16_HI
:
7936 case elfcpp::R_POWERPC_DTPREL16_HA
:
7944 // This prevents us from issuing more than one error per reloc
7945 // section. But we can still wind up issuing more than one
7946 // error per object file.
7947 if (this->issued_non_pic_error_
)
7949 gold_assert(parameters
->options().output_is_position_independent());
7950 object
->error(_("requires unsupported dynamic reloc; "
7951 "recompile with -fPIC"));
7952 this->issued_non_pic_error_
= true;
7956 // Return whether we need to make a PLT entry for a relocation of the
7957 // given type against a STT_GNU_IFUNC symbol.
7959 template<int size
, bool big_endian
>
7961 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7962 Target_powerpc
<size
, big_endian
>* target
,
7963 Sized_relobj_file
<size
, big_endian
>* object
,
7964 unsigned int r_type
,
7967 // In non-pic code any reference will resolve to the plt call stub
7968 // for the ifunc symbol.
7969 if ((size
== 32 || target
->abiversion() >= 2)
7970 && !parameters
->options().output_is_position_independent())
7975 // Word size refs from data sections are OK, but don't need a PLT entry.
7976 case elfcpp::R_POWERPC_ADDR32
:
7977 case elfcpp::R_POWERPC_UADDR32
:
7982 case elfcpp::R_PPC64_ADDR64
:
7983 case elfcpp::R_PPC64_UADDR64
:
7988 // GOT refs are good, but also don't need a PLT entry.
7989 case elfcpp::R_POWERPC_GOT16
:
7990 case elfcpp::R_POWERPC_GOT16_LO
:
7991 case elfcpp::R_POWERPC_GOT16_HI
:
7992 case elfcpp::R_POWERPC_GOT16_HA
:
7993 case elfcpp::R_PPC64_GOT16_DS
:
7994 case elfcpp::R_PPC64_GOT16_LO_DS
:
7995 case elfcpp::R_PPC64_GOT_PCREL34
:
7998 // PLT relocs are OK and need a PLT entry.
7999 case elfcpp::R_POWERPC_PLT16_LO
:
8000 case elfcpp::R_POWERPC_PLT16_HI
:
8001 case elfcpp::R_POWERPC_PLT16_HA
:
8002 case elfcpp::R_PPC64_PLT16_LO_DS
:
8003 case elfcpp::R_POWERPC_PLTSEQ
:
8004 case elfcpp::R_POWERPC_PLTCALL
:
8005 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8006 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8007 case elfcpp::R_PPC64_PLT_PCREL34
:
8008 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8012 // Function calls are good, and these do need a PLT entry.
8013 case elfcpp::R_PPC64_REL24_NOTOC
:
8017 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8018 case elfcpp::R_POWERPC_ADDR24
:
8019 case elfcpp::R_POWERPC_ADDR14
:
8020 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8021 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8022 case elfcpp::R_POWERPC_REL24
:
8023 case elfcpp::R_PPC_PLTREL24
:
8024 case elfcpp::R_POWERPC_REL14
:
8025 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8026 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8033 // Anything else is a problem.
8034 // If we are building a static executable, the libc startup function
8035 // responsible for applying indirect function relocations is going
8036 // to complain about the reloc type.
8037 // If we are building a dynamic executable, we will have a text
8038 // relocation. The dynamic loader will set the text segment
8039 // writable and non-executable to apply text relocations. So we'll
8040 // segfault when trying to run the indirection function to resolve
8043 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
8044 object
->name().c_str(), r_type
);
8048 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
8052 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
8054 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8055 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8056 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8057 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8058 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8059 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8060 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8061 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8062 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8063 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8064 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8065 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8066 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8067 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8068 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8069 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8070 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8071 /* Exclude lfqu by testing reloc. If relocs are ever
8072 defined for the reduced D field in psq_lu then those
8073 will need testing too. */
8074 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8075 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8076 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8078 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8079 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8080 /* Exclude stfqu. psq_stu as above for psq_lu. */
8081 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8082 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8083 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8084 && (insn
& 1) == 0));
8087 // Scan a relocation for a local symbol.
8089 template<int size
, bool big_endian
>
8091 Target_powerpc
<size
, big_endian
>::Scan::local(
8092 Symbol_table
* symtab
,
8094 Target_powerpc
<size
, big_endian
>* target
,
8095 Sized_relobj_file
<size
, big_endian
>* object
,
8096 unsigned int data_shndx
,
8097 Output_section
* output_section
,
8098 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8099 unsigned int r_type
,
8100 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8103 Powerpc_relobj
<size
, big_endian
>* ppc_object
8104 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8106 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
8108 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8109 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8111 this->expect_tls_get_addr_call();
8112 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8113 if (tls_type
!= tls::TLSOPT_NONE
)
8114 this->skip_next_tls_get_addr_call();
8116 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8117 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8119 this->expect_tls_get_addr_call();
8120 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8121 if (tls_type
!= tls::TLSOPT_NONE
)
8122 this->skip_next_tls_get_addr_call();
8128 && data_shndx
== ppc_object
->opd_shndx()
8129 && r_type
== elfcpp::R_PPC64_ADDR64
)
8130 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8134 // A local STT_GNU_IFUNC symbol may require a PLT entry.
8135 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
8136 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8138 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8139 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8140 r_type
, r_sym
, reloc
.get_r_addend());
8141 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
8146 case elfcpp::R_POWERPC_NONE
:
8147 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8148 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8149 case elfcpp::R_POWERPC_TLS
:
8150 case elfcpp::R_PPC64_ENTRY
:
8151 case elfcpp::R_POWERPC_PLTSEQ
:
8152 case elfcpp::R_POWERPC_PLTCALL
:
8153 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8154 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8155 case elfcpp::R_PPC64_PCREL_OPT
:
8156 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8157 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8158 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8159 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8160 case elfcpp::R_PPC64_REL16_HIGHER34
:
8161 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8162 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8163 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8164 case elfcpp::R_PPC64_D34
:
8165 case elfcpp::R_PPC64_D34_LO
:
8166 case elfcpp::R_PPC64_D34_HI30
:
8167 case elfcpp::R_PPC64_D34_HA30
:
8168 case elfcpp::R_PPC64_D28
:
8169 case elfcpp::R_PPC64_PCREL34
:
8170 case elfcpp::R_PPC64_PCREL28
:
8171 case elfcpp::R_PPC64_TPREL34
:
8172 case elfcpp::R_PPC64_DTPREL34
:
8175 case elfcpp::R_PPC64_TOC
:
8177 Output_data_got_powerpc
<size
, big_endian
>* got
8178 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8179 if (parameters
->options().output_is_position_independent())
8181 Address off
= reloc
.get_r_offset();
8183 && target
->abiversion() < 2
8184 && data_shndx
== ppc_object
->opd_shndx()
8185 && ppc_object
->get_opd_discard(off
- 8))
8188 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8189 Address got_off
= got
->g_o_t();
8190 rela_dyn
->add_output_section_relative(got
->output_section(),
8191 elfcpp::R_POWERPC_RELATIVE
,
8193 object
, data_shndx
, off
,
8199 case elfcpp::R_PPC64_ADDR64
:
8200 case elfcpp::R_PPC64_UADDR64
:
8201 case elfcpp::R_POWERPC_ADDR32
:
8202 case elfcpp::R_POWERPC_UADDR32
:
8203 case elfcpp::R_POWERPC_ADDR24
:
8204 case elfcpp::R_POWERPC_ADDR16
:
8205 case elfcpp::R_POWERPC_ADDR16_LO
:
8206 case elfcpp::R_POWERPC_ADDR16_HI
:
8207 case elfcpp::R_POWERPC_ADDR16_HA
:
8208 case elfcpp::R_POWERPC_UADDR16
:
8209 case elfcpp::R_PPC64_ADDR16_HIGH
:
8210 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8211 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8212 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8213 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8214 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8215 case elfcpp::R_PPC64_ADDR16_DS
:
8216 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8217 case elfcpp::R_POWERPC_ADDR14
:
8218 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8219 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8220 // If building a shared library (or a position-independent
8221 // executable), we need to create a dynamic relocation for
8223 if (parameters
->options().output_is_position_independent()
8224 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8226 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8228 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8229 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8230 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8232 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8233 : elfcpp::R_POWERPC_RELATIVE
);
8234 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8235 output_section
, data_shndx
,
8236 reloc
.get_r_offset(),
8237 reloc
.get_r_addend(), false);
8239 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8241 check_non_pic(object
, r_type
);
8242 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8243 data_shndx
, reloc
.get_r_offset(),
8244 reloc
.get_r_addend());
8248 gold_assert(lsym
.get_st_value() == 0);
8249 unsigned int shndx
= lsym
.get_st_shndx();
8251 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8254 object
->error(_("section symbol %u has bad shndx %u"),
8257 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8258 output_section
, data_shndx
,
8259 reloc
.get_r_offset());
8264 case elfcpp::R_PPC64_PLT_PCREL34
:
8265 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8266 case elfcpp::R_POWERPC_PLT16_LO
:
8267 case elfcpp::R_POWERPC_PLT16_HI
:
8268 case elfcpp::R_POWERPC_PLT16_HA
:
8269 case elfcpp::R_PPC64_PLT16_LO_DS
:
8272 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8273 target
->make_local_plt_entry(symtab
, layout
, object
, r_sym
);
8277 case elfcpp::R_PPC64_REL24_NOTOC
:
8281 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8282 case elfcpp::R_POWERPC_REL24
:
8283 case elfcpp::R_PPC_PLTREL24
:
8284 case elfcpp::R_PPC_LOCAL24PC
:
8285 case elfcpp::R_POWERPC_REL14
:
8286 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8287 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8290 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8291 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8292 r_type
, r_sym
, reloc
.get_r_addend());
8296 case elfcpp::R_PPC64_TOCSAVE
:
8297 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8298 // caller has already saved r2 and thus a plt call stub need not
8301 && target
->mark_pltcall(ppc_object
, data_shndx
,
8302 reloc
.get_r_offset() - 4, symtab
))
8304 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8305 unsigned int shndx
= lsym
.get_st_shndx();
8307 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8309 object
->error(_("tocsave symbol %u has bad shndx %u"),
8312 target
->add_tocsave(ppc_object
, shndx
,
8313 lsym
.get_st_value() + reloc
.get_r_addend());
8317 case elfcpp::R_PPC64_REL64
:
8318 case elfcpp::R_POWERPC_REL32
:
8319 case elfcpp::R_POWERPC_REL16
:
8320 case elfcpp::R_POWERPC_REL16_LO
:
8321 case elfcpp::R_POWERPC_REL16_HI
:
8322 case elfcpp::R_POWERPC_REL16_HA
:
8323 case elfcpp::R_POWERPC_REL16DX_HA
:
8324 case elfcpp::R_PPC64_REL16_HIGH
:
8325 case elfcpp::R_PPC64_REL16_HIGHA
:
8326 case elfcpp::R_PPC64_REL16_HIGHER
:
8327 case elfcpp::R_PPC64_REL16_HIGHERA
:
8328 case elfcpp::R_PPC64_REL16_HIGHEST
:
8329 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8330 case elfcpp::R_POWERPC_SECTOFF
:
8331 case elfcpp::R_POWERPC_SECTOFF_LO
:
8332 case elfcpp::R_POWERPC_SECTOFF_HI
:
8333 case elfcpp::R_POWERPC_SECTOFF_HA
:
8334 case elfcpp::R_PPC64_SECTOFF_DS
:
8335 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8336 case elfcpp::R_POWERPC_TPREL16
:
8337 case elfcpp::R_POWERPC_TPREL16_LO
:
8338 case elfcpp::R_POWERPC_TPREL16_HI
:
8339 case elfcpp::R_POWERPC_TPREL16_HA
:
8340 case elfcpp::R_PPC64_TPREL16_DS
:
8341 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8342 case elfcpp::R_PPC64_TPREL16_HIGH
:
8343 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8344 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8345 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8346 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8347 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8348 case elfcpp::R_POWERPC_DTPREL16
:
8349 case elfcpp::R_POWERPC_DTPREL16_LO
:
8350 case elfcpp::R_POWERPC_DTPREL16_HI
:
8351 case elfcpp::R_POWERPC_DTPREL16_HA
:
8352 case elfcpp::R_PPC64_DTPREL16_DS
:
8353 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8354 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8355 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8356 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8357 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8358 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8359 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8360 case elfcpp::R_PPC64_TLSGD
:
8361 case elfcpp::R_PPC64_TLSLD
:
8362 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8365 case elfcpp::R_PPC64_GOT_PCREL34
:
8366 case elfcpp::R_POWERPC_GOT16
:
8367 case elfcpp::R_POWERPC_GOT16_LO
:
8368 case elfcpp::R_POWERPC_GOT16_HI
:
8369 case elfcpp::R_POWERPC_GOT16_HA
:
8370 case elfcpp::R_PPC64_GOT16_DS
:
8371 case elfcpp::R_PPC64_GOT16_LO_DS
:
8373 // The symbol requires a GOT entry.
8374 Got_type got_type
= ((size
== 32
8375 || r_type
== elfcpp::R_POWERPC_GOT16
8376 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8377 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8378 Output_data_got_powerpc
<size
, big_endian
>* got
8379 = target
->got_section(symtab
, layout
, got_type
);
8380 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8381 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8383 if (!parameters
->options().output_is_position_independent())
8386 && (size
== 32 || target
->abiversion() >= 2))
8387 got
->add_local_plt(object
, r_sym
, got_type
, addend
);
8389 got
->add_local(object
, r_sym
, got_type
, addend
);
8391 else if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8393 // If we are generating a shared object or a pie, this
8394 // symbol's GOT entry will be set by a dynamic relocation.
8396 off
= got
->add_constant(0);
8397 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8399 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8401 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8402 : elfcpp::R_POWERPC_RELATIVE
);
8403 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8404 got
, off
, addend
, false);
8409 case elfcpp::R_PPC64_TOC16
:
8410 case elfcpp::R_PPC64_TOC16_LO
:
8411 case elfcpp::R_PPC64_TOC16_HI
:
8412 case elfcpp::R_PPC64_TOC16_HA
:
8413 case elfcpp::R_PPC64_TOC16_DS
:
8414 case elfcpp::R_PPC64_TOC16_LO_DS
:
8415 // We need a GOT section.
8416 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8419 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8420 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8421 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8422 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8423 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8425 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8426 if (tls_type
== tls::TLSOPT_NONE
)
8428 Got_type got_type
= ((size
== 32
8429 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8430 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8431 Output_data_got_powerpc
<size
, big_endian
>* got
8432 = target
->got_section(symtab
, layout
, got_type
);
8433 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8434 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8435 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8436 got
->add_local_tls_pair(object
, r_sym
, got_type
,
8437 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
,
8440 else if (tls_type
== tls::TLSOPT_TO_LE
)
8442 // no GOT relocs needed for Local Exec.
8449 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8450 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8451 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8452 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8453 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8455 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8456 if (tls_type
== tls::TLSOPT_NONE
)
8457 target
->tlsld_got_offset(symtab
, layout
, object
);
8458 else if (tls_type
== tls::TLSOPT_TO_LE
)
8460 // no GOT relocs needed for Local Exec.
8461 if (parameters
->options().emit_relocs())
8463 Output_section
* os
= layout
->tls_segment()->first_section();
8464 gold_assert(os
!= NULL
);
8465 os
->set_needs_symtab_index();
8473 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8474 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8475 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8476 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8477 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8479 Got_type got_type
= ((size
== 32
8480 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
8481 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
8482 Output_data_got_powerpc
<size
, big_endian
>* got
8483 = target
->got_section(symtab
, layout
, got_type
);
8484 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8485 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8486 got
->add_local_tls(object
, r_sym
, got_type
, addend
);
8490 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8491 case elfcpp::R_POWERPC_GOT_TPREL16
:
8492 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8493 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8494 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8496 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8497 if (tls_type
== tls::TLSOPT_NONE
)
8499 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8500 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8501 Got_type got_type
= ((size
== 32
8502 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
8503 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
8504 if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8506 Output_data_got_powerpc
<size
, big_endian
>* got
8507 = target
->got_section(symtab
, layout
, got_type
);
8508 unsigned int off
= got
->add_constant(0);
8509 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8511 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8512 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8513 elfcpp::R_POWERPC_TPREL
,
8517 else if (tls_type
== tls::TLSOPT_TO_LE
)
8519 // no GOT relocs needed for Local Exec.
8527 unsupported_reloc_local(object
, r_type
);
8532 && parameters
->options().toc_optimize())
8534 if (data_shndx
== ppc_object
->toc_shndx())
8537 if (r_type
!= elfcpp::R_PPC64_ADDR64
8538 || (is_ifunc
&& target
->abiversion() < 2))
8540 else if (parameters
->options().output_is_position_independent())
8546 unsigned int shndx
= lsym
.get_st_shndx();
8547 if (shndx
>= elfcpp::SHN_LORESERVE
8548 && shndx
!= elfcpp::SHN_XINDEX
)
8553 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8556 enum {no_check
, check_lo
, check_ha
} insn_check
;
8560 insn_check
= no_check
;
8563 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8564 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8565 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8566 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8567 case elfcpp::R_POWERPC_GOT16_HA
:
8568 case elfcpp::R_PPC64_TOC16_HA
:
8569 insn_check
= check_ha
;
8572 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8573 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8574 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8575 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8576 case elfcpp::R_POWERPC_GOT16_LO
:
8577 case elfcpp::R_PPC64_GOT16_LO_DS
:
8578 case elfcpp::R_PPC64_TOC16_LO
:
8579 case elfcpp::R_PPC64_TOC16_LO_DS
:
8580 insn_check
= check_lo
;
8584 section_size_type slen
;
8585 const unsigned char* view
= NULL
;
8586 if (insn_check
!= no_check
)
8588 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8589 section_size_type off
=
8590 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8593 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8594 if (insn_check
== check_lo
8595 ? !ok_lo_toc_insn(insn
, r_type
)
8596 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8597 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8599 ppc_object
->set_no_toc_opt();
8600 gold_warning(_("%s: toc optimization is not supported "
8601 "for %#08x instruction"),
8602 ppc_object
->name().c_str(), insn
);
8611 case elfcpp::R_PPC64_TOC16
:
8612 case elfcpp::R_PPC64_TOC16_LO
:
8613 case elfcpp::R_PPC64_TOC16_HI
:
8614 case elfcpp::R_PPC64_TOC16_HA
:
8615 case elfcpp::R_PPC64_TOC16_DS
:
8616 case elfcpp::R_PPC64_TOC16_LO_DS
:
8617 unsigned int shndx
= lsym
.get_st_shndx();
8618 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8620 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8621 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8623 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8624 if (dst_off
< ppc_object
->section_size(shndx
))
8627 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8629 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8631 // Need to check that the insn is a ld
8633 view
= ppc_object
->section_contents(data_shndx
,
8636 section_size_type off
=
8637 (convert_to_section_size_type(reloc
.get_r_offset())
8638 + (big_endian
? -2 : 3));
8640 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8644 ppc_object
->set_no_toc_opt(dst_off
);
8655 case elfcpp::R_POWERPC_REL32
:
8656 if (ppc_object
->got2_shndx() != 0
8657 && parameters
->options().output_is_position_independent())
8659 unsigned int shndx
= lsym
.get_st_shndx();
8660 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8662 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8663 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8664 && (ppc_object
->section_flags(data_shndx
)
8665 & elfcpp::SHF_EXECINSTR
) != 0)
8666 gold_error(_("%s: unsupported -mbss-plt code"),
8667 ppc_object
->name().c_str());
8677 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8678 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8679 case elfcpp::R_POWERPC_GOT_TPREL16
:
8680 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8681 case elfcpp::R_POWERPC_GOT16
:
8682 case elfcpp::R_PPC64_GOT16_DS
:
8683 case elfcpp::R_PPC64_TOC16
:
8684 case elfcpp::R_PPC64_TOC16_DS
:
8685 ppc_object
->set_has_small_toc_reloc();
8693 case elfcpp::R_PPC64_TPREL16_DS
:
8694 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8695 case elfcpp::R_PPC64_TPREL16_HIGH
:
8696 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8697 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8698 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8699 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8700 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8701 case elfcpp::R_PPC64_TPREL34
:
8705 case elfcpp::R_POWERPC_TPREL16
:
8706 case elfcpp::R_POWERPC_TPREL16_LO
:
8707 case elfcpp::R_POWERPC_TPREL16_HI
:
8708 case elfcpp::R_POWERPC_TPREL16_HA
:
8709 layout
->set_has_static_tls();
8717 case elfcpp::R_POWERPC_TPREL16_HA
:
8718 if (target
->tprel_opt())
8720 section_size_type slen
;
8721 const unsigned char* view
= NULL
;
8722 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8723 section_size_type off
8724 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8727 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8728 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8729 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8730 target
->set_no_tprel_opt();
8735 case elfcpp::R_PPC64_TPREL16_HIGH
:
8736 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8737 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8738 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8739 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8740 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8744 case elfcpp::R_POWERPC_TPREL16_HI
:
8745 target
->set_no_tprel_opt();
8753 case elfcpp::R_PPC64_D34
:
8754 case elfcpp::R_PPC64_D34_LO
:
8755 case elfcpp::R_PPC64_D34_HI30
:
8756 case elfcpp::R_PPC64_D34_HA30
:
8757 case elfcpp::R_PPC64_D28
:
8758 case elfcpp::R_PPC64_PCREL34
:
8759 case elfcpp::R_PPC64_PCREL28
:
8760 case elfcpp::R_PPC64_TPREL34
:
8761 case elfcpp::R_PPC64_DTPREL34
:
8762 case elfcpp::R_PPC64_PLT_PCREL34
:
8763 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8764 case elfcpp::R_PPC64_GOT_PCREL34
:
8765 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8766 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8767 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8768 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8769 target
->set_power10_relocs();
8776 // Report an unsupported relocation against a global symbol.
8778 template<int size
, bool big_endian
>
8780 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8781 Sized_relobj_file
<size
, big_endian
>* object
,
8782 unsigned int r_type
,
8785 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8786 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8789 // Scan a relocation for a global symbol.
8791 template<int size
, bool big_endian
>
8793 Target_powerpc
<size
, big_endian
>::Scan::global(
8794 Symbol_table
* symtab
,
8796 Target_powerpc
<size
, big_endian
>* target
,
8797 Sized_relobj_file
<size
, big_endian
>* object
,
8798 unsigned int data_shndx
,
8799 Output_section
* output_section
,
8800 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8801 unsigned int r_type
,
8804 Powerpc_relobj
<size
, big_endian
>* ppc_object
8805 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8807 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8809 case Track_tls::SKIP
:
8815 if (target
->replace_tls_get_addr(gsym
))
8816 // Change a __tls_get_addr reference to __tls_get_addr_opt
8817 // so dynamic relocs are emitted against the latter symbol.
8818 gsym
= target
->tls_get_addr_opt();
8820 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8821 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8823 this->expect_tls_get_addr_call();
8824 bool final
= gsym
->final_value_is_known();
8825 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8826 if (tls_type
!= tls::TLSOPT_NONE
)
8827 this->skip_next_tls_get_addr_call();
8829 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8830 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8832 this->expect_tls_get_addr_call();
8833 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8834 if (tls_type
!= tls::TLSOPT_NONE
)
8835 this->skip_next_tls_get_addr_call();
8838 // A STT_GNU_IFUNC symbol may require a PLT entry.
8839 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8840 bool pushed_ifunc
= false;
8841 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8843 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8844 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8845 r_type
, r_sym
, reloc
.get_r_addend());
8846 target
->make_plt_entry(symtab
, layout
, gsym
);
8847 pushed_ifunc
= true;
8852 case elfcpp::R_POWERPC_NONE
:
8853 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8854 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8855 case elfcpp::R_PPC_LOCAL24PC
:
8856 case elfcpp::R_POWERPC_TLS
:
8857 case elfcpp::R_PPC64_ENTRY
:
8858 case elfcpp::R_POWERPC_PLTSEQ
:
8859 case elfcpp::R_POWERPC_PLTCALL
:
8860 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8861 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8862 case elfcpp::R_PPC64_PCREL_OPT
:
8863 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8864 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8865 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8866 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8867 case elfcpp::R_PPC64_REL16_HIGHER34
:
8868 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8869 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8870 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8871 case elfcpp::R_PPC64_D34
:
8872 case elfcpp::R_PPC64_D34_LO
:
8873 case elfcpp::R_PPC64_D34_HI30
:
8874 case elfcpp::R_PPC64_D34_HA30
:
8875 case elfcpp::R_PPC64_D28
:
8876 case elfcpp::R_PPC64_PCREL34
:
8877 case elfcpp::R_PPC64_PCREL28
:
8878 case elfcpp::R_PPC64_TPREL34
:
8879 case elfcpp::R_PPC64_DTPREL34
:
8882 case elfcpp::R_PPC64_TOC
:
8884 Output_data_got_powerpc
<size
, big_endian
>* got
8885 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8886 if (parameters
->options().output_is_position_independent())
8888 Address off
= reloc
.get_r_offset();
8890 && data_shndx
== ppc_object
->opd_shndx()
8891 && ppc_object
->get_opd_discard(off
- 8))
8894 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8895 Address got_off
= got
->g_o_t();
8896 rela_dyn
->add_output_section_relative(got
->output_section(),
8897 elfcpp::R_POWERPC_RELATIVE
,
8899 object
, data_shndx
, off
,
8905 case elfcpp::R_PPC64_ADDR64
:
8907 && target
->abiversion() < 2
8908 && data_shndx
== ppc_object
->opd_shndx()
8909 && (gsym
->is_defined_in_discarded_section()
8910 || gsym
->object() != object
))
8912 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8916 case elfcpp::R_PPC64_UADDR64
:
8917 case elfcpp::R_POWERPC_ADDR32
:
8918 case elfcpp::R_POWERPC_UADDR32
:
8919 case elfcpp::R_POWERPC_ADDR24
:
8920 case elfcpp::R_POWERPC_ADDR16
:
8921 case elfcpp::R_POWERPC_ADDR16_LO
:
8922 case elfcpp::R_POWERPC_ADDR16_HI
:
8923 case elfcpp::R_POWERPC_ADDR16_HA
:
8924 case elfcpp::R_POWERPC_UADDR16
:
8925 case elfcpp::R_PPC64_ADDR16_HIGH
:
8926 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8927 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8928 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8929 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8930 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8931 case elfcpp::R_PPC64_ADDR16_DS
:
8932 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8933 case elfcpp::R_POWERPC_ADDR14
:
8934 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8935 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8937 // Make a PLT entry if necessary.
8938 if (gsym
->needs_plt_entry())
8940 // Since this is not a PC-relative relocation, we may be
8941 // taking the address of a function. In that case we need to
8942 // set the entry in the dynamic symbol table to the address of
8943 // the PLT call stub.
8944 bool need_ifunc_plt
= false;
8945 if ((size
== 32 || target
->abiversion() >= 2)
8946 && gsym
->is_from_dynobj()
8947 && !parameters
->options().output_is_position_independent())
8949 gsym
->set_needs_dynsym_value();
8950 need_ifunc_plt
= true;
8952 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8954 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8955 target
->push_branch(ppc_object
, data_shndx
,
8956 reloc
.get_r_offset(), r_type
, r_sym
,
8957 reloc
.get_r_addend());
8958 target
->make_plt_entry(symtab
, layout
, gsym
);
8961 // Make a dynamic relocation if necessary.
8962 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8963 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8965 if (!parameters
->options().output_is_position_independent()
8966 && gsym
->may_need_copy_reloc())
8968 target
->copy_reloc(symtab
, layout
, object
,
8969 data_shndx
, output_section
, gsym
, reloc
);
8971 else if ((((size
== 32
8972 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8974 && r_type
== elfcpp::R_PPC64_ADDR64
8975 && target
->abiversion() >= 2))
8976 && gsym
->can_use_relative_reloc(false)
8977 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8978 && parameters
->options().shared()))
8980 && r_type
== elfcpp::R_PPC64_ADDR64
8981 && target
->abiversion() < 2
8982 && (gsym
->can_use_relative_reloc(false)
8983 || data_shndx
== ppc_object
->opd_shndx())))
8985 Reloc_section
* rela_dyn
8986 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8987 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8988 : elfcpp::R_POWERPC_RELATIVE
);
8989 // Use the "add" method that marks the reloc as being
8990 // relative. This is proper here and in other places
8991 // that add IRELATIVE relocs because those relocs go
8992 // into a separate section that isn't sorted, so it
8993 // doesn't matter that they are marked is_relative.
8994 rela_dyn
->add_global_relative(
8995 gsym
, dynrel
, output_section
, object
, data_shndx
,
8996 reloc
.get_r_offset(), reloc
.get_r_addend(), false);
9000 Reloc_section
* rela_dyn
9001 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9002 check_non_pic(object
, r_type
);
9003 rela_dyn
->add_global(gsym
, r_type
, output_section
,
9005 reloc
.get_r_offset(),
9006 reloc
.get_r_addend());
9009 && parameters
->options().toc_optimize()
9010 && data_shndx
== ppc_object
->toc_shndx())
9011 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9017 case elfcpp::R_PPC64_PLT_PCREL34
:
9018 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9019 case elfcpp::R_POWERPC_PLT16_LO
:
9020 case elfcpp::R_POWERPC_PLT16_HI
:
9021 case elfcpp::R_POWERPC_PLT16_HA
:
9022 case elfcpp::R_PPC64_PLT16_LO_DS
:
9025 if (branch_needs_plt_entry(gsym
))
9026 target
->make_plt_entry(symtab
, layout
, gsym
);
9028 target
->make_local_plt_entry(symtab
, layout
, gsym
);
9032 case elfcpp::R_PPC64_REL24_NOTOC
:
9036 case elfcpp::R_PPC64_REL24_P9NOTOC
:
9037 case elfcpp::R_PPC_PLTREL24
:
9038 case elfcpp::R_POWERPC_REL24
:
9041 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9042 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9043 r_type
, r_sym
, reloc
.get_r_addend());
9044 if (branch_needs_plt_entry(gsym
))
9045 target
->make_plt_entry(symtab
, layout
, gsym
);
9049 case elfcpp::R_PPC64_REL64
:
9050 case elfcpp::R_POWERPC_REL32
:
9051 // Make a dynamic relocation if necessary.
9052 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
9054 if (!parameters
->options().output_is_position_independent()
9055 && gsym
->may_need_copy_reloc())
9057 target
->copy_reloc(symtab
, layout
, object
,
9058 data_shndx
, output_section
, gsym
,
9063 Reloc_section
* rela_dyn
9064 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9065 check_non_pic(object
, r_type
);
9066 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
9067 data_shndx
, reloc
.get_r_offset(),
9068 reloc
.get_r_addend());
9073 case elfcpp::R_POWERPC_REL14
:
9074 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9075 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9078 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9079 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9080 r_type
, r_sym
, reloc
.get_r_addend());
9084 case elfcpp::R_PPC64_TOCSAVE
:
9085 // R_PPC64_TOCSAVE follows a call instruction to indicate the
9086 // caller has already saved r2 and thus a plt call stub need not
9089 && target
->mark_pltcall(ppc_object
, data_shndx
,
9090 reloc
.get_r_offset() - 4, symtab
))
9092 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9094 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9096 object
->error(_("tocsave symbol %u has bad shndx %u"),
9100 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9101 target
->add_tocsave(ppc_object
, shndx
,
9102 sym
->value() + reloc
.get_r_addend());
9107 case elfcpp::R_POWERPC_REL16
:
9108 case elfcpp::R_POWERPC_REL16_LO
:
9109 case elfcpp::R_POWERPC_REL16_HI
:
9110 case elfcpp::R_POWERPC_REL16_HA
:
9111 case elfcpp::R_POWERPC_REL16DX_HA
:
9112 case elfcpp::R_PPC64_REL16_HIGH
:
9113 case elfcpp::R_PPC64_REL16_HIGHA
:
9114 case elfcpp::R_PPC64_REL16_HIGHER
:
9115 case elfcpp::R_PPC64_REL16_HIGHERA
:
9116 case elfcpp::R_PPC64_REL16_HIGHEST
:
9117 case elfcpp::R_PPC64_REL16_HIGHESTA
:
9118 case elfcpp::R_POWERPC_SECTOFF
:
9119 case elfcpp::R_POWERPC_SECTOFF_LO
:
9120 case elfcpp::R_POWERPC_SECTOFF_HI
:
9121 case elfcpp::R_POWERPC_SECTOFF_HA
:
9122 case elfcpp::R_PPC64_SECTOFF_DS
:
9123 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9124 case elfcpp::R_POWERPC_TPREL16
:
9125 case elfcpp::R_POWERPC_TPREL16_LO
:
9126 case elfcpp::R_POWERPC_TPREL16_HI
:
9127 case elfcpp::R_POWERPC_TPREL16_HA
:
9128 case elfcpp::R_PPC64_TPREL16_DS
:
9129 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9130 case elfcpp::R_PPC64_TPREL16_HIGH
:
9131 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9132 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9133 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9134 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9135 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9136 case elfcpp::R_POWERPC_DTPREL16
:
9137 case elfcpp::R_POWERPC_DTPREL16_LO
:
9138 case elfcpp::R_POWERPC_DTPREL16_HI
:
9139 case elfcpp::R_POWERPC_DTPREL16_HA
:
9140 case elfcpp::R_PPC64_DTPREL16_DS
:
9141 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
9142 case elfcpp::R_PPC64_DTPREL16_HIGH
:
9143 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
9144 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
9145 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
9146 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
9147 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
9148 case elfcpp::R_PPC64_TLSGD
:
9149 case elfcpp::R_PPC64_TLSLD
:
9150 case elfcpp::R_PPC64_ADDR64_LOCAL
:
9153 case elfcpp::R_PPC64_GOT_PCREL34
:
9154 case elfcpp::R_POWERPC_GOT16
:
9155 case elfcpp::R_POWERPC_GOT16_LO
:
9156 case elfcpp::R_POWERPC_GOT16_HI
:
9157 case elfcpp::R_POWERPC_GOT16_HA
:
9158 case elfcpp::R_PPC64_GOT16_DS
:
9159 case elfcpp::R_PPC64_GOT16_LO_DS
:
9161 // The symbol requires a GOT entry.
9162 Output_data_got_powerpc
<size
, big_endian
>* got
;
9163 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9164 Got_type got_type
= ((size
== 32
9165 || r_type
== elfcpp::R_POWERPC_GOT16
9166 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
9167 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
9169 got
= target
->got_section(symtab
, layout
, got_type
);
9170 if (gsym
->final_value_is_known())
9173 && (size
== 32 || target
->abiversion() >= 2))
9174 got
->add_global_plt(gsym
, got_type
, addend
);
9176 got
->add_global(gsym
, got_type
, addend
);
9178 else if (!gsym
->has_got_offset(got_type
, addend
))
9180 // If we are generating a shared object or a pie, this
9181 // symbol's GOT entry will be set by a dynamic relocation.
9182 unsigned int off
= got
->add_constant(0);
9183 gsym
->set_got_offset(got_type
, off
, addend
);
9185 Reloc_section
* rela_dyn
9186 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9188 if (gsym
->can_use_relative_reloc(false)
9190 || target
->abiversion() >= 2)
9191 && gsym
->visibility() == elfcpp::STV_PROTECTED
9192 && parameters
->options().shared()))
9194 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
9195 : elfcpp::R_POWERPC_RELATIVE
);
9196 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
,
9201 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
9202 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, addend
);
9208 case elfcpp::R_PPC64_TOC16
:
9209 case elfcpp::R_PPC64_TOC16_LO
:
9210 case elfcpp::R_PPC64_TOC16_HI
:
9211 case elfcpp::R_PPC64_TOC16_HA
:
9212 case elfcpp::R_PPC64_TOC16_DS
:
9213 case elfcpp::R_PPC64_TOC16_LO_DS
:
9214 // We need a GOT section.
9215 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
9218 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9219 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9220 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9221 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9222 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9224 bool final
= gsym
->final_value_is_known();
9225 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9226 if (tls_type
== tls::TLSOPT_NONE
)
9228 Got_type got_type
= ((size
== 32
9229 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9230 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
9231 Output_data_got_powerpc
<size
, big_endian
>* got
9232 = target
->got_section(symtab
, layout
, got_type
);
9233 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9234 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9235 got
->add_global_pair_with_rel(gsym
, got_type
, rela_dyn
,
9236 elfcpp::R_POWERPC_DTPMOD
,
9237 elfcpp::R_POWERPC_DTPREL
,
9240 else if (tls_type
== tls::TLSOPT_TO_IE
)
9242 Got_type got_type
= ((size
== 32
9243 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9244 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9245 if (!gsym
->has_got_offset(got_type
))
9247 Output_data_got_powerpc
<size
, big_endian
>* got
9248 = target
->got_section(symtab
, layout
, got_type
);
9249 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9250 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9251 if (gsym
->is_undefined()
9252 || gsym
->is_from_dynobj())
9254 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9255 elfcpp::R_POWERPC_TPREL
, addend
);
9259 unsigned int off
= got
->add_constant(0);
9260 gsym
->set_got_offset(got_type
, off
);
9261 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9262 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9267 else if (tls_type
== tls::TLSOPT_TO_LE
)
9269 // no GOT relocs needed for Local Exec.
9276 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9277 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9278 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9279 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9280 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9282 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9283 if (tls_type
== tls::TLSOPT_NONE
)
9284 target
->tlsld_got_offset(symtab
, layout
, object
);
9285 else if (tls_type
== tls::TLSOPT_TO_LE
)
9287 // no GOT relocs needed for Local Exec.
9288 if (parameters
->options().emit_relocs())
9290 Output_section
* os
= layout
->tls_segment()->first_section();
9291 gold_assert(os
!= NULL
);
9292 os
->set_needs_symtab_index();
9300 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9301 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9302 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9303 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9304 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9306 Got_type got_type
= ((size
== 32
9307 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
9308 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
9309 Output_data_got_powerpc
<size
, big_endian
>* got
9310 = target
->got_section(symtab
, layout
, got_type
);
9311 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9312 if (!gsym
->final_value_is_known()
9313 && (gsym
->is_from_dynobj()
9314 || gsym
->is_undefined()
9315 || gsym
->is_preemptible()))
9316 got
->add_global_with_rel(gsym
, got_type
,
9317 target
->rela_dyn_section(layout
),
9318 elfcpp::R_POWERPC_DTPREL
, addend
);
9320 got
->add_global_tls(gsym
, got_type
, addend
);
9324 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9325 case elfcpp::R_POWERPC_GOT_TPREL16
:
9326 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9327 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9328 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9330 bool final
= gsym
->final_value_is_known();
9331 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9332 if (tls_type
== tls::TLSOPT_NONE
)
9334 Got_type got_type
= ((size
== 32
9335 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
9336 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9337 if (!gsym
->has_got_offset(got_type
))
9339 Output_data_got_powerpc
<size
, big_endian
>* got
9340 = target
->got_section(symtab
, layout
, got_type
);
9341 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9342 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9343 if (gsym
->is_undefined()
9344 || gsym
->is_from_dynobj())
9346 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9347 elfcpp::R_POWERPC_TPREL
, addend
);
9351 unsigned int off
= got
->add_constant(0);
9352 gsym
->set_got_offset(got_type
, off
);
9353 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9354 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9359 else if (tls_type
== tls::TLSOPT_TO_LE
)
9361 // no GOT relocs needed for Local Exec.
9369 unsupported_reloc_global(object
, r_type
, gsym
);
9374 && parameters
->options().toc_optimize())
9376 if (data_shndx
== ppc_object
->toc_shndx())
9379 if (r_type
!= elfcpp::R_PPC64_ADDR64
9380 || (is_ifunc
&& target
->abiversion() < 2))
9382 else if (parameters
->options().output_is_position_independent()
9383 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9386 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9389 enum {no_check
, check_lo
, check_ha
} insn_check
;
9393 insn_check
= no_check
;
9396 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9397 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9398 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9399 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9400 case elfcpp::R_POWERPC_GOT16_HA
:
9401 case elfcpp::R_PPC64_TOC16_HA
:
9402 insn_check
= check_ha
;
9405 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9406 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9407 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9408 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9409 case elfcpp::R_POWERPC_GOT16_LO
:
9410 case elfcpp::R_PPC64_GOT16_LO_DS
:
9411 case elfcpp::R_PPC64_TOC16_LO
:
9412 case elfcpp::R_PPC64_TOC16_LO_DS
:
9413 insn_check
= check_lo
;
9417 section_size_type slen
;
9418 const unsigned char* view
= NULL
;
9419 if (insn_check
!= no_check
)
9421 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9422 section_size_type off
=
9423 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9426 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9427 if (insn_check
== check_lo
9428 ? !ok_lo_toc_insn(insn
, r_type
)
9429 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9430 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9432 ppc_object
->set_no_toc_opt();
9433 gold_warning(_("%s: toc optimization is not supported "
9434 "for %#08x instruction"),
9435 ppc_object
->name().c_str(), insn
);
9444 case elfcpp::R_PPC64_TOC16
:
9445 case elfcpp::R_PPC64_TOC16_LO
:
9446 case elfcpp::R_PPC64_TOC16_HI
:
9447 case elfcpp::R_PPC64_TOC16_HA
:
9448 case elfcpp::R_PPC64_TOC16_DS
:
9449 case elfcpp::R_PPC64_TOC16_LO_DS
:
9450 if (gsym
->source() == Symbol::FROM_OBJECT
9451 && !gsym
->object()->is_dynamic())
9453 Powerpc_relobj
<size
, big_endian
>* sym_object
9454 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9456 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9457 if (shndx
== sym_object
->toc_shndx())
9459 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9460 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9461 if (dst_off
< sym_object
->section_size(shndx
))
9464 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9466 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9468 // Need to check that the insn is a ld
9470 view
= ppc_object
->section_contents(data_shndx
,
9473 section_size_type off
=
9474 (convert_to_section_size_type(reloc
.get_r_offset())
9475 + (big_endian
? -2 : 3));
9477 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9481 sym_object
->set_no_toc_opt(dst_off
);
9493 case elfcpp::R_PPC_LOCAL24PC
:
9494 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9495 gold_error(_("%s: unsupported -mbss-plt code"),
9496 ppc_object
->name().c_str());
9505 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9506 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9507 case elfcpp::R_POWERPC_GOT_TPREL16
:
9508 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9509 case elfcpp::R_POWERPC_GOT16
:
9510 case elfcpp::R_PPC64_GOT16_DS
:
9511 case elfcpp::R_PPC64_TOC16
:
9512 case elfcpp::R_PPC64_TOC16_DS
:
9513 ppc_object
->set_has_small_toc_reloc();
9521 case elfcpp::R_PPC64_TPREL16_DS
:
9522 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9523 case elfcpp::R_PPC64_TPREL16_HIGH
:
9524 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9525 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9526 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9527 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9528 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9529 case elfcpp::R_PPC64_TPREL34
:
9533 case elfcpp::R_POWERPC_TPREL16
:
9534 case elfcpp::R_POWERPC_TPREL16_LO
:
9535 case elfcpp::R_POWERPC_TPREL16_HI
:
9536 case elfcpp::R_POWERPC_TPREL16_HA
:
9537 layout
->set_has_static_tls();
9545 case elfcpp::R_POWERPC_TPREL16_HA
:
9546 if (target
->tprel_opt())
9548 section_size_type slen
;
9549 const unsigned char* view
= NULL
;
9550 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9551 section_size_type off
9552 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9555 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9556 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9557 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9558 target
->set_no_tprel_opt();
9563 case elfcpp::R_PPC64_TPREL16_HIGH
:
9564 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9565 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9566 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9567 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9568 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9572 case elfcpp::R_POWERPC_TPREL16_HI
:
9573 target
->set_no_tprel_opt();
9581 case elfcpp::R_PPC64_D34
:
9582 case elfcpp::R_PPC64_D34_LO
:
9583 case elfcpp::R_PPC64_D34_HI30
:
9584 case elfcpp::R_PPC64_D34_HA30
:
9585 case elfcpp::R_PPC64_D28
:
9586 case elfcpp::R_PPC64_PCREL34
:
9587 case elfcpp::R_PPC64_PCREL28
:
9588 case elfcpp::R_PPC64_TPREL34
:
9589 case elfcpp::R_PPC64_DTPREL34
:
9590 case elfcpp::R_PPC64_PLT_PCREL34
:
9591 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9592 case elfcpp::R_PPC64_GOT_PCREL34
:
9593 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9594 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9595 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9596 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9597 target
->set_power10_relocs();
9604 // Process relocations for gc.
9606 template<int size
, bool big_endian
>
9608 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9609 Symbol_table
* symtab
,
9611 Sized_relobj_file
<size
, big_endian
>* object
,
9612 unsigned int data_shndx
,
9614 const unsigned char* prelocs
,
9616 Output_section
* output_section
,
9617 bool needs_special_offset_handling
,
9618 size_t local_symbol_count
,
9619 const unsigned char* plocal_symbols
)
9621 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9622 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9625 Powerpc_relobj
<size
, big_endian
>* ppc_object
9626 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9628 ppc_object
->set_opd_valid();
9629 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9631 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9632 for (p
= ppc_object
->access_from_map()->begin();
9633 p
!= ppc_object
->access_from_map()->end();
9636 Address dst_off
= p
->first
;
9637 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9638 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9639 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9641 Relobj
* src_obj
= s
->first
;
9642 unsigned int src_indx
= s
->second
;
9643 symtab
->gc()->add_reference(src_obj
, src_indx
,
9644 ppc_object
, dst_indx
);
9648 ppc_object
->access_from_map()->clear();
9649 ppc_object
->process_gc_mark(symtab
);
9650 // Don't look at .opd relocs as .opd will reference everything.
9654 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9663 needs_special_offset_handling
,
9668 // Handle target specific gc actions when adding a gc reference from
9669 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9670 // and DST_OFF. For powerpc64, this adds a referenc to the code
9671 // section of a function descriptor.
9673 template<int size
, bool big_endian
>
9675 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9676 Symbol_table
* symtab
,
9678 unsigned int src_shndx
,
9680 unsigned int dst_shndx
,
9681 Address dst_off
) const
9683 if (size
!= 64 || dst_obj
->is_dynamic())
9686 Powerpc_relobj
<size
, big_endian
>* ppc_object
9687 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9688 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9690 if (ppc_object
->opd_valid())
9692 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9693 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9697 // If we haven't run scan_opd_relocs, we must delay
9698 // processing this function descriptor reference.
9699 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9704 // Add any special sections for this symbol to the gc work list.
9705 // For powerpc64, this adds the code section of a function
9708 template<int size
, bool big_endian
>
9710 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9711 Symbol_table
* symtab
,
9714 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9716 Powerpc_relobj
<size
, big_endian
>* ppc_object
9717 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9719 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9720 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9722 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9723 Address dst_off
= gsym
->value();
9724 if (ppc_object
->opd_valid())
9726 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9727 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9731 ppc_object
->add_gc_mark(dst_off
);
9736 // For a symbol location in .opd, set LOC to the location of the
9739 template<int size
, bool big_endian
>
9741 Target_powerpc
<size
, big_endian
>::do_function_location(
9742 Symbol_location
* loc
) const
9744 if (size
== 64 && loc
->shndx
!= 0)
9746 if (loc
->object
->is_dynamic())
9748 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9749 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9750 if (loc
->shndx
== ppc_object
->opd_shndx())
9753 Address off
= loc
->offset
- ppc_object
->opd_address();
9754 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9755 loc
->offset
= dest_off
;
9760 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9761 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9762 if (loc
->shndx
== ppc_object
->opd_shndx())
9765 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9766 loc
->offset
= dest_off
;
9772 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9773 // compiled with -fsplit-stack. The function calls non-split-stack
9774 // code. Change the function to ensure it has enough stack space to
9775 // call some random function.
9777 template<int size
, bool big_endian
>
9779 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9782 section_offset_type fnoffset
,
9783 section_size_type fnsize
,
9784 const unsigned char* prelocs
,
9786 unsigned char* view
,
9787 section_size_type view_size
,
9789 std::string
* to
) const
9791 // 32-bit not supported.
9795 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9796 prelocs
, reloc_count
, view
, view_size
,
9801 // The function always starts with
9802 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9803 // addis %r12,%r1,-allocate@ha
9804 // addi %r12,%r12,-allocate@l
9806 // but note that the addis or addi may be replaced with a nop
9808 unsigned char *entry
= view
+ fnoffset
;
9809 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9811 if ((insn
& 0xffff0000) == addis_2_12
)
9813 /* Skip ELFv2 global entry code. */
9815 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9818 unsigned char *pinsn
= entry
;
9820 const uint32_t ld_private_ss
= 0xe80d8fc0;
9821 if (insn
== ld_private_ss
)
9823 int32_t allocate
= 0;
9827 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9828 if ((insn
& 0xffff0000) == addis_12_1
)
9829 allocate
+= (insn
& 0xffff) << 16;
9830 else if ((insn
& 0xffff0000) == addi_12_1
9831 || (insn
& 0xffff0000) == addi_12_12
)
9832 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9833 else if (insn
!= nop
)
9836 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9838 int extra
= parameters
->options().split_stack_adjust_size();
9840 if (allocate
>= 0 || extra
< 0)
9842 object
->error(_("split-stack stack size overflow at "
9843 "section %u offset %0zx"),
9844 shndx
, static_cast<size_t>(fnoffset
));
9848 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9849 if (insn
!= addis_12_1
)
9851 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9853 insn
= addi_12_12
| (allocate
& 0xffff);
9854 if (insn
!= addi_12_12
)
9856 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9862 insn
= addi_12_1
| (allocate
& 0xffff);
9863 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9866 if (pinsn
!= entry
+ 12)
9867 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9875 if (!object
->has_no_split_stack())
9876 object
->error(_("failed to match split-stack sequence at "
9877 "section %u offset %0zx"),
9878 shndx
, static_cast<size_t>(fnoffset
));
9882 // Scan relocations for a section.
9884 template<int size
, bool big_endian
>
9886 Target_powerpc
<size
, big_endian
>::scan_relocs(
9887 Symbol_table
* symtab
,
9889 Sized_relobj_file
<size
, big_endian
>* object
,
9890 unsigned int data_shndx
,
9891 unsigned int sh_type
,
9892 const unsigned char* prelocs
,
9894 Output_section
* output_section
,
9895 bool needs_special_offset_handling
,
9896 size_t local_symbol_count
,
9897 const unsigned char* plocal_symbols
)
9899 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9900 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9903 if (!this->plt_localentry0_init_
)
9905 bool plt_localentry0
= false;
9907 && this->abiversion() >= 2)
9909 if (parameters
->options().user_set_plt_localentry())
9910 plt_localentry0
= parameters
->options().plt_localentry();
9912 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9913 gold_warning(_("--plt-localentry is especially dangerous without "
9914 "ld.so support to detect ABI violations"));
9916 this->plt_localentry0_
= plt_localentry0
;
9917 this->plt_localentry0_init_
= true;
9920 if (sh_type
== elfcpp::SHT_REL
)
9922 gold_error(_("%s: unsupported REL reloc section"),
9923 object
->name().c_str());
9927 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9936 needs_special_offset_handling
,
9940 if (this->plt_localentry0_
&& this->power10_relocs_
)
9942 gold_warning(_("--plt-localentry is incompatible with "
9943 "power10 pc-relative code"));
9944 this->plt_localentry0_
= false;
9948 // Functor class for processing the global symbol table.
9949 // Removes symbols defined on discarded opd entries.
9951 template<bool big_endian
>
9952 class Global_symbol_visitor_opd
9955 Global_symbol_visitor_opd()
9959 operator()(Sized_symbol
<64>* sym
)
9961 if (sym
->has_symtab_index()
9962 || sym
->source() != Symbol::FROM_OBJECT
9963 || !sym
->in_real_elf())
9966 if (sym
->object()->is_dynamic())
9969 Powerpc_relobj
<64, big_endian
>* symobj
9970 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9971 if (symobj
->opd_shndx() == 0)
9975 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9976 if (shndx
== symobj
->opd_shndx()
9977 && symobj
->get_opd_discard(sym
->value()))
9979 sym
->set_undefined();
9980 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9981 sym
->set_is_defined_in_discarded_section();
9982 sym
->set_symtab_index(-1U);
9987 template<int size
, bool big_endian
>
9989 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9991 Symbol_table
* symtab
)
9995 Output_data_save_res
<size
, big_endian
>* savres
9996 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9997 this->savres_section_
= savres
;
9998 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9999 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
10000 savres
, ORDER_TEXT
, false);
10004 // Sort linker created .got section first (for the header), then input
10005 // sections belonging to files using small model code.
10007 template<bool big_endian
>
10008 class Sort_toc_sections
10010 const Output_section_data
*
10011 small_got_section() const
10013 return (static_cast<Target_powerpc
<64, big_endian
>*>(
10014 parameters
->sized_target
<64, big_endian
>())
10015 ->got_section(GOT_TYPE_SMALL
));
10019 rank(const Output_section::Input_section
& isec
) const
10021 if (!isec
.is_input_section())
10023 if (isec
.output_section_data() == this->small_got_section())
10027 if (static_cast<const Powerpc_relobj
<64, big_endian
>*>(isec
.relobj())
10028 ->has_small_toc_reloc())
10035 operator()(const Output_section::Input_section
& is1
,
10036 const Output_section::Input_section
& is2
) const
10038 return rank(is1
) < rank(is2
);
10042 // Finalize the sections.
10044 template<int size
, bool big_endian
>
10046 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
10048 const Input_objects
* input_objects
,
10049 Symbol_table
* symtab
)
10051 if (parameters
->doing_static_link())
10053 // At least some versions of glibc elf-init.o have a strong
10054 // reference to __rela_iplt marker syms. A weak ref would be
10056 if (this->iplt_
!= NULL
)
10058 Reloc_section
* rel
= this->iplt_
->rel_plt();
10059 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
10060 Symbol_table::PREDEFINED
, rel
, 0, 0,
10061 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10062 elfcpp::STV_HIDDEN
, 0, false, true);
10063 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
10064 Symbol_table::PREDEFINED
, rel
, 0, 0,
10065 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10066 elfcpp::STV_HIDDEN
, 0, true, true);
10070 symtab
->define_as_constant("__rela_iplt_start", NULL
,
10071 Symbol_table::PREDEFINED
, 0, 0,
10072 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10073 elfcpp::STV_HIDDEN
, 0, true, false);
10074 symtab
->define_as_constant("__rela_iplt_end", NULL
,
10075 Symbol_table::PREDEFINED
, 0, 0,
10076 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10077 elfcpp::STV_HIDDEN
, 0, true, false);
10083 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
10084 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
10086 if (!parameters
->options().relocatable())
10088 this->define_save_restore_funcs(layout
, symtab
);
10090 // Annoyingly, we need to make these sections now whether or
10091 // not we need them. If we delay until do_relax then we
10092 // need to mess with the relaxation machinery checkpointing.
10093 this->got_section(symtab
, layout
, GOT_TYPE_STANDARD
);
10094 this->make_brlt_section(layout
);
10096 // FIXME, maybe. Here we could run through all the got
10097 // entries in the small got section, removing any duplicates
10098 // found in the big got section and renumbering offsets.
10100 if (parameters
->options().toc_sort())
10102 Output_section
* os
= this->got_
->output_section();
10103 if (os
!= NULL
&& os
->input_sections().size() > 1)
10104 std::stable_sort(os
->input_sections().begin(),
10105 os
->input_sections().end(),
10106 Sort_toc_sections
<big_endian
>());
10111 // Fill in some more dynamic tags.
10112 Output_data_dynamic
* odyn
= layout
->dynamic_data();
10115 const Reloc_section
* rel_plt
= (this->plt_
== NULL
10117 : this->plt_
->rel_plt());
10118 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
10119 this->rela_dyn_
, true, size
== 32, true);
10123 if (this->got_
!= NULL
)
10125 this->got_
->finalize_data_size();
10126 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
10127 this->got_
, this->got_
->g_o_t());
10129 if (this->has_tls_get_addr_opt_
)
10130 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
10134 if (this->glink_
!= NULL
)
10136 this->glink_
->finalize_data_size();
10137 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
10139 (this->glink_
->pltresolve_size()
10142 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
10143 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
10144 ((this->has_localentry0_
10145 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
10146 | (this->has_tls_get_addr_opt_
10147 ? elfcpp::PPC64_OPT_TLS
: 0)));
10151 // Emit any relocs we saved in an attempt to avoid generating COPY
10153 if (this->copy_relocs_
.any_saved_relocs())
10154 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
10156 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
10157 p
!= input_objects
->relobj_end();
10160 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
10161 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
10162 if (ppc_relobj
->attributes_section_data())
10163 this->merge_object_attributes(ppc_relobj
,
10164 ppc_relobj
->attributes_section_data());
10166 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
10167 p
!= input_objects
->dynobj_end();
10170 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
10171 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
10172 if (ppc_dynobj
->attributes_section_data())
10173 this->merge_object_attributes(ppc_dynobj
,
10174 ppc_dynobj
->attributes_section_data());
10177 // Create a .gnu.attributes section if we have merged any attributes
10179 if (this->attributes_section_data_
!= NULL
10180 && this->attributes_section_data_
->size() != 0)
10182 Output_attributes_section_data
* attributes_section
10183 = new Output_attributes_section_data(*this->attributes_section_data_
);
10184 layout
->add_output_section_data(".gnu.attributes",
10185 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
10186 attributes_section
, ORDER_INVALID
, false);
10190 // Get the custom dynamic tag value.
10192 template<int size
, bool big_endian
>
10194 Target_powerpc
<size
, big_endian
>::do_dynamic_tag_custom_value(
10195 elfcpp::DT tag
) const
10197 if (tag
!= elfcpp::DT_RELACOUNT
)
10198 gold_unreachable();
10199 return this->rela_dyn_
->relative_reloc_count();
10202 // Merge object attributes from input file called NAME with those of the
10203 // output. The input object attributes are in the object pointed by PASD.
10205 template<int size
, bool big_endian
>
10207 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
10209 const Attributes_section_data
* pasd
)
10211 // Return if there is no attributes section data.
10215 // Create output object attributes.
10216 if (this->attributes_section_data_
== NULL
)
10217 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
10219 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
10220 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
10221 Object_attribute
* out_attr
10222 = this->attributes_section_data_
->known_attributes(vendor
);
10224 const char* name
= obj
->name().c_str();
10227 const char* second
;
10228 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
10229 int in_fp
= in_attr
[tag
].int_value() & 0xf;
10230 int out_fp
= out_attr
[tag
].int_value() & 0xf;
10231 bool warn_only
= obj
->is_dynamic();
10232 if (in_fp
!= out_fp
)
10235 if ((in_fp
& 3) == 0)
10237 else if ((out_fp
& 3) == 0)
10241 out_fp
|= in_fp
& 3;
10242 out_attr
[tag
].set_int_value(out_fp
);
10243 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10244 this->last_fp_
= name
;
10247 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
10249 err
= N_("%s uses hard float, %s uses soft float");
10250 first
= this->last_fp_
;
10253 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10255 err
= N_("%s uses hard float, %s uses soft float");
10257 second
= this->last_fp_
;
10259 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10261 err
= N_("%s uses double-precision hard float, "
10262 "%s uses single-precision hard float");
10263 first
= this->last_fp_
;
10266 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10268 err
= N_("%s uses double-precision hard float, "
10269 "%s uses single-precision hard float");
10271 second
= this->last_fp_
;
10274 if (err
|| (in_fp
& 0xc) == 0)
10276 else if ((out_fp
& 0xc) == 0)
10280 out_fp
|= in_fp
& 0xc;
10281 out_attr
[tag
].set_int_value(out_fp
);
10282 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10283 this->last_ld_
= name
;
10286 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10288 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10290 second
= this->last_ld_
;
10292 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10294 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10295 first
= this->last_ld_
;
10298 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10300 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10301 first
= this->last_ld_
;
10304 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10306 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10308 second
= this->last_ld_
;
10313 if (parameters
->options().warn_mismatch())
10316 gold_warning(_(err
), first
, second
);
10318 gold_error(_(err
), first
, second
);
10320 // Arrange for this attribute to be deleted. It's better to
10321 // say "don't know" about a file than to wrongly claim compliance.
10323 out_attr
[tag
].set_type(0);
10329 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10330 int in_vec
= in_attr
[tag
].int_value() & 3;
10331 int out_vec
= out_attr
[tag
].int_value() & 3;
10332 if (in_vec
!= out_vec
)
10337 else if (out_vec
== 0)
10340 out_attr
[tag
].set_int_value(out_vec
);
10341 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10342 this->last_vec_
= name
;
10344 // For now, allow generic to transition to AltiVec or SPE
10345 // without a warning. If GCC marked files with their stack
10346 // alignment and used don't-care markings for files which are
10347 // not affected by the vector ABI, we could warn about this
10349 else if (in_vec
== 1)
10351 else if (out_vec
== 1)
10354 out_attr
[tag
].set_int_value(out_vec
);
10355 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10356 this->last_vec_
= name
;
10358 else if (out_vec
< in_vec
)
10360 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10361 first
= this->last_vec_
;
10364 else if (out_vec
> in_vec
)
10366 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10368 second
= this->last_vec_
;
10372 if (parameters
->options().warn_mismatch())
10373 gold_error(_(err
), first
, second
);
10374 out_attr
[tag
].set_type(0);
10378 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10379 int in_struct
= in_attr
[tag
].int_value() & 3;
10380 int out_struct
= out_attr
[tag
].int_value() & 3;
10381 if (in_struct
!= out_struct
)
10384 if (in_struct
== 0 || in_struct
== 3)
10386 else if (out_struct
== 0)
10388 out_struct
= in_struct
;
10389 out_attr
[tag
].set_int_value(out_struct
);
10390 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10391 this->last_struct_
= name
;
10393 else if (out_struct
< in_struct
)
10395 err
= N_("%s uses r3/r4 for small structure returns, "
10397 first
= this->last_struct_
;
10400 else if (out_struct
> in_struct
)
10402 err
= N_("%s uses r3/r4 for small structure returns, "
10405 second
= this->last_struct_
;
10409 if (parameters
->options().warn_mismatch())
10410 gold_error(_(err
), first
, second
);
10411 out_attr
[tag
].set_type(0);
10416 // Merge Tag_compatibility attributes and any common GNU ones.
10417 this->attributes_section_data_
->merge(name
, pasd
);
10420 // Emit any saved relocs, and mark toc entries using any of these
10421 // relocs as not optimizable.
10423 template<int sh_type
, int size
, bool big_endian
>
10425 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10426 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10429 && parameters
->options().toc_optimize())
10431 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10432 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10433 p
!= this->entries_
.end();
10436 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10439 // If the symbol is no longer defined in a dynamic object,
10440 // then we emitted a COPY relocation. If it is still
10441 // dynamic then we'll need dynamic relocations and thus
10442 // can't optimize toc entries.
10443 if (entry
.sym_
->is_from_dynobj())
10445 Powerpc_relobj
<size
, big_endian
>* ppc_object
10446 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10447 if (entry
.shndx_
== ppc_object
->toc_shndx())
10448 ppc_object
->set_no_toc_opt(entry
.address_
);
10453 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10456 // Return the value to use for a branch relocation.
10458 template<int size
, bool big_endian
>
10460 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10461 const Symbol_table
* symtab
,
10462 const Sized_symbol
<size
>* gsym
,
10463 Powerpc_relobj
<size
, big_endian
>* object
,
10465 unsigned int *dest_shndx
)
10467 if (size
== 32 || this->abiversion() >= 2)
10468 gold_unreachable();
10471 // If the symbol is defined in an opd section, ie. is a function
10472 // descriptor, use the function descriptor code entry address
10473 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10475 && (gsym
->source() != Symbol::FROM_OBJECT
10476 || gsym
->object()->is_dynamic()))
10479 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10480 unsigned int shndx
= symobj
->opd_shndx();
10483 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10484 if (opd_addr
== invalid_address
)
10486 opd_addr
+= symobj
->output_section_address(shndx
);
10487 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10490 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10491 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10494 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10495 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10496 *dest_shndx
= folded
.second
;
10498 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10499 if (sec_addr
== invalid_address
)
10502 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10503 *value
= sec_addr
+ sec_off
;
10510 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10512 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10515 if (gsym
->is_from_dynobj()
10516 || gsym
->is_undefined()
10517 || gsym
->is_preemptible())
10520 if (gsym
->is_absolute())
10521 return !parameters
->options().output_is_position_independent();
10528 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10530 if (psymval
->is_ifunc_symbol())
10534 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10536 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10539 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10540 // pld ra,symbol@got@pcrel
10541 // load/store rt,0(ra)
10543 // pla ra,symbol@pcrel
10544 // load/store rt,0(ra)
10545 // may be translated to
10546 // pload/pstore rt,symbol@pcrel
10548 // This function returns true if the optimization is possible, placing
10549 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10551 // On entry to this function, the linker has already determined that
10552 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10553 // while *PINSN2 is the second instruction.
10556 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10558 uint32_t insn2
= *pinsn2
>> 32;
10561 // Check that regs match.
10562 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10565 switch ((insn2
>> 26) & 63)
10581 // These are the PMLS cases, where we just need to tack a prefix
10582 // on the insn. Check that the D field is zero.
10583 if ((insn2
& 0xffff) != 0)
10585 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10586 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10589 case 58: // lwa, ld
10590 if ((insn2
& 0xfffd) != 0)
10592 i1new
= ((1ULL << 58) | (1ULL << 52)
10593 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10594 | (insn2
& (31ULL << 21)));
10597 case 57: // lxsd, lxssp
10598 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10600 i1new
= ((1ULL << 58) | (1ULL << 52)
10601 | ((40ULL | (insn2
& 3)) << 26)
10602 | (insn2
& (31ULL << 21)));
10605 case 61: // stxsd, stxssp, lxv, stxv
10606 if ((insn2
& 3) == 0)
10608 else if ((insn2
& 3) >= 2)
10610 if ((insn2
& 0xfffc) != 0)
10612 i1new
= ((1ULL << 58) | (1ULL << 52)
10613 | ((44ULL | (insn2
& 3)) << 26)
10614 | (insn2
& (31ULL << 21)));
10618 if ((insn2
& 0xfff0) != 0)
10620 i1new
= ((1ULL << 58) | (1ULL << 52)
10621 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10622 | (insn2
& (31ULL << 21)));
10627 if ((insn2
& 0xffff) != 0)
10629 i1new
= ((1ULL << 58) | (1ULL << 52)
10630 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10633 case 62: // std, stq
10634 if ((insn2
& 0xfffd) != 0)
10636 i1new
= ((1ULL << 58) | (1ULL << 52)
10637 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10638 | (insn2
& (31ULL << 21)));
10643 *pinsn2
= (uint64_t) nop
<< 32;
10647 // Perform a relocation.
10649 template<int size
, bool big_endian
>
10651 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10652 const Relocate_info
<size
, big_endian
>* relinfo
,
10654 Target_powerpc
* target
,
10655 Output_section
* os
,
10657 const unsigned char* preloc
,
10658 const Sized_symbol
<size
>* gsym
,
10659 const Symbol_value
<size
>* psymval
,
10660 unsigned char* view
,
10662 section_size_type view_size
)
10664 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10665 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10666 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10671 if (target
->replace_tls_get_addr(gsym
))
10672 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10674 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10675 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10676 Powerpc_relobj
<size
, big_endian
>* const object
10677 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10678 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10680 case Track_tls::NOT_EXPECTED
:
10681 // No warning. This will result in really old code without tls
10682 // marker relocs being mis-optimised, but there shouldn't be too
10683 // much of that code around. The problem with warning is that
10684 // glibc and libphobos both construct direct calls to
10685 // __tls_get_addr in a way that is harmless.
10687 case Track_tls::EXPECTED
:
10688 // We have already complained.
10690 case Track_tls::SKIP
:
10691 if (is_plt16_reloc
<size
>(r_type
)
10692 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10693 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10695 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10696 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10698 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10700 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10701 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10703 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10704 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10706 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10707 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10708 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10711 case Track_tls::NORMAL
:
10715 // Offset from start of insn to d-field reloc.
10716 const int d_offset
= big_endian
? 2 : 0;
10719 bool has_stub_value
= false;
10720 bool localentry0
= false;
10721 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10722 bool pltcall_to_direct
= false;
10724 if (is_plt16_reloc
<size
>(r_type
)
10725 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10726 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10727 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10728 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
10729 || r_type
== elfcpp::R_POWERPC_PLTCALL
10730 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10732 // It would be possible to replace inline plt calls with direct
10733 // calls if the PLTCALL is in range. The only difficulty is
10734 // that the decision depends on the PLTCALL reloc, and we don't
10735 // know the address of that instruction when processing others
10736 // in the sequence. So the decision needs to be made in
10738 pltcall_to_direct
= !(gsym
!= NULL
10739 ? gsym
->has_plt_offset()
10740 : object
->local_has_plt_offset(r_sym
));
10742 else if ((gsym
!= NULL
10743 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10744 : psymval
->is_ifunc_symbol() && object
->local_has_plt_offset(r_sym
))
10745 && !is_got_reloc(r_type
)
10746 && (!psymval
->is_ifunc_symbol()
10747 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
,
10752 && target
->abiversion() >= 2
10753 && !parameters
->options().output_is_position_independent()
10754 && !is_branch_reloc
<size
>(r_type
))
10756 Address off
= target
->glink_section()->find_global_entry(gsym
);
10757 if (off
!= invalid_address
)
10759 value
= target
->glink_section()->global_entry_address() + off
;
10760 has_stub_value
= true;
10765 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10766 if (target
->stub_tables().size() == 1)
10767 stub_table
= target
->stub_tables()[0];
10768 if (stub_table
== NULL
10771 && !parameters
->options().output_is_position_independent()
10772 && !is_branch_reloc
<size
>(r_type
)))
10773 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10774 if (stub_table
== NULL
)
10776 // This is a ref from a data section to an ifunc symbol,
10777 // or a non-branch reloc for which we always want to use
10778 // one set of stubs for resolving function addresses.
10779 if (target
->stub_tables().size() != 0)
10780 stub_table
= target
->stub_tables()[0];
10782 if (stub_table
!= NULL
)
10784 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10786 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10787 rela
.get_r_addend());
10789 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10790 rela
.get_r_addend());
10793 value
= stub_table
->stub_address() + ent
->off_
;
10794 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10795 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10796 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10799 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10802 value
+= ent
->p9off_
;
10804 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10805 value
+= ent
->p9off_
;
10807 value
+= ent
->tocoff_
;
10812 && target
->is_tls_get_addr_opt(gsym
)))
10814 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
10815 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10817 if (!(target
->power10_stubs()
10818 && target
->power10_stubs_auto()))
10821 else if (relnum
< reloc_count
- 1)
10823 Reltype
next_rela(preloc
+ reloc_size
);
10824 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10825 == elfcpp::R_PPC64_TOCSAVE
10826 && (next_rela
.get_r_offset()
10827 == rela
.get_r_offset() + 4))
10831 localentry0
= ent
->localentry0_
;
10832 has_stub_value
= true;
10836 // We don't care too much about bogus debug references to
10837 // non-local functions, but otherwise there had better be a plt
10838 // call stub or global entry stub as appropriate.
10839 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10842 if (!pltcall_to_direct
&& (is_plt16_reloc
<size
>(r_type
)
10843 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10844 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10846 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10848 value
= target
->plt_off(gsym
, &plt
);
10850 value
= target
->plt_off(object
, r_sym
, &plt
);
10851 value
+= plt
->address();
10855 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10856 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10857 value
-= target
->toc_pointer();
10859 else if (parameters
->options().output_is_position_independent())
10861 if (rela
.get_r_addend() >= 32768)
10863 unsigned int got2
= object
->got2_shndx();
10864 value
-= (object
->get_output_section_offset(got2
)
10865 + object
->output_section(got2
)->address()
10866 + rela
.get_r_addend());
10869 value
-= target
->toc_pointer();
10872 else if (pltcall_to_direct
10873 && (is_plt16_reloc
<size
>(r_type
)
10874 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10875 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10877 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10878 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10879 r_type
= elfcpp::R_POWERPC_NONE
;
10881 else if (pltcall_to_direct
10882 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10883 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10885 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10886 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10887 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10888 r_type
= elfcpp::R_POWERPC_NONE
;
10890 else if (is_got_reloc(r_type
))
10892 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10893 Got_type got_type
= ((size
== 32
10894 || r_type
== elfcpp::R_POWERPC_GOT16
10895 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
10896 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10898 value
= gsym
->got_offset(got_type
, addend
);
10900 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10901 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10902 value
+= target
->got_section(got_type
)->address();
10904 value
-= target
->got_base_offset(got_type
);
10906 else if (r_type
== elfcpp::R_PPC64_TOC
)
10908 value
= target
->toc_pointer();
10910 else if (gsym
!= NULL
10911 && (r_type
== elfcpp::R_POWERPC_REL24
10912 || r_type
== elfcpp::R_PPC_PLTREL24
)
10917 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10918 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10919 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10920 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10922 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10923 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10924 if ((insn
& 1) != 0
10926 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10928 elfcpp::Swap
<32, big_endian
>::
10929 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10930 can_plt_call
= true;
10935 // If we don't have a branch and link followed by a nop,
10936 // we can't go via the plt because there is no place to
10937 // put a toc restoring instruction.
10938 // Unless we know we won't be returning.
10939 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10940 can_plt_call
= true;
10944 // g++ as of 20130507 emits self-calls without a
10945 // following nop. This is arguably wrong since we have
10946 // conflicting information. On the one hand a global
10947 // symbol and on the other a local call sequence, but
10948 // don't error for this special case.
10949 // It isn't possible to cheaply verify we have exactly
10950 // such a call. Allow all calls to the same section.
10952 Address code
= value
;
10953 if (gsym
->source() == Symbol::FROM_OBJECT
10954 && gsym
->object() == object
)
10956 unsigned int dest_shndx
= 0;
10957 if (target
->abiversion() < 2)
10959 Address addend
= rela
.get_r_addend();
10960 code
= psymval
->value(object
, addend
);
10961 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10962 &code
, &dest_shndx
);
10965 if (dest_shndx
== 0)
10966 dest_shndx
= gsym
->shndx(&is_ordinary
);
10967 ok
= dest_shndx
== relinfo
->data_shndx
;
10971 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10972 _("call lacks nop, can't restore toc; "
10973 "recompile with -fPIC"));
10979 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10980 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10981 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10982 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10983 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10985 // First instruction of a global dynamic sequence, arg setup insn.
10986 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10987 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10988 Got_type got_type
= ((size
== 32
10989 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
10990 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10991 if (tls_type
== tls::TLSOPT_NONE
)
10992 got_type
= Got_type(got_type
| GOT_TYPE_TLSGD
);
10993 else if (tls_type
== tls::TLSOPT_TO_IE
)
10994 got_type
= Got_type(got_type
| GOT_TYPE_TPREL
);
10995 if ((got_type
& ~GOT_TYPE_SMALL
) != GOT_TYPE_STANDARD
)
10997 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10999 value
= gsym
->got_offset(got_type
, addend
);
11001 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11002 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11003 value
+= target
->got_section(got_type
)->address();
11005 value
-= target
->got_base_offset(got_type
);
11007 if (tls_type
== tls::TLSOPT_TO_IE
)
11009 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11011 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11012 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11014 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11016 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
11017 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11018 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11019 pinsn
& 0xffffffff);
11020 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
11024 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11025 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11027 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11028 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11029 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
11031 insn
|= 32 << 26; // lwz
11033 insn
|= 58 << 26; // ld
11034 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11036 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11037 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11040 else if (tls_type
== tls::TLSOPT_TO_LE
)
11042 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11044 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11045 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11047 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11048 // pla pcrel -> paddi r13
11049 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11050 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11051 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11052 pinsn
& 0xffffffff);
11053 r_type
= elfcpp::R_PPC64_TPREL34
;
11054 value
= psymval
->value(object
, rela
.get_r_addend());
11058 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11059 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11061 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11062 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11063 insn
&= (1 << 26) - (1 << 21); // extract rt
11067 insn
|= addis_0_13
;
11068 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11069 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11070 value
= psymval
->value(object
, rela
.get_r_addend());
11074 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11076 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11077 r_type
= elfcpp::R_POWERPC_NONE
;
11082 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11083 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11084 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11085 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
11086 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11088 // First instruction of a local dynamic sequence, arg setup insn.
11089 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11090 if (tls_type
== tls::TLSOPT_NONE
)
11092 value
= target
->tlsld_got_offset();
11093 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11094 value
+= target
->got_section(GOT_TYPE_SMALL
)->address();
11096 value
-= target
->got_base_offset(GOT_TYPE_SMALL
);
11100 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11101 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11103 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11104 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11106 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11107 // pla pcrel -> paddi r13
11108 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11109 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11110 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11111 pinsn
& 0xffffffff);
11112 r_type
= elfcpp::R_PPC64_TPREL34
;
11113 value
= dtp_offset
;
11115 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11116 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11118 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11119 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11120 insn
&= (1 << 26) - (1 << 21); // extract rt
11124 insn
|= addis_0_13
;
11125 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11126 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11127 value
= dtp_offset
;
11131 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11133 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11134 r_type
= elfcpp::R_POWERPC_NONE
;
11138 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
11139 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
11140 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
11141 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
11142 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11144 // Accesses relative to a local dynamic sequence address,
11145 // no optimisation here.
11146 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11147 Got_type got_type
= ((size
== 32
11148 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
11149 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
11151 value
= gsym
->got_offset(got_type
, addend
);
11153 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11154 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11155 value
+= target
->got_section(got_type
)->address();
11157 value
-= target
->got_base_offset(got_type
);
11159 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11160 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11161 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11162 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
11163 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11165 // First instruction of initial exec sequence.
11166 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11167 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11168 if (tls_type
== tls::TLSOPT_NONE
)
11170 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11171 Got_type got_type
= ((size
== 32
11172 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
11173 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
11175 value
= gsym
->got_offset(got_type
, addend
);
11177 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11178 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11179 value
+= target
->got_section(got_type
)->address();
11181 value
-= target
->got_base_offset(got_type
);
11185 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11186 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11188 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11189 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11191 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11192 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
11193 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
11194 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
11195 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11196 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11197 pinsn
& 0xffffffff);
11198 r_type
= elfcpp::R_PPC64_TPREL34
;
11199 value
= psymval
->value(object
, rela
.get_r_addend());
11201 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11202 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11204 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11205 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11206 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
11210 insn
|= addis_0_13
;
11211 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11212 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11213 value
= psymval
->value(object
, rela
.get_r_addend());
11217 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11219 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11220 r_type
= elfcpp::R_POWERPC_NONE
;
11224 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11225 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11227 // Second instruction of a global dynamic sequence,
11228 // the __tls_get_addr call
11229 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11230 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11231 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
11232 if (tls_type
!= tls::TLSOPT_NONE
)
11234 if (tls_type
== tls::TLSOPT_TO_IE
)
11236 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11237 Insn insn
= add_3_3_13
;
11240 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11241 r_type
= elfcpp::R_POWERPC_NONE
;
11245 bool is_pcrel
= false;
11246 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11247 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11248 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11249 if (relnum
< reloc_count
- 1)
11251 Reltype
next_rela(preloc
+ reloc_size
);
11252 unsigned int r_type2
11253 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11254 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11255 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11256 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11257 && next_rela
.get_r_offset() == rela
.get_r_offset())
11260 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11263 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11264 r_type
= elfcpp::R_POWERPC_NONE
;
11268 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11269 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11271 value
= psymval
->value(object
, rela
.get_r_addend());
11274 this->skip_next_tls_get_addr_call();
11277 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11278 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11280 // Second instruction of a local dynamic sequence,
11281 // the __tls_get_addr call
11282 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11283 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11284 if (tls_type
== tls::TLSOPT_TO_LE
)
11286 bool is_pcrel
= false;
11287 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11288 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11289 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11290 if (relnum
< reloc_count
- 1)
11292 Reltype
next_rela(preloc
+ reloc_size
);
11293 unsigned int r_type2
11294 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11295 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11296 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11297 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11298 && next_rela
.get_r_offset() == rela
.get_r_offset())
11301 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11304 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11305 r_type
= elfcpp::R_POWERPC_NONE
;
11309 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11310 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11312 value
= dtp_offset
;
11314 this->skip_next_tls_get_addr_call();
11317 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11319 // Second instruction of an initial exec sequence
11320 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11321 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11322 if (tls_type
== tls::TLSOPT_TO_LE
)
11324 Address roff
= rela
.get_r_offset() & 3;
11325 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11326 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11327 unsigned int reg
= size
== 32 ? 2 : 13;
11328 insn
= at_tls_transform(insn
, reg
);
11329 gold_assert(insn
!= 0);
11332 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11333 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11335 value
= psymval
->value(object
, rela
.get_r_addend());
11337 else if (roff
== 1)
11339 // For pcrel IE to LE we already have the full offset
11340 // and thus don't need an addi here. A nop or mr will do.
11341 if ((insn
& (0x3f << 26)) == 14 << 26)
11343 // Extract regs from addi rt,ra,si.
11344 unsigned int rt
= (insn
>> 21) & 0x1f;
11345 unsigned int ra
= (insn
>> 16) & 0x1f;
11350 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11351 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11352 insn
|= (31u << 26) | (444u << 1);
11355 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11356 r_type
= elfcpp::R_POWERPC_NONE
;
11360 else if (!has_stub_value
)
11362 if (pltcall_to_direct
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11363 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11365 // PLTCALL without plt entry => convert to direct call
11366 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11367 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11368 insn
= (insn
& 1) | b
;
11369 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11371 r_type
= elfcpp::R_PPC_PLTREL24
;
11372 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11373 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11375 r_type
= elfcpp::R_POWERPC_REL24
;
11377 Address addend
= 0;
11379 && (r_type
== elfcpp::R_PPC_PLTREL24
11380 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11381 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11382 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11383 addend
= rela
.get_r_addend();
11384 value
= psymval
->value(object
, addend
);
11385 unsigned int local_ent
= 0;
11386 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11388 if (target
->abiversion() >= 2)
11391 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11393 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11397 unsigned int dest_shndx
;
11398 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11399 &value
, &dest_shndx
);
11402 Address max_branch
= max_branch_delta
<size
>(r_type
);
11403 if (max_branch
!= 0
11404 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11406 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
11407 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11409 ? object
->ppc64_needs_toc(gsym
)
11410 : object
->ppc64_needs_toc(r_sym
)))))
11412 Stub_table
<size
, big_endian
>* stub_table
11413 = object
->stub_table(relinfo
->data_shndx
);
11414 if (stub_table
!= NULL
)
11416 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11417 = stub_table
->find_long_branch_entry(value
);
11420 if (ent
->save_res_
)
11421 value
= (value
- target
->savres_section()->address()
11422 + stub_table
->stub_address()
11423 + stub_table
->plt_size()
11424 + stub_table
->branch_size());
11427 value
= (stub_table
->stub_address()
11428 + stub_table
->plt_size()
11432 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11435 value
+= ent
->p9off_
;
11437 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
11438 value
+= ent
->p9off_
;
11440 value
+= ent
->tocoff_
;
11443 has_stub_value
= true;
11447 if (!has_stub_value
)
11448 value
+= local_ent
;
11453 case elfcpp::R_PPC64_REL24_NOTOC
:
11457 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11458 case elfcpp::R_PPC64_REL64
:
11459 case elfcpp::R_POWERPC_REL32
:
11460 case elfcpp::R_POWERPC_REL24
:
11461 case elfcpp::R_PPC_PLTREL24
:
11462 case elfcpp::R_PPC_LOCAL24PC
:
11463 case elfcpp::R_POWERPC_REL16
:
11464 case elfcpp::R_POWERPC_REL16_LO
:
11465 case elfcpp::R_POWERPC_REL16_HI
:
11466 case elfcpp::R_POWERPC_REL16_HA
:
11467 case elfcpp::R_POWERPC_REL16DX_HA
:
11468 case elfcpp::R_PPC64_REL16_HIGH
:
11469 case elfcpp::R_PPC64_REL16_HIGHA
:
11470 case elfcpp::R_PPC64_REL16_HIGHER
:
11471 case elfcpp::R_PPC64_REL16_HIGHERA
:
11472 case elfcpp::R_PPC64_REL16_HIGHEST
:
11473 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11474 case elfcpp::R_POWERPC_REL14
:
11475 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11476 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11477 case elfcpp::R_PPC64_PCREL34
:
11478 case elfcpp::R_PPC64_GOT_PCREL34
:
11479 case elfcpp::R_PPC64_PLT_PCREL34
:
11480 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11481 case elfcpp::R_PPC64_PCREL28
:
11482 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11483 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11484 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11485 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11486 case elfcpp::R_PPC64_REL16_HIGHER34
:
11487 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11488 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11489 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11493 case elfcpp::R_PPC64_TOC16
:
11494 case elfcpp::R_PPC64_TOC16_LO
:
11495 case elfcpp::R_PPC64_TOC16_HI
:
11496 case elfcpp::R_PPC64_TOC16_HA
:
11497 case elfcpp::R_PPC64_TOC16_DS
:
11498 case elfcpp::R_PPC64_TOC16_LO_DS
:
11499 // Subtract the TOC base address.
11500 value
-= target
->toc_pointer();
11503 case elfcpp::R_POWERPC_SECTOFF
:
11504 case elfcpp::R_POWERPC_SECTOFF_LO
:
11505 case elfcpp::R_POWERPC_SECTOFF_HI
:
11506 case elfcpp::R_POWERPC_SECTOFF_HA
:
11507 case elfcpp::R_PPC64_SECTOFF_DS
:
11508 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11510 value
-= os
->address();
11513 case elfcpp::R_PPC64_TPREL16_DS
:
11514 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11515 case elfcpp::R_PPC64_TPREL16_HIGH
:
11516 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11518 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11521 case elfcpp::R_POWERPC_TPREL16
:
11522 case elfcpp::R_POWERPC_TPREL16_LO
:
11523 case elfcpp::R_POWERPC_TPREL16_HI
:
11524 case elfcpp::R_POWERPC_TPREL16_HA
:
11525 case elfcpp::R_POWERPC_TPREL
:
11526 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11527 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11528 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11529 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11530 case elfcpp::R_PPC64_TPREL34
:
11531 // tls symbol values are relative to tls_segment()->vaddr()
11532 value
-= tp_offset
;
11535 case elfcpp::R_PPC64_DTPREL16_DS
:
11536 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11537 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11538 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11539 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11540 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11542 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11543 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11546 case elfcpp::R_POWERPC_DTPREL16
:
11547 case elfcpp::R_POWERPC_DTPREL16_LO
:
11548 case elfcpp::R_POWERPC_DTPREL16_HI
:
11549 case elfcpp::R_POWERPC_DTPREL16_HA
:
11550 case elfcpp::R_POWERPC_DTPREL
:
11551 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11552 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11553 case elfcpp::R_PPC64_DTPREL34
:
11554 // tls symbol values are relative to tls_segment()->vaddr()
11555 value
-= dtp_offset
;
11558 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11560 value
+= object
->ppc64_local_entry_offset(gsym
);
11562 value
+= object
->ppc64_local_entry_offset(r_sym
);
11569 Insn branch_bit
= 0;
11572 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11573 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11574 branch_bit
= 1 << 21;
11576 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11577 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11579 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11580 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11581 insn
&= ~(1 << 21);
11582 insn
|= branch_bit
;
11583 if (this->is_isa_v2
)
11585 // Set 'a' bit. This is 0b00010 in BO field for branch
11586 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11587 // for branch on CTR insns (BO == 1a00t or 1a01t).
11588 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11589 insn
|= 0x02 << 21;
11590 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11591 insn
|= 0x08 << 21;
11597 // Invert 'y' bit if not the default.
11598 if (static_cast<Signed_address
>(value
) < 0)
11601 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11605 case elfcpp::R_POWERPC_PLT16_HA
:
11607 && !parameters
->options().output_is_position_independent())
11609 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11610 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11612 // Convert addis to lis.
11613 if ((insn
& (0x3f << 26)) == 15u << 26
11614 && (insn
& (0x1f << 16)) != 0)
11616 insn
&= ~(0x1f << 16);
11617 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11627 ? relative_value_is_known(gsym
)
11628 : relative_value_is_known(psymval
))
11633 uint64_t pinsn
, pinsn2
;
11640 // Multi-instruction sequences that access the GOT/TOC can
11641 // be optimized, eg.
11642 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11643 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11645 // addis ra,r2,0; addi rb,ra,x@toc@l;
11646 // to nop; addi rb,r2,x@toc;
11647 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11648 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11649 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11650 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11651 case elfcpp::R_POWERPC_GOT16_HA
:
11652 case elfcpp::R_PPC64_TOC16_HA
:
11653 if (size
== 64 && parameters
->options().toc_optimize())
11655 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11656 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11657 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11658 && object
->make_toc_relative(target
, &value
))
11659 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11660 && object
->make_got_relative(target
, psymval
,
11661 rela
.get_r_addend(),
11664 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11665 == ((15u << 26) | (2 << 16)));
11667 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11668 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11669 && value
+ 0x8000 < 0x10000)
11671 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11677 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11678 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11679 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11680 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11681 case elfcpp::R_POWERPC_GOT16_LO
:
11682 case elfcpp::R_PPC64_GOT16_LO_DS
:
11683 case elfcpp::R_PPC64_TOC16_LO
:
11684 case elfcpp::R_PPC64_TOC16_LO_DS
:
11685 if (size
== 64 && parameters
->options().toc_optimize())
11687 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11688 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11689 bool changed
= false;
11690 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11691 && object
->make_toc_relative(target
, &value
))
11692 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11693 && object
->make_got_relative(target
, psymval
,
11694 rela
.get_r_addend(),
11697 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11698 insn
^= (14u << 26) ^ (58u << 26);
11699 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11702 if (ok_lo_toc_insn(insn
, r_type
)
11703 && value
+ 0x8000 < 0x10000)
11705 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11707 // Transform addic to addi when we change reg.
11708 insn
&= ~((0x3f << 26) | (0x1f << 16));
11709 insn
|= (14u << 26) | (2 << 16);
11713 insn
&= ~(0x1f << 16);
11719 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11723 case elfcpp::R_PPC64_GOT_PCREL34
:
11724 if (size
== 64 && parameters
->options().toc_optimize())
11726 iview
= reinterpret_cast<Insn
*>(view
);
11727 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11729 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11730 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11731 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11734 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11736 if (relval
+ (1ULL << 33) < 1ULL << 34)
11739 // Replace with paddi
11740 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11741 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11742 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11743 pinsn
& 0xffffffff);
11749 case elfcpp::R_PPC64_PCREL34
:
11752 iview
= reinterpret_cast<Insn
*>(view
);
11753 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11755 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11756 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11757 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11758 | (14ULL << 26) /* paddi */))
11762 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11763 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11764 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11765 if (relnum
>= reloc_count
- 1)
11768 Reltype
next_rela(preloc
+ reloc_size
);
11769 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11770 != elfcpp::R_PPC64_PCREL_OPT
)
11771 || next_rela
.get_r_offset() != rela
.get_r_offset())
11774 Address off
= next_rela
.get_r_addend();
11776 off
= 8; // zero means next insn.
11777 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11780 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11781 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11783 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11785 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11787 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11788 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11789 pinsn
& 0xffffffff);
11790 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11795 case elfcpp::R_POWERPC_TPREL16_HA
:
11796 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11798 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11799 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11804 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11806 // R_PPC_TLSGD, R_PPC_TLSLD
11809 case elfcpp::R_POWERPC_TPREL16_LO
:
11810 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11812 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11813 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11814 insn
&= ~(0x1f << 16);
11815 insn
|= (size
== 32 ? 2 : 13) << 16;
11816 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11820 case elfcpp::R_PPC64_ENTRY
:
11823 value
= target
->toc_pointer();
11824 if (value
+ 0x80008000 <= 0xffffffff
11825 && !parameters
->options().output_is_position_independent())
11827 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11828 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11829 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11831 if ((insn1
& ~0xfffc) == ld_2_12
11832 && insn2
== add_2_2_12
)
11834 insn1
= lis_2
+ ha(value
);
11835 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11836 insn2
= addi_2_2
+ l(value
);
11837 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11844 if (value
+ 0x80008000 <= 0xffffffff)
11846 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11847 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11848 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11850 if ((insn1
& ~0xfffc) == ld_2_12
11851 && insn2
== add_2_2_12
)
11853 insn1
= addis_2_12
+ ha(value
);
11854 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11855 insn2
= addi_2_2
+ l(value
);
11856 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11864 case elfcpp::R_POWERPC_REL16_LO
:
11865 // If we are generating a non-PIC executable, edit
11866 // 0: addis 2,12,.TOC.-0b@ha
11867 // addi 2,2,.TOC.-0b@l
11868 // used by ELFv2 global entry points to set up r2, to
11870 // addi 2,2,.TOC.@l
11871 // if .TOC. is in range. */
11873 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11876 && target
->abiversion() >= 2
11877 && !parameters
->options().output_is_position_independent()
11878 && rela
.get_r_addend() == d_offset
+ 4
11880 && strcmp(gsym
->name(), ".TOC.") == 0)
11882 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11883 Reltype
prev_rela(preloc
- reloc_size
);
11884 if ((prev_rela
.get_r_info()
11885 == elfcpp::elf_r_info
<size
>(r_sym
,
11886 elfcpp::R_POWERPC_REL16_HA
))
11887 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11888 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11890 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11891 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11892 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11894 if ((insn1
& 0xffff0000) == addis_2_12
11895 && (insn2
& 0xffff0000) == addi_2_2
)
11897 insn1
= lis_2
+ ha(value
+ address
- 4);
11898 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11899 insn2
= addi_2_2
+ l(value
+ address
- 4);
11900 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11903 relinfo
->rr
->set_strategy(relnum
- 1,
11904 Relocatable_relocs::RELOC_SPECIAL
);
11905 relinfo
->rr
->set_strategy(relnum
,
11906 Relocatable_relocs::RELOC_SPECIAL
);
11916 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11917 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11920 case elfcpp::R_POWERPC_ADDR32
:
11921 case elfcpp::R_POWERPC_UADDR32
:
11923 overflow
= Reloc::CHECK_BITFIELD
;
11926 case elfcpp::R_POWERPC_REL32
:
11927 case elfcpp::R_POWERPC_REL16DX_HA
:
11929 overflow
= Reloc::CHECK_SIGNED
;
11932 case elfcpp::R_POWERPC_UADDR16
:
11933 overflow
= Reloc::CHECK_BITFIELD
;
11936 case elfcpp::R_POWERPC_ADDR16
:
11937 // We really should have three separate relocations,
11938 // one for 16-bit data, one for insns with 16-bit signed fields,
11939 // and one for insns with 16-bit unsigned fields.
11940 overflow
= Reloc::CHECK_BITFIELD
;
11941 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11942 overflow
= Reloc::CHECK_LOW_INSN
;
11945 case elfcpp::R_POWERPC_ADDR16_HI
:
11946 case elfcpp::R_POWERPC_ADDR16_HA
:
11947 case elfcpp::R_POWERPC_GOT16_HI
:
11948 case elfcpp::R_POWERPC_GOT16_HA
:
11949 case elfcpp::R_POWERPC_PLT16_HI
:
11950 case elfcpp::R_POWERPC_PLT16_HA
:
11951 case elfcpp::R_POWERPC_SECTOFF_HI
:
11952 case elfcpp::R_POWERPC_SECTOFF_HA
:
11953 case elfcpp::R_PPC64_TOC16_HI
:
11954 case elfcpp::R_PPC64_TOC16_HA
:
11955 case elfcpp::R_PPC64_PLTGOT16_HI
:
11956 case elfcpp::R_PPC64_PLTGOT16_HA
:
11957 case elfcpp::R_POWERPC_TPREL16_HI
:
11958 case elfcpp::R_POWERPC_TPREL16_HA
:
11959 case elfcpp::R_POWERPC_DTPREL16_HI
:
11960 case elfcpp::R_POWERPC_DTPREL16_HA
:
11961 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11962 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11963 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11964 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11965 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11966 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11967 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11968 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11969 case elfcpp::R_POWERPC_REL16_HI
:
11970 case elfcpp::R_POWERPC_REL16_HA
:
11972 overflow
= Reloc::CHECK_HIGH_INSN
;
11975 case elfcpp::R_POWERPC_REL16
:
11976 case elfcpp::R_PPC64_TOC16
:
11977 case elfcpp::R_POWERPC_GOT16
:
11978 case elfcpp::R_POWERPC_SECTOFF
:
11979 case elfcpp::R_POWERPC_TPREL16
:
11980 case elfcpp::R_POWERPC_DTPREL16
:
11981 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11982 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11983 case elfcpp::R_POWERPC_GOT_TPREL16
:
11984 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11985 overflow
= Reloc::CHECK_LOW_INSN
;
11988 case elfcpp::R_PPC64_REL24_NOTOC
:
11992 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11993 case elfcpp::R_POWERPC_ADDR24
:
11994 case elfcpp::R_POWERPC_ADDR14
:
11995 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11996 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11997 case elfcpp::R_PPC64_ADDR16_DS
:
11998 case elfcpp::R_POWERPC_REL24
:
11999 case elfcpp::R_PPC_PLTREL24
:
12000 case elfcpp::R_PPC_LOCAL24PC
:
12001 case elfcpp::R_PPC64_TPREL16_DS
:
12002 case elfcpp::R_PPC64_DTPREL16_DS
:
12003 case elfcpp::R_PPC64_TOC16_DS
:
12004 case elfcpp::R_PPC64_GOT16_DS
:
12005 case elfcpp::R_PPC64_SECTOFF_DS
:
12006 case elfcpp::R_POWERPC_REL14
:
12007 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12008 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12009 case elfcpp::R_PPC64_D34
:
12010 case elfcpp::R_PPC64_PCREL34
:
12011 case elfcpp::R_PPC64_GOT_PCREL34
:
12012 case elfcpp::R_PPC64_PLT_PCREL34
:
12013 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12014 case elfcpp::R_PPC64_D28
:
12015 case elfcpp::R_PPC64_PCREL28
:
12016 case elfcpp::R_PPC64_TPREL34
:
12017 case elfcpp::R_PPC64_DTPREL34
:
12018 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12019 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12020 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12021 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12022 overflow
= Reloc::CHECK_SIGNED
;
12026 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
12029 if (overflow
== Reloc::CHECK_LOW_INSN
12030 || overflow
== Reloc::CHECK_HIGH_INSN
)
12032 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12034 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
12035 overflow
= Reloc::CHECK_BITFIELD
;
12036 else if (overflow
== Reloc::CHECK_LOW_INSN
12037 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
12038 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
12039 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
12040 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
12041 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
12042 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
12043 overflow
= Reloc::CHECK_UNSIGNED
;
12045 overflow
= Reloc::CHECK_SIGNED
;
12048 bool maybe_dq_reloc
= false;
12049 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
12050 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
12053 case elfcpp::R_POWERPC_NONE
:
12054 case elfcpp::R_POWERPC_TLS
:
12055 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
12056 case elfcpp::R_POWERPC_GNU_VTENTRY
:
12057 case elfcpp::R_POWERPC_PLTSEQ
:
12058 case elfcpp::R_POWERPC_PLTCALL
:
12059 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
12060 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
12061 case elfcpp::R_PPC64_PCREL_OPT
:
12064 case elfcpp::R_PPC64_ADDR64
:
12065 case elfcpp::R_PPC64_REL64
:
12066 case elfcpp::R_PPC64_TOC
:
12067 case elfcpp::R_PPC64_ADDR64_LOCAL
:
12068 Reloc::addr64(view
, value
);
12071 case elfcpp::R_POWERPC_TPREL
:
12072 case elfcpp::R_POWERPC_DTPREL
:
12074 Reloc::addr64(view
, value
);
12076 status
= Reloc::addr32(view
, value
, overflow
);
12079 case elfcpp::R_PPC64_UADDR64
:
12080 Reloc::addr64_u(view
, value
);
12083 case elfcpp::R_POWERPC_ADDR32
:
12084 status
= Reloc::addr32(view
, value
, overflow
);
12087 case elfcpp::R_POWERPC_REL32
:
12088 case elfcpp::R_POWERPC_UADDR32
:
12089 status
= Reloc::addr32_u(view
, value
, overflow
);
12092 case elfcpp::R_PPC64_REL24_NOTOC
:
12094 goto unsupp
; // R_PPC_EMB_RELSDA
12096 case elfcpp::R_PPC64_REL24_P9NOTOC
:
12097 case elfcpp::R_POWERPC_ADDR24
:
12098 case elfcpp::R_POWERPC_REL24
:
12099 case elfcpp::R_PPC_PLTREL24
:
12100 case elfcpp::R_PPC_LOCAL24PC
:
12101 status
= Reloc::addr24(view
, value
, overflow
);
12104 case elfcpp::R_POWERPC_GOT_DTPREL16
:
12105 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
12106 case elfcpp::R_POWERPC_GOT_TPREL16
:
12107 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
12110 // On ppc64 these are all ds form
12111 maybe_dq_reloc
= true;
12115 case elfcpp::R_POWERPC_ADDR16
:
12116 case elfcpp::R_POWERPC_REL16
:
12117 case elfcpp::R_PPC64_TOC16
:
12118 case elfcpp::R_POWERPC_GOT16
:
12119 case elfcpp::R_POWERPC_SECTOFF
:
12120 case elfcpp::R_POWERPC_TPREL16
:
12121 case elfcpp::R_POWERPC_DTPREL16
:
12122 case elfcpp::R_POWERPC_GOT_TLSGD16
:
12123 case elfcpp::R_POWERPC_GOT_TLSLD16
:
12124 case elfcpp::R_POWERPC_ADDR16_LO
:
12125 case elfcpp::R_POWERPC_REL16_LO
:
12126 case elfcpp::R_PPC64_TOC16_LO
:
12127 case elfcpp::R_POWERPC_GOT16_LO
:
12128 case elfcpp::R_POWERPC_PLT16_LO
:
12129 case elfcpp::R_POWERPC_SECTOFF_LO
:
12130 case elfcpp::R_POWERPC_TPREL16_LO
:
12131 case elfcpp::R_POWERPC_DTPREL16_LO
:
12132 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
12133 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
12135 status
= Reloc::addr16(view
, value
, overflow
);
12137 maybe_dq_reloc
= true;
12140 case elfcpp::R_POWERPC_UADDR16
:
12141 status
= Reloc::addr16_u(view
, value
, overflow
);
12144 case elfcpp::R_PPC64_ADDR16_HIGH
:
12145 case elfcpp::R_PPC64_TPREL16_HIGH
:
12146 case elfcpp::R_PPC64_DTPREL16_HIGH
:
12148 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
12151 case elfcpp::R_POWERPC_ADDR16_HI
:
12152 case elfcpp::R_POWERPC_REL16_HI
:
12153 case elfcpp::R_PPC64_REL16_HIGH
:
12154 case elfcpp::R_PPC64_TOC16_HI
:
12155 case elfcpp::R_POWERPC_GOT16_HI
:
12156 case elfcpp::R_POWERPC_PLT16_HI
:
12157 case elfcpp::R_POWERPC_SECTOFF_HI
:
12158 case elfcpp::R_POWERPC_TPREL16_HI
:
12159 case elfcpp::R_POWERPC_DTPREL16_HI
:
12160 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
12161 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
12162 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
12163 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
12164 Reloc::addr16_hi(view
, value
);
12167 case elfcpp::R_PPC64_ADDR16_HIGHA
:
12168 case elfcpp::R_PPC64_TPREL16_HIGHA
:
12169 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
12171 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
12174 case elfcpp::R_POWERPC_ADDR16_HA
:
12175 case elfcpp::R_POWERPC_REL16_HA
:
12176 case elfcpp::R_PPC64_REL16_HIGHA
:
12177 case elfcpp::R_PPC64_TOC16_HA
:
12178 case elfcpp::R_POWERPC_GOT16_HA
:
12179 case elfcpp::R_POWERPC_PLT16_HA
:
12180 case elfcpp::R_POWERPC_SECTOFF_HA
:
12181 case elfcpp::R_POWERPC_TPREL16_HA
:
12182 case elfcpp::R_POWERPC_DTPREL16_HA
:
12183 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
12184 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
12185 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
12186 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
12187 Reloc::addr16_ha(view
, value
);
12190 case elfcpp::R_POWERPC_REL16DX_HA
:
12191 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
12194 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
12196 // R_PPC_EMB_NADDR16_LO
12199 case elfcpp::R_PPC64_ADDR16_HIGHER
:
12200 case elfcpp::R_PPC64_REL16_HIGHER
:
12201 case elfcpp::R_PPC64_TPREL16_HIGHER
:
12202 Reloc::addr16_hi2(view
, value
);
12205 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
12207 // R_PPC_EMB_NADDR16_HI
12210 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
12211 case elfcpp::R_PPC64_REL16_HIGHERA
:
12212 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
12213 Reloc::addr16_ha2(view
, value
);
12216 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
12218 // R_PPC_EMB_NADDR16_HA
12221 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
12222 case elfcpp::R_PPC64_REL16_HIGHEST
:
12223 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
12224 Reloc::addr16_hi3(view
, value
);
12227 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
12229 // R_PPC_EMB_SDAI16
12232 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
12233 case elfcpp::R_PPC64_REL16_HIGHESTA
:
12234 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
12235 Reloc::addr16_ha3(view
, value
);
12238 case elfcpp::R_PPC64_DTPREL16_DS
:
12239 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
12241 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
12244 case elfcpp::R_PPC64_TPREL16_DS
:
12245 case elfcpp::R_PPC64_TPREL16_LO_DS
:
12247 // R_PPC_TLSGD, R_PPC_TLSLD
12250 case elfcpp::R_PPC64_ADDR16_DS
:
12251 case elfcpp::R_PPC64_ADDR16_LO_DS
:
12252 case elfcpp::R_PPC64_TOC16_DS
:
12253 case elfcpp::R_PPC64_TOC16_LO_DS
:
12254 case elfcpp::R_PPC64_GOT16_DS
:
12255 case elfcpp::R_PPC64_GOT16_LO_DS
:
12256 case elfcpp::R_PPC64_PLT16_LO_DS
:
12257 case elfcpp::R_PPC64_SECTOFF_DS
:
12258 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
12259 maybe_dq_reloc
= true;
12262 case elfcpp::R_POWERPC_ADDR14
:
12263 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
12264 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12265 case elfcpp::R_POWERPC_REL14
:
12266 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12267 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12268 status
= Reloc::addr14(view
, value
, overflow
);
12271 case elfcpp::R_POWERPC_COPY
:
12272 case elfcpp::R_POWERPC_GLOB_DAT
:
12273 case elfcpp::R_POWERPC_JMP_SLOT
:
12274 case elfcpp::R_POWERPC_RELATIVE
:
12275 case elfcpp::R_POWERPC_DTPMOD
:
12276 case elfcpp::R_PPC64_JMP_IREL
:
12277 case elfcpp::R_POWERPC_IRELATIVE
:
12278 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12279 _("unexpected reloc %u in object file"),
12283 case elfcpp::R_PPC64_TOCSAVE
:
12289 Symbol_location loc
;
12290 loc
.object
= relinfo
->object
;
12291 loc
.shndx
= relinfo
->data_shndx
;
12292 loc
.offset
= rela
.get_r_offset();
12293 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12294 if (tocsave
->find(loc
) != tocsave
->end())
12296 // If we've generated plt calls using this tocsave, then
12297 // the nop needs to be changed to save r2.
12298 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12299 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12300 elfcpp::Swap
<32, big_endian
>::
12301 writeval(iview
, std_2_1
+ target
->stk_toc());
12306 case elfcpp::R_PPC_EMB_SDA2I16
:
12307 case elfcpp::R_PPC_EMB_SDA2REL
:
12310 // R_PPC64_TLSGD, R_PPC64_TLSLD
12313 case elfcpp::R_PPC64_D34
:
12314 case elfcpp::R_PPC64_D34_LO
:
12315 case elfcpp::R_PPC64_PCREL34
:
12316 case elfcpp::R_PPC64_GOT_PCREL34
:
12317 case elfcpp::R_PPC64_PLT_PCREL34
:
12318 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12319 case elfcpp::R_PPC64_TPREL34
:
12320 case elfcpp::R_PPC64_DTPREL34
:
12321 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12322 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12323 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12324 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12327 status
= Reloc::addr34(view
, value
, overflow
);
12330 case elfcpp::R_PPC64_D34_HI30
:
12333 Reloc::addr34_hi(view
, value
);
12336 case elfcpp::R_PPC64_D34_HA30
:
12339 Reloc::addr34_ha(view
, value
);
12342 case elfcpp::R_PPC64_D28
:
12343 case elfcpp::R_PPC64_PCREL28
:
12346 status
= Reloc::addr28(view
, value
, overflow
);
12349 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12350 case elfcpp::R_PPC64_REL16_HIGHER34
:
12353 Reloc::addr16_higher34(view
, value
);
12356 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12357 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12360 Reloc::addr16_highera34(view
, value
);
12363 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12364 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12367 Reloc::addr16_highest34(view
, value
);
12370 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12371 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12374 Reloc::addr16_highesta34(view
, value
);
12377 case elfcpp::R_POWERPC_PLT32
:
12378 case elfcpp::R_POWERPC_PLTREL32
:
12379 case elfcpp::R_PPC_SDAREL16
:
12380 case elfcpp::R_POWERPC_ADDR30
:
12381 case elfcpp::R_PPC64_PLT64
:
12382 case elfcpp::R_PPC64_PLTREL64
:
12383 case elfcpp::R_PPC64_PLTGOT16
:
12384 case elfcpp::R_PPC64_PLTGOT16_LO
:
12385 case elfcpp::R_PPC64_PLTGOT16_HI
:
12386 case elfcpp::R_PPC64_PLTGOT16_HA
:
12387 case elfcpp::R_PPC64_PLTGOT16_DS
:
12388 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12389 case elfcpp::R_PPC_TOC16
:
12392 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12393 _("unsupported reloc %u"),
12398 if (maybe_dq_reloc
)
12401 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12403 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12404 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12405 && (insn
& 3) == 1))
12406 status
= Reloc::addr16_dq(view
, value
, overflow
);
12407 else if (size
== 64
12408 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12409 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12410 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12411 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12412 status
= Reloc::addr16_ds(view
, value
, overflow
);
12414 status
= Reloc::addr16(view
, value
, overflow
);
12417 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12420 && gsym
->is_undefined()
12421 && is_branch_reloc
<size
>(r_type
))))
12425 name
= gsym
->demangled_name();
12427 name
= relinfo
->object
->get_symbol_name(r_sym
);
12428 if (os
->flags() & elfcpp::SHF_ALLOC
)
12430 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12431 _("reloc type %u overflow against '%s'"),
12432 r_type
, name
.c_str());
12433 if (has_stub_value
)
12434 gold_info(_("try relinking with a smaller --stub-group-size"));
12438 gold_warning_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12439 _("reloc type %u overflow against '%s'"),
12440 r_type
, name
.c_str());
12441 gold_info(_("debug info may be unreliable, compile with -gdwarf64"));
12448 // Relocate section data.
12450 template<int size
, bool big_endian
>
12452 Target_powerpc
<size
, big_endian
>::relocate_section(
12453 const Relocate_info
<size
, big_endian
>* relinfo
,
12454 unsigned int sh_type
,
12455 const unsigned char* prelocs
,
12456 size_t reloc_count
,
12457 Output_section
* output_section
,
12458 bool needs_special_offset_handling
,
12459 unsigned char* view
,
12461 section_size_type view_size
,
12462 const Reloc_symbol_changes
* reloc_symbol_changes
)
12464 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12465 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12466 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12467 Powerpc_comdat_behavior
;
12468 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12471 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12473 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12474 Powerpc_comdat_behavior
, Classify_reloc
>(
12480 needs_special_offset_handling
,
12484 reloc_symbol_changes
);
12487 template<int size
, bool big_endian
>
12488 class Powerpc_scan_relocatable_reloc
12491 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12492 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12493 static const int sh_type
= elfcpp::SHT_RELA
;
12495 // Return the symbol referred to by the relocation.
12496 static inline unsigned int
12497 get_r_sym(const Reltype
* reloc
)
12498 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12500 // Return the type of the relocation.
12501 static inline unsigned int
12502 get_r_type(const Reltype
* reloc
)
12503 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12505 // Return the strategy to use for a local symbol which is not a
12506 // section symbol, given the relocation type.
12507 inline Relocatable_relocs::Reloc_strategy
12508 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12510 if (r_type
== 0 && r_sym
== 0)
12511 return Relocatable_relocs::RELOC_DISCARD
;
12512 return Relocatable_relocs::RELOC_COPY
;
12515 // Return the strategy to use for a local symbol which is a section
12516 // symbol, given the relocation type.
12517 inline Relocatable_relocs::Reloc_strategy
12518 local_section_strategy(unsigned int, Relobj
*)
12520 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12523 // Return the strategy to use for a global symbol, given the
12524 // relocation type, the object, and the symbol index.
12525 inline Relocatable_relocs::Reloc_strategy
12526 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12529 && (r_type
== elfcpp::R_PPC_PLTREL24
12530 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12531 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12532 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12533 return Relocatable_relocs::RELOC_SPECIAL
;
12534 return Relocatable_relocs::RELOC_COPY
;
12538 // Scan the relocs during a relocatable link.
12540 template<int size
, bool big_endian
>
12542 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12543 Symbol_table
* symtab
,
12545 Sized_relobj_file
<size
, big_endian
>* object
,
12546 unsigned int data_shndx
,
12547 unsigned int sh_type
,
12548 const unsigned char* prelocs
,
12549 size_t reloc_count
,
12550 Output_section
* output_section
,
12551 bool needs_special_offset_handling
,
12552 size_t local_symbol_count
,
12553 const unsigned char* plocal_symbols
,
12554 Relocatable_relocs
* rr
)
12556 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12558 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12560 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12568 needs_special_offset_handling
,
12569 local_symbol_count
,
12574 // Scan the relocs for --emit-relocs.
12576 template<int size
, bool big_endian
>
12578 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12579 Symbol_table
* symtab
,
12581 Sized_relobj_file
<size
, big_endian
>* object
,
12582 unsigned int data_shndx
,
12583 unsigned int sh_type
,
12584 const unsigned char* prelocs
,
12585 size_t reloc_count
,
12586 Output_section
* output_section
,
12587 bool needs_special_offset_handling
,
12588 size_t local_symbol_count
,
12589 const unsigned char* plocal_syms
,
12590 Relocatable_relocs
* rr
)
12592 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12594 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12595 Emit_relocs_strategy
;
12597 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12599 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12607 needs_special_offset_handling
,
12608 local_symbol_count
,
12613 // Emit relocations for a section.
12614 // This is a modified version of the function by the same name in
12615 // target-reloc.h. Using relocate_special_relocatable for
12616 // R_PPC_PLTREL24 would require duplication of the entire body of the
12617 // loop, so we may as well duplicate the whole thing.
12619 template<int size
, bool big_endian
>
12621 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12622 const Relocate_info
<size
, big_endian
>* relinfo
,
12623 unsigned int sh_type
,
12624 const unsigned char* prelocs
,
12625 size_t reloc_count
,
12626 Output_section
* output_section
,
12627 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12629 Address view_address
,
12631 unsigned char* reloc_view
,
12632 section_size_type reloc_view_size
)
12634 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12636 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12637 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12638 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12639 // Offset from start of insn to d-field reloc.
12640 const int d_offset
= big_endian
? 2 : 0;
12642 Powerpc_relobj
<size
, big_endian
>* const object
12643 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12644 const unsigned int local_count
= object
->local_symbol_count();
12645 unsigned int got2_shndx
= object
->got2_shndx();
12646 Address got2_addend
= 0;
12647 if (got2_shndx
!= 0)
12649 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12650 gold_assert(got2_addend
!= invalid_address
);
12653 const bool relocatable
= parameters
->options().relocatable();
12655 unsigned char* pwrite
= reloc_view
;
12656 bool zap_next
= false;
12657 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12659 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12660 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12663 Reltype
reloc(prelocs
);
12664 Reltype_write
reloc_write(pwrite
);
12666 Address offset
= reloc
.get_r_offset();
12667 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12668 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12669 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12670 const unsigned int orig_r_sym
= r_sym
;
12671 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12672 = reloc
.get_r_addend();
12673 const Symbol
* gsym
= NULL
;
12677 // We could arrange to discard these and other relocs for
12678 // tls optimised sequences in the strategy methods, but for
12679 // now do as BFD ld does.
12680 r_type
= elfcpp::R_POWERPC_NONE
;
12684 // Get the new symbol index.
12685 Output_section
* os
= NULL
;
12686 if (r_sym
< local_count
)
12690 case Relocatable_relocs::RELOC_COPY
:
12691 case Relocatable_relocs::RELOC_SPECIAL
:
12694 r_sym
= object
->symtab_index(r_sym
);
12695 gold_assert(r_sym
!= -1U);
12699 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12701 // We are adjusting a section symbol. We need to find
12702 // the symbol table index of the section symbol for
12703 // the output section corresponding to input section
12704 // in which this symbol is defined.
12705 gold_assert(r_sym
< local_count
);
12707 unsigned int shndx
=
12708 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12709 gold_assert(is_ordinary
);
12710 os
= object
->output_section(shndx
);
12711 gold_assert(os
!= NULL
);
12712 gold_assert(os
->needs_symtab_index());
12713 r_sym
= os
->symtab_index();
12718 gold_unreachable();
12723 gsym
= object
->global_symbol(r_sym
);
12724 gold_assert(gsym
!= NULL
);
12725 if (gsym
->is_forwarder())
12726 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12728 gold_assert(gsym
->has_symtab_index());
12729 r_sym
= gsym
->symtab_index();
12732 // Get the new offset--the location in the output section where
12733 // this relocation should be applied.
12734 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12735 offset
+= offset_in_output_section
;
12738 section_offset_type sot_offset
=
12739 convert_types
<section_offset_type
, Address
>(offset
);
12740 section_offset_type new_sot_offset
=
12741 output_section
->output_offset(object
, relinfo
->data_shndx
,
12743 gold_assert(new_sot_offset
!= -1);
12744 offset
= new_sot_offset
;
12747 // In an object file, r_offset is an offset within the section.
12748 // In an executable or dynamic object, generated by
12749 // --emit-relocs, r_offset is an absolute address.
12752 offset
+= view_address
;
12753 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12754 offset
-= offset_in_output_section
;
12757 // Handle the reloc addend based on the strategy.
12758 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12760 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12762 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12763 addend
= psymval
->value(object
, addend
);
12764 // In a relocatable link, the symbol value is relative to
12765 // the start of the output section. For a non-relocatable
12766 // link, we need to adjust the addend.
12769 gold_assert(os
!= NULL
);
12770 addend
-= os
->address();
12773 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12777 if (addend
>= 32768)
12778 addend
+= got2_addend
;
12780 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12782 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12783 addend
-= d_offset
;
12785 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12787 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12788 addend
-= d_offset
+ 4;
12792 gold_unreachable();
12796 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12797 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12798 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12799 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12801 // First instruction of a global dynamic sequence,
12803 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12804 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12807 case tls::TLSOPT_TO_IE
:
12808 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12809 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12811 case tls::TLSOPT_TO_LE
:
12812 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12813 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12814 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12817 r_type
= elfcpp::R_POWERPC_NONE
;
12818 offset
-= d_offset
;
12825 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12826 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12827 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12828 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12830 // First instruction of a local dynamic sequence,
12832 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12833 if (tls_type
== tls::TLSOPT_TO_LE
)
12835 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12836 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12838 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12839 const Output_section
* os
= relinfo
->layout
->tls_segment()
12841 gold_assert(os
!= NULL
);
12842 gold_assert(os
->needs_symtab_index());
12843 r_sym
= os
->symtab_index();
12844 addend
= dtp_offset
;
12848 r_type
= elfcpp::R_POWERPC_NONE
;
12849 offset
-= d_offset
;
12853 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12854 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12855 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12856 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12858 // First instruction of initial exec sequence.
12859 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12860 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12862 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12863 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12864 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12867 r_type
= elfcpp::R_POWERPC_NONE
;
12868 offset
-= d_offset
;
12872 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12873 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12875 // Second instruction of a global dynamic sequence,
12876 // the __tls_get_addr call
12877 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12878 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12881 case tls::TLSOPT_TO_IE
:
12882 r_type
= elfcpp::R_POWERPC_NONE
;
12885 case tls::TLSOPT_TO_LE
:
12886 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12887 offset
+= d_offset
;
12894 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12895 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12897 // Second instruction of a local dynamic sequence,
12898 // the __tls_get_addr call
12899 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12900 if (tls_type
== tls::TLSOPT_TO_LE
)
12902 const Output_section
* os
= relinfo
->layout
->tls_segment()
12904 gold_assert(os
!= NULL
);
12905 gold_assert(os
->needs_symtab_index());
12906 r_sym
= os
->symtab_index();
12907 addend
= dtp_offset
;
12908 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12909 offset
+= d_offset
;
12913 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12915 // Second instruction of an initial exec sequence
12916 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12917 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12919 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12920 offset
+= d_offset
;
12925 reloc_write
.put_r_offset(offset
);
12926 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12927 reloc_write
.put_r_addend(addend
);
12929 pwrite
+= reloc_size
;
12932 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12933 == reloc_view_size
);
12936 // Return the value to use for a dynamic symbol which requires special
12937 // treatment. This is how we support equality comparisons of function
12938 // pointers across shared library boundaries, as described in the
12939 // processor specific ABI supplement.
12941 template<int size
, bool big_endian
>
12943 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12947 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12948 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12949 p
!= this->stub_tables_
.end();
12952 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12953 = (*p
)->find_plt_call_entry(gsym
);
12955 return (*p
)->stub_address() + ent
->off_
;
12958 else if (this->abiversion() >= 2)
12960 Address off
= this->glink_section()->find_global_entry(gsym
);
12961 if (off
!= invalid_address
)
12962 return this->glink_section()->global_entry_address() + off
;
12964 gold_unreachable();
12967 // Return the PLT address to use for a local symbol.
12968 template<int size
, bool big_endian
>
12970 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12971 const Relobj
* object
,
12972 unsigned int symndx
) const
12976 const Sized_relobj
<size
, big_endian
>* relobj
12977 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12978 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12979 p
!= this->stub_tables_
.end();
12982 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12983 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12985 return (*p
)->stub_address() + ent
->off_
;
12988 gold_unreachable();
12991 // Return the PLT address to use for a global symbol.
12992 template<int size
, bool big_endian
>
12994 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12995 const Symbol
* gsym
) const
12999 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
13000 p
!= this->stub_tables_
.end();
13003 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
13004 = (*p
)->find_plt_call_entry(gsym
);
13006 return (*p
)->stub_address() + ent
->off_
;
13009 else if (this->abiversion() >= 2)
13011 Address off
= this->glink_section()->find_global_entry(gsym
);
13012 if (off
!= invalid_address
)
13013 return this->glink_section()->global_entry_address() + off
;
13015 gold_unreachable();
13018 // Return the offset to use for the GOT_INDX'th got entry which is
13019 // for a local tls symbol specified by OBJECT, SYMNDX.
13020 template<int size
, bool big_endian
>
13022 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
13023 const Relobj
* object
,
13024 unsigned int symndx
,
13025 Output_data_got_base
* got
,
13026 unsigned int got_indx
,
13027 uint64_t addend
) const
13029 const Powerpc_relobj
<size
, big_endian
>* ppc_object
13030 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
13031 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
13033 for (Got_type got_type
= (size
== 32
13034 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13035 got_type
<= GOT_TYPE_SMALL_TPREL
;
13036 got_type
= Got_type(got_type
+ 1))
13037 if (got_type
!= GOT_TYPE_SMALL
13038 && ppc_object
->local_has_got_offset(symndx
, got_type
, addend
))
13041 = ppc_object
->local_got_offset(symndx
, got_type
, addend
);
13042 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13044 if (off
== got_indx
* (size
/ 8)
13045 && (size
== 32 || got
== this->got_section(got_type
)))
13047 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13050 return -dtp_offset
;
13054 gold_unreachable();
13057 // Return the offset to use for the GOT_INDX'th got entry which is
13058 // for global tls symbol GSYM.
13059 template<int size
, bool big_endian
>
13061 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
13063 Output_data_got_base
* got
,
13064 unsigned int got_indx
,
13065 uint64_t addend
) const
13067 if (gsym
->type() == elfcpp::STT_TLS
)
13069 for (Got_type got_type
= (size
== 32
13070 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13071 got_type
<= GOT_TYPE_SMALL_TPREL
;
13072 got_type
= Got_type(got_type
+ 1))
13073 if (got_type
!= GOT_TYPE_SMALL
13074 && gsym
->has_got_offset(got_type
, addend
))
13076 unsigned int off
= gsym
->got_offset(got_type
, addend
);
13077 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13079 if (off
== got_indx
* (size
/ 8)
13080 && (size
== 32 || got
== this->got_section(got_type
)))
13082 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13085 return -dtp_offset
;
13089 gold_unreachable();
13092 // The selector for powerpc object files.
13094 template<int size
, bool big_endian
>
13095 class Target_selector_powerpc
: public Target_selector
13098 Target_selector_powerpc()
13099 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
13102 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
13103 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
13105 ? (big_endian
? "elf64ppc" : "elf64lppc")
13106 : (big_endian
? "elf32ppc" : "elf32lppc")))
13110 do_instantiate_target()
13111 { return new Target_powerpc
<size
, big_endian
>(); }
13114 Target_selector_powerpc
<32, true> target_selector_ppc32
;
13115 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
13116 Target_selector_powerpc
<64, true> target_selector_ppc64
;
13117 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
13119 // Instantiate these constants for -O0
13120 template<int size
, bool big_endian
>
13121 const typename Output_data_glink
<size
, big_endian
>::Address
13122 Output_data_glink
<size
, big_endian
>::invalid_address
;
13123 template<int size
, bool big_endian
>
13124 const typename Stub_table
<size
, big_endian
>::Address
13125 Stub_table
<size
, big_endian
>::invalid_address
;
13126 template<int size
, bool big_endian
>
13127 const typename Target_powerpc
<size
, big_endian
>::Address
13128 Target_powerpc
<size
, big_endian
>::invalid_address
;
13130 } // End anonymous namespace.