1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2024 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;
3717 if (size
== 64 && this->abiversion() < 2)
3719 static const char* const thread_starter
[] =
3723 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3725 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3726 "mq_notify", "create_timer",
3731 "GOMP_parallel_start",
3732 "GOMP_parallel_loop_static",
3733 "GOMP_parallel_loop_static_start",
3734 "GOMP_parallel_loop_dynamic",
3735 "GOMP_parallel_loop_dynamic_start",
3736 "GOMP_parallel_loop_guided",
3737 "GOMP_parallel_loop_guided_start",
3738 "GOMP_parallel_loop_runtime",
3739 "GOMP_parallel_loop_runtime_start",
3740 "GOMP_parallel_sections",
3741 "GOMP_parallel_sections_start",
3745 bool thread_safe
= parameters
->options().plt_thread_safe();
3748 && !parameters
->options().user_set_plt_thread_safe())
3750 if (parameters
->options().shared())
3754 for (unsigned int i
= 0;
3755 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3758 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3759 thread_safe
= (sym
!= NULL
3761 && sym
->in_real_elf());
3767 this->plt_thread_safe_
= thread_safe
;
3771 && parameters
->options().output_is_position_independent())
3773 gold_assert (this->rela_dyn_
);
3774 this->rela_dyn_size_
= this->rela_dyn_
->current_data_size();
3777 this->stub_group_size_
= parameters
->options().stub_group_size();
3778 bool no_size_errors
= true;
3779 if (this->stub_group_size_
== 1)
3780 this->stub_group_size_
= 0x1c00000;
3781 else if (this->stub_group_size_
== -1)
3782 this->stub_group_size_
= -0x1e00000;
3784 no_size_errors
= false;
3785 this->group_sections(layout
, task
, no_size_errors
);
3787 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3789 this->branch_lookup_table_
.clear();
3790 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3791 p
!= this->stub_tables_
.end();
3794 (*p
)->clear_stubs(true);
3796 this->stub_tables_
.clear();
3797 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3798 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3799 program_name
, this->stub_group_size_
);
3800 this->group_sections(layout
, task
, true);
3803 // We need address of stub tables valid for make_stub.
3804 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3805 p
!= this->stub_tables_
.end();
3808 const Powerpc_relobj
<size
, big_endian
>* object
3809 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3810 Address off
= object
->get_output_section_offset((*p
)->shndx());
3811 gold_assert(off
!= invalid_address
);
3812 Output_section
* os
= (*p
)->output_section();
3813 (*p
)->set_address_and_size(os
, off
);
3818 // Clear plt call stubs, long branch stubs and branch lookup table.
3819 prev_brlt_size
= this->branch_lookup_table_
.size();
3820 this->branch_lookup_table_
.clear();
3821 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3822 p
!= this->stub_tables_
.end();
3825 (*p
)->clear_stubs(false);
3829 // Build all the stubs.
3830 this->relax_failed_
= false;
3831 Stub_table
<size
, big_endian
>* ifunc_stub_table
3832 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3833 Stub_table
<size
, big_endian
>* one_stub_table
3834 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3835 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3836 b
!= this->branch_info_
.end();
3839 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3840 && !this->relax_failed_
)
3842 this->relax_failed_
= true;
3843 this->relax_fail_count_
++;
3844 if (this->relax_fail_count_
< 3)
3848 bool do_resize
= false;
3849 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3850 p
!= this->stub_tables_
.end();
3852 if ((*p
)->need_resize())
3859 this->branch_lookup_table_
.clear();
3860 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3861 p
!= this->stub_tables_
.end();
3863 (*p
)->set_resizing(true);
3864 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3865 b
!= this->branch_info_
.end();
3868 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3869 && !this->relax_failed_
)
3871 this->relax_failed_
= true;
3872 this->relax_fail_count_
++;
3873 if (this->relax_fail_count_
< 3)
3877 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3878 p
!= this->stub_tables_
.end();
3880 (*p
)->set_resizing(false);
3883 // Did anything change size?
3884 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3885 bool again
= num_huge_branches
!= prev_brlt_size
;
3886 if (size
== 64 && num_huge_branches
!= 0)
3887 this->make_brlt_section(layout
);
3888 if (size
== 64 && again
)
3890 update_current_size(this->brlt_section_
, num_huge_branches
* 16);
3891 if (parameters
->options().output_is_position_independent())
3893 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
3894 off_t cur
= this->rela_dyn_size_
+ num_huge_branches
* reloc_size
;
3895 update_current_size(this->rela_dyn_
, cur
);
3899 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3900 p
!= this->stub_tables_
.rend();
3902 (*p
)->remove_eh_frame(layout
);
3904 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3905 p
!= this->stub_tables_
.end();
3907 (*p
)->add_eh_frame(layout
);
3909 typedef Unordered_set
<Output_section
*> Output_sections
;
3910 Output_sections os_need_update
;
3911 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3912 p
!= this->stub_tables_
.end();
3915 if ((*p
)->size_update())
3918 os_need_update
.insert((*p
)->output_section());
3922 // Set output section offsets for all input sections in an output
3923 // section that just changed size. Anything past the stubs will
3925 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3926 p
!= os_need_update
.end();
3929 Output_section
* os
= *p
;
3931 typedef Output_section::Input_section_list Input_section_list
;
3932 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3933 i
!= os
->input_sections().end();
3936 off
= align_address(off
, i
->addralign());
3937 if (i
->is_input_section() || i
->is_relaxed_input_section())
3938 i
->relobj()->set_section_offset(i
->shndx(), off
);
3939 if (i
->is_relaxed_input_section())
3941 Stub_table
<size
, big_endian
>* stub_table
3942 = static_cast<Stub_table
<size
, big_endian
>*>(
3943 i
->relaxed_input_section());
3944 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3945 off
+= stub_table_size
;
3946 // After a few iterations, set current stub table size
3947 // as min size threshold, so later stub tables can only
3950 stub_table
->set_min_size_threshold(stub_table_size
);
3953 off
+= i
->data_size();
3955 // If .branch_lt is part of this output section, then we have
3956 // just done the offset adjustment.
3957 os
->clear_section_offsets_need_adjustment();
3962 && num_huge_branches
!= 0
3963 && parameters
->options().output_is_position_independent())
3965 // Fill in the BRLT relocs.
3966 this->rela_dyn_
->reset_data_size();
3967 this->rela_dyn_
->set_current_data_size(this->rela_dyn_size_
);
3968 for (typename
Branch_lookup_table::const_iterator p
3969 = this->branch_lookup_table_
.begin();
3970 p
!= this->branch_lookup_table_
.end();
3973 this->rela_dyn_
->add_relative(elfcpp::R_POWERPC_RELATIVE
,
3974 this->brlt_section_
, p
->second
,
3977 this->rela_dyn_
->finalize_data_size();
3978 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
3979 gold_assert(this->rela_dyn_
->data_size()
3980 == this->rela_dyn_size_
+ num_huge_branches
* reloc_size
);
3984 && (parameters
->options().user_set_emit_stub_syms()
3985 ? parameters
->options().emit_stub_syms()
3987 || parameters
->options().output_is_position_independent()
3988 || parameters
->options().emit_relocs())))
3990 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3991 p
!= this->stub_tables_
.end();
3993 (*p
)->define_stub_syms(symtab
);
3995 if (this->glink_
!= NULL
)
3997 int stub_size
= this->glink_
->pltresolve_size();
3998 Address value
= -stub_size
;
4004 this->define_local(symtab
, "__glink_PLTresolve",
4005 this->glink_
, value
, stub_size
);
4008 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
4015 template<int size
, bool big_endian
>
4017 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
4018 unsigned char* oview
,
4022 uint64_t address
= plt
->address();
4023 off_t len
= plt
->data_size();
4025 if (plt
== this->glink_
)
4027 // See Output_data_glink::do_write() for glink contents.
4030 // Static linking may need stubs, to support ifunc and long
4031 // branches. We need to create an output section for
4032 // .eh_frame early in the link process, to have a place to
4033 // attach stub .eh_frame info. We also need to have
4034 // registered a CIE that matches the stub CIE. Both of
4035 // these requirements are satisfied by creating an FDE and
4036 // CIE for .glink, even though static linking will leave
4037 // .glink zero length.
4038 // ??? Hopefully generating an FDE with a zero address range
4039 // won't confuse anything that consumes .eh_frame info.
4041 else if (size
== 64)
4043 // There is one word before __glink_PLTresolve
4047 else if (parameters
->options().output_is_position_independent())
4049 // There are two FDEs for a position independent glink.
4050 // The first covers the branch table, the second
4051 // __glink_PLTresolve at the end of glink.
4052 off_t resolve_size
= this->glink_
->pltresolve_size();
4053 if (oview
[9] == elfcpp::DW_CFA_nop
)
4054 len
-= resolve_size
;
4057 address
+= len
- resolve_size
;
4064 // Must be a stub table.
4065 const Stub_table
<size
, big_endian
>* stub_table
4066 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
4067 uint64_t stub_address
= stub_table
->stub_address();
4068 len
-= stub_address
- address
;
4069 address
= stub_address
;
4072 *paddress
= address
;
4076 // A class to handle the PLT data.
4078 template<int size
, bool big_endian
>
4079 class Output_data_plt_powerpc
: public Output_section_data_build
4082 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4083 size
, big_endian
> Reloc_section
;
4085 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4086 Symbol_table
* symtab
,
4087 Reloc_section
* plt_rel
,
4089 : Output_section_data_build(size
== 32 ? 4 : 8),
4090 rel_(plt_rel
), targ_(targ
), symtab_(symtab
), name_(name
), sym_ents_()
4093 // Add an entry to the PLT.
4095 add_entry(Symbol
*, bool = false);
4098 add_ifunc_entry(Symbol
*);
4101 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4104 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4106 // Return the .rela.plt section data.
4113 // Return the number of PLT entries.
4117 if (this->current_data_size() == 0)
4119 return ((this->current_data_size() - this->first_plt_entry_offset())
4120 / this->plt_entry_size());
4125 do_adjust_output_section(Output_section
* os
)
4130 // Write to a map file.
4132 do_print_to_mapfile(Mapfile
* mapfile
) const
4133 { mapfile
->print_output_data(this, this->name_
); }
4136 struct Local_plt_ent
4138 Local_plt_ent(Sized_relobj_file
<size
, big_endian
>* obj
, unsigned int rsym
)
4139 { rsym_
= rsym
; u
.obj_
= obj
; }
4140 Local_plt_ent(Symbol
* sym
)
4141 { rsym_
= -1u; u
.gsym_
= sym
; }
4148 Sized_relobj_file
<size
, big_endian
>* obj_
;
4153 // Return the offset of the first non-reserved PLT entry.
4155 first_plt_entry_offset() const
4157 // IPLT and LPLT have no reserved entry.
4158 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4160 return this->targ_
->first_plt_entry_offset();
4163 // Return the size of each PLT entry.
4165 plt_entry_size() const
4167 return this->targ_
->plt_entry_size();
4170 // Write out the PLT data.
4172 do_write(Output_file
*);
4174 // The reloc section.
4175 Reloc_section
* rel_
;
4176 // Allows access to .glink for do_write.
4177 Target_powerpc
<size
, big_endian
>* targ_
;
4178 Symbol_table
* symtab_
;
4179 // What to report in map file.
4182 std::vector
<Local_plt_ent
> sym_ents_
;
4185 // Add an entry to the PLT.
4187 template<int size
, bool big_endian
>
4189 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
,
4192 if (!gsym
->has_plt_offset())
4194 section_size_type off
= this->current_data_size();
4196 off
+= this->first_plt_entry_offset();
4197 gsym
->set_plt_offset(off
);
4202 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4203 if (size
== 64 && this->targ_
->abiversion() < 2)
4204 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4205 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
,
4210 gsym
->set_needs_dynsym_entry();
4211 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4212 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4215 off
+= this->plt_entry_size();
4216 this->set_current_data_size(off
);
4219 Local_plt_ent
sym(gsym
);
4220 this->sym_ents_
.push_back(sym
);
4225 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4227 template<int size
, bool big_endian
>
4229 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4231 if (!gsym
->has_plt_offset())
4233 section_size_type off
= this->current_data_size();
4234 gsym
->set_plt_offset(off
);
4235 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4236 if (size
== 64 && this->targ_
->abiversion() < 2)
4237 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4238 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4239 off
+= this->plt_entry_size();
4240 this->set_current_data_size(off
);
4244 // Add an entry for a local symbol to the PLT.
4246 template<int size
, bool big_endian
>
4248 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4249 Sized_relobj_file
<size
, big_endian
>* relobj
,
4250 unsigned int local_sym_index
)
4252 if (!relobj
->local_has_plt_offset(local_sym_index
))
4254 section_size_type off
= this->current_data_size();
4255 relobj
->set_local_plt_offset(local_sym_index
, off
);
4258 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4259 if (size
== 64 && this->targ_
->abiversion() < 2)
4260 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4261 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4262 dynrel
, this, off
, 0);
4264 off
+= this->plt_entry_size();
4265 this->set_current_data_size(off
);
4266 Local_plt_ent
sym(relobj
, local_sym_index
);
4267 this->sym_ents_
.push_back(sym
);
4271 // Add an entry for a local ifunc symbol to the IPLT.
4273 template<int size
, bool big_endian
>
4275 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4276 Sized_relobj_file
<size
, big_endian
>* relobj
,
4277 unsigned int local_sym_index
)
4279 if (!relobj
->local_has_plt_offset(local_sym_index
))
4281 section_size_type off
= this->current_data_size();
4282 relobj
->set_local_plt_offset(local_sym_index
, off
);
4283 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4284 if (size
== 64 && this->targ_
->abiversion() < 2)
4285 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4286 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4288 off
+= this->plt_entry_size();
4289 this->set_current_data_size(off
);
4293 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4294 static const uint32_t add_2_2_11
= 0x7c425a14;
4295 static const uint32_t add_2_2_12
= 0x7c426214;
4296 static const uint32_t add_3_3_2
= 0x7c631214;
4297 static const uint32_t add_3_3_13
= 0x7c636a14;
4298 static const uint32_t add_3_12_2
= 0x7c6c1214;
4299 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4300 static const uint32_t add_11_0_11
= 0x7d605a14;
4301 static const uint32_t add_11_2_11
= 0x7d625a14;
4302 static const uint32_t add_11_11_2
= 0x7d6b1214;
4303 static const uint32_t add_12_11_12
= 0x7d8b6214;
4304 static const uint32_t addi_0_12
= 0x380c0000;
4305 static const uint32_t addi_2_2
= 0x38420000;
4306 static const uint32_t addi_3_3
= 0x38630000;
4307 static const uint32_t addi_11_11
= 0x396b0000;
4308 static const uint32_t addi_12_1
= 0x39810000;
4309 static const uint32_t addi_12_11
= 0x398b0000;
4310 static const uint32_t addi_12_12
= 0x398c0000;
4311 static const uint32_t addis_0_2
= 0x3c020000;
4312 static const uint32_t addis_0_13
= 0x3c0d0000;
4313 static const uint32_t addis_2_12
= 0x3c4c0000;
4314 static const uint32_t addis_11_2
= 0x3d620000;
4315 static const uint32_t addis_11_11
= 0x3d6b0000;
4316 static const uint32_t addis_11_30
= 0x3d7e0000;
4317 static const uint32_t addis_12_1
= 0x3d810000;
4318 static const uint32_t addis_12_2
= 0x3d820000;
4319 static const uint32_t addis_12_11
= 0x3d8b0000;
4320 static const uint32_t addis_12_12
= 0x3d8c0000;
4321 static const uint32_t b
= 0x48000000;
4322 static const uint32_t bcl_20_31
= 0x429f0005;
4323 static const uint32_t bctr
= 0x4e800420;
4324 static const uint32_t bctrl
= 0x4e800421;
4325 static const uint32_t beqlr
= 0x4d820020;
4326 static const uint32_t blr
= 0x4e800020;
4327 static const uint32_t bnectr_p4
= 0x4ce20420;
4328 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4329 static const uint32_t cmpldi_2_0
= 0x28220000;
4330 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4331 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4332 static const uint32_t cror_15_15_15
= 0x4def7b82;
4333 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4334 static const uint32_t ld_0_1
= 0xe8010000;
4335 static const uint32_t ld_0_11
= 0xe80b0000;
4336 static const uint32_t ld_0_12
= 0xe80c0000;
4337 static const uint32_t ld_2_1
= 0xe8410000;
4338 static const uint32_t ld_2_2
= 0xe8420000;
4339 static const uint32_t ld_2_11
= 0xe84b0000;
4340 static const uint32_t ld_2_12
= 0xe84c0000;
4341 static const uint32_t ld_11_1
= 0xe9610000;
4342 static const uint32_t ld_11_2
= 0xe9620000;
4343 static const uint32_t ld_11_3
= 0xe9630000;
4344 static const uint32_t ld_11_11
= 0xe96b0000;
4345 static const uint32_t ld_12_2
= 0xe9820000;
4346 static const uint32_t ld_12_3
= 0xe9830000;
4347 static const uint32_t ld_12_11
= 0xe98b0000;
4348 static const uint32_t ld_12_12
= 0xe98c0000;
4349 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4350 static const uint32_t lfd_0_1
= 0xc8010000;
4351 static const uint32_t li_0_0
= 0x38000000;
4352 static const uint32_t li_11_0
= 0x39600000;
4353 static const uint32_t li_12_0
= 0x39800000;
4354 static const uint32_t lis_0
= 0x3c000000;
4355 static const uint32_t lis_2
= 0x3c400000;
4356 static const uint32_t lis_11
= 0x3d600000;
4357 static const uint32_t lis_12
= 0x3d800000;
4358 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4359 static const uint32_t lwz_0_12
= 0x800c0000;
4360 static const uint32_t lwz_11_3
= 0x81630000;
4361 static const uint32_t lwz_11_11
= 0x816b0000;
4362 static const uint32_t lwz_11_30
= 0x817e0000;
4363 static const uint32_t lwz_12_3
= 0x81830000;
4364 static const uint32_t lwz_12_12
= 0x818c0000;
4365 static const uint32_t lwzu_0_12
= 0x840c0000;
4366 static const uint32_t mflr_0
= 0x7c0802a6;
4367 static const uint32_t mflr_11
= 0x7d6802a6;
4368 static const uint32_t mflr_12
= 0x7d8802a6;
4369 static const uint32_t mr_0_3
= 0x7c601b78;
4370 static const uint32_t mr_3_0
= 0x7c030378;
4371 static const uint32_t mtctr_0
= 0x7c0903a6;
4372 static const uint32_t mtctr_11
= 0x7d6903a6;
4373 static const uint32_t mtctr_12
= 0x7d8903a6;
4374 static const uint32_t mtlr_0
= 0x7c0803a6;
4375 static const uint32_t mtlr_11
= 0x7d6803a6;
4376 static const uint32_t mtlr_12
= 0x7d8803a6;
4377 static const uint32_t nop
= 0x60000000;
4378 static const uint32_t ori_0_0_0
= 0x60000000;
4379 static const uint32_t ori_11_11_0
= 0x616b0000;
4380 static const uint32_t ori_12_12_0
= 0x618c0000;
4381 static const uint32_t oris_12_12_0
= 0x658c0000;
4382 static const uint32_t sldi_11_11_34
= 0x796b1746;
4383 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4384 static const uint32_t srdi_0_0_2
= 0x7800f082;
4385 static const uint32_t std_0_1
= 0xf8010000;
4386 static const uint32_t std_0_12
= 0xf80c0000;
4387 static const uint32_t std_2_1
= 0xf8410000;
4388 static const uint32_t std_11_1
= 0xf9610000;
4389 static const uint32_t stfd_0_1
= 0xd8010000;
4390 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4391 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4392 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4393 static const uint32_t xor_2_12_12
= 0x7d826278;
4394 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4396 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4397 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4398 static const uint64_t pnop
= 0x0700000000000000ULL
;
4400 // Write out the PLT.
4402 template<int size
, bool big_endian
>
4404 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4406 if (!this->sym_ents_
.empty()
4407 && !parameters
->options().output_is_position_independent())
4409 const section_size_type offset
= this->offset();
4410 const section_size_type oview_size
4411 = convert_to_section_size_type(this->data_size());
4412 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4413 unsigned char* pov
= oview
;
4414 unsigned char* endpov
= oview
+ oview_size
;
4416 for (typename
std::vector
<Local_plt_ent
>::iterator e
4417 = this->sym_ents_
.begin();
4418 e
!= this->sym_ents_
.end();
4421 typename
elfcpp::Elf_types
<size
>::Elf_Addr val
;
4422 Sized_symbol
<size
>* gsym
= NULL
;
4423 Powerpc_relobj
<size
, big_endian
>* obj
= NULL
;
4424 if (e
->rsym_
== -1u)
4426 gsym
= static_cast<Sized_symbol
<size
>*>(e
->u
.gsym_
);
4427 val
= gsym
->value();
4431 obj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(e
->u
.obj_
);
4432 val
= obj
->local_symbol(e
->rsym_
)->value(obj
, 0);
4434 if (this->targ_
->abiversion() >= 2)
4436 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4442 this->targ_
->symval_for_branch(this->symtab_
, gsym
, obj
,
4444 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4446 val
= this->targ_
->toc_pointer();
4447 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4449 if (this->plt_entry_size() > 16)
4451 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, 0);
4456 gold_assert(pov
== endpov
);
4459 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4461 const section_size_type offset
= this->offset();
4462 const section_size_type oview_size
4463 = convert_to_section_size_type(this->data_size());
4464 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4465 unsigned char* pov
= oview
;
4466 unsigned char* endpov
= oview
+ oview_size
;
4468 // The address of the .glink branch table
4469 const Output_data_glink
<size
, big_endian
>* glink
4470 = this->targ_
->glink_section();
4471 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4473 while (pov
< endpov
)
4475 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4480 of
->write_output_view(offset
, oview_size
, oview
);
4484 // Create the PLT section.
4486 template<int size
, bool big_endian
>
4488 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4491 if (this->plt_
== NULL
)
4493 if (this->got_
== NULL
)
4494 this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
4496 if (this->glink_
== NULL
)
4497 make_glink_section(layout
);
4499 // Ensure that .rela.dyn always appears before .rela.plt This is
4500 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4501 // needs to include .rela.plt in its range.
4502 this->rela_dyn_section(layout
);
4504 Reloc_section
* plt_rel
= new Reloc_section(false);
4505 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4506 elfcpp::SHF_ALLOC
, plt_rel
,
4507 ORDER_DYNAMIC_PLT_RELOCS
, false);
4509 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, plt_rel
,
4511 layout
->add_output_section_data(".plt",
4513 ? elfcpp::SHT_PROGBITS
4514 : elfcpp::SHT_NOBITS
),
4515 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4522 Output_section
* rela_plt_os
= plt_rel
->output_section();
4523 rela_plt_os
->set_info_section(this->plt_
->output_section());
4527 // Create the IPLT section.
4529 template<int size
, bool big_endian
>
4531 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4534 if (this->iplt_
== NULL
)
4536 this->make_plt_section(symtab
, layout
);
4537 this->make_lplt_section(symtab
, layout
);
4539 Reloc_section
* iplt_rel
= new Reloc_section(false);
4540 if (this->rela_dyn_
->output_section())
4541 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4543 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, iplt_rel
,
4545 if (this->plt_
->output_section())
4546 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4550 // Create the LPLT section.
4552 template<int size
, bool big_endian
>
4554 Target_powerpc
<size
, big_endian
>::make_lplt_section(Symbol_table
* symtab
,
4557 if (this->lplt_
== NULL
)
4559 Reloc_section
* lplt_rel
= NULL
;
4560 if (parameters
->options().output_is_position_independent())
4561 lplt_rel
= this->rela_dyn_section(layout
);
4563 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, lplt_rel
,
4565 this->make_brlt_section(layout
);
4566 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4567 this->brlt_section_
->output_section()
4568 ->add_output_section_data(this->lplt_
);
4570 layout
->add_output_section_data(".branch_lt",
4571 elfcpp::SHT_PROGBITS
,
4572 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4579 // A section for huge long branch addresses, similar to plt section.
4581 template<int size
, bool big_endian
>
4582 class Output_data_brlt_powerpc
: public Output_section_data_build
4585 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4586 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4587 size
, big_endian
> Reloc_section
;
4589 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
)
4590 : Output_section_data_build(size
== 32 ? 4 : 8),
4596 do_adjust_output_section(Output_section
* os
)
4601 // Write to a map file.
4603 do_print_to_mapfile(Mapfile
* mapfile
) const
4604 { mapfile
->print_output_data(this, "** BRLT"); }
4607 // Write out the BRLT data.
4609 do_write(Output_file
*);
4611 Target_powerpc
<size
, big_endian
>* targ_
;
4614 // Make the branch lookup table section.
4616 template<int size
, bool big_endian
>
4618 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4620 if (size
== 64 && this->brlt_section_
== NULL
)
4622 bool is_pic
= parameters
->options().output_is_position_independent();
4625 // When PIC we can't fill in .branch_lt but must initialise at
4626 // runtime via dynamic relocations.
4627 this->rela_dyn_section(layout
);
4630 = new Output_data_brlt_powerpc
<size
, big_endian
>(this);
4631 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4632 this->plt_
->output_section()
4633 ->add_output_section_data(this->brlt_section_
);
4635 layout
->add_output_section_data(".branch_lt",
4636 elfcpp::SHT_PROGBITS
,
4637 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4638 this->brlt_section_
,
4644 // Write out .branch_lt when non-PIC.
4646 template<int size
, bool big_endian
>
4648 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4650 if (size
== 64 && !parameters
->options().output_is_position_independent())
4652 const section_size_type offset
= this->offset();
4653 const section_size_type oview_size
4654 = convert_to_section_size_type(this->data_size());
4655 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4657 this->targ_
->write_branch_lookup_table(oview
);
4658 of
->write_output_view(offset
, oview_size
, oview
);
4662 static inline uint32_t
4668 static inline uint32_t
4674 static inline uint32_t
4677 return hi(a
+ 0x8000);
4680 static inline uint64_t
4683 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4686 static inline uint64_t
4689 return (v
+ (1ULL << 33)) >> 34;
4695 static const unsigned char eh_frame_cie
[12];
4699 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4702 'z', 'R', 0, // Augmentation string.
4703 4, // Code alignment.
4704 0x80 - size
/ 8 , // Data alignment.
4706 1, // Augmentation size.
4707 (elfcpp::DW_EH_PE_pcrel
4708 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4709 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4712 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4713 static const unsigned char glink_eh_frame_fde_64v1
[] =
4715 0, 0, 0, 0, // Replaced with offset to .glink.
4716 0, 0, 0, 0, // Replaced with size of .glink.
4717 0, // Augmentation size.
4718 elfcpp::DW_CFA_advance_loc
+ 2,
4719 elfcpp::DW_CFA_register
, 65, 12,
4720 elfcpp::DW_CFA_advance_loc
+ 4,
4721 elfcpp::DW_CFA_restore_extended
, 65
4724 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4725 static const unsigned char glink_eh_frame_fde_64v2
[] =
4727 0, 0, 0, 0, // Replaced with offset to .glink.
4728 0, 0, 0, 0, // Replaced with size of .glink.
4729 0, // Augmentation size.
4730 elfcpp::DW_CFA_advance_loc
+ 2,
4731 elfcpp::DW_CFA_register
, 65, 0,
4732 elfcpp::DW_CFA_advance_loc
+ 2,
4733 elfcpp::DW_CFA_restore_extended
, 65
4736 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4738 0, 0, 0, 0, // Replaced with offset to .glink.
4739 0, 0, 0, 0, // Replaced with size of .glink.
4740 0, // Augmentation size.
4741 elfcpp::DW_CFA_advance_loc
+ 3,
4742 elfcpp::DW_CFA_register
, 65, 0,
4743 elfcpp::DW_CFA_advance_loc
+ 2,
4744 elfcpp::DW_CFA_restore_extended
, 65
4747 // Describe __glink_PLTresolve use of LR, 32-bit version.
4748 static const unsigned char glink_eh_frame_fde_32
[] =
4750 0, 0, 0, 0, // Replaced with offset to .glink.
4751 0, 0, 0, 0, // Replaced with size of .glink.
4752 0, // Augmentation size.
4753 elfcpp::DW_CFA_advance_loc
+ 2,
4754 elfcpp::DW_CFA_register
, 65, 0,
4755 elfcpp::DW_CFA_advance_loc
+ 4,
4756 elfcpp::DW_CFA_restore_extended
, 65
4759 static const unsigned char default_fde
[] =
4761 0, 0, 0, 0, // Replaced with offset to stubs.
4762 0, 0, 0, 0, // Replaced with size of stubs.
4763 0, // Augmentation size.
4764 elfcpp::DW_CFA_nop
, // Pad.
4769 template<bool big_endian
>
4771 write_insn(unsigned char* p
, uint32_t v
)
4773 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4777 static inline unsigned int
4780 if (!parameters
->options().user_set_plt_align())
4781 return size
== 64 ? 32 : 8;
4782 return 1 << parameters
->options().plt_align();
4785 // Stub_table holds information about plt and long branch stubs.
4786 // Stubs are built in an area following some input section determined
4787 // by group_sections(). This input section is converted to a relaxed
4788 // input section allowing it to be resized to accommodate the stubs
4790 template<int size
, bool big_endian
>
4791 class Stub_table
: public Output_relaxed_input_section
4796 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4797 : off_(off
), indx_(indx
), tocoff_(0), p9off_(0), tsize_ (0), iter_(0),
4798 toc_(0), notoc_(0), p9notoc_(0), r2save_(0), localentry0_(0)
4803 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4804 // toc stub, p9off_ is offset to p9notoc stub
4805 unsigned int tocoff_
: 8;
4806 unsigned int p9off_
: 8;
4807 // The size of the toc stub, used to locate blr on tls_get_addr stub.
4808 unsigned int tsize_
: 8;
4809 // Stub revision management
4810 unsigned int iter_
: 1;
4811 // The three types of stubs.
4812 unsigned int toc_
: 1;
4813 unsigned int notoc_
: 1;
4814 unsigned int p9notoc_
: 1;
4815 // Each with a possible variant saving r2 first
4816 unsigned int r2save_
: 1;
4817 // Handy cached info from symbol
4818 unsigned int localentry0_
: 1;
4820 struct Branch_stub_ent
4822 Branch_stub_ent(unsigned int off
)
4823 : off_(off
), tocoff_(0), p9off_(0), iter_(0), toc_(0), notoc_(0),
4824 p9notoc_(0), save_res_(0), other_(0)
4828 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4829 // toc stub, p9off_ is offset to p9notoc stub
4830 unsigned int tocoff_
: 8;
4831 unsigned int p9off_
: 8;
4832 // Stub revision management
4833 unsigned int iter_
: 1;
4834 // Four types of stubs.
4835 unsigned int toc_
: 1;
4836 unsigned int notoc_
: 1;
4837 unsigned int p9notoc_
: 1;
4838 unsigned int save_res_
: 1;
4839 // Handy cached info from symbol
4840 unsigned int other_
: 3;
4842 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4843 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4845 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4846 Output_section
* output_section
,
4847 const Output_section::Input_section
* owner
,
4849 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4851 ->section_addralign(owner
->shndx())),
4852 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4853 orig_data_size_(owner
->current_data_size()),
4854 plt_size_(0), last_plt_size_(0),
4855 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4856 need_save_res_(false), need_resize_(false), resizing_(false),
4859 this->set_output_section(output_section
);
4861 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4862 new_relaxed
.push_back(this);
4863 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4866 // Add a plt call stub.
4868 add_plt_call_entry(Address
,
4869 const Sized_relobj_file
<size
, big_endian
>*,
4876 add_plt_call_entry(Address
,
4877 const Sized_relobj_file
<size
, big_endian
>*,
4883 // Find a given plt call stub.
4885 find_plt_call_entry(const Symbol
*) const;
4888 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4889 unsigned int) const;
4892 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4898 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4903 // Add a long branch stub.
4905 add_long_branch_entry(unsigned int, Address
, Address
, unsigned int, bool);
4907 const Branch_stub_ent
*
4908 find_long_branch_entry(Address
) const;
4911 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4913 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4914 if (max_branch_offset
== 0)
4916 gold_assert(from
!= invalid_address
);
4917 Address loc
= off
+ this->stub_address();
4918 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4922 clear_stubs(bool all
)
4924 this->plt_call_stubs_
.clear();
4925 this->plt_size_
= 0;
4926 this->long_branch_stubs_
.clear();
4927 this->branch_size_
= 0;
4928 this->need_save_res_
= false;
4931 this->last_plt_size_
= 0;
4932 this->last_branch_size_
= 0;
4938 { return need_resize_
; }
4941 set_resizing(bool val
)
4943 this->resizing_
= val
;
4946 this->need_resize_
= false;
4947 this->plt_size_
= 0;
4948 this->branch_size_
= 0;
4949 this->need_save_res_
= false;
4954 set_address_and_size(const Output_section
* os
, Address off
)
4956 Address start_off
= off
;
4957 off
+= this->orig_data_size_
;
4958 Address my_size
= this->plt_size_
+ this->branch_size_
;
4959 if (this->need_save_res_
)
4960 my_size
+= this->targ_
->savres_section()->data_size();
4962 off
= align_address(off
, this->stub_align());
4963 // Include original section size and alignment padding in size
4964 my_size
+= off
- start_off
;
4965 // Ensure new size is always larger than min size
4966 // threshold. Alignment requirement is included in "my_size", so
4967 // increase "my_size" does not invalidate alignment.
4968 if (my_size
< this->min_size_threshold_
)
4969 my_size
= this->min_size_threshold_
;
4970 this->reset_address_and_file_offset();
4971 this->set_current_data_size(my_size
);
4972 this->set_address_and_file_offset(os
->address() + start_off
,
4973 os
->offset() + start_off
);
4978 stub_address() const
4980 return align_address(this->address() + this->orig_data_size_
,
4981 this->stub_align());
4987 return align_address(this->offset() + this->orig_data_size_
,
4988 this->stub_align());
4993 { return this->plt_size_
; }
4997 { return this->branch_size_
; }
5000 set_min_size_threshold(Address min_size
)
5001 { this->min_size_threshold_
= min_size
; }
5004 define_stub_syms(Symbol_table
*);
5009 Output_section
* os
= this->output_section();
5010 if (os
->addralign() < this->stub_align())
5012 os
->set_addralign(this->stub_align());
5013 // FIXME: get rid of the insane checkpointing.
5014 // We can't increase alignment of the input section to which
5015 // stubs are attached; The input section may be .init which
5016 // is pasted together with other .init sections to form a
5017 // function. Aligning might insert zero padding resulting in
5018 // sigill. However we do need to increase alignment of the
5019 // output section so that the align_address() on offset in
5020 // set_address_and_size() adds the same padding as the
5021 // align_address() on address in stub_address().
5022 // What's more, we need this alignment for the layout done in
5023 // relaxation_loop_body() so that the output section starts at
5024 // a suitably aligned address.
5025 os
->checkpoint_set_addralign(this->stub_align());
5027 if (this->last_plt_size_
!= this->plt_size_
5028 || this->last_branch_size_
!= this->branch_size_
)
5030 this->last_plt_size_
= this->plt_size_
;
5031 this->last_branch_size_
= this->branch_size_
;
5037 // Add .eh_frame info for this stub section.
5039 add_eh_frame(Layout
* layout
);
5041 // Remove .eh_frame info for this stub section.
5043 remove_eh_frame(Layout
* layout
);
5045 Target_powerpc
<size
, big_endian
>*
5051 class Plt_stub_key_hash
;
5052 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
5053 Plt_stub_key_hash
> Plt_stub_entries
;
5054 class Branch_stub_key
;
5055 class Branch_stub_key_hash
;
5056 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
5057 Branch_stub_key_hash
> Branch_stub_entries
;
5059 // Alignment of stub section.
5063 unsigned int min_align
= size
== 64 ? 32 : 16;
5064 unsigned int user_align
= 1 << parameters
->options().plt_align();
5065 return std::max(user_align
, min_align
);
5068 // Return the plt offset for the given call stub.
5070 plt_off(typename
Plt_stub_entries::const_iterator p
,
5071 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
5073 const Symbol
* gsym
= p
->first
.sym_
;
5075 return this->targ_
->plt_off(gsym
, sec
);
5078 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
5079 unsigned int local_sym_index
= p
->first
.locsym_
;
5080 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
5084 // Size of a given plt call stub.
5086 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
5089 plt_call_align(unsigned int bytes
) const
5091 unsigned int align
= param_plt_align
<size
>();
5092 return (bytes
+ align
- 1) & -align
;
5095 // Return long branch stub size.
5097 branch_stub_size(typename
Branch_stub_entries::iterator p
,
5101 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
5104 build_tls_opt_tail(unsigned char* p
);
5107 plt_error(const Plt_stub_key
& p
);
5111 do_write(Output_file
*);
5113 // Plt call stub keys.
5117 Plt_stub_key(const Symbol
* sym
)
5118 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5121 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5122 unsigned int locsym_index
)
5123 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5126 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5128 unsigned int r_type
,
5130 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5133 this->addend_
= addend
;
5134 else if (parameters
->options().output_is_position_independent()
5135 && (r_type
== elfcpp::R_PPC_PLTREL24
5136 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5138 this->addend_
= addend
;
5139 if (this->addend_
>= 32768)
5140 this->object_
= object
;
5144 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5145 unsigned int locsym_index
,
5146 unsigned int r_type
,
5148 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5151 this->addend_
= addend
;
5152 else if (parameters
->options().output_is_position_independent()
5153 && (r_type
== elfcpp::R_PPC_PLTREL24
5154 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5155 this->addend_
= addend
;
5158 bool operator==(const Plt_stub_key
& that
) const
5160 return (this->sym_
== that
.sym_
5161 && this->object_
== that
.object_
5162 && this->addend_
== that
.addend_
5163 && this->locsym_
== that
.locsym_
);
5167 const Sized_relobj_file
<size
, big_endian
>* object_
;
5168 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5169 unsigned int locsym_
;
5172 class Plt_stub_key_hash
5175 size_t operator()(const Plt_stub_key
& ent
) const
5177 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5178 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5184 // Long branch stub keys.
5185 class Branch_stub_key
5188 Branch_stub_key(Address to
)
5192 bool operator==(const Branch_stub_key
& that
) const
5194 return this->dest_
== that
.dest_
;
5200 class Branch_stub_key_hash
5203 size_t operator()(const Branch_stub_key
& key
) const
5204 { return key
.dest_
; }
5207 // In a sane world this would be a global.
5208 Target_powerpc
<size
, big_endian
>* targ_
;
5209 // Map sym/object/addend to stub offset.
5210 Plt_stub_entries plt_call_stubs_
;
5211 // Map destination address to stub offset.
5212 Branch_stub_entries long_branch_stubs_
;
5213 // size of input section
5214 section_size_type orig_data_size_
;
5216 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5217 // Some rare cases cause (PR/20529) fluctuation in stub table
5218 // size, which leads to an endless relax loop. This is to be fixed
5219 // by, after the first few iterations, allowing only increase of
5220 // stub table size. This variable sets the minimal possible size of
5221 // a stub table, it is zero for the first few iterations, then
5222 // increases monotonically.
5223 Address min_size_threshold_
;
5224 // Set if this stub group needs a copy of out-of-line register
5225 // save/restore functions.
5226 bool need_save_res_
;
5227 // Set when notoc_/r2save_ changes after sizing a stub
5229 // Set when resizing stubs
5231 // Per stub table unique identifier.
5235 // Add a plt call stub, if we do not already have one for this
5236 // sym/object/addend combo.
5238 template<int size
, bool big_endian
>
5240 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5242 const Sized_relobj_file
<size
, big_endian
>* object
,
5244 unsigned int r_type
,
5248 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5249 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5250 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5251 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5255 && this->targ_
->is_elfv2_localentry0(gsym
))
5257 p
.first
->second
.localentry0_
= 1;
5258 this->targ_
->set_has_localentry0();
5260 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5261 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5263 if (this->targ_
->power10_stubs()
5264 && (!this->targ_
->power10_stubs_auto()
5265 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5267 if (!p
.second
&& !p
.first
->second
.notoc_
)
5268 this->need_resize_
= true;
5269 p
.first
->second
.notoc_
= 1;
5273 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5274 this->need_resize_
= true;
5275 p
.first
->second
.p9notoc_
= 1;
5280 if (!p
.second
&& !p
.first
->second
.toc_
)
5281 this->need_resize_
= true;
5282 p
.first
->second
.toc_
= 1;
5283 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5285 if (!p
.second
&& !p
.first
->second
.r2save_
)
5286 this->need_resize_
= true;
5287 p
.first
->second
.r2save_
= 1;
5291 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5293 if (this->resizing_
)
5295 p
.first
->second
.iter_
= 1;
5296 p
.first
->second
.off_
= this->plt_size_
;
5298 this->plt_size_
+= this->plt_call_size(p
.first
);
5299 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5300 this->targ_
->set_has_tls_get_addr_opt();
5302 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5305 template<int size
, bool big_endian
>
5307 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5309 const Sized_relobj_file
<size
, big_endian
>* object
,
5310 unsigned int locsym_index
,
5311 unsigned int r_type
,
5315 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5316 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5317 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5318 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5322 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5324 p
.first
->second
.localentry0_
= 1;
5325 this->targ_
->set_has_localentry0();
5327 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5328 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5330 if (this->targ_
->power10_stubs()
5331 && (!this->targ_
->power10_stubs_auto()
5332 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5334 if (!p
.second
&& !p
.first
->second
.notoc_
)
5335 this->need_resize_
= true;
5336 p
.first
->second
.notoc_
= 1;
5340 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5341 this->need_resize_
= true;
5342 p
.first
->second
.p9notoc_
= 1;
5347 if (!p
.second
&& !p
.first
->second
.toc_
)
5348 this->need_resize_
= true;
5349 p
.first
->second
.toc_
= 1;
5350 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5352 if (!p
.second
&& !p
.first
->second
.r2save_
)
5353 this->need_resize_
= true;
5354 p
.first
->second
.r2save_
= 1;
5358 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5360 if (this->resizing_
)
5362 p
.first
->second
.iter_
= 1;
5363 p
.first
->second
.off_
= this->plt_size_
;
5365 this->plt_size_
+= this->plt_call_size(p
.first
);
5367 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5370 // Find a plt call stub.
5372 template<int size
, bool big_endian
>
5373 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5374 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5375 const Sized_relobj_file
<size
, big_endian
>* object
,
5377 unsigned int r_type
,
5378 Address addend
) const
5380 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5381 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5382 if (p
== this->plt_call_stubs_
.end())
5387 template<int size
, bool big_endian
>
5388 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5389 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5391 Plt_stub_key
key(gsym
);
5392 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5393 if (p
== this->plt_call_stubs_
.end())
5398 template<int size
, bool big_endian
>
5399 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5400 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5401 const Sized_relobj_file
<size
, big_endian
>* object
,
5402 unsigned int locsym_index
,
5403 unsigned int r_type
,
5404 Address addend
) const
5406 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5407 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5408 if (p
== this->plt_call_stubs_
.end())
5413 template<int size
, bool big_endian
>
5414 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5415 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5416 const Sized_relobj_file
<size
, big_endian
>* object
,
5417 unsigned int locsym_index
) const
5419 Plt_stub_key
key(object
, locsym_index
);
5420 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5421 if (p
== this->plt_call_stubs_
.end())
5426 // Add a long branch stub if we don't already have one to given
5429 template<int size
, bool big_endian
>
5431 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5432 unsigned int r_type
,
5438 Branch_stub_key
key(to
);
5439 Branch_stub_ent
ent(this->branch_size_
);
5440 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5441 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5444 if (!p
.second
&& !p
.first
->second
.save_res_
)
5445 this->need_resize_
= true;
5446 p
.first
->second
.save_res_
= true;
5449 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5450 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
))
5452 if (this->targ_
->power10_stubs()
5453 && (!this->targ_
->power10_stubs_auto()
5454 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5456 if (!p
.second
&& !p
.first
->second
.notoc_
)
5457 this->need_resize_
= true;
5458 p
.first
->second
.notoc_
= true;
5462 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5463 this->need_resize_
= true;
5464 p
.first
->second
.p9notoc_
= true;
5469 if (!p
.second
&& !p
.first
->second
.toc_
)
5470 this->need_resize_
= true;
5471 p
.first
->second
.toc_
= true;
5473 if (size
== 64 && p
.first
->second
.other_
== 0)
5474 p
.first
->second
.other_
= other
;
5475 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5477 if (this->resizing_
)
5479 p
.first
->second
.iter_
= 1;
5480 p
.first
->second
.off_
= this->branch_size_
;
5483 this->need_save_res_
= true;
5486 bool need_lt
= false;
5487 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5488 this->branch_size_
+= stub_size
;
5489 if (size
== 64 && need_lt
)
5490 this->targ_
->add_branch_lookup_table(to
);
5493 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5496 // Find long branch stub offset.
5498 template<int size
, bool big_endian
>
5499 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5500 Stub_table
<size
, big_endian
>::find_long_branch_entry(Address to
) const
5502 Branch_stub_key
key(to
);
5503 typename
Branch_stub_entries::const_iterator p
5504 = this->long_branch_stubs_
.find(key
);
5505 if (p
== this->long_branch_stubs_
.end())
5510 template<bool big_endian
>
5512 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5516 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5517 else if (delta
< 256)
5519 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5520 fde
.push_back(delta
);
5522 else if (delta
< 65536)
5524 fde
.resize(fde
.size() + 3);
5525 unsigned char *p
= &*fde
.end() - 3;
5526 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5527 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5531 fde
.resize(fde
.size() + 5);
5532 unsigned char *p
= &*fde
.end() - 5;
5533 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5534 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5538 template<typename T
>
5540 stub_sort(T s1
, T s2
)
5542 return s1
->second
.off_
< s2
->second
.off_
;
5545 // Add .eh_frame info for this stub section. Unlike other linker
5546 // generated .eh_frame this is added late in the link, because we
5547 // only want the .eh_frame info if this particular stub section is
5550 template<int size
, bool big_endian
>
5552 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5555 || !parameters
->options().ld_generated_unwind_info())
5558 // Since we add stub .eh_frame info late, it must be placed
5559 // after all other linker generated .eh_frame info so that
5560 // merge mapping need not be updated for input sections.
5561 // There is no provision to use a different CIE to that used
5563 if (!this->targ_
->has_glink())
5566 typedef typename
Plt_stub_entries::iterator plt_iter
;
5567 std::vector
<plt_iter
> calls
;
5568 if (!this->plt_call_stubs_
.empty())
5569 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5570 cs
!= this->plt_call_stubs_
.end();
5572 if (cs
->second
.p9notoc_
5574 && cs
->second
.r2save_
5575 && !cs
->second
.localentry0_
5576 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)))
5577 calls
.push_back(cs
);
5578 if (calls
.size() > 1)
5579 std::stable_sort(calls
.begin(), calls
.end(),
5580 stub_sort
<plt_iter
>);
5582 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5583 std::vector
<branch_iter
> branches
;
5584 if (!this->long_branch_stubs_
.empty()
5585 && !this->targ_
->power10_stubs())
5586 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5587 bs
!= this->long_branch_stubs_
.end();
5589 if (bs
->second
.notoc_
)
5590 branches
.push_back(bs
);
5591 if (branches
.size() > 1)
5592 std::stable_sort(branches
.begin(), branches
.end(),
5593 stub_sort
<branch_iter
>);
5595 if (calls
.empty() && branches
.empty())
5598 unsigned int last_eh_loc
= 0;
5599 // offset pcrel sdata4, size udata4, and augmentation size byte.
5600 std::vector
<unsigned char> fde(9, 0);
5602 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5604 plt_iter cs
= calls
[i
];
5605 unsigned int off
= cs
->second
.off_
;
5606 // The __tls_get_addr_opt call stub needs to describe where
5607 // it saves LR, to support exceptions that might be thrown
5608 // from __tls_get_addr, and to support asynchronous exceptions.
5609 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5613 && cs
->second
.r2save_
5614 && !cs
->second
.localentry0_
)
5616 off
+= cs
->second
.tocoff_
+ 2 * 4;
5617 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5618 fde
.resize(fde
.size() + 6);
5619 unsigned char* p
= &*fde
.end() - 6;
5620 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5622 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5623 unsigned int delta
= cs
->second
.tsize_
- 9 * 4 - 4;
5624 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5625 *p
++ = elfcpp::DW_CFA_restore_extended
;
5627 last_eh_loc
= off
+ delta
;
5628 off
= cs
->second
.off_
+ 7 * 4;
5631 // notoc stubs also should describe LR changes, to support
5632 // asynchronous exceptions.
5633 if (cs
->second
.p9notoc_
)
5635 off
+= cs
->second
.p9off_
;
5636 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5637 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5638 fde
.resize(fde
.size() + 6);
5639 unsigned char* p
= &*fde
.end() - 6;
5640 *p
++ = elfcpp::DW_CFA_register
;
5643 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5644 *p
++ = elfcpp::DW_CFA_restore_extended
;
5646 last_eh_loc
= off
+ 8;
5650 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5652 branch_iter bs
= branches
[i
];
5653 unsigned int off
= bs
->second
.off_
+ 8;
5654 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5655 fde
.resize(fde
.size() + 6);
5656 unsigned char* p
= &*fde
.end() - 6;
5657 *p
++ = elfcpp::DW_CFA_register
;
5660 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5661 *p
++ = elfcpp::DW_CFA_restore_extended
;
5663 last_eh_loc
= off
+ 8;
5666 layout
->add_eh_frame_for_plt(this,
5667 Eh_cie
<size
>::eh_frame_cie
,
5668 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5669 &*fde
.begin(), fde
.size());
5672 template<int size
, bool big_endian
>
5674 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5677 && parameters
->options().ld_generated_unwind_info()
5678 && this->targ_
->has_glink())
5679 layout
->remove_eh_frame_for_plt(this,
5680 Eh_cie
<size
>::eh_frame_cie
,
5681 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5684 // A class to handle .glink.
5686 template<int size
, bool big_endian
>
5687 class Output_data_glink
: public Output_section_data
5690 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5691 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5693 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5694 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5695 end_branch_table_(), ge_size_(0)
5699 add_eh_frame(Layout
* layout
);
5702 add_global_entry(const Symbol
*);
5705 find_global_entry(const Symbol
*) const;
5708 global_entry_align(unsigned int off
) const
5710 unsigned int align
= param_plt_align
<size
>();
5711 return (off
+ align
- 1) & -align
;
5715 global_entry_off() const
5717 return this->global_entry_align(this->end_branch_table_
);
5721 global_entry_address() const
5723 gold_assert(this->is_data_size_valid());
5724 return this->address() + this->global_entry_off();
5728 pltresolve_size() const
5732 + (this->targ_
->abiversion() < 2 ? 11 * 4
5733 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5738 // Write to a map file.
5740 do_print_to_mapfile(Mapfile
* mapfile
) const
5741 { mapfile
->print_output_data(this, _("** glink")); }
5745 set_final_data_size();
5749 do_write(Output_file
*);
5751 // Allows access to .got and .plt for do_write.
5752 Target_powerpc
<size
, big_endian
>* targ_
;
5754 // Map sym to stub offset.
5755 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5756 Global_entry_stub_entries global_entry_stubs_
;
5758 unsigned int end_branch_table_
, ge_size_
;
5761 template<int size
, bool big_endian
>
5763 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5765 if (!parameters
->options().ld_generated_unwind_info())
5770 if (this->targ_
->abiversion() < 2)
5771 layout
->add_eh_frame_for_plt(this,
5772 Eh_cie
<64>::eh_frame_cie
,
5773 sizeof (Eh_cie
<64>::eh_frame_cie
),
5774 glink_eh_frame_fde_64v1
,
5775 sizeof (glink_eh_frame_fde_64v1
));
5776 else if (this->targ_
->has_localentry0())
5777 layout
->add_eh_frame_for_plt(this,
5778 Eh_cie
<64>::eh_frame_cie
,
5779 sizeof (Eh_cie
<64>::eh_frame_cie
),
5780 glink_eh_frame_fde_64v2_localentry0
,
5781 sizeof (glink_eh_frame_fde_64v2
));
5783 layout
->add_eh_frame_for_plt(this,
5784 Eh_cie
<64>::eh_frame_cie
,
5785 sizeof (Eh_cie
<64>::eh_frame_cie
),
5786 glink_eh_frame_fde_64v2
,
5787 sizeof (glink_eh_frame_fde_64v2
));
5791 // 32-bit .glink can use the default since the CIE return
5792 // address reg, LR, is valid.
5793 layout
->add_eh_frame_for_plt(this,
5794 Eh_cie
<32>::eh_frame_cie
,
5795 sizeof (Eh_cie
<32>::eh_frame_cie
),
5797 sizeof (default_fde
));
5798 // Except where LR is used in a PIC __glink_PLTresolve.
5799 if (parameters
->options().output_is_position_independent())
5800 layout
->add_eh_frame_for_plt(this,
5801 Eh_cie
<32>::eh_frame_cie
,
5802 sizeof (Eh_cie
<32>::eh_frame_cie
),
5803 glink_eh_frame_fde_32
,
5804 sizeof (glink_eh_frame_fde_32
));
5808 template<int size
, bool big_endian
>
5810 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5812 unsigned int off
= this->global_entry_align(this->ge_size_
);
5813 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5814 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5816 this->ge_size_
= off
+ 16;
5819 template<int size
, bool big_endian
>
5820 typename Output_data_glink
<size
, big_endian
>::Address
5821 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5823 typename
Global_entry_stub_entries::const_iterator p
5824 = this->global_entry_stubs_
.find(gsym
);
5825 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5828 template<int size
, bool big_endian
>
5830 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5832 unsigned int count
= this->targ_
->plt_entry_count();
5833 section_size_type total
= 0;
5839 // space for branch table
5840 total
+= 4 * (count
- 1);
5842 total
+= -total
& 15;
5843 total
+= this->pltresolve_size();
5847 total
+= this->pltresolve_size();
5849 // space for branch table
5851 if (this->targ_
->abiversion() < 2)
5855 total
+= 4 * (count
- 0x8000);
5859 this->end_branch_table_
= total
;
5860 total
= this->global_entry_align(total
);
5861 total
+= this->ge_size_
;
5863 this->set_data_size(total
);
5866 // Define symbols on stubs, identifying the stub.
5868 template<int size
, bool big_endian
>
5870 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5872 if (!this->plt_call_stubs_
.empty())
5874 // The key for the plt call stub hash table includes addresses,
5875 // therefore traversal order depends on those addresses, which
5876 // can change between runs if gold is a PIE. Unfortunately the
5877 // output .symtab ordering depends on the order in which symbols
5878 // are added to the linker symtab. We want reproducible output
5879 // so must sort the call stub symbols.
5880 typedef typename
Plt_stub_entries::iterator plt_iter
;
5881 std::vector
<plt_iter
> sorted
;
5882 sorted
.resize(this->plt_call_stubs_
.size());
5884 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5885 cs
!= this->plt_call_stubs_
.end();
5887 sorted
[cs
->second
.indx_
] = cs
;
5889 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5891 plt_iter cs
= sorted
[i
];
5894 if (cs
->first
.addend_
!= 0)
5895 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5898 if (cs
->first
.object_
)
5900 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5901 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5902 sprintf(obj
, "%x:", ppcobj
->uniq());
5905 const char *symname
;
5906 if (cs
->first
.sym_
== NULL
)
5908 sprintf(localname
, "%x", cs
->first
.locsym_
);
5909 symname
= localname
;
5911 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5912 symname
= this->targ_
->tls_get_addr_opt()->name();
5914 symname
= cs
->first
.sym_
->name();
5915 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5916 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5918 = this->stub_address() - this->address() + cs
->second
.off_
;
5919 unsigned int stub_size
= this->plt_call_size(cs
);
5920 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5924 typedef typename
Branch_stub_entries::iterator branch_iter
;
5925 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5926 bs
!= this->long_branch_stubs_
.end();
5929 if (bs
->second
.save_res_
)
5932 char* name
= new char[8 + 13 + 16 + 1];
5933 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5934 static_cast<unsigned long long>(bs
->first
.dest_
));
5935 Address value
= (this->stub_address() - this->address()
5936 + this->plt_size_
+ bs
->second
.off_
);
5937 bool need_lt
= false;
5938 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5939 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5943 // Emit the start of a __tls_get_addr_opt plt call stub.
5945 template<int size
, bool big_endian
>
5947 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5950 unsigned char* p
= *pp
;
5953 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5955 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5957 write_insn
<big_endian
>(p
, mr_0_3
);
5959 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5961 write_insn
<big_endian
>(p
, add_3_12_13
);
5963 write_insn
<big_endian
>(p
, beqlr
);
5965 write_insn
<big_endian
>(p
, mr_3_0
);
5969 write_insn
<big_endian
>(p
, mflr_11
);
5971 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5977 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5979 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5981 write_insn
<big_endian
>(p
, mr_0_3
);
5983 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5985 write_insn
<big_endian
>(p
, add_3_12_2
);
5987 write_insn
<big_endian
>(p
, beqlr
);
5989 write_insn
<big_endian
>(p
, mr_3_0
);
5991 write_insn
<big_endian
>(p
, nop
);
5997 // Emit the tail of a __tls_get_addr_opt plt call stub.
5999 template<int size
, bool big_endian
>
6001 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
6003 write_insn
<big_endian
>(p
, bctrl
);
6005 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
6007 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
6009 write_insn
<big_endian
>(p
, mtlr_11
);
6011 write_insn
<big_endian
>(p
, blr
);
6014 // Emit pc-relative plt call stub code.
6016 template<bool big_endian
>
6017 static unsigned char*
6018 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
6021 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6026 write_insn
<big_endian
>(p
, nop
);
6034 write_insn
<big_endian
>(p
, insn
>> 32);
6036 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6038 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6041 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
6045 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6048 insn
= paddi_12_pc
| d34(off
);
6049 write_insn
<big_endian
>(p
, insn
>> 32);
6051 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6055 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6059 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6061 write_insn
<big_endian
>(p
, add_12_11_12
);
6066 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
6068 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
6072 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6075 insn
= paddi_12_pc
| d34(off
);
6076 write_insn
<big_endian
>(p
, insn
>> 32);
6078 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6082 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6086 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6088 write_insn
<big_endian
>(p
, add_12_11_12
);
6094 // Gets the address of a label (1:) in r11 and builds an offset in r12,
6095 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
6100 // lis %r12,xxx-1b@highest
6101 // ori %r12,%r12,xxx-1b@higher
6102 // sldi %r12,%r12,32
6103 // oris %r12,%r12,xxx-1b@high
6104 // ori %r12,%r12,xxx-1b@l
6105 // add/ldx %r12,%r11,%r12
6107 template<bool big_endian
>
6108 static unsigned char*
6109 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
6111 write_insn
<big_endian
>(p
, mflr_12
);
6113 write_insn
<big_endian
>(p
, bcl_20_31
);
6115 write_insn
<big_endian
>(p
, mflr_11
);
6117 write_insn
<big_endian
>(p
, mtlr_12
);
6119 if (off
+ 0x8000 < 0x10000)
6122 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6124 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
6126 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6128 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
6131 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6133 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
6137 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
6139 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
6144 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
6146 if (((off
>> 32) & 0xffff) != 0)
6148 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
6152 if (((off
>> 32) & 0xffffffffULL
) != 0)
6154 write_insn
<big_endian
>(p
, sldi_12_12_32
);
6159 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
6164 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6168 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6170 write_insn
<big_endian
>(p
, add_12_11_12
);
6176 // Size of a given plt call stub.
6178 template<int size
, bool big_endian
>
6180 Stub_table
<size
, big_endian
>::plt_call_size(
6181 typename
Plt_stub_entries::iterator p
) const
6185 unsigned int bytes
= 4 * 4;
6186 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6188 return this->plt_call_align(bytes
);
6191 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6192 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6193 plt_addr
+= plt
->address();
6194 if (this->targ_
->power10_stubs()
6195 && this->targ_
->power10_stubs_auto())
6197 unsigned int bytes
= 0;
6198 if (p
->second
.notoc_
)
6200 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6202 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6203 uint64_t odd
= from
& 4;
6204 uint64_t off
= plt_addr
- from
;
6205 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6206 bytes
+= odd
+ 4 * 4;
6207 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6211 bytes
= this->plt_call_align(bytes
);
6215 p
->second
.tocoff_
= bytes
;
6216 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6219 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6220 bytes
+= 2 * 4 + 4 * 4;
6222 if (p
->second
.r2save_
)
6224 uint64_t got_addr
= this->targ_
->toc_pointer();
6225 uint64_t off
= plt_addr
- got_addr
;
6226 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6227 p
->second
.tsize_
= bytes
- p
->second
.tocoff_
;
6228 bytes
= this->plt_call_align(bytes
);
6230 if (p
->second
.p9notoc_
)
6232 p
->second
.p9off_
= bytes
;
6233 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6235 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6236 uint64_t off
= plt_addr
- from
;
6237 if (off
+ 0x8000 < 0x10000)
6239 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6244 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6245 && ((off
>> 32) & 0xffff) != 0)
6247 if (((off
>> 32) & 0xffffffffULL
) != 0)
6254 bytes
= this->plt_call_align(bytes
);
6260 unsigned int bytes
= 0;
6261 unsigned int tail
= 0;
6262 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6265 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6272 if (p
->second
.r2save_
)
6275 if (this->targ_
->power10_stubs())
6277 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6278 uint64_t odd
= from
& 4;
6279 uint64_t off
= plt_addr
- from
;
6280 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6281 bytes
+= odd
+ 4 * 4;
6282 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6286 return this->plt_call_align(bytes
+ tail
);
6289 if (p
->second
.p9notoc_
)
6291 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6292 uint64_t off
= plt_addr
- from
;
6293 if (off
+ 0x8000 < 0x10000)
6295 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6300 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6301 && ((off
>> 32) & 0xffff) != 0)
6303 if (((off
>> 32) & 0xffffffffULL
) != 0)
6310 return this->plt_call_align(bytes
+ tail
);
6313 uint64_t got_addr
= this->targ_
->toc_pointer();
6314 uint64_t off
= plt_addr
- got_addr
;
6315 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6316 if (this->targ_
->abiversion() < 2)
6318 bool static_chain
= parameters
->options().plt_static_chain();
6319 bool thread_safe
= this->targ_
->plt_thread_safe();
6323 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6325 return this->plt_call_align(bytes
+ tail
);
6329 // Return long branch stub size.
6331 template<int size
, bool big_endian
>
6333 Stub_table
<size
, big_endian
>::branch_stub_size(
6334 typename
Branch_stub_entries::iterator p
,
6337 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6340 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6342 if (parameters
->options().output_is_position_independent())
6347 uint64_t off
= p
->first
.dest_
- loc
;
6348 unsigned int bytes
= 0;
6349 if (p
->second
.notoc_
)
6351 if (this->targ_
->power10_stubs())
6353 Address odd
= loc
& 4;
6354 if (off
+ (1 << 25) < 2 << 25)
6356 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6358 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6362 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6364 p
->second
.tocoff_
= bytes
;
6369 if (off
+ 0x8000 < 0x10000)
6371 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6373 if (off
+ 24 + (1 << 25) < 2 << 25)
6379 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6380 && ((off
>> 32) & 0xffff) != 0)
6382 if (((off
>> 32) & 0xffffffffULL
) != 0)
6392 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6393 if (off
+ (1 << 25) < 2 << 25)
6395 if (!this->targ_
->power10_stubs()
6396 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6401 template<int size
, bool big_endian
>
6403 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6406 gold_error(_("linkage table error against `%s'"),
6407 p
.sym_
->demangled_name().c_str());
6409 gold_error(_("linkage table error against `%s:[local %u]'"),
6410 p
.object_
->name().c_str(),
6414 // Write out plt and long branch stub code.
6416 template<int size
, bool big_endian
>
6418 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6420 if (this->plt_call_stubs_
.empty()
6421 && this->long_branch_stubs_
.empty())
6424 const section_size_type start_off
= this->offset();
6425 const section_size_type off
= this->stub_offset();
6426 const section_size_type oview_size
=
6427 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6428 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6432 && this->targ_
->power10_stubs())
6434 if (!this->plt_call_stubs_
.empty())
6436 // Write out plt call stubs.
6437 typename
Plt_stub_entries::const_iterator cs
;
6438 for (cs
= this->plt_call_stubs_
.begin();
6439 cs
!= this->plt_call_stubs_
.end();
6442 p
= oview
+ cs
->second
.off_
;
6443 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6444 Address pltoff
= this->plt_off(cs
, &plt
);
6445 Address plt_addr
= pltoff
+ plt
->address();
6446 if (this->targ_
->power10_stubs_auto())
6448 if (cs
->second
.notoc_
)
6450 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6451 this->build_tls_opt_head(&p
, false);
6452 Address from
= this->stub_address() + (p
- oview
);
6453 Address delta
= plt_addr
- from
;
6454 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6456 write_insn
<big_endian
>(p
, mtctr_12
);
6458 write_insn
<big_endian
>(p
, bctr
);
6460 p
= oview
+ this->plt_call_align(p
- oview
);
6462 if (cs
->second
.toc_
)
6464 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6467 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6468 this->build_tls_opt_head(&p
, save_lr
);
6470 Address got_addr
= this->targ_
->toc_pointer();
6471 Address off
= plt_addr
- got_addr
;
6473 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6474 this->plt_error(cs
->first
);
6476 if (cs
->second
.r2save_
)
6478 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6483 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6485 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6490 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6493 write_insn
<big_endian
>(p
, mtctr_12
);
6495 if (cs
->second
.r2save_
6496 && !cs
->second
.localentry0_
6497 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6498 this->build_tls_opt_tail(p
);
6500 write_insn
<big_endian
>(p
, bctr
);
6502 if (cs
->second
.p9notoc_
)
6504 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6505 this->build_tls_opt_head(&p
, false);
6506 Address from
= this->stub_address() + (p
- oview
);
6507 Address delta
= plt_addr
- from
;
6508 p
= build_notoc_offset
<big_endian
>(p
, delta
, true);
6509 write_insn
<big_endian
>(p
, mtctr_12
);
6511 write_insn
<big_endian
>(p
, bctr
);
6513 p
= oview
+ this->plt_call_align(p
- oview
);
6518 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6521 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6522 this->build_tls_opt_head(&p
, save_lr
);
6524 if (cs
->second
.r2save_
)
6526 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6529 Address from
= this->stub_address() + (p
- oview
);
6530 Address delta
= plt_addr
- from
;
6531 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6532 write_insn
<big_endian
>(p
, mtctr_12
);
6534 if (cs
->second
.r2save_
6535 && !cs
->second
.localentry0_
6536 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6537 this->build_tls_opt_tail(p
);
6539 write_insn
<big_endian
>(p
, bctr
);
6544 // Write out long branch stubs.
6545 typename
Branch_stub_entries::const_iterator bs
;
6546 for (bs
= this->long_branch_stubs_
.begin();
6547 bs
!= this->long_branch_stubs_
.end();
6550 if (bs
->second
.save_res_
)
6552 Address off
= this->plt_size_
+ bs
->second
.off_
;
6554 Address loc
= this->stub_address() + off
;
6555 Address delta
= bs
->first
.dest_
- loc
;
6556 if (this->targ_
->power10_stubs_auto())
6558 if (bs
->second
.notoc_
)
6560 unsigned char* startp
= p
;
6561 p
= build_power10_offset
<big_endian
>(p
, delta
,
6563 delta
-= p
- startp
;
6565 if (delta
+ (1 << 25) < 2 << 25)
6566 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6569 write_insn
<big_endian
>(p
, mtctr_12
);
6571 write_insn
<big_endian
>(p
, bctr
);
6574 delta
-= p
- startp
;
6576 if (bs
->second
.toc_
)
6578 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6579 if (delta
+ (1 << 25) >= 2 << 25)
6582 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6583 gold_assert(brlt_addr
!= invalid_address
);
6584 brlt_addr
+= this->targ_
->brlt_section()->address();
6585 Address got_addr
= this->targ_
->toc_pointer();
6586 Address brltoff
= brlt_addr
- got_addr
;
6587 if (ha(brltoff
) == 0)
6589 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6594 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6596 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6600 if (delta
+ (1 << 25) < 2 << 25)
6601 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6604 write_insn
<big_endian
>(p
, mtctr_12
);
6606 write_insn
<big_endian
>(p
, bctr
);
6609 if (bs
->second
.p9notoc_
)
6611 unsigned char* startp
= p
;
6612 p
= build_notoc_offset
<big_endian
>(p
, delta
, false);
6613 delta
-= p
- startp
;
6615 if (delta
+ (1 << 25) < 2 << 25)
6616 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6619 write_insn
<big_endian
>(p
, mtctr_12
);
6621 write_insn
<big_endian
>(p
, bctr
);
6624 delta
-= p
- startp
;
6629 if (!bs
->second
.notoc_
)
6630 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6631 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6633 unsigned char* startp
= p
;
6634 p
= build_power10_offset
<big_endian
>(p
, delta
,
6636 delta
-= p
- startp
;
6638 if (delta
+ (1 << 25) < 2 << 25)
6639 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6642 write_insn
<big_endian
>(p
, mtctr_12
);
6644 write_insn
<big_endian
>(p
, bctr
);
6649 else if (size
== 64)
6652 if (!this->plt_call_stubs_
.empty()
6653 && this->targ_
->abiversion() >= 2)
6655 // Write out plt call stubs for ELFv2.
6656 typename
Plt_stub_entries::const_iterator cs
;
6657 for (cs
= this->plt_call_stubs_
.begin();
6658 cs
!= this->plt_call_stubs_
.end();
6661 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6662 Address pltoff
= this->plt_off(cs
, &plt
);
6663 Address plt_addr
= pltoff
+ plt
->address();
6665 p
= oview
+ cs
->second
.off_
;
6666 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6668 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6669 this->build_tls_opt_head(&p
, save_lr
);
6671 if (cs
->second
.r2save_
)
6673 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6676 if (cs
->second
.p9notoc_
)
6678 Address from
= this->stub_address() + (p
- oview
) + 8;
6679 Address off
= plt_addr
- from
;
6680 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6684 Address got_addr
= this->targ_
->toc_pointer();
6685 Address off
= plt_addr
- got_addr
;
6687 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6688 this->plt_error(cs
->first
);
6692 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6694 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6699 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6703 write_insn
<big_endian
>(p
, mtctr_12
);
6705 if (cs
->second
.r2save_
6706 && !cs
->second
.localentry0_
6707 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6708 this->build_tls_opt_tail(p
);
6710 write_insn
<big_endian
>(p
, bctr
);
6713 else if (!this->plt_call_stubs_
.empty())
6715 // Write out plt call stubs for ELFv1.
6716 typename
Plt_stub_entries::const_iterator cs
;
6717 for (cs
= this->plt_call_stubs_
.begin();
6718 cs
!= this->plt_call_stubs_
.end();
6721 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6722 Address pltoff
= this->plt_off(cs
, &plt
);
6723 Address plt_addr
= pltoff
+ plt
->address();
6724 Address got_addr
= this->targ_
->toc_pointer();
6725 Address off
= plt_addr
- got_addr
;
6727 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6728 || cs
->second
.notoc_
)
6729 this->plt_error(cs
->first
);
6731 bool static_chain
= parameters
->options().plt_static_chain();
6732 bool thread_safe
= this->targ_
->plt_thread_safe();
6733 bool use_fake_dep
= false;
6734 Address cmp_branch_off
= 0;
6737 unsigned int pltindex
6738 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6739 / this->targ_
->plt_entry_size());
6741 = (this->targ_
->glink_section()->pltresolve_size()
6743 if (pltindex
> 32768)
6744 glinkoff
+= (pltindex
- 32768) * 4;
6746 = this->targ_
->glink_section()->address() + glinkoff
;
6748 = (this->stub_address() + cs
->second
.off_
+ 20
6749 + 4 * cs
->second
.r2save_
6750 + 4 * (ha(off
) != 0)
6751 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6752 + 4 * static_chain
);
6753 cmp_branch_off
= to
- from
;
6754 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6757 p
= oview
+ cs
->second
.off_
;
6758 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6760 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6761 this->build_tls_opt_head(&p
, save_lr
);
6762 use_fake_dep
= thread_safe
;
6764 if (cs
->second
.r2save_
)
6766 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6771 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6773 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6775 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6777 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6781 write_insn
<big_endian
>(p
, mtctr_12
);
6785 write_insn
<big_endian
>(p
, xor_2_12_12
);
6787 write_insn
<big_endian
>(p
, add_11_11_2
);
6790 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6794 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6800 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6802 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6804 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6808 write_insn
<big_endian
>(p
, mtctr_12
);
6812 write_insn
<big_endian
>(p
, xor_11_12_12
);
6814 write_insn
<big_endian
>(p
, add_2_2_11
);
6819 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6822 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6825 if (cs
->second
.r2save_
6826 && !cs
->second
.localentry0_
6827 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6828 this->build_tls_opt_tail(p
);
6829 else if (thread_safe
&& !use_fake_dep
)
6831 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6833 write_insn
<big_endian
>(p
, bnectr_p4
);
6835 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6838 write_insn
<big_endian
>(p
, bctr
);
6842 // Write out long branch stubs.
6843 typename
Branch_stub_entries::const_iterator bs
;
6844 for (bs
= this->long_branch_stubs_
.begin();
6845 bs
!= this->long_branch_stubs_
.end();
6848 if (bs
->second
.save_res_
)
6850 Address off
= this->plt_size_
+ bs
->second
.off_
;
6852 Address loc
= this->stub_address() + off
;
6853 Address delta
= bs
->first
.dest_
- loc
;
6854 if (!bs
->second
.p9notoc_
)
6855 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6856 if (bs
->second
.p9notoc_
)
6858 unsigned char* startp
= p
;
6859 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6860 delta
-= p
- startp
;
6862 else if (delta
+ (1 << 25) >= 2 << 25)
6865 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6866 gold_assert(brlt_addr
!= invalid_address
);
6867 brlt_addr
+= this->targ_
->brlt_section()->address();
6868 Address got_addr
= this->targ_
->toc_pointer();
6869 Address brltoff
= brlt_addr
- got_addr
;
6870 if (ha(brltoff
) == 0)
6872 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6877 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6879 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6883 if (delta
+ (1 << 25) < 2 << 25)
6884 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6887 write_insn
<big_endian
>(p
, mtctr_12
);
6889 write_insn
<big_endian
>(p
, bctr
);
6895 if (!this->plt_call_stubs_
.empty())
6897 // The address of _GLOBAL_OFFSET_TABLE_.
6898 Address g_o_t
= invalid_address
;
6900 // Write out plt call stubs.
6901 typename
Plt_stub_entries::const_iterator cs
;
6902 for (cs
= this->plt_call_stubs_
.begin();
6903 cs
!= this->plt_call_stubs_
.end();
6906 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6907 Address plt_addr
= this->plt_off(cs
, &plt
);
6908 plt_addr
+= plt
->address();
6910 p
= oview
+ cs
->second
.off_
;
6911 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6912 this->build_tls_opt_head(&p
, false);
6913 if (parameters
->options().output_is_position_independent())
6916 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6917 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6918 (cs
->first
.object_
));
6919 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6921 unsigned int got2
= ppcobj
->got2_shndx();
6922 got_addr
= ppcobj
->get_output_section_offset(got2
);
6923 gold_assert(got_addr
!= invalid_address
);
6924 got_addr
+= (ppcobj
->output_section(got2
)->address()
6925 + cs
->first
.addend_
);
6929 if (g_o_t
== invalid_address
)
6930 g_o_t
= this->targ_
->toc_pointer();
6934 Address off
= plt_addr
- got_addr
;
6936 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6939 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6941 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6946 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6948 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6951 write_insn
<big_endian
>(p
, mtctr_11
);
6953 write_insn
<big_endian
>(p
, bctr
);
6957 // Write out long branch stubs.
6958 typename
Branch_stub_entries::const_iterator bs
;
6959 for (bs
= this->long_branch_stubs_
.begin();
6960 bs
!= this->long_branch_stubs_
.end();
6963 if (bs
->second
.save_res_
)
6965 Address off
= this->plt_size_
+ bs
->second
.off_
;
6967 Address loc
= this->stub_address() + off
;
6968 Address delta
= bs
->first
.dest_
- loc
;
6969 if (delta
+ (1 << 25) < 2 << 25)
6970 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6971 else if (!parameters
->options().output_is_position_independent())
6973 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6975 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6980 write_insn
<big_endian
>(p
, mflr_0
);
6982 write_insn
<big_endian
>(p
, bcl_20_31
);
6984 write_insn
<big_endian
>(p
, mflr_12
);
6986 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6988 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6990 write_insn
<big_endian
>(p
, mtlr_0
);
6993 write_insn
<big_endian
>(p
, mtctr_12
);
6995 write_insn
<big_endian
>(p
, bctr
);
6998 if (this->need_save_res_
)
7000 p
= oview
+ this->plt_size_
+ this->branch_size_
;
7001 memcpy (p
, this->targ_
->savres_section()->contents(),
7002 this->targ_
->savres_section()->data_size());
7006 // Write out .glink.
7008 template<int size
, bool big_endian
>
7010 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
7012 const section_size_type off
= this->offset();
7013 const section_size_type oview_size
=
7014 convert_to_section_size_type(this->data_size());
7015 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7018 // The base address of the .plt section.
7019 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
7020 Address plt_base
= this->targ_
->plt_section()->address();
7024 if (this->end_branch_table_
!= 0)
7026 // Write pltresolve stub.
7028 Address after_bcl
= this->address() + 16;
7029 Address pltoff
= plt_base
- after_bcl
;
7031 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
7033 if (this->targ_
->abiversion() < 2)
7035 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
7036 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7037 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7038 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
7039 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
7040 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
7041 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7042 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
7043 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7044 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
7048 if (this->targ_
->has_localentry0())
7050 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
7052 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
7053 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7054 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7055 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
7056 if (this->targ_
->has_localentry0())
7058 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
7062 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
7064 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
7065 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
7066 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
7067 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7068 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
7069 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7070 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
7072 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
7073 gold_assert(p
== oview
+ this->pltresolve_size());
7075 // Write lazy link call stubs.
7077 while (p
< oview
+ this->end_branch_table_
)
7079 if (this->targ_
->abiversion() < 2)
7083 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
7087 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
7088 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
7091 uint32_t branch_off
= 8 - (p
- oview
);
7092 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
7097 Address plt_base
= this->targ_
->plt_section()->address();
7098 Address iplt_base
= invalid_address
;
7099 unsigned int global_entry_off
= this->global_entry_off();
7100 Address global_entry_base
= this->address() + global_entry_off
;
7101 typename
Global_entry_stub_entries::const_iterator ge
;
7102 for (ge
= this->global_entry_stubs_
.begin();
7103 ge
!= this->global_entry_stubs_
.end();
7106 p
= oview
+ global_entry_off
+ ge
->second
;
7107 Address plt_addr
= ge
->first
->plt_offset();
7108 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
7109 && ge
->first
->can_use_relative_reloc(false))
7111 if (iplt_base
== invalid_address
)
7112 iplt_base
= this->targ_
->iplt_section()->address();
7113 plt_addr
+= iplt_base
;
7116 plt_addr
+= plt_base
;
7117 Address my_addr
= global_entry_base
+ ge
->second
;
7118 Address off
= plt_addr
- my_addr
;
7120 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
7121 gold_error(_("linkage table error against `%s'"),
7122 ge
->first
->demangled_name().c_str());
7124 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
7125 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
7126 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7127 write_insn
<big_endian
>(p
, bctr
);
7132 // The address of _GLOBAL_OFFSET_TABLE_.
7133 Address g_o_t
= this->targ_
->toc_pointer();
7135 // Write out pltresolve branch table.
7137 unsigned int the_end
= oview_size
- this->pltresolve_size();
7138 unsigned char* end_p
= oview
+ the_end
;
7139 while (p
< end_p
- 8 * 4)
7140 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
7142 write_insn
<big_endian
>(p
, nop
), p
+= 4;
7144 // Write out pltresolve call stub.
7145 end_p
= oview
+ oview_size
;
7146 if (parameters
->options().output_is_position_independent())
7148 Address res0_off
= 0;
7149 Address after_bcl_off
= the_end
+ 12;
7150 Address bcl_res0
= after_bcl_off
- res0_off
;
7152 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
7154 write_insn
<big_endian
>(p
, mflr_0
);
7156 write_insn
<big_endian
>(p
, bcl_20_31
);
7158 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
7160 write_insn
<big_endian
>(p
, mflr_12
);
7162 write_insn
<big_endian
>(p
, mtlr_0
);
7164 write_insn
<big_endian
>(p
, sub_11_11_12
);
7167 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
7169 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
7171 if (ha(got_bcl
) == ha(got_bcl
+ 4))
7173 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
7175 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
7179 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
7181 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7184 write_insn
<big_endian
>(p
, mtctr_0
);
7186 write_insn
<big_endian
>(p
, add_0_11_11
);
7188 write_insn
<big_endian
>(p
, add_11_0_11
);
7192 Address res0
= this->address();
7194 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7196 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7198 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7199 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7201 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7203 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7205 write_insn
<big_endian
>(p
, mtctr_0
);
7207 write_insn
<big_endian
>(p
, add_0_11_11
);
7209 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7210 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7212 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7214 write_insn
<big_endian
>(p
, add_11_0_11
);
7217 write_insn
<big_endian
>(p
, bctr
);
7221 write_insn
<big_endian
>(p
, nop
);
7226 of
->write_output_view(off
, oview_size
, oview
);
7230 // A class to handle linker generated save/restore functions.
7232 template<int size
, bool big_endian
>
7233 class Output_data_save_res
: public Output_section_data_build
7236 Output_data_save_res(Symbol_table
* symtab
);
7238 const unsigned char*
7245 // Write to a map file.
7247 do_print_to_mapfile(Mapfile
* mapfile
) const
7248 { mapfile
->print_output_data(this, _("** save/restore")); }
7251 do_write(Output_file
*);
7254 // The maximum size of save/restore contents.
7255 static const unsigned int savres_max
= 218*4;
7258 savres_define(Symbol_table
* symtab
,
7260 unsigned int lo
, unsigned int hi
,
7261 unsigned char* write_ent(unsigned char*, int),
7262 unsigned char* write_tail(unsigned char*, int));
7264 unsigned char *contents_
;
7267 template<bool big_endian
>
7268 static unsigned char*
7269 savegpr0(unsigned char* p
, int r
)
7271 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7272 write_insn
<big_endian
>(p
, insn
);
7276 template<bool big_endian
>
7277 static unsigned char*
7278 savegpr0_tail(unsigned char* p
, int r
)
7280 p
= savegpr0
<big_endian
>(p
, r
);
7281 uint32_t insn
= std_0_1
+ 16;
7282 write_insn
<big_endian
>(p
, insn
);
7284 write_insn
<big_endian
>(p
, blr
);
7288 template<bool big_endian
>
7289 static unsigned char*
7290 restgpr0(unsigned char* p
, int r
)
7292 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7293 write_insn
<big_endian
>(p
, insn
);
7297 template<bool big_endian
>
7298 static unsigned char*
7299 restgpr0_tail(unsigned char* p
, int r
)
7301 uint32_t insn
= ld_0_1
+ 16;
7302 write_insn
<big_endian
>(p
, insn
);
7304 p
= restgpr0
<big_endian
>(p
, r
);
7305 write_insn
<big_endian
>(p
, mtlr_0
);
7309 p
= restgpr0
<big_endian
>(p
, 30);
7310 p
= restgpr0
<big_endian
>(p
, 31);
7312 write_insn
<big_endian
>(p
, blr
);
7316 template<bool big_endian
>
7317 static unsigned char*
7318 savegpr1(unsigned char* p
, int r
)
7320 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7321 write_insn
<big_endian
>(p
, insn
);
7325 template<bool big_endian
>
7326 static unsigned char*
7327 savegpr1_tail(unsigned char* p
, int r
)
7329 p
= savegpr1
<big_endian
>(p
, r
);
7330 write_insn
<big_endian
>(p
, blr
);
7334 template<bool big_endian
>
7335 static unsigned char*
7336 restgpr1(unsigned char* p
, int r
)
7338 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7339 write_insn
<big_endian
>(p
, insn
);
7343 template<bool big_endian
>
7344 static unsigned char*
7345 restgpr1_tail(unsigned char* p
, int r
)
7347 p
= restgpr1
<big_endian
>(p
, r
);
7348 write_insn
<big_endian
>(p
, blr
);
7352 template<bool big_endian
>
7353 static unsigned char*
7354 savefpr(unsigned char* p
, int r
)
7356 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7357 write_insn
<big_endian
>(p
, insn
);
7361 template<bool big_endian
>
7362 static unsigned char*
7363 savefpr0_tail(unsigned char* p
, int r
)
7365 p
= savefpr
<big_endian
>(p
, r
);
7366 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7368 write_insn
<big_endian
>(p
, blr
);
7372 template<bool big_endian
>
7373 static unsigned char*
7374 restfpr(unsigned char* p
, int r
)
7376 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7377 write_insn
<big_endian
>(p
, insn
);
7381 template<bool big_endian
>
7382 static unsigned char*
7383 restfpr0_tail(unsigned char* p
, int r
)
7385 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7387 p
= restfpr
<big_endian
>(p
, r
);
7388 write_insn
<big_endian
>(p
, mtlr_0
);
7392 p
= restfpr
<big_endian
>(p
, 30);
7393 p
= restfpr
<big_endian
>(p
, 31);
7395 write_insn
<big_endian
>(p
, blr
);
7399 template<bool big_endian
>
7400 static unsigned char*
7401 savefpr1_tail(unsigned char* p
, int r
)
7403 p
= savefpr
<big_endian
>(p
, r
);
7404 write_insn
<big_endian
>(p
, blr
);
7408 template<bool big_endian
>
7409 static unsigned char*
7410 restfpr1_tail(unsigned char* p
, int r
)
7412 p
= restfpr
<big_endian
>(p
, r
);
7413 write_insn
<big_endian
>(p
, blr
);
7417 template<bool big_endian
>
7418 static unsigned char*
7419 savevr(unsigned char* p
, int r
)
7421 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7422 write_insn
<big_endian
>(p
, insn
);
7424 insn
= stvx_0_12_0
+ (r
<< 21);
7425 write_insn
<big_endian
>(p
, insn
);
7429 template<bool big_endian
>
7430 static unsigned char*
7431 savevr_tail(unsigned char* p
, int r
)
7433 p
= savevr
<big_endian
>(p
, r
);
7434 write_insn
<big_endian
>(p
, blr
);
7438 template<bool big_endian
>
7439 static unsigned char*
7440 restvr(unsigned char* p
, int r
)
7442 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7443 write_insn
<big_endian
>(p
, insn
);
7445 insn
= lvx_0_12_0
+ (r
<< 21);
7446 write_insn
<big_endian
>(p
, insn
);
7450 template<bool big_endian
>
7451 static unsigned char*
7452 restvr_tail(unsigned char* p
, int r
)
7454 p
= restvr
<big_endian
>(p
, r
);
7455 write_insn
<big_endian
>(p
, blr
);
7460 template<int size
, bool big_endian
>
7461 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7462 Symbol_table
* symtab
)
7463 : Output_section_data_build(4),
7466 this->savres_define(symtab
,
7467 "_savegpr0_", 14, 31,
7468 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7469 this->savres_define(symtab
,
7470 "_restgpr0_", 14, 29,
7471 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7472 this->savres_define(symtab
,
7473 "_restgpr0_", 30, 31,
7474 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7475 this->savres_define(symtab
,
7476 "_savegpr1_", 14, 31,
7477 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7478 this->savres_define(symtab
,
7479 "_restgpr1_", 14, 31,
7480 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7481 this->savres_define(symtab
,
7482 "_savefpr_", 14, 31,
7483 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7484 this->savres_define(symtab
,
7485 "_restfpr_", 14, 29,
7486 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7487 this->savres_define(symtab
,
7488 "_restfpr_", 30, 31,
7489 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7490 this->savres_define(symtab
,
7492 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7493 this->savres_define(symtab
,
7495 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7496 this->savres_define(symtab
,
7498 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7499 this->savres_define(symtab
,
7501 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7504 template<int size
, bool big_endian
>
7506 Output_data_save_res
<size
, big_endian
>::savres_define(
7507 Symbol_table
* symtab
,
7509 unsigned int lo
, unsigned int hi
,
7510 unsigned char* write_ent(unsigned char*, int),
7511 unsigned char* write_tail(unsigned char*, int))
7513 size_t len
= strlen(name
);
7514 bool writing
= false;
7517 memcpy(sym
, name
, len
);
7520 for (unsigned int i
= lo
; i
<= hi
; i
++)
7522 sym
[len
+ 0] = i
/ 10 + '0';
7523 sym
[len
+ 1] = i
% 10 + '0';
7524 Symbol
* gsym
= symtab
->lookup(sym
);
7525 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7526 writing
= writing
|| refd
;
7529 if (this->contents_
== NULL
)
7530 this->contents_
= new unsigned char[this->savres_max
];
7532 section_size_type value
= this->current_data_size();
7533 unsigned char* p
= this->contents_
+ value
;
7535 p
= write_ent(p
, i
);
7537 p
= write_tail(p
, i
);
7538 section_size_type cur_size
= p
- this->contents_
;
7539 this->set_current_data_size(cur_size
);
7541 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7542 this, value
, cur_size
- value
,
7543 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7544 elfcpp::STV_HIDDEN
, 0, false, false);
7549 // Write out save/restore.
7551 template<int size
, bool big_endian
>
7553 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7555 const section_size_type off
= this->offset();
7556 const section_size_type oview_size
=
7557 convert_to_section_size_type(this->data_size());
7558 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7559 memcpy(oview
, this->contents_
, oview_size
);
7560 of
->write_output_view(off
, oview_size
, oview
);
7564 // Create the glink section.
7566 template<int size
, bool big_endian
>
7568 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7570 if (this->glink_
== NULL
)
7572 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7573 this->glink_
->add_eh_frame(layout
);
7574 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7575 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7576 this->glink_
, ORDER_TEXT
, false);
7580 // Create a PLT entry for a global symbol.
7582 template<int size
, bool big_endian
>
7584 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7588 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7589 && gsym
->can_use_relative_reloc(false))
7591 if (this->iplt_
== NULL
)
7592 this->make_iplt_section(symtab
, layout
);
7593 this->iplt_
->add_ifunc_entry(gsym
);
7597 if (this->plt_
== NULL
)
7598 this->make_plt_section(symtab
, layout
);
7599 this->plt_
->add_entry(gsym
);
7603 // Make a PLT entry for a local symbol.
7605 template<int size
, bool big_endian
>
7607 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7608 Symbol_table
* symtab
,
7610 Sized_relobj_file
<size
, big_endian
>* relobj
,
7613 if (this->lplt_
== NULL
)
7614 this->make_lplt_section(symtab
, layout
);
7615 this->lplt_
->add_local_entry(relobj
, r_sym
);
7618 template<int size
, bool big_endian
>
7620 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(Symbol_table
* symtab
,
7624 if (this->lplt_
== NULL
)
7625 this->make_lplt_section(symtab
, layout
);
7626 this->lplt_
->add_entry(gsym
, true);
7629 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7631 template<int size
, bool big_endian
>
7633 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7634 Symbol_table
* symtab
,
7636 Sized_relobj_file
<size
, big_endian
>* relobj
,
7639 if (this->iplt_
== NULL
)
7640 this->make_iplt_section(symtab
, layout
);
7641 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7644 // Return the number of entries in the PLT.
7646 template<int size
, bool big_endian
>
7648 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7650 if (this->plt_
== NULL
)
7652 return this->plt_
->entry_count();
7655 // Create a GOT entry for local dynamic __tls_get_addr calls.
7657 template<int size
, bool big_endian
>
7659 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7660 Symbol_table
* symtab
,
7662 Sized_relobj_file
<size
, big_endian
>* object
)
7664 if (this->tlsld_got_offset_
== -1U)
7666 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7667 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7668 Output_data_got_powerpc
<size
, big_endian
>* got
7669 = this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
7670 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7671 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7673 this->tlsld_got_offset_
= got_offset
;
7675 return this->tlsld_got_offset_
;
7678 // Get the Reference_flags for a particular relocation.
7680 template<int size
, bool big_endian
>
7682 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7683 unsigned int r_type
,
7684 const Target_powerpc
* target
)
7690 case elfcpp::R_PPC64_TOC
:
7694 case elfcpp::R_POWERPC_NONE
:
7695 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7696 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7697 // No symbol reference.
7700 case elfcpp::R_PPC64_ADDR64
:
7701 case elfcpp::R_PPC64_UADDR64
:
7702 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7703 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7704 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7705 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7706 case elfcpp::R_PPC64_D34
:
7707 case elfcpp::R_PPC64_D34_LO
:
7708 case elfcpp::R_PPC64_D34_HI30
:
7709 case elfcpp::R_PPC64_D34_HA30
:
7710 case elfcpp::R_PPC64_D28
:
7714 case elfcpp::R_POWERPC_ADDR32
:
7715 case elfcpp::R_POWERPC_UADDR32
:
7716 case elfcpp::R_POWERPC_ADDR16
:
7717 case elfcpp::R_POWERPC_UADDR16
:
7718 case elfcpp::R_POWERPC_ADDR16_LO
:
7719 case elfcpp::R_POWERPC_ADDR16_HI
:
7720 case elfcpp::R_POWERPC_ADDR16_HA
:
7721 ref
= Symbol::ABSOLUTE_REF
;
7724 case elfcpp::R_POWERPC_ADDR24
:
7725 case elfcpp::R_POWERPC_ADDR14
:
7726 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7727 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7728 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7731 case elfcpp::R_PPC_LOCAL24PC
:
7735 ref
= Symbol::RELATIVE_REF
;
7738 case elfcpp::R_PPC64_REL64
:
7739 case elfcpp::R_PPC64_REL16_HIGH
:
7740 case elfcpp::R_PPC64_REL16_HIGHA
:
7741 case elfcpp::R_PPC64_REL16_HIGHER
:
7742 case elfcpp::R_PPC64_REL16_HIGHERA
:
7743 case elfcpp::R_PPC64_REL16_HIGHEST
:
7744 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7745 case elfcpp::R_PPC64_PCREL34
:
7746 case elfcpp::R_PPC64_REL16_HIGHER34
:
7747 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7748 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7749 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7750 case elfcpp::R_PPC64_PCREL28
:
7754 case elfcpp::R_POWERPC_REL32
:
7755 case elfcpp::R_POWERPC_REL16
:
7756 case elfcpp::R_POWERPC_REL16_LO
:
7757 case elfcpp::R_POWERPC_REL16_HI
:
7758 case elfcpp::R_POWERPC_REL16_HA
:
7759 ref
= Symbol::RELATIVE_REF
;
7762 case elfcpp::R_PPC_PLTREL24
:
7765 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7768 case elfcpp::R_PPC64_REL24_NOTOC
:
7769 case elfcpp::R_PPC64_REL24_P9NOTOC
:
7770 case elfcpp::R_PPC64_PLT16_LO_DS
:
7771 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7772 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7773 case elfcpp::R_PPC64_PLT_PCREL34
:
7774 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7778 case elfcpp::R_POWERPC_REL24
:
7779 case elfcpp::R_POWERPC_REL14
:
7780 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7781 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7782 case elfcpp::R_POWERPC_PLT16_LO
:
7783 case elfcpp::R_POWERPC_PLT16_HI
:
7784 case elfcpp::R_POWERPC_PLT16_HA
:
7785 case elfcpp::R_POWERPC_PLTSEQ
:
7786 case elfcpp::R_POWERPC_PLTCALL
:
7787 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7790 case elfcpp::R_PPC64_GOT16_DS
:
7791 case elfcpp::R_PPC64_GOT16_LO_DS
:
7792 case elfcpp::R_PPC64_GOT_PCREL34
:
7793 case elfcpp::R_PPC64_TOC16
:
7794 case elfcpp::R_PPC64_TOC16_LO
:
7795 case elfcpp::R_PPC64_TOC16_HI
:
7796 case elfcpp::R_PPC64_TOC16_HA
:
7797 case elfcpp::R_PPC64_TOC16_DS
:
7798 case elfcpp::R_PPC64_TOC16_LO_DS
:
7802 case elfcpp::R_POWERPC_GOT16
:
7803 case elfcpp::R_POWERPC_GOT16_LO
:
7804 case elfcpp::R_POWERPC_GOT16_HI
:
7805 case elfcpp::R_POWERPC_GOT16_HA
:
7806 ref
= Symbol::RELATIVE_REF
;
7809 case elfcpp::R_PPC64_TLSGD
:
7810 case elfcpp::R_PPC64_TLSLD
:
7811 case elfcpp::R_PPC64_TPREL34
:
7812 case elfcpp::R_PPC64_DTPREL34
:
7813 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7814 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7815 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7816 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7820 case elfcpp::R_POWERPC_GOT_TPREL16
:
7821 case elfcpp::R_POWERPC_TLS
:
7822 ref
= Symbol::TLS_REF
;
7825 case elfcpp::R_POWERPC_COPY
:
7826 case elfcpp::R_POWERPC_GLOB_DAT
:
7827 case elfcpp::R_POWERPC_JMP_SLOT
:
7828 case elfcpp::R_POWERPC_RELATIVE
:
7829 case elfcpp::R_POWERPC_DTPMOD
:
7831 // Not expected. We will give an error later.
7835 if (size
== 64 && target
->abiversion() < 2)
7836 ref
|= Symbol::FUNC_DESC_ABI
;
7840 // Report an unsupported relocation against a local symbol.
7842 template<int size
, bool big_endian
>
7844 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7845 Sized_relobj_file
<size
, big_endian
>* object
,
7846 unsigned int r_type
)
7848 gold_error(_("%s: unsupported reloc %u against local symbol"),
7849 object
->name().c_str(), r_type
);
7852 // We are about to emit a dynamic relocation of type R_TYPE. If the
7853 // dynamic linker does not support it, issue an error.
7855 template<int size
, bool big_endian
>
7857 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7858 unsigned int r_type
)
7860 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7862 // These are the relocation types supported by glibc for both 32-bit
7863 // and 64-bit powerpc.
7866 case elfcpp::R_POWERPC_NONE
:
7867 case elfcpp::R_POWERPC_RELATIVE
:
7868 case elfcpp::R_POWERPC_GLOB_DAT
:
7869 case elfcpp::R_POWERPC_DTPMOD
:
7870 case elfcpp::R_POWERPC_DTPREL
:
7871 case elfcpp::R_POWERPC_TPREL
:
7872 case elfcpp::R_POWERPC_JMP_SLOT
:
7873 case elfcpp::R_POWERPC_COPY
:
7874 case elfcpp::R_POWERPC_IRELATIVE
:
7875 case elfcpp::R_POWERPC_ADDR32
:
7876 case elfcpp::R_POWERPC_UADDR32
:
7877 case elfcpp::R_POWERPC_ADDR24
:
7878 case elfcpp::R_POWERPC_ADDR16
:
7879 case elfcpp::R_POWERPC_UADDR16
:
7880 case elfcpp::R_POWERPC_ADDR16_LO
:
7881 case elfcpp::R_POWERPC_ADDR16_HI
:
7882 case elfcpp::R_POWERPC_ADDR16_HA
:
7883 case elfcpp::R_POWERPC_ADDR14
:
7884 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7885 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7886 case elfcpp::R_POWERPC_REL32
:
7887 case elfcpp::R_POWERPC_TPREL16
:
7888 case elfcpp::R_POWERPC_TPREL16_LO
:
7889 case elfcpp::R_POWERPC_TPREL16_HI
:
7890 case elfcpp::R_POWERPC_TPREL16_HA
:
7901 // These are the relocation types supported only on 64-bit.
7902 case elfcpp::R_PPC64_ADDR64
:
7903 case elfcpp::R_PPC64_UADDR64
:
7904 case elfcpp::R_PPC64_JMP_IREL
:
7905 case elfcpp::R_PPC64_ADDR16_DS
:
7906 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7907 case elfcpp::R_PPC64_ADDR16_HIGH
:
7908 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7909 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7910 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7911 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7912 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7913 case elfcpp::R_PPC64_REL64
:
7914 case elfcpp::R_POWERPC_ADDR30
:
7915 case elfcpp::R_PPC64_TPREL16_DS
:
7916 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7917 case elfcpp::R_PPC64_TPREL16_HIGH
:
7918 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7919 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7920 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7921 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7922 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7933 // These are the relocation types supported only on 32-bit.
7934 // ??? glibc ld.so doesn't need to support these.
7935 case elfcpp::R_POWERPC_REL24
:
7936 case elfcpp::R_POWERPC_DTPREL16
:
7937 case elfcpp::R_POWERPC_DTPREL16_LO
:
7938 case elfcpp::R_POWERPC_DTPREL16_HI
:
7939 case elfcpp::R_POWERPC_DTPREL16_HA
:
7947 // This prevents us from issuing more than one error per reloc
7948 // section. But we can still wind up issuing more than one
7949 // error per object file.
7950 if (this->issued_non_pic_error_
)
7952 gold_assert(parameters
->options().output_is_position_independent());
7953 object
->error(_("requires unsupported dynamic reloc; "
7954 "recompile with -fPIC"));
7955 this->issued_non_pic_error_
= true;
7959 // Return whether we need to make a PLT entry for a relocation of the
7960 // given type against a STT_GNU_IFUNC symbol.
7962 template<int size
, bool big_endian
>
7964 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7965 Target_powerpc
<size
, big_endian
>* target
,
7966 Sized_relobj_file
<size
, big_endian
>* object
,
7967 unsigned int r_type
,
7970 // In non-pic code any reference will resolve to the plt call stub
7971 // for the ifunc symbol.
7972 if ((size
== 32 || target
->abiversion() >= 2)
7973 && !parameters
->options().output_is_position_independent())
7978 // Word size refs from data sections are OK, but don't need a PLT entry.
7979 case elfcpp::R_POWERPC_ADDR32
:
7980 case elfcpp::R_POWERPC_UADDR32
:
7985 case elfcpp::R_PPC64_ADDR64
:
7986 case elfcpp::R_PPC64_UADDR64
:
7991 // GOT refs are good, but also don't need a PLT entry.
7992 case elfcpp::R_POWERPC_GOT16
:
7993 case elfcpp::R_POWERPC_GOT16_LO
:
7994 case elfcpp::R_POWERPC_GOT16_HI
:
7995 case elfcpp::R_POWERPC_GOT16_HA
:
7996 case elfcpp::R_PPC64_GOT16_DS
:
7997 case elfcpp::R_PPC64_GOT16_LO_DS
:
7998 case elfcpp::R_PPC64_GOT_PCREL34
:
8001 // PLT relocs are OK and need a PLT entry.
8002 case elfcpp::R_POWERPC_PLT16_LO
:
8003 case elfcpp::R_POWERPC_PLT16_HI
:
8004 case elfcpp::R_POWERPC_PLT16_HA
:
8005 case elfcpp::R_PPC64_PLT16_LO_DS
:
8006 case elfcpp::R_POWERPC_PLTSEQ
:
8007 case elfcpp::R_POWERPC_PLTCALL
:
8008 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8009 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8010 case elfcpp::R_PPC64_PLT_PCREL34
:
8011 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8015 // Function calls are good, and these do need a PLT entry.
8016 case elfcpp::R_PPC64_REL24_NOTOC
:
8020 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8021 case elfcpp::R_POWERPC_ADDR24
:
8022 case elfcpp::R_POWERPC_ADDR14
:
8023 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8024 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8025 case elfcpp::R_POWERPC_REL24
:
8026 case elfcpp::R_PPC_PLTREL24
:
8027 case elfcpp::R_POWERPC_REL14
:
8028 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8029 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8036 // Anything else is a problem.
8037 // If we are building a static executable, the libc startup function
8038 // responsible for applying indirect function relocations is going
8039 // to complain about the reloc type.
8040 // If we are building a dynamic executable, we will have a text
8041 // relocation. The dynamic loader will set the text segment
8042 // writable and non-executable to apply text relocations. So we'll
8043 // segfault when trying to run the indirection function to resolve
8046 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
8047 object
->name().c_str(), r_type
);
8051 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
8055 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
8057 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8058 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8059 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8060 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8061 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8062 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8063 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8064 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8065 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8066 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8067 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8068 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8069 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8070 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8071 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8072 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8073 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8074 /* Exclude lfqu by testing reloc. If relocs are ever
8075 defined for the reduced D field in psq_lu then those
8076 will need testing too. */
8077 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8078 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8079 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8081 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8082 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8083 /* Exclude stfqu. psq_stu as above for psq_lu. */
8084 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8085 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8086 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8087 && (insn
& 1) == 0));
8090 // Scan a relocation for a local symbol.
8092 template<int size
, bool big_endian
>
8094 Target_powerpc
<size
, big_endian
>::Scan::local(
8095 Symbol_table
* symtab
,
8097 Target_powerpc
<size
, big_endian
>* target
,
8098 Sized_relobj_file
<size
, big_endian
>* object
,
8099 unsigned int data_shndx
,
8100 Output_section
* output_section
,
8101 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8102 unsigned int r_type
,
8103 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8106 Powerpc_relobj
<size
, big_endian
>* ppc_object
8107 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8109 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
8111 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8112 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8114 this->expect_tls_get_addr_call();
8115 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8116 if (tls_type
!= tls::TLSOPT_NONE
)
8117 this->skip_next_tls_get_addr_call();
8119 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8120 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8122 this->expect_tls_get_addr_call();
8123 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8124 if (tls_type
!= tls::TLSOPT_NONE
)
8125 this->skip_next_tls_get_addr_call();
8131 && data_shndx
== ppc_object
->opd_shndx()
8132 && r_type
== elfcpp::R_PPC64_ADDR64
)
8133 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8137 // A local STT_GNU_IFUNC symbol may require a PLT entry.
8138 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
8139 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8141 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8142 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8143 r_type
, r_sym
, reloc
.get_r_addend());
8144 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
8149 case elfcpp::R_POWERPC_NONE
:
8150 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8151 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8152 case elfcpp::R_POWERPC_TLS
:
8153 case elfcpp::R_PPC64_ENTRY
:
8154 case elfcpp::R_POWERPC_PLTSEQ
:
8155 case elfcpp::R_POWERPC_PLTCALL
:
8156 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8157 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8158 case elfcpp::R_PPC64_PCREL_OPT
:
8159 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8160 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8161 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8162 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8163 case elfcpp::R_PPC64_REL16_HIGHER34
:
8164 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8165 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8166 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8167 case elfcpp::R_PPC64_D34
:
8168 case elfcpp::R_PPC64_D34_LO
:
8169 case elfcpp::R_PPC64_D34_HI30
:
8170 case elfcpp::R_PPC64_D34_HA30
:
8171 case elfcpp::R_PPC64_D28
:
8172 case elfcpp::R_PPC64_PCREL34
:
8173 case elfcpp::R_PPC64_PCREL28
:
8174 case elfcpp::R_PPC64_TPREL34
:
8175 case elfcpp::R_PPC64_DTPREL34
:
8178 case elfcpp::R_PPC64_TOC
:
8180 Output_data_got_powerpc
<size
, big_endian
>* got
8181 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8182 if (parameters
->options().output_is_position_independent())
8184 Address off
= reloc
.get_r_offset();
8186 && target
->abiversion() < 2
8187 && data_shndx
== ppc_object
->opd_shndx()
8188 && ppc_object
->get_opd_discard(off
- 8))
8191 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8192 Address got_off
= got
->g_o_t();
8193 rela_dyn
->add_output_section_relative(got
->output_section(),
8194 elfcpp::R_POWERPC_RELATIVE
,
8196 object
, data_shndx
, off
,
8202 case elfcpp::R_PPC64_ADDR64
:
8203 case elfcpp::R_PPC64_UADDR64
:
8204 case elfcpp::R_POWERPC_ADDR32
:
8205 case elfcpp::R_POWERPC_UADDR32
:
8206 case elfcpp::R_POWERPC_ADDR24
:
8207 case elfcpp::R_POWERPC_ADDR16
:
8208 case elfcpp::R_POWERPC_ADDR16_LO
:
8209 case elfcpp::R_POWERPC_ADDR16_HI
:
8210 case elfcpp::R_POWERPC_ADDR16_HA
:
8211 case elfcpp::R_POWERPC_UADDR16
:
8212 case elfcpp::R_PPC64_ADDR16_HIGH
:
8213 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8214 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8215 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8216 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8217 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8218 case elfcpp::R_PPC64_ADDR16_DS
:
8219 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8220 case elfcpp::R_POWERPC_ADDR14
:
8221 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8222 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8223 // If building a shared library (or a position-independent
8224 // executable), we need to create a dynamic relocation for
8226 if (parameters
->options().output_is_position_independent()
8227 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8229 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8231 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8232 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8233 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8235 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8236 : elfcpp::R_POWERPC_RELATIVE
);
8237 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8238 output_section
, data_shndx
,
8239 reloc
.get_r_offset(),
8240 reloc
.get_r_addend(), false);
8242 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8244 check_non_pic(object
, r_type
);
8245 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8246 data_shndx
, reloc
.get_r_offset(),
8247 reloc
.get_r_addend());
8251 gold_assert(lsym
.get_st_value() == 0);
8252 unsigned int shndx
= lsym
.get_st_shndx();
8254 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8257 object
->error(_("section symbol %u has bad shndx %u"),
8260 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8261 output_section
, data_shndx
,
8262 reloc
.get_r_offset());
8267 case elfcpp::R_PPC64_PLT_PCREL34
:
8268 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8269 case elfcpp::R_POWERPC_PLT16_LO
:
8270 case elfcpp::R_POWERPC_PLT16_HI
:
8271 case elfcpp::R_POWERPC_PLT16_HA
:
8272 case elfcpp::R_PPC64_PLT16_LO_DS
:
8275 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8276 target
->make_local_plt_entry(symtab
, layout
, object
, r_sym
);
8280 case elfcpp::R_PPC64_REL24_NOTOC
:
8284 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8285 case elfcpp::R_POWERPC_REL24
:
8286 case elfcpp::R_PPC_PLTREL24
:
8287 case elfcpp::R_PPC_LOCAL24PC
:
8288 case elfcpp::R_POWERPC_REL14
:
8289 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8290 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8293 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8294 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8295 r_type
, r_sym
, reloc
.get_r_addend());
8299 case elfcpp::R_PPC64_TOCSAVE
:
8300 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8301 // caller has already saved r2 and thus a plt call stub need not
8304 && target
->mark_pltcall(ppc_object
, data_shndx
,
8305 reloc
.get_r_offset() - 4, symtab
))
8307 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8308 unsigned int shndx
= lsym
.get_st_shndx();
8310 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8312 object
->error(_("tocsave symbol %u has bad shndx %u"),
8315 target
->add_tocsave(ppc_object
, shndx
,
8316 lsym
.get_st_value() + reloc
.get_r_addend());
8320 case elfcpp::R_PPC64_REL64
:
8321 case elfcpp::R_POWERPC_REL32
:
8322 case elfcpp::R_POWERPC_REL16
:
8323 case elfcpp::R_POWERPC_REL16_LO
:
8324 case elfcpp::R_POWERPC_REL16_HI
:
8325 case elfcpp::R_POWERPC_REL16_HA
:
8326 case elfcpp::R_POWERPC_REL16DX_HA
:
8327 case elfcpp::R_PPC64_REL16_HIGH
:
8328 case elfcpp::R_PPC64_REL16_HIGHA
:
8329 case elfcpp::R_PPC64_REL16_HIGHER
:
8330 case elfcpp::R_PPC64_REL16_HIGHERA
:
8331 case elfcpp::R_PPC64_REL16_HIGHEST
:
8332 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8333 case elfcpp::R_POWERPC_SECTOFF
:
8334 case elfcpp::R_POWERPC_SECTOFF_LO
:
8335 case elfcpp::R_POWERPC_SECTOFF_HI
:
8336 case elfcpp::R_POWERPC_SECTOFF_HA
:
8337 case elfcpp::R_PPC64_SECTOFF_DS
:
8338 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8339 case elfcpp::R_POWERPC_TPREL16
:
8340 case elfcpp::R_POWERPC_TPREL16_LO
:
8341 case elfcpp::R_POWERPC_TPREL16_HI
:
8342 case elfcpp::R_POWERPC_TPREL16_HA
:
8343 case elfcpp::R_PPC64_TPREL16_DS
:
8344 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8345 case elfcpp::R_PPC64_TPREL16_HIGH
:
8346 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8347 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8348 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8349 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8350 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8351 case elfcpp::R_POWERPC_DTPREL16
:
8352 case elfcpp::R_POWERPC_DTPREL16_LO
:
8353 case elfcpp::R_POWERPC_DTPREL16_HI
:
8354 case elfcpp::R_POWERPC_DTPREL16_HA
:
8355 case elfcpp::R_PPC64_DTPREL16_DS
:
8356 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8357 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8358 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8359 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8360 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8361 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8362 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8363 case elfcpp::R_PPC64_TLSGD
:
8364 case elfcpp::R_PPC64_TLSLD
:
8365 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8368 case elfcpp::R_PPC64_GOT_PCREL34
:
8369 case elfcpp::R_POWERPC_GOT16
:
8370 case elfcpp::R_POWERPC_GOT16_LO
:
8371 case elfcpp::R_POWERPC_GOT16_HI
:
8372 case elfcpp::R_POWERPC_GOT16_HA
:
8373 case elfcpp::R_PPC64_GOT16_DS
:
8374 case elfcpp::R_PPC64_GOT16_LO_DS
:
8376 // The symbol requires a GOT entry.
8377 Got_type got_type
= ((size
== 32
8378 || r_type
== elfcpp::R_POWERPC_GOT16
8379 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8380 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8381 Output_data_got_powerpc
<size
, big_endian
>* got
8382 = target
->got_section(symtab
, layout
, got_type
);
8383 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8384 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8386 if (!parameters
->options().output_is_position_independent())
8389 && (size
== 32 || target
->abiversion() >= 2))
8390 got
->add_local_plt(object
, r_sym
, got_type
, addend
);
8392 got
->add_local(object
, r_sym
, got_type
, addend
);
8394 else if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8396 // If we are generating a shared object or a pie, this
8397 // symbol's GOT entry will be set by a dynamic relocation.
8399 off
= got
->add_constant(0);
8400 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8402 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8404 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8405 : elfcpp::R_POWERPC_RELATIVE
);
8406 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8407 got
, off
, addend
, false);
8412 case elfcpp::R_PPC64_TOC16
:
8413 case elfcpp::R_PPC64_TOC16_LO
:
8414 case elfcpp::R_PPC64_TOC16_HI
:
8415 case elfcpp::R_PPC64_TOC16_HA
:
8416 case elfcpp::R_PPC64_TOC16_DS
:
8417 case elfcpp::R_PPC64_TOC16_LO_DS
:
8418 // We need a GOT section.
8419 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8422 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8423 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8424 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8425 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8426 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8428 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8429 if (tls_type
== tls::TLSOPT_NONE
)
8431 Got_type got_type
= ((size
== 32
8432 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8433 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8434 Output_data_got_powerpc
<size
, big_endian
>* got
8435 = target
->got_section(symtab
, layout
, got_type
);
8436 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8437 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8438 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8439 got
->add_local_tls_pair(object
, r_sym
, got_type
,
8440 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
,
8443 else if (tls_type
== tls::TLSOPT_TO_LE
)
8445 // no GOT relocs needed for Local Exec.
8452 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8453 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8454 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8455 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8456 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8458 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8459 if (tls_type
== tls::TLSOPT_NONE
)
8460 target
->tlsld_got_offset(symtab
, layout
, object
);
8461 else if (tls_type
== tls::TLSOPT_TO_LE
)
8463 // no GOT relocs needed for Local Exec.
8464 if (parameters
->options().emit_relocs())
8466 Output_section
* os
= layout
->tls_segment()->first_section();
8467 gold_assert(os
!= NULL
);
8468 os
->set_needs_symtab_index();
8476 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8477 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8478 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8479 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8480 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8482 Got_type got_type
= ((size
== 32
8483 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
8484 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
8485 Output_data_got_powerpc
<size
, big_endian
>* got
8486 = target
->got_section(symtab
, layout
, got_type
);
8487 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8488 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8489 got
->add_local_tls(object
, r_sym
, got_type
, addend
);
8493 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8494 case elfcpp::R_POWERPC_GOT_TPREL16
:
8495 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8496 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8497 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8499 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8500 if (tls_type
== tls::TLSOPT_NONE
)
8502 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8503 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8504 Got_type got_type
= ((size
== 32
8505 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
8506 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
8507 if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8509 Output_data_got_powerpc
<size
, big_endian
>* got
8510 = target
->got_section(symtab
, layout
, got_type
);
8511 unsigned int off
= got
->add_constant(0);
8512 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8514 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8515 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8516 elfcpp::R_POWERPC_TPREL
,
8520 else if (tls_type
== tls::TLSOPT_TO_LE
)
8522 // no GOT relocs needed for Local Exec.
8530 unsupported_reloc_local(object
, r_type
);
8535 && parameters
->options().toc_optimize())
8537 if (data_shndx
== ppc_object
->toc_shndx())
8540 if (r_type
!= elfcpp::R_PPC64_ADDR64
8541 || (is_ifunc
&& target
->abiversion() < 2))
8543 else if (parameters
->options().output_is_position_independent())
8549 unsigned int shndx
= lsym
.get_st_shndx();
8550 if (shndx
>= elfcpp::SHN_LORESERVE
8551 && shndx
!= elfcpp::SHN_XINDEX
)
8556 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8559 enum {no_check
, check_lo
, check_ha
} insn_check
;
8563 insn_check
= no_check
;
8566 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8567 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8568 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8569 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8570 case elfcpp::R_POWERPC_GOT16_HA
:
8571 case elfcpp::R_PPC64_TOC16_HA
:
8572 insn_check
= check_ha
;
8575 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8576 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8577 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8578 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8579 case elfcpp::R_POWERPC_GOT16_LO
:
8580 case elfcpp::R_PPC64_GOT16_LO_DS
:
8581 case elfcpp::R_PPC64_TOC16_LO
:
8582 case elfcpp::R_PPC64_TOC16_LO_DS
:
8583 insn_check
= check_lo
;
8587 section_size_type slen
;
8588 const unsigned char* view
= NULL
;
8589 if (insn_check
!= no_check
)
8591 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8592 section_size_type off
=
8593 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8596 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8597 if (insn_check
== check_lo
8598 ? !ok_lo_toc_insn(insn
, r_type
)
8599 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8600 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8602 ppc_object
->set_no_toc_opt();
8603 gold_warning(_("%s: toc optimization is not supported "
8604 "for %#08x instruction"),
8605 ppc_object
->name().c_str(), insn
);
8614 case elfcpp::R_PPC64_TOC16
:
8615 case elfcpp::R_PPC64_TOC16_LO
:
8616 case elfcpp::R_PPC64_TOC16_HI
:
8617 case elfcpp::R_PPC64_TOC16_HA
:
8618 case elfcpp::R_PPC64_TOC16_DS
:
8619 case elfcpp::R_PPC64_TOC16_LO_DS
:
8620 unsigned int shndx
= lsym
.get_st_shndx();
8621 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8623 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8624 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8626 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8627 if (dst_off
< ppc_object
->section_size(shndx
))
8630 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8632 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8634 // Need to check that the insn is a ld
8636 view
= ppc_object
->section_contents(data_shndx
,
8639 section_size_type off
=
8640 (convert_to_section_size_type(reloc
.get_r_offset())
8641 + (big_endian
? -2 : 3));
8643 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8647 ppc_object
->set_no_toc_opt(dst_off
);
8658 case elfcpp::R_POWERPC_REL32
:
8659 if (ppc_object
->got2_shndx() != 0
8660 && parameters
->options().output_is_position_independent())
8662 unsigned int shndx
= lsym
.get_st_shndx();
8663 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8665 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8666 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8667 && (ppc_object
->section_flags(data_shndx
)
8668 & elfcpp::SHF_EXECINSTR
) != 0)
8669 gold_error(_("%s: unsupported -mbss-plt code"),
8670 ppc_object
->name().c_str());
8680 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8681 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8682 case elfcpp::R_POWERPC_GOT_TPREL16
:
8683 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8684 case elfcpp::R_POWERPC_GOT16
:
8685 case elfcpp::R_PPC64_GOT16_DS
:
8686 case elfcpp::R_PPC64_TOC16
:
8687 case elfcpp::R_PPC64_TOC16_DS
:
8688 ppc_object
->set_has_small_toc_reloc();
8696 case elfcpp::R_PPC64_TPREL16_DS
:
8697 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8698 case elfcpp::R_PPC64_TPREL16_HIGH
:
8699 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8700 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8701 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8702 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8703 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8704 case elfcpp::R_PPC64_TPREL34
:
8708 case elfcpp::R_POWERPC_TPREL16
:
8709 case elfcpp::R_POWERPC_TPREL16_LO
:
8710 case elfcpp::R_POWERPC_TPREL16_HI
:
8711 case elfcpp::R_POWERPC_TPREL16_HA
:
8712 layout
->set_has_static_tls();
8720 case elfcpp::R_POWERPC_TPREL16_HA
:
8721 if (target
->tprel_opt())
8723 section_size_type slen
;
8724 const unsigned char* view
= NULL
;
8725 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8726 section_size_type off
8727 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8730 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8731 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8732 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8733 target
->set_no_tprel_opt();
8738 case elfcpp::R_PPC64_TPREL16_HIGH
:
8739 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8740 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8741 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8742 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8743 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8747 case elfcpp::R_POWERPC_TPREL16_HI
:
8748 target
->set_no_tprel_opt();
8756 case elfcpp::R_PPC64_D34
:
8757 case elfcpp::R_PPC64_D34_LO
:
8758 case elfcpp::R_PPC64_D34_HI30
:
8759 case elfcpp::R_PPC64_D34_HA30
:
8760 case elfcpp::R_PPC64_D28
:
8761 case elfcpp::R_PPC64_PCREL34
:
8762 case elfcpp::R_PPC64_PCREL28
:
8763 case elfcpp::R_PPC64_TPREL34
:
8764 case elfcpp::R_PPC64_DTPREL34
:
8765 case elfcpp::R_PPC64_PLT_PCREL34
:
8766 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8767 case elfcpp::R_PPC64_GOT_PCREL34
:
8768 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8769 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8770 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8771 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8772 target
->set_power10_relocs();
8779 // Report an unsupported relocation against a global symbol.
8781 template<int size
, bool big_endian
>
8783 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8784 Sized_relobj_file
<size
, big_endian
>* object
,
8785 unsigned int r_type
,
8788 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8789 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8792 // Scan a relocation for a global symbol.
8794 template<int size
, bool big_endian
>
8796 Target_powerpc
<size
, big_endian
>::Scan::global(
8797 Symbol_table
* symtab
,
8799 Target_powerpc
<size
, big_endian
>* target
,
8800 Sized_relobj_file
<size
, big_endian
>* object
,
8801 unsigned int data_shndx
,
8802 Output_section
* output_section
,
8803 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8804 unsigned int r_type
,
8807 Powerpc_relobj
<size
, big_endian
>* ppc_object
8808 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8810 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8812 case Track_tls::SKIP
:
8818 if (target
->replace_tls_get_addr(gsym
))
8819 // Change a __tls_get_addr reference to __tls_get_addr_opt
8820 // so dynamic relocs are emitted against the latter symbol.
8821 gsym
= target
->tls_get_addr_opt();
8823 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8824 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8826 this->expect_tls_get_addr_call();
8827 bool final
= gsym
->final_value_is_known();
8828 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8829 if (tls_type
!= tls::TLSOPT_NONE
)
8830 this->skip_next_tls_get_addr_call();
8832 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8833 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8835 this->expect_tls_get_addr_call();
8836 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8837 if (tls_type
!= tls::TLSOPT_NONE
)
8838 this->skip_next_tls_get_addr_call();
8841 // A STT_GNU_IFUNC symbol may require a PLT entry.
8842 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8843 bool pushed_ifunc
= false;
8844 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8846 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8847 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8848 r_type
, r_sym
, reloc
.get_r_addend());
8849 target
->make_plt_entry(symtab
, layout
, gsym
);
8850 pushed_ifunc
= true;
8855 case elfcpp::R_POWERPC_NONE
:
8856 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8857 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8858 case elfcpp::R_PPC_LOCAL24PC
:
8859 case elfcpp::R_POWERPC_TLS
:
8860 case elfcpp::R_PPC64_ENTRY
:
8861 case elfcpp::R_POWERPC_PLTSEQ
:
8862 case elfcpp::R_POWERPC_PLTCALL
:
8863 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8864 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8865 case elfcpp::R_PPC64_PCREL_OPT
:
8866 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8867 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8868 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8869 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8870 case elfcpp::R_PPC64_REL16_HIGHER34
:
8871 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8872 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8873 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8874 case elfcpp::R_PPC64_D34
:
8875 case elfcpp::R_PPC64_D34_LO
:
8876 case elfcpp::R_PPC64_D34_HI30
:
8877 case elfcpp::R_PPC64_D34_HA30
:
8878 case elfcpp::R_PPC64_D28
:
8879 case elfcpp::R_PPC64_PCREL34
:
8880 case elfcpp::R_PPC64_PCREL28
:
8881 case elfcpp::R_PPC64_TPREL34
:
8882 case elfcpp::R_PPC64_DTPREL34
:
8885 case elfcpp::R_PPC64_TOC
:
8887 Output_data_got_powerpc
<size
, big_endian
>* got
8888 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8889 if (parameters
->options().output_is_position_independent())
8891 Address off
= reloc
.get_r_offset();
8893 && data_shndx
== ppc_object
->opd_shndx()
8894 && ppc_object
->get_opd_discard(off
- 8))
8897 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8898 Address got_off
= got
->g_o_t();
8899 rela_dyn
->add_output_section_relative(got
->output_section(),
8900 elfcpp::R_POWERPC_RELATIVE
,
8902 object
, data_shndx
, off
,
8908 case elfcpp::R_PPC64_ADDR64
:
8910 && target
->abiversion() < 2
8911 && data_shndx
== ppc_object
->opd_shndx()
8912 && (gsym
->is_defined_in_discarded_section()
8913 || gsym
->object() != object
))
8915 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8919 case elfcpp::R_PPC64_UADDR64
:
8920 case elfcpp::R_POWERPC_ADDR32
:
8921 case elfcpp::R_POWERPC_UADDR32
:
8922 case elfcpp::R_POWERPC_ADDR24
:
8923 case elfcpp::R_POWERPC_ADDR16
:
8924 case elfcpp::R_POWERPC_ADDR16_LO
:
8925 case elfcpp::R_POWERPC_ADDR16_HI
:
8926 case elfcpp::R_POWERPC_ADDR16_HA
:
8927 case elfcpp::R_POWERPC_UADDR16
:
8928 case elfcpp::R_PPC64_ADDR16_HIGH
:
8929 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8930 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8931 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8932 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8933 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8934 case elfcpp::R_PPC64_ADDR16_DS
:
8935 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8936 case elfcpp::R_POWERPC_ADDR14
:
8937 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8938 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8940 // Make a PLT entry if necessary.
8941 if (gsym
->needs_plt_entry())
8943 // Since this is not a PC-relative relocation, we may be
8944 // taking the address of a function. In that case we need to
8945 // set the entry in the dynamic symbol table to the address of
8946 // the PLT call stub.
8947 bool need_ifunc_plt
= false;
8948 if ((size
== 32 || target
->abiversion() >= 2)
8949 && gsym
->is_from_dynobj()
8950 && !parameters
->options().output_is_position_independent())
8952 gsym
->set_needs_dynsym_value();
8953 need_ifunc_plt
= true;
8955 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8957 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8958 target
->push_branch(ppc_object
, data_shndx
,
8959 reloc
.get_r_offset(), r_type
, r_sym
,
8960 reloc
.get_r_addend());
8961 target
->make_plt_entry(symtab
, layout
, gsym
);
8964 // Make a dynamic relocation if necessary.
8965 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8966 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8968 if (!parameters
->options().output_is_position_independent()
8969 && gsym
->may_need_copy_reloc())
8971 target
->copy_reloc(symtab
, layout
, object
,
8972 data_shndx
, output_section
, gsym
, reloc
);
8974 else if ((((size
== 32
8975 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8977 && r_type
== elfcpp::R_PPC64_ADDR64
8978 && target
->abiversion() >= 2))
8979 && gsym
->can_use_relative_reloc(false)
8980 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8981 && parameters
->options().shared()))
8983 && r_type
== elfcpp::R_PPC64_ADDR64
8984 && target
->abiversion() < 2
8985 && (gsym
->can_use_relative_reloc(false)
8986 || data_shndx
== ppc_object
->opd_shndx())))
8988 Reloc_section
* rela_dyn
8989 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8990 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8991 : elfcpp::R_POWERPC_RELATIVE
);
8992 // Use the "add" method that marks the reloc as being
8993 // relative. This is proper here and in other places
8994 // that add IRELATIVE relocs because those relocs go
8995 // into a separate section that isn't sorted, so it
8996 // doesn't matter that they are marked is_relative.
8997 rela_dyn
->add_global_relative(
8998 gsym
, dynrel
, output_section
, object
, data_shndx
,
8999 reloc
.get_r_offset(), reloc
.get_r_addend(), false);
9003 Reloc_section
* rela_dyn
9004 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9005 check_non_pic(object
, r_type
);
9006 rela_dyn
->add_global(gsym
, r_type
, output_section
,
9008 reloc
.get_r_offset(),
9009 reloc
.get_r_addend());
9012 && parameters
->options().toc_optimize()
9013 && data_shndx
== ppc_object
->toc_shndx())
9014 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9020 case elfcpp::R_PPC64_PLT_PCREL34
:
9021 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9022 case elfcpp::R_POWERPC_PLT16_LO
:
9023 case elfcpp::R_POWERPC_PLT16_HI
:
9024 case elfcpp::R_POWERPC_PLT16_HA
:
9025 case elfcpp::R_PPC64_PLT16_LO_DS
:
9028 if (branch_needs_plt_entry(gsym
))
9029 target
->make_plt_entry(symtab
, layout
, gsym
);
9031 target
->make_local_plt_entry(symtab
, layout
, gsym
);
9035 case elfcpp::R_PPC64_REL24_NOTOC
:
9039 case elfcpp::R_PPC64_REL24_P9NOTOC
:
9040 case elfcpp::R_PPC_PLTREL24
:
9041 case elfcpp::R_POWERPC_REL24
:
9044 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9045 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9046 r_type
, r_sym
, reloc
.get_r_addend());
9047 if (branch_needs_plt_entry(gsym
))
9048 target
->make_plt_entry(symtab
, layout
, gsym
);
9052 case elfcpp::R_PPC64_REL64
:
9053 case elfcpp::R_POWERPC_REL32
:
9054 // Make a dynamic relocation if necessary.
9055 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
9057 if (!parameters
->options().output_is_position_independent()
9058 && gsym
->may_need_copy_reloc())
9060 target
->copy_reloc(symtab
, layout
, object
,
9061 data_shndx
, output_section
, gsym
,
9066 Reloc_section
* rela_dyn
9067 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9068 check_non_pic(object
, r_type
);
9069 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
9070 data_shndx
, reloc
.get_r_offset(),
9071 reloc
.get_r_addend());
9076 case elfcpp::R_POWERPC_REL14
:
9077 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9078 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9081 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9082 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9083 r_type
, r_sym
, reloc
.get_r_addend());
9087 case elfcpp::R_PPC64_TOCSAVE
:
9088 // R_PPC64_TOCSAVE follows a call instruction to indicate the
9089 // caller has already saved r2 and thus a plt call stub need not
9092 && target
->mark_pltcall(ppc_object
, data_shndx
,
9093 reloc
.get_r_offset() - 4, symtab
))
9095 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9097 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9099 object
->error(_("tocsave symbol %u has bad shndx %u"),
9103 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9104 target
->add_tocsave(ppc_object
, shndx
,
9105 sym
->value() + reloc
.get_r_addend());
9110 case elfcpp::R_POWERPC_REL16
:
9111 case elfcpp::R_POWERPC_REL16_LO
:
9112 case elfcpp::R_POWERPC_REL16_HI
:
9113 case elfcpp::R_POWERPC_REL16_HA
:
9114 case elfcpp::R_POWERPC_REL16DX_HA
:
9115 case elfcpp::R_PPC64_REL16_HIGH
:
9116 case elfcpp::R_PPC64_REL16_HIGHA
:
9117 case elfcpp::R_PPC64_REL16_HIGHER
:
9118 case elfcpp::R_PPC64_REL16_HIGHERA
:
9119 case elfcpp::R_PPC64_REL16_HIGHEST
:
9120 case elfcpp::R_PPC64_REL16_HIGHESTA
:
9121 case elfcpp::R_POWERPC_SECTOFF
:
9122 case elfcpp::R_POWERPC_SECTOFF_LO
:
9123 case elfcpp::R_POWERPC_SECTOFF_HI
:
9124 case elfcpp::R_POWERPC_SECTOFF_HA
:
9125 case elfcpp::R_PPC64_SECTOFF_DS
:
9126 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9127 case elfcpp::R_POWERPC_TPREL16
:
9128 case elfcpp::R_POWERPC_TPREL16_LO
:
9129 case elfcpp::R_POWERPC_TPREL16_HI
:
9130 case elfcpp::R_POWERPC_TPREL16_HA
:
9131 case elfcpp::R_PPC64_TPREL16_DS
:
9132 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9133 case elfcpp::R_PPC64_TPREL16_HIGH
:
9134 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9135 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9136 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9137 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9138 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9139 case elfcpp::R_POWERPC_DTPREL16
:
9140 case elfcpp::R_POWERPC_DTPREL16_LO
:
9141 case elfcpp::R_POWERPC_DTPREL16_HI
:
9142 case elfcpp::R_POWERPC_DTPREL16_HA
:
9143 case elfcpp::R_PPC64_DTPREL16_DS
:
9144 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
9145 case elfcpp::R_PPC64_DTPREL16_HIGH
:
9146 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
9147 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
9148 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
9149 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
9150 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
9151 case elfcpp::R_PPC64_TLSGD
:
9152 case elfcpp::R_PPC64_TLSLD
:
9153 case elfcpp::R_PPC64_ADDR64_LOCAL
:
9156 case elfcpp::R_PPC64_GOT_PCREL34
:
9157 case elfcpp::R_POWERPC_GOT16
:
9158 case elfcpp::R_POWERPC_GOT16_LO
:
9159 case elfcpp::R_POWERPC_GOT16_HI
:
9160 case elfcpp::R_POWERPC_GOT16_HA
:
9161 case elfcpp::R_PPC64_GOT16_DS
:
9162 case elfcpp::R_PPC64_GOT16_LO_DS
:
9164 // The symbol requires a GOT entry.
9165 Output_data_got_powerpc
<size
, big_endian
>* got
;
9166 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9167 Got_type got_type
= ((size
== 32
9168 || r_type
== elfcpp::R_POWERPC_GOT16
9169 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
9170 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
9172 got
= target
->got_section(symtab
, layout
, got_type
);
9173 if (gsym
->final_value_is_known())
9176 && (size
== 32 || target
->abiversion() >= 2))
9177 got
->add_global_plt(gsym
, got_type
, addend
);
9179 got
->add_global(gsym
, got_type
, addend
);
9181 else if (!gsym
->has_got_offset(got_type
, addend
))
9183 // If we are generating a shared object or a pie, this
9184 // symbol's GOT entry will be set by a dynamic relocation.
9185 unsigned int off
= got
->add_constant(0);
9186 gsym
->set_got_offset(got_type
, off
, addend
);
9188 Reloc_section
* rela_dyn
9189 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9191 if (gsym
->can_use_relative_reloc(false)
9193 || target
->abiversion() >= 2)
9194 && gsym
->visibility() == elfcpp::STV_PROTECTED
9195 && parameters
->options().shared()))
9197 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
9198 : elfcpp::R_POWERPC_RELATIVE
);
9199 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
,
9204 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
9205 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, addend
);
9211 case elfcpp::R_PPC64_TOC16
:
9212 case elfcpp::R_PPC64_TOC16_LO
:
9213 case elfcpp::R_PPC64_TOC16_HI
:
9214 case elfcpp::R_PPC64_TOC16_HA
:
9215 case elfcpp::R_PPC64_TOC16_DS
:
9216 case elfcpp::R_PPC64_TOC16_LO_DS
:
9217 // We need a GOT section.
9218 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
9221 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9222 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9223 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9224 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9225 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9227 bool final
= gsym
->final_value_is_known();
9228 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9229 if (tls_type
== tls::TLSOPT_NONE
)
9231 Got_type got_type
= ((size
== 32
9232 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9233 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
9234 Output_data_got_powerpc
<size
, big_endian
>* got
9235 = target
->got_section(symtab
, layout
, got_type
);
9236 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9237 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9238 got
->add_global_pair_with_rel(gsym
, got_type
, rela_dyn
,
9239 elfcpp::R_POWERPC_DTPMOD
,
9240 elfcpp::R_POWERPC_DTPREL
,
9243 else if (tls_type
== tls::TLSOPT_TO_IE
)
9245 Got_type got_type
= ((size
== 32
9246 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9247 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9248 if (!gsym
->has_got_offset(got_type
))
9250 Output_data_got_powerpc
<size
, big_endian
>* got
9251 = target
->got_section(symtab
, layout
, got_type
);
9252 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9253 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9254 if (gsym
->is_undefined()
9255 || gsym
->is_from_dynobj())
9257 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9258 elfcpp::R_POWERPC_TPREL
, addend
);
9262 unsigned int off
= got
->add_constant(0);
9263 gsym
->set_got_offset(got_type
, off
);
9264 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9265 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9270 else if (tls_type
== tls::TLSOPT_TO_LE
)
9272 // no GOT relocs needed for Local Exec.
9279 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9280 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9281 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9282 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9283 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9285 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9286 if (tls_type
== tls::TLSOPT_NONE
)
9287 target
->tlsld_got_offset(symtab
, layout
, object
);
9288 else if (tls_type
== tls::TLSOPT_TO_LE
)
9290 // no GOT relocs needed for Local Exec.
9291 if (parameters
->options().emit_relocs())
9293 Output_section
* os
= layout
->tls_segment()->first_section();
9294 gold_assert(os
!= NULL
);
9295 os
->set_needs_symtab_index();
9303 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9304 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9305 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9306 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9307 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9309 Got_type got_type
= ((size
== 32
9310 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
9311 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
9312 Output_data_got_powerpc
<size
, big_endian
>* got
9313 = target
->got_section(symtab
, layout
, got_type
);
9314 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9315 if (!gsym
->final_value_is_known()
9316 && (gsym
->is_from_dynobj()
9317 || gsym
->is_undefined()
9318 || gsym
->is_preemptible()))
9319 got
->add_global_with_rel(gsym
, got_type
,
9320 target
->rela_dyn_section(layout
),
9321 elfcpp::R_POWERPC_DTPREL
, addend
);
9323 got
->add_global_tls(gsym
, got_type
, addend
);
9327 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9328 case elfcpp::R_POWERPC_GOT_TPREL16
:
9329 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9330 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9331 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9333 bool final
= gsym
->final_value_is_known();
9334 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9335 if (tls_type
== tls::TLSOPT_NONE
)
9337 Got_type got_type
= ((size
== 32
9338 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
9339 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9340 if (!gsym
->has_got_offset(got_type
))
9342 Output_data_got_powerpc
<size
, big_endian
>* got
9343 = target
->got_section(symtab
, layout
, got_type
);
9344 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9345 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9346 if (gsym
->is_undefined()
9347 || gsym
->is_from_dynobj())
9349 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9350 elfcpp::R_POWERPC_TPREL
, addend
);
9354 unsigned int off
= got
->add_constant(0);
9355 gsym
->set_got_offset(got_type
, off
);
9356 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9357 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9362 else if (tls_type
== tls::TLSOPT_TO_LE
)
9364 // no GOT relocs needed for Local Exec.
9372 unsupported_reloc_global(object
, r_type
, gsym
);
9377 && parameters
->options().toc_optimize())
9379 if (data_shndx
== ppc_object
->toc_shndx())
9382 if (r_type
!= elfcpp::R_PPC64_ADDR64
9383 || (is_ifunc
&& target
->abiversion() < 2))
9385 else if (parameters
->options().output_is_position_independent()
9386 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9389 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9392 enum {no_check
, check_lo
, check_ha
} insn_check
;
9396 insn_check
= no_check
;
9399 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9400 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9401 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9402 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9403 case elfcpp::R_POWERPC_GOT16_HA
:
9404 case elfcpp::R_PPC64_TOC16_HA
:
9405 insn_check
= check_ha
;
9408 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9409 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9410 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9411 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9412 case elfcpp::R_POWERPC_GOT16_LO
:
9413 case elfcpp::R_PPC64_GOT16_LO_DS
:
9414 case elfcpp::R_PPC64_TOC16_LO
:
9415 case elfcpp::R_PPC64_TOC16_LO_DS
:
9416 insn_check
= check_lo
;
9420 section_size_type slen
;
9421 const unsigned char* view
= NULL
;
9422 if (insn_check
!= no_check
)
9424 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9425 section_size_type off
=
9426 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9429 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9430 if (insn_check
== check_lo
9431 ? !ok_lo_toc_insn(insn
, r_type
)
9432 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9433 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9435 ppc_object
->set_no_toc_opt();
9436 gold_warning(_("%s: toc optimization is not supported "
9437 "for %#08x instruction"),
9438 ppc_object
->name().c_str(), insn
);
9447 case elfcpp::R_PPC64_TOC16
:
9448 case elfcpp::R_PPC64_TOC16_LO
:
9449 case elfcpp::R_PPC64_TOC16_HI
:
9450 case elfcpp::R_PPC64_TOC16_HA
:
9451 case elfcpp::R_PPC64_TOC16_DS
:
9452 case elfcpp::R_PPC64_TOC16_LO_DS
:
9453 if (gsym
->source() == Symbol::FROM_OBJECT
9454 && !gsym
->object()->is_dynamic())
9456 Powerpc_relobj
<size
, big_endian
>* sym_object
9457 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9459 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9460 if (shndx
== sym_object
->toc_shndx())
9462 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9463 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9464 if (dst_off
< sym_object
->section_size(shndx
))
9467 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9469 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9471 // Need to check that the insn is a ld
9473 view
= ppc_object
->section_contents(data_shndx
,
9476 section_size_type off
=
9477 (convert_to_section_size_type(reloc
.get_r_offset())
9478 + (big_endian
? -2 : 3));
9480 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9484 sym_object
->set_no_toc_opt(dst_off
);
9496 case elfcpp::R_PPC_LOCAL24PC
:
9497 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9498 gold_error(_("%s: unsupported -mbss-plt code"),
9499 ppc_object
->name().c_str());
9508 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9509 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9510 case elfcpp::R_POWERPC_GOT_TPREL16
:
9511 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9512 case elfcpp::R_POWERPC_GOT16
:
9513 case elfcpp::R_PPC64_GOT16_DS
:
9514 case elfcpp::R_PPC64_TOC16
:
9515 case elfcpp::R_PPC64_TOC16_DS
:
9516 ppc_object
->set_has_small_toc_reloc();
9524 case elfcpp::R_PPC64_TPREL16_DS
:
9525 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9526 case elfcpp::R_PPC64_TPREL16_HIGH
:
9527 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9528 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9529 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9530 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9531 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9532 case elfcpp::R_PPC64_TPREL34
:
9536 case elfcpp::R_POWERPC_TPREL16
:
9537 case elfcpp::R_POWERPC_TPREL16_LO
:
9538 case elfcpp::R_POWERPC_TPREL16_HI
:
9539 case elfcpp::R_POWERPC_TPREL16_HA
:
9540 layout
->set_has_static_tls();
9548 case elfcpp::R_POWERPC_TPREL16_HA
:
9549 if (target
->tprel_opt())
9551 section_size_type slen
;
9552 const unsigned char* view
= NULL
;
9553 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9554 section_size_type off
9555 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9558 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9559 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9560 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9561 target
->set_no_tprel_opt();
9566 case elfcpp::R_PPC64_TPREL16_HIGH
:
9567 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9568 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9569 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9570 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9571 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9575 case elfcpp::R_POWERPC_TPREL16_HI
:
9576 target
->set_no_tprel_opt();
9584 case elfcpp::R_PPC64_D34
:
9585 case elfcpp::R_PPC64_D34_LO
:
9586 case elfcpp::R_PPC64_D34_HI30
:
9587 case elfcpp::R_PPC64_D34_HA30
:
9588 case elfcpp::R_PPC64_D28
:
9589 case elfcpp::R_PPC64_PCREL34
:
9590 case elfcpp::R_PPC64_PCREL28
:
9591 case elfcpp::R_PPC64_TPREL34
:
9592 case elfcpp::R_PPC64_DTPREL34
:
9593 case elfcpp::R_PPC64_PLT_PCREL34
:
9594 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9595 case elfcpp::R_PPC64_GOT_PCREL34
:
9596 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9597 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9598 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9599 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9600 target
->set_power10_relocs();
9607 // Process relocations for gc.
9609 template<int size
, bool big_endian
>
9611 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9612 Symbol_table
* symtab
,
9614 Sized_relobj_file
<size
, big_endian
>* object
,
9615 unsigned int data_shndx
,
9617 const unsigned char* prelocs
,
9619 Output_section
* output_section
,
9620 bool needs_special_offset_handling
,
9621 size_t local_symbol_count
,
9622 const unsigned char* plocal_symbols
)
9624 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9625 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9628 Powerpc_relobj
<size
, big_endian
>* ppc_object
9629 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9631 ppc_object
->set_opd_valid();
9632 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9634 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9635 for (p
= ppc_object
->access_from_map()->begin();
9636 p
!= ppc_object
->access_from_map()->end();
9639 Address dst_off
= p
->first
;
9640 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9641 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9642 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9644 Relobj
* src_obj
= s
->first
;
9645 unsigned int src_indx
= s
->second
;
9646 symtab
->gc()->add_reference(src_obj
, src_indx
,
9647 ppc_object
, dst_indx
);
9651 ppc_object
->access_from_map()->clear();
9652 ppc_object
->process_gc_mark(symtab
);
9653 // Don't look at .opd relocs as .opd will reference everything.
9657 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9666 needs_special_offset_handling
,
9671 // Handle target specific gc actions when adding a gc reference from
9672 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9673 // and DST_OFF. For powerpc64, this adds a referenc to the code
9674 // section of a function descriptor.
9676 template<int size
, bool big_endian
>
9678 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9679 Symbol_table
* symtab
,
9681 unsigned int src_shndx
,
9683 unsigned int dst_shndx
,
9684 Address dst_off
) const
9686 if (size
!= 64 || dst_obj
->is_dynamic())
9689 Powerpc_relobj
<size
, big_endian
>* ppc_object
9690 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9691 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9693 if (ppc_object
->opd_valid())
9695 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9696 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9700 // If we haven't run scan_opd_relocs, we must delay
9701 // processing this function descriptor reference.
9702 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9707 // Add any special sections for this symbol to the gc work list.
9708 // For powerpc64, this adds the code section of a function
9711 template<int size
, bool big_endian
>
9713 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9714 Symbol_table
* symtab
,
9717 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9719 Powerpc_relobj
<size
, big_endian
>* ppc_object
9720 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9722 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9723 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9725 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9726 Address dst_off
= gsym
->value();
9727 if (ppc_object
->opd_valid())
9729 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9730 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9734 ppc_object
->add_gc_mark(dst_off
);
9739 // For a symbol location in .opd, set LOC to the location of the
9742 template<int size
, bool big_endian
>
9744 Target_powerpc
<size
, big_endian
>::do_function_location(
9745 Symbol_location
* loc
) const
9747 if (size
== 64 && loc
->shndx
!= 0)
9749 if (loc
->object
->is_dynamic())
9751 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9752 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9753 if (loc
->shndx
== ppc_object
->opd_shndx())
9756 Address off
= loc
->offset
- ppc_object
->opd_address();
9757 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9758 loc
->offset
= dest_off
;
9763 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9764 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9765 if (loc
->shndx
== ppc_object
->opd_shndx())
9768 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9769 loc
->offset
= dest_off
;
9775 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9776 // compiled with -fsplit-stack. The function calls non-split-stack
9777 // code. Change the function to ensure it has enough stack space to
9778 // call some random function.
9780 template<int size
, bool big_endian
>
9782 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9785 section_offset_type fnoffset
,
9786 section_size_type fnsize
,
9787 const unsigned char* prelocs
,
9789 unsigned char* view
,
9790 section_size_type view_size
,
9792 std::string
* to
) const
9794 // 32-bit not supported.
9798 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9799 prelocs
, reloc_count
, view
, view_size
,
9804 // The function always starts with
9805 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9806 // addis %r12,%r1,-allocate@ha
9807 // addi %r12,%r12,-allocate@l
9809 // but note that the addis or addi may be replaced with a nop
9811 unsigned char *entry
= view
+ fnoffset
;
9812 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9814 if ((insn
& 0xffff0000) == addis_2_12
)
9816 /* Skip ELFv2 global entry code. */
9818 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9821 unsigned char *pinsn
= entry
;
9823 const uint32_t ld_private_ss
= 0xe80d8fc0;
9824 if (insn
== ld_private_ss
)
9826 int32_t allocate
= 0;
9830 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9831 if ((insn
& 0xffff0000) == addis_12_1
)
9832 allocate
+= (insn
& 0xffff) << 16;
9833 else if ((insn
& 0xffff0000) == addi_12_1
9834 || (insn
& 0xffff0000) == addi_12_12
)
9835 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9836 else if (insn
!= nop
)
9839 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9841 int extra
= parameters
->options().split_stack_adjust_size();
9843 if (allocate
>= 0 || extra
< 0)
9845 object
->error(_("split-stack stack size overflow at "
9846 "section %u offset %0zx"),
9847 shndx
, static_cast<size_t>(fnoffset
));
9851 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9852 if (insn
!= addis_12_1
)
9854 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9856 insn
= addi_12_12
| (allocate
& 0xffff);
9857 if (insn
!= addi_12_12
)
9859 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9865 insn
= addi_12_1
| (allocate
& 0xffff);
9866 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9869 if (pinsn
!= entry
+ 12)
9870 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9878 if (!object
->has_no_split_stack())
9879 object
->error(_("failed to match split-stack sequence at "
9880 "section %u offset %0zx"),
9881 shndx
, static_cast<size_t>(fnoffset
));
9885 // Scan relocations for a section.
9887 template<int size
, bool big_endian
>
9889 Target_powerpc
<size
, big_endian
>::scan_relocs(
9890 Symbol_table
* symtab
,
9892 Sized_relobj_file
<size
, big_endian
>* object
,
9893 unsigned int data_shndx
,
9894 unsigned int sh_type
,
9895 const unsigned char* prelocs
,
9897 Output_section
* output_section
,
9898 bool needs_special_offset_handling
,
9899 size_t local_symbol_count
,
9900 const unsigned char* plocal_symbols
)
9902 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9903 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9906 if (!this->plt_localentry0_init_
)
9908 bool plt_localentry0
= false;
9910 && this->abiversion() >= 2)
9912 if (parameters
->options().user_set_plt_localentry())
9913 plt_localentry0
= parameters
->options().plt_localentry();
9915 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9916 gold_warning(_("--plt-localentry is especially dangerous without "
9917 "ld.so support to detect ABI violations"));
9919 this->plt_localentry0_
= plt_localentry0
;
9920 this->plt_localentry0_init_
= true;
9923 if (sh_type
== elfcpp::SHT_REL
)
9925 gold_error(_("%s: unsupported REL reloc section"),
9926 object
->name().c_str());
9930 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9939 needs_special_offset_handling
,
9943 if (this->plt_localentry0_
&& this->power10_relocs_
)
9945 gold_warning(_("--plt-localentry is incompatible with "
9946 "power10 pc-relative code"));
9947 this->plt_localentry0_
= false;
9951 // Functor class for processing the global symbol table.
9952 // Removes symbols defined on discarded opd entries.
9954 template<bool big_endian
>
9955 class Global_symbol_visitor_opd
9958 Global_symbol_visitor_opd()
9962 operator()(Sized_symbol
<64>* sym
)
9964 if (sym
->has_symtab_index()
9965 || sym
->source() != Symbol::FROM_OBJECT
9966 || !sym
->in_real_elf())
9969 if (sym
->object()->is_dynamic())
9972 Powerpc_relobj
<64, big_endian
>* symobj
9973 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9974 if (symobj
->opd_shndx() == 0)
9978 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9979 if (shndx
== symobj
->opd_shndx()
9980 && symobj
->get_opd_discard(sym
->value()))
9982 sym
->set_undefined();
9983 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9984 sym
->set_is_defined_in_discarded_section();
9985 sym
->set_symtab_index(-1U);
9990 template<int size
, bool big_endian
>
9992 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9994 Symbol_table
* symtab
)
9998 Output_data_save_res
<size
, big_endian
>* savres
9999 = new Output_data_save_res
<size
, big_endian
>(symtab
);
10000 this->savres_section_
= savres
;
10001 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
10002 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
10003 savres
, ORDER_TEXT
, false);
10007 // Sort linker created .got section first (for the header), then input
10008 // sections belonging to files using small model code.
10010 template<bool big_endian
>
10011 class Sort_toc_sections
10013 const Output_section_data
*
10014 small_got_section() const
10016 return (static_cast<Target_powerpc
<64, big_endian
>*>(
10017 parameters
->sized_target
<64, big_endian
>())
10018 ->got_section(GOT_TYPE_SMALL
));
10022 rank(const Output_section::Input_section
& isec
) const
10024 if (!isec
.is_input_section())
10026 if (isec
.output_section_data() == this->small_got_section())
10030 if (static_cast<const Powerpc_relobj
<64, big_endian
>*>(isec
.relobj())
10031 ->has_small_toc_reloc())
10038 operator()(const Output_section::Input_section
& is1
,
10039 const Output_section::Input_section
& is2
) const
10041 return rank(is1
) < rank(is2
);
10045 // Finalize the sections.
10047 template<int size
, bool big_endian
>
10049 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
10051 const Input_objects
* input_objects
,
10052 Symbol_table
* symtab
)
10054 if (parameters
->doing_static_link())
10056 // At least some versions of glibc elf-init.o have a strong
10057 // reference to __rela_iplt marker syms. A weak ref would be
10059 if (this->iplt_
!= NULL
)
10061 Reloc_section
* rel
= this->iplt_
->rel_plt();
10062 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
10063 Symbol_table::PREDEFINED
, rel
, 0, 0,
10064 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10065 elfcpp::STV_HIDDEN
, 0, false, true);
10066 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
10067 Symbol_table::PREDEFINED
, rel
, 0, 0,
10068 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10069 elfcpp::STV_HIDDEN
, 0, true, true);
10073 symtab
->define_as_constant("__rela_iplt_start", NULL
,
10074 Symbol_table::PREDEFINED
, 0, 0,
10075 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10076 elfcpp::STV_HIDDEN
, 0, true, false);
10077 symtab
->define_as_constant("__rela_iplt_end", NULL
,
10078 Symbol_table::PREDEFINED
, 0, 0,
10079 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10080 elfcpp::STV_HIDDEN
, 0, true, false);
10086 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
10087 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
10089 if (!parameters
->options().relocatable())
10091 this->define_save_restore_funcs(layout
, symtab
);
10093 // Annoyingly, we need to make these sections now whether or
10094 // not we need them. If we delay until do_relax then we
10095 // need to mess with the relaxation machinery checkpointing.
10096 this->got_section(symtab
, layout
, GOT_TYPE_STANDARD
);
10097 this->make_brlt_section(layout
);
10099 // FIXME, maybe. Here we could run through all the got
10100 // entries in the small got section, removing any duplicates
10101 // found in the big got section and renumbering offsets.
10103 if (parameters
->options().toc_sort())
10105 Output_section
* os
= this->got_
->output_section();
10106 if (os
!= NULL
&& os
->input_sections().size() > 1)
10107 std::stable_sort(os
->input_sections().begin(),
10108 os
->input_sections().end(),
10109 Sort_toc_sections
<big_endian
>());
10114 // Fill in some more dynamic tags.
10115 Output_data_dynamic
* odyn
= layout
->dynamic_data();
10118 const Reloc_section
* rel_plt
= (this->plt_
== NULL
10120 : this->plt_
->rel_plt());
10121 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
10122 this->rela_dyn_
, true, size
== 32, true);
10126 if (this->got_
!= NULL
)
10128 this->got_
->finalize_data_size();
10129 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
10130 this->got_
, this->got_
->g_o_t());
10132 if (this->has_tls_get_addr_opt_
)
10133 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
10137 if (this->glink_
!= NULL
)
10139 this->glink_
->finalize_data_size();
10140 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
10142 (this->glink_
->pltresolve_size()
10145 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
10146 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
10147 ((this->has_localentry0_
10148 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
10149 | (this->has_tls_get_addr_opt_
10150 ? elfcpp::PPC64_OPT_TLS
: 0)));
10154 // Emit any relocs we saved in an attempt to avoid generating COPY
10156 if (this->copy_relocs_
.any_saved_relocs())
10157 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
10159 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
10160 p
!= input_objects
->relobj_end();
10163 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
10164 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
10165 if (ppc_relobj
->attributes_section_data())
10166 this->merge_object_attributes(ppc_relobj
,
10167 ppc_relobj
->attributes_section_data());
10169 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
10170 p
!= input_objects
->dynobj_end();
10173 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
10174 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
10175 if (ppc_dynobj
->attributes_section_data())
10176 this->merge_object_attributes(ppc_dynobj
,
10177 ppc_dynobj
->attributes_section_data());
10180 // Create a .gnu.attributes section if we have merged any attributes
10182 if (this->attributes_section_data_
!= NULL
10183 && this->attributes_section_data_
->size() != 0)
10185 Output_attributes_section_data
* attributes_section
10186 = new Output_attributes_section_data(*this->attributes_section_data_
);
10187 layout
->add_output_section_data(".gnu.attributes",
10188 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
10189 attributes_section
, ORDER_INVALID
, false);
10193 // Get the custom dynamic tag value.
10195 template<int size
, bool big_endian
>
10197 Target_powerpc
<size
, big_endian
>::do_dynamic_tag_custom_value(
10198 elfcpp::DT tag
) const
10200 if (tag
!= elfcpp::DT_RELACOUNT
)
10201 gold_unreachable();
10202 return this->rela_dyn_
->relative_reloc_count();
10205 // Merge object attributes from input file called NAME with those of the
10206 // output. The input object attributes are in the object pointed by PASD.
10208 template<int size
, bool big_endian
>
10210 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
10212 const Attributes_section_data
* pasd
)
10214 // Return if there is no attributes section data.
10218 // Create output object attributes.
10219 if (this->attributes_section_data_
== NULL
)
10220 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
10222 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
10223 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
10224 Object_attribute
* out_attr
10225 = this->attributes_section_data_
->known_attributes(vendor
);
10227 const char* name
= obj
->name().c_str();
10230 const char* second
;
10231 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
10232 int in_fp
= in_attr
[tag
].int_value() & 0xf;
10233 int out_fp
= out_attr
[tag
].int_value() & 0xf;
10234 bool warn_only
= obj
->is_dynamic();
10235 if (in_fp
!= out_fp
)
10238 if ((in_fp
& 3) == 0)
10240 else if ((out_fp
& 3) == 0)
10244 out_fp
|= in_fp
& 3;
10245 out_attr
[tag
].set_int_value(out_fp
);
10246 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10247 this->last_fp_
= name
;
10250 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
10252 err
= N_("%s uses hard float, %s uses soft float");
10253 first
= this->last_fp_
;
10256 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10258 err
= N_("%s uses hard float, %s uses soft float");
10260 second
= this->last_fp_
;
10262 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10264 err
= N_("%s uses double-precision hard float, "
10265 "%s uses single-precision hard float");
10266 first
= this->last_fp_
;
10269 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10271 err
= N_("%s uses double-precision hard float, "
10272 "%s uses single-precision hard float");
10274 second
= this->last_fp_
;
10277 if (err
|| (in_fp
& 0xc) == 0)
10279 else if ((out_fp
& 0xc) == 0)
10283 out_fp
|= in_fp
& 0xc;
10284 out_attr
[tag
].set_int_value(out_fp
);
10285 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10286 this->last_ld_
= name
;
10289 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10291 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10293 second
= this->last_ld_
;
10295 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10297 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10298 first
= this->last_ld_
;
10301 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10303 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10304 first
= this->last_ld_
;
10307 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10309 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10311 second
= this->last_ld_
;
10316 if (parameters
->options().warn_mismatch())
10319 gold_warning(_(err
), first
, second
);
10321 gold_error(_(err
), first
, second
);
10323 // Arrange for this attribute to be deleted. It's better to
10324 // say "don't know" about a file than to wrongly claim compliance.
10326 out_attr
[tag
].set_type(0);
10332 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10333 int in_vec
= in_attr
[tag
].int_value() & 3;
10334 int out_vec
= out_attr
[tag
].int_value() & 3;
10335 if (in_vec
!= out_vec
)
10340 else if (out_vec
== 0)
10343 out_attr
[tag
].set_int_value(out_vec
);
10344 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10345 this->last_vec_
= name
;
10347 // For now, allow generic to transition to AltiVec or SPE
10348 // without a warning. If GCC marked files with their stack
10349 // alignment and used don't-care markings for files which are
10350 // not affected by the vector ABI, we could warn about this
10352 else if (in_vec
== 1)
10354 else if (out_vec
== 1)
10357 out_attr
[tag
].set_int_value(out_vec
);
10358 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10359 this->last_vec_
= name
;
10361 else if (out_vec
< in_vec
)
10363 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10364 first
= this->last_vec_
;
10367 else if (out_vec
> in_vec
)
10369 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10371 second
= this->last_vec_
;
10375 if (parameters
->options().warn_mismatch())
10376 gold_error(_(err
), first
, second
);
10377 out_attr
[tag
].set_type(0);
10381 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10382 int in_struct
= in_attr
[tag
].int_value() & 3;
10383 int out_struct
= out_attr
[tag
].int_value() & 3;
10384 if (in_struct
!= out_struct
)
10387 if (in_struct
== 0 || in_struct
== 3)
10389 else if (out_struct
== 0)
10391 out_struct
= in_struct
;
10392 out_attr
[tag
].set_int_value(out_struct
);
10393 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10394 this->last_struct_
= name
;
10396 else if (out_struct
< in_struct
)
10398 err
= N_("%s uses r3/r4 for small structure returns, "
10400 first
= this->last_struct_
;
10403 else if (out_struct
> in_struct
)
10405 err
= N_("%s uses r3/r4 for small structure returns, "
10408 second
= this->last_struct_
;
10412 if (parameters
->options().warn_mismatch())
10413 gold_error(_(err
), first
, second
);
10414 out_attr
[tag
].set_type(0);
10419 // Merge Tag_compatibility attributes and any common GNU ones.
10420 this->attributes_section_data_
->merge(name
, pasd
);
10423 // Emit any saved relocs, and mark toc entries using any of these
10424 // relocs as not optimizable.
10426 template<int sh_type
, int size
, bool big_endian
>
10428 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10429 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10432 && parameters
->options().toc_optimize())
10434 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10435 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10436 p
!= this->entries_
.end();
10439 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10442 // If the symbol is no longer defined in a dynamic object,
10443 // then we emitted a COPY relocation. If it is still
10444 // dynamic then we'll need dynamic relocations and thus
10445 // can't optimize toc entries.
10446 if (entry
.sym_
->is_from_dynobj())
10448 Powerpc_relobj
<size
, big_endian
>* ppc_object
10449 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10450 if (entry
.shndx_
== ppc_object
->toc_shndx())
10451 ppc_object
->set_no_toc_opt(entry
.address_
);
10456 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10459 // Return the value to use for a branch relocation.
10461 template<int size
, bool big_endian
>
10463 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10464 const Symbol_table
* symtab
,
10465 const Sized_symbol
<size
>* gsym
,
10466 Powerpc_relobj
<size
, big_endian
>* object
,
10468 unsigned int *dest_shndx
)
10470 if (size
== 32 || this->abiversion() >= 2)
10471 gold_unreachable();
10474 // If the symbol is defined in an opd section, ie. is a function
10475 // descriptor, use the function descriptor code entry address
10476 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10478 && (gsym
->source() != Symbol::FROM_OBJECT
10479 || gsym
->object()->is_dynamic()))
10482 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10483 unsigned int shndx
= symobj
->opd_shndx();
10486 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10487 if (opd_addr
== invalid_address
)
10489 opd_addr
+= symobj
->output_section_address(shndx
);
10490 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10493 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10494 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10497 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10498 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10499 *dest_shndx
= folded
.second
;
10501 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10502 if (sec_addr
== invalid_address
)
10505 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10506 *value
= sec_addr
+ sec_off
;
10513 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10515 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10518 if (gsym
->is_from_dynobj()
10519 || gsym
->is_undefined()
10520 || gsym
->is_preemptible())
10523 if (gsym
->is_absolute())
10524 return !parameters
->options().output_is_position_independent();
10531 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10533 if (psymval
->is_ifunc_symbol())
10537 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10539 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10542 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10543 // pld ra,symbol@got@pcrel
10544 // load/store rt,0(ra)
10546 // pla ra,symbol@pcrel
10547 // load/store rt,0(ra)
10548 // may be translated to
10549 // pload/pstore rt,symbol@pcrel
10551 // This function returns true if the optimization is possible, placing
10552 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10554 // On entry to this function, the linker has already determined that
10555 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10556 // while *PINSN2 is the second instruction.
10559 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10561 uint32_t insn2
= *pinsn2
>> 32;
10564 // Check that regs match.
10565 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10568 switch ((insn2
>> 26) & 63)
10584 // These are the PMLS cases, where we just need to tack a prefix
10585 // on the insn. Check that the D field is zero.
10586 if ((insn2
& 0xffff) != 0)
10588 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10589 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10592 case 58: // lwa, ld
10593 if ((insn2
& 0xfffd) != 0)
10595 i1new
= ((1ULL << 58) | (1ULL << 52)
10596 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10597 | (insn2
& (31ULL << 21)));
10600 case 57: // lxsd, lxssp
10601 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10603 i1new
= ((1ULL << 58) | (1ULL << 52)
10604 | ((40ULL | (insn2
& 3)) << 26)
10605 | (insn2
& (31ULL << 21)));
10608 case 61: // stxsd, stxssp, lxv, stxv
10609 if ((insn2
& 3) == 0)
10611 else if ((insn2
& 3) >= 2)
10613 if ((insn2
& 0xfffc) != 0)
10615 i1new
= ((1ULL << 58) | (1ULL << 52)
10616 | ((44ULL | (insn2
& 3)) << 26)
10617 | (insn2
& (31ULL << 21)));
10621 if ((insn2
& 0xfff0) != 0)
10623 i1new
= ((1ULL << 58) | (1ULL << 52)
10624 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10625 | (insn2
& (31ULL << 21)));
10630 if ((insn2
& 0xffff) != 0)
10632 i1new
= ((1ULL << 58) | (1ULL << 52)
10633 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10636 case 62: // std, stq
10637 if ((insn2
& 0xfffd) != 0)
10639 i1new
= ((1ULL << 58) | (1ULL << 52)
10640 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10641 | (insn2
& (31ULL << 21)));
10646 *pinsn2
= (uint64_t) nop
<< 32;
10650 // Perform a relocation.
10652 template<int size
, bool big_endian
>
10654 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10655 const Relocate_info
<size
, big_endian
>* relinfo
,
10657 Target_powerpc
* target
,
10658 Output_section
* os
,
10660 const unsigned char* preloc
,
10661 const Sized_symbol
<size
>* gsym
,
10662 const Symbol_value
<size
>* psymval
,
10663 unsigned char* view
,
10665 section_size_type view_size
)
10667 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10668 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10669 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10674 if (target
->replace_tls_get_addr(gsym
))
10675 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10677 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10678 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10679 Powerpc_relobj
<size
, big_endian
>* const object
10680 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10681 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10683 case Track_tls::NOT_EXPECTED
:
10684 // No warning. This will result in really old code without tls
10685 // marker relocs being mis-optimised, but there shouldn't be too
10686 // much of that code around. The problem with warning is that
10687 // glibc and libphobos both construct direct calls to
10688 // __tls_get_addr in a way that is harmless.
10690 case Track_tls::EXPECTED
:
10691 // We have already complained.
10693 case Track_tls::SKIP
:
10694 if (is_plt16_reloc
<size
>(r_type
)
10695 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10696 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10698 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10699 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10701 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10703 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10704 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10706 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10707 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10709 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10710 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10711 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10714 case Track_tls::NORMAL
:
10718 // Offset from start of insn to d-field reloc.
10719 const int d_offset
= big_endian
? 2 : 0;
10722 bool has_stub_value
= false;
10723 bool localentry0
= false;
10724 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10725 bool pltcall_to_direct
= false;
10727 if (is_plt16_reloc
<size
>(r_type
)
10728 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10729 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10730 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10731 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
10732 || r_type
== elfcpp::R_POWERPC_PLTCALL
10733 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10735 // It would be possible to replace inline plt calls with direct
10736 // calls if the PLTCALL is in range. The only difficulty is
10737 // that the decision depends on the PLTCALL reloc, and we don't
10738 // know the address of that instruction when processing others
10739 // in the sequence. So the decision needs to be made in
10741 pltcall_to_direct
= !(gsym
!= NULL
10742 ? gsym
->has_plt_offset()
10743 : object
->local_has_plt_offset(r_sym
));
10745 else if ((gsym
!= NULL
10746 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10747 : psymval
->is_ifunc_symbol() && object
->local_has_plt_offset(r_sym
))
10748 && !is_got_reloc(r_type
)
10749 && (!psymval
->is_ifunc_symbol()
10750 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
,
10755 && target
->abiversion() >= 2
10756 && !parameters
->options().output_is_position_independent()
10757 && !is_branch_reloc
<size
>(r_type
))
10759 Address off
= target
->glink_section()->find_global_entry(gsym
);
10760 if (off
!= invalid_address
)
10762 value
= target
->glink_section()->global_entry_address() + off
;
10763 has_stub_value
= true;
10768 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10769 if (target
->stub_tables().size() == 1)
10770 stub_table
= target
->stub_tables()[0];
10771 if (stub_table
== NULL
10774 && !parameters
->options().output_is_position_independent()
10775 && !is_branch_reloc
<size
>(r_type
)))
10776 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10777 if (stub_table
== NULL
)
10779 // This is a ref from a data section to an ifunc symbol,
10780 // or a non-branch reloc for which we always want to use
10781 // one set of stubs for resolving function addresses.
10782 if (target
->stub_tables().size() != 0)
10783 stub_table
= target
->stub_tables()[0];
10785 if (stub_table
!= NULL
)
10787 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10789 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10790 rela
.get_r_addend());
10792 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10793 rela
.get_r_addend());
10796 value
= stub_table
->stub_address() + ent
->off_
;
10797 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10798 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10799 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10802 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10805 value
+= ent
->p9off_
;
10807 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10808 value
+= ent
->p9off_
;
10810 value
+= ent
->tocoff_
;
10815 && target
->is_tls_get_addr_opt(gsym
)))
10817 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
10818 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10820 if (!(target
->power10_stubs()
10821 && target
->power10_stubs_auto()))
10824 else if (relnum
< reloc_count
- 1)
10826 Reltype
next_rela(preloc
+ reloc_size
);
10827 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10828 == elfcpp::R_PPC64_TOCSAVE
10829 && (next_rela
.get_r_offset()
10830 == rela
.get_r_offset() + 4))
10834 localentry0
= ent
->localentry0_
;
10835 has_stub_value
= true;
10839 // We don't care too much about bogus debug references to
10840 // non-local functions, but otherwise there had better be a plt
10841 // call stub or global entry stub as appropriate.
10842 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10845 if (!pltcall_to_direct
&& (is_plt16_reloc
<size
>(r_type
)
10846 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10847 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10849 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10851 value
= target
->plt_off(gsym
, &plt
);
10853 value
= target
->plt_off(object
, r_sym
, &plt
);
10854 value
+= plt
->address();
10858 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10859 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10860 value
-= target
->toc_pointer();
10862 else if (parameters
->options().output_is_position_independent())
10864 if (rela
.get_r_addend() >= 32768)
10866 unsigned int got2
= object
->got2_shndx();
10867 value
-= (object
->get_output_section_offset(got2
)
10868 + object
->output_section(got2
)->address()
10869 + rela
.get_r_addend());
10872 value
-= target
->toc_pointer();
10875 else if (pltcall_to_direct
10876 && (is_plt16_reloc
<size
>(r_type
)
10877 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10878 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10880 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10881 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10882 r_type
= elfcpp::R_POWERPC_NONE
;
10884 else if (pltcall_to_direct
10885 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10886 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10888 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10889 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10890 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10891 r_type
= elfcpp::R_POWERPC_NONE
;
10893 else if (is_got_reloc(r_type
))
10895 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10896 Got_type got_type
= ((size
== 32
10897 || r_type
== elfcpp::R_POWERPC_GOT16
10898 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
10899 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10901 value
= gsym
->got_offset(got_type
, addend
);
10903 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10904 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10905 value
+= target
->got_section(got_type
)->address();
10907 value
-= target
->got_base_offset(got_type
);
10909 else if (r_type
== elfcpp::R_PPC64_TOC
)
10911 value
= target
->toc_pointer();
10913 else if (gsym
!= NULL
10914 && (r_type
== elfcpp::R_POWERPC_REL24
10915 || r_type
== elfcpp::R_PPC_PLTREL24
)
10920 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10921 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10922 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10923 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10925 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10926 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10927 if ((insn
& 1) != 0
10929 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10931 elfcpp::Swap
<32, big_endian
>::
10932 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10933 can_plt_call
= true;
10938 // If we don't have a branch and link followed by a nop,
10939 // we can't go via the plt because there is no place to
10940 // put a toc restoring instruction.
10941 // Unless we know we won't be returning.
10942 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10943 can_plt_call
= true;
10947 // g++ as of 20130507 emits self-calls without a
10948 // following nop. This is arguably wrong since we have
10949 // conflicting information. On the one hand a global
10950 // symbol and on the other a local call sequence, but
10951 // don't error for this special case.
10952 // It isn't possible to cheaply verify we have exactly
10953 // such a call. Allow all calls to the same section.
10955 Address code
= value
;
10956 if (gsym
->source() == Symbol::FROM_OBJECT
10957 && gsym
->object() == object
)
10959 unsigned int dest_shndx
= 0;
10960 if (target
->abiversion() < 2)
10962 Address addend
= rela
.get_r_addend();
10963 code
= psymval
->value(object
, addend
);
10964 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10965 &code
, &dest_shndx
);
10968 if (dest_shndx
== 0)
10969 dest_shndx
= gsym
->shndx(&is_ordinary
);
10970 ok
= dest_shndx
== relinfo
->data_shndx
;
10974 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10975 _("call lacks nop, can't restore toc; "
10976 "recompile with -fPIC"));
10982 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10983 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10984 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10985 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10986 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10988 // First instruction of a global dynamic sequence, arg setup insn.
10989 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10990 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10991 Got_type got_type
= ((size
== 32
10992 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
10993 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10994 if (tls_type
== tls::TLSOPT_NONE
)
10995 got_type
= Got_type(got_type
| GOT_TYPE_TLSGD
);
10996 else if (tls_type
== tls::TLSOPT_TO_IE
)
10997 got_type
= Got_type(got_type
| GOT_TYPE_TPREL
);
10998 if ((got_type
& ~GOT_TYPE_SMALL
) != GOT_TYPE_STANDARD
)
11000 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11002 value
= gsym
->got_offset(got_type
, addend
);
11004 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11005 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11006 value
+= target
->got_section(got_type
)->address();
11008 value
-= target
->got_base_offset(got_type
);
11010 if (tls_type
== tls::TLSOPT_TO_IE
)
11012 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11014 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11015 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11017 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11019 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
11020 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11021 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11022 pinsn
& 0xffffffff);
11023 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
11027 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11028 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11030 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11031 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11032 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
11034 insn
|= 32 << 26; // lwz
11036 insn
|= 58 << 26; // ld
11037 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11039 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11040 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11043 else if (tls_type
== tls::TLSOPT_TO_LE
)
11045 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11047 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11048 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11050 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11051 // pla pcrel -> paddi r13
11052 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11053 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11054 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11055 pinsn
& 0xffffffff);
11056 r_type
= elfcpp::R_PPC64_TPREL34
;
11057 value
= psymval
->value(object
, rela
.get_r_addend());
11061 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11062 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11064 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11065 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11066 insn
&= (1 << 26) - (1 << 21); // extract rt
11070 insn
|= addis_0_13
;
11071 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11072 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11073 value
= psymval
->value(object
, rela
.get_r_addend());
11077 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11079 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11080 r_type
= elfcpp::R_POWERPC_NONE
;
11085 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11086 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11087 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11088 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
11089 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11091 // First instruction of a local dynamic sequence, arg setup insn.
11092 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11093 if (tls_type
== tls::TLSOPT_NONE
)
11095 value
= target
->tlsld_got_offset();
11096 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11097 value
+= target
->got_section(GOT_TYPE_SMALL
)->address();
11099 value
-= target
->got_base_offset(GOT_TYPE_SMALL
);
11103 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11104 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11106 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11107 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11109 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11110 // pla pcrel -> paddi r13
11111 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11112 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11113 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11114 pinsn
& 0xffffffff);
11115 r_type
= elfcpp::R_PPC64_TPREL34
;
11116 value
= dtp_offset
;
11118 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11119 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11121 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11122 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11123 insn
&= (1 << 26) - (1 << 21); // extract rt
11127 insn
|= addis_0_13
;
11128 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11129 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11130 value
= dtp_offset
;
11134 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11136 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11137 r_type
= elfcpp::R_POWERPC_NONE
;
11141 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
11142 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
11143 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
11144 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
11145 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11147 // Accesses relative to a local dynamic sequence address,
11148 // no optimisation here.
11149 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11150 Got_type got_type
= ((size
== 32
11151 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
11152 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
11154 value
= gsym
->got_offset(got_type
, addend
);
11156 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11157 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11158 value
+= target
->got_section(got_type
)->address();
11160 value
-= target
->got_base_offset(got_type
);
11162 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11163 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11164 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11165 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
11166 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11168 // First instruction of initial exec sequence.
11169 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11170 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11171 if (tls_type
== tls::TLSOPT_NONE
)
11173 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11174 Got_type got_type
= ((size
== 32
11175 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
11176 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
11178 value
= gsym
->got_offset(got_type
, addend
);
11180 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11181 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11182 value
+= target
->got_section(got_type
)->address();
11184 value
-= target
->got_base_offset(got_type
);
11188 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11189 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11191 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11192 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11194 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11195 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
11196 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
11197 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
11198 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11199 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11200 pinsn
& 0xffffffff);
11201 r_type
= elfcpp::R_PPC64_TPREL34
;
11202 value
= psymval
->value(object
, rela
.get_r_addend());
11204 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11205 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11207 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11208 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11209 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
11213 insn
|= addis_0_13
;
11214 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11215 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11216 value
= psymval
->value(object
, rela
.get_r_addend());
11220 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11222 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11223 r_type
= elfcpp::R_POWERPC_NONE
;
11227 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11228 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11230 // Second instruction of a global dynamic sequence,
11231 // the __tls_get_addr call
11232 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11233 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11234 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
11235 if (tls_type
!= tls::TLSOPT_NONE
)
11237 if (tls_type
== tls::TLSOPT_TO_IE
)
11239 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11240 Insn insn
= add_3_3_13
;
11243 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11244 r_type
= elfcpp::R_POWERPC_NONE
;
11248 bool is_pcrel
= false;
11249 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11250 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11251 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11252 if (relnum
< reloc_count
- 1)
11254 Reltype
next_rela(preloc
+ reloc_size
);
11255 unsigned int r_type2
11256 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11257 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11258 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11259 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11260 && next_rela
.get_r_offset() == rela
.get_r_offset())
11263 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11266 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11267 r_type
= elfcpp::R_POWERPC_NONE
;
11271 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11272 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11274 value
= psymval
->value(object
, rela
.get_r_addend());
11277 this->skip_next_tls_get_addr_call();
11280 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11281 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11283 // Second instruction of a local dynamic sequence,
11284 // the __tls_get_addr call
11285 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11286 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11287 if (tls_type
== tls::TLSOPT_TO_LE
)
11289 bool is_pcrel
= false;
11290 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11291 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11292 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11293 if (relnum
< reloc_count
- 1)
11295 Reltype
next_rela(preloc
+ reloc_size
);
11296 unsigned int r_type2
11297 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11298 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11299 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11300 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11301 && next_rela
.get_r_offset() == rela
.get_r_offset())
11304 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11307 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11308 r_type
= elfcpp::R_POWERPC_NONE
;
11312 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11313 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11315 value
= dtp_offset
;
11317 this->skip_next_tls_get_addr_call();
11320 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11322 // Second instruction of an initial exec sequence
11323 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11324 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11325 if (tls_type
== tls::TLSOPT_TO_LE
)
11327 Address roff
= rela
.get_r_offset() & 3;
11328 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11329 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11330 unsigned int reg
= size
== 32 ? 2 : 13;
11331 insn
= at_tls_transform(insn
, reg
);
11332 gold_assert(insn
!= 0);
11335 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11336 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11338 value
= psymval
->value(object
, rela
.get_r_addend());
11340 else if (roff
== 1)
11342 // For pcrel IE to LE we already have the full offset
11343 // and thus don't need an addi here. A nop or mr will do.
11344 if ((insn
& (0x3f << 26)) == 14 << 26)
11346 // Extract regs from addi rt,ra,si.
11347 unsigned int rt
= (insn
>> 21) & 0x1f;
11348 unsigned int ra
= (insn
>> 16) & 0x1f;
11353 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11354 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11355 insn
|= (31u << 26) | (444u << 1);
11358 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11359 r_type
= elfcpp::R_POWERPC_NONE
;
11363 else if (!has_stub_value
)
11365 if (pltcall_to_direct
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11366 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11368 // PLTCALL without plt entry => convert to direct call
11369 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11370 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11371 insn
= (insn
& 1) | b
;
11372 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11374 r_type
= elfcpp::R_PPC_PLTREL24
;
11375 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11376 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11378 r_type
= elfcpp::R_POWERPC_REL24
;
11380 Address addend
= 0;
11382 && (r_type
== elfcpp::R_PPC_PLTREL24
11383 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11384 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11385 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11386 addend
= rela
.get_r_addend();
11387 value
= psymval
->value(object
, addend
);
11388 unsigned int local_ent
= 0;
11389 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11391 if (target
->abiversion() >= 2)
11394 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11396 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11400 unsigned int dest_shndx
;
11401 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11402 &value
, &dest_shndx
);
11405 Address max_branch
= max_branch_delta
<size
>(r_type
);
11406 if (max_branch
!= 0
11407 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11409 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
11410 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11412 ? object
->ppc64_needs_toc(gsym
)
11413 : object
->ppc64_needs_toc(r_sym
)))))
11415 Stub_table
<size
, big_endian
>* stub_table
11416 = object
->stub_table(relinfo
->data_shndx
);
11417 if (stub_table
!= NULL
)
11419 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11420 = stub_table
->find_long_branch_entry(value
);
11423 if (ent
->save_res_
)
11424 value
= (value
- target
->savres_section()->address()
11425 + stub_table
->stub_address()
11426 + stub_table
->plt_size()
11427 + stub_table
->branch_size());
11430 value
= (stub_table
->stub_address()
11431 + stub_table
->plt_size()
11435 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11438 value
+= ent
->p9off_
;
11440 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
11441 value
+= ent
->p9off_
;
11443 value
+= ent
->tocoff_
;
11446 has_stub_value
= true;
11450 if (!has_stub_value
)
11451 value
+= local_ent
;
11456 case elfcpp::R_PPC64_REL24_NOTOC
:
11460 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11461 case elfcpp::R_PPC64_REL64
:
11462 case elfcpp::R_POWERPC_REL32
:
11463 case elfcpp::R_POWERPC_REL24
:
11464 case elfcpp::R_PPC_PLTREL24
:
11465 case elfcpp::R_PPC_LOCAL24PC
:
11466 case elfcpp::R_POWERPC_REL16
:
11467 case elfcpp::R_POWERPC_REL16_LO
:
11468 case elfcpp::R_POWERPC_REL16_HI
:
11469 case elfcpp::R_POWERPC_REL16_HA
:
11470 case elfcpp::R_POWERPC_REL16DX_HA
:
11471 case elfcpp::R_PPC64_REL16_HIGH
:
11472 case elfcpp::R_PPC64_REL16_HIGHA
:
11473 case elfcpp::R_PPC64_REL16_HIGHER
:
11474 case elfcpp::R_PPC64_REL16_HIGHERA
:
11475 case elfcpp::R_PPC64_REL16_HIGHEST
:
11476 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11477 case elfcpp::R_POWERPC_REL14
:
11478 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11479 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11480 case elfcpp::R_PPC64_PCREL34
:
11481 case elfcpp::R_PPC64_GOT_PCREL34
:
11482 case elfcpp::R_PPC64_PLT_PCREL34
:
11483 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11484 case elfcpp::R_PPC64_PCREL28
:
11485 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11486 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11487 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11488 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11489 case elfcpp::R_PPC64_REL16_HIGHER34
:
11490 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11491 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11492 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11496 case elfcpp::R_PPC64_TOC16
:
11497 case elfcpp::R_PPC64_TOC16_LO
:
11498 case elfcpp::R_PPC64_TOC16_HI
:
11499 case elfcpp::R_PPC64_TOC16_HA
:
11500 case elfcpp::R_PPC64_TOC16_DS
:
11501 case elfcpp::R_PPC64_TOC16_LO_DS
:
11502 // Subtract the TOC base address.
11503 value
-= target
->toc_pointer();
11506 case elfcpp::R_POWERPC_SECTOFF
:
11507 case elfcpp::R_POWERPC_SECTOFF_LO
:
11508 case elfcpp::R_POWERPC_SECTOFF_HI
:
11509 case elfcpp::R_POWERPC_SECTOFF_HA
:
11510 case elfcpp::R_PPC64_SECTOFF_DS
:
11511 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11513 value
-= os
->address();
11516 case elfcpp::R_PPC64_TPREL16_DS
:
11517 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11518 case elfcpp::R_PPC64_TPREL16_HIGH
:
11519 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11521 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11524 case elfcpp::R_POWERPC_TPREL16
:
11525 case elfcpp::R_POWERPC_TPREL16_LO
:
11526 case elfcpp::R_POWERPC_TPREL16_HI
:
11527 case elfcpp::R_POWERPC_TPREL16_HA
:
11528 case elfcpp::R_POWERPC_TPREL
:
11529 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11530 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11531 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11532 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11533 case elfcpp::R_PPC64_TPREL34
:
11534 // tls symbol values are relative to tls_segment()->vaddr()
11535 value
-= tp_offset
;
11538 case elfcpp::R_PPC64_DTPREL16_DS
:
11539 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11540 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11541 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11542 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11543 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11545 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11546 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11549 case elfcpp::R_POWERPC_DTPREL16
:
11550 case elfcpp::R_POWERPC_DTPREL16_LO
:
11551 case elfcpp::R_POWERPC_DTPREL16_HI
:
11552 case elfcpp::R_POWERPC_DTPREL16_HA
:
11553 case elfcpp::R_POWERPC_DTPREL
:
11554 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11555 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11556 case elfcpp::R_PPC64_DTPREL34
:
11557 // tls symbol values are relative to tls_segment()->vaddr()
11558 value
-= dtp_offset
;
11561 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11563 value
+= object
->ppc64_local_entry_offset(gsym
);
11565 value
+= object
->ppc64_local_entry_offset(r_sym
);
11572 Insn branch_bit
= 0;
11575 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11576 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11577 branch_bit
= 1 << 21;
11579 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11580 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11582 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11583 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11584 insn
&= ~(1 << 21);
11585 insn
|= branch_bit
;
11586 if (this->is_isa_v2
)
11588 // Set 'a' bit. This is 0b00010 in BO field for branch
11589 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11590 // for branch on CTR insns (BO == 1a00t or 1a01t).
11591 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11592 insn
|= 0x02 << 21;
11593 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11594 insn
|= 0x08 << 21;
11600 // Invert 'y' bit if not the default.
11601 if (static_cast<Signed_address
>(value
) < 0)
11604 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11608 case elfcpp::R_POWERPC_PLT16_HA
:
11610 && !parameters
->options().output_is_position_independent())
11612 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11613 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11615 // Convert addis to lis.
11616 if ((insn
& (0x3f << 26)) == 15u << 26
11617 && (insn
& (0x1f << 16)) != 0)
11619 insn
&= ~(0x1f << 16);
11620 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11630 ? relative_value_is_known(gsym
)
11631 : relative_value_is_known(psymval
))
11636 uint64_t pinsn
, pinsn2
;
11643 // Multi-instruction sequences that access the GOT/TOC can
11644 // be optimized, eg.
11645 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11646 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11648 // addis ra,r2,0; addi rb,ra,x@toc@l;
11649 // to nop; addi rb,r2,x@toc;
11650 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11651 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11652 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11653 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11654 case elfcpp::R_POWERPC_GOT16_HA
:
11655 case elfcpp::R_PPC64_TOC16_HA
:
11656 if (size
== 64 && parameters
->options().toc_optimize())
11658 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11659 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11660 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11661 && object
->make_toc_relative(target
, &value
))
11662 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11663 && object
->make_got_relative(target
, psymval
,
11664 rela
.get_r_addend(),
11667 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11668 == ((15u << 26) | (2 << 16)));
11670 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11671 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11672 && value
+ 0x8000 < 0x10000)
11674 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11680 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11681 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11682 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11683 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11684 case elfcpp::R_POWERPC_GOT16_LO
:
11685 case elfcpp::R_PPC64_GOT16_LO_DS
:
11686 case elfcpp::R_PPC64_TOC16_LO
:
11687 case elfcpp::R_PPC64_TOC16_LO_DS
:
11688 if (size
== 64 && parameters
->options().toc_optimize())
11690 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11691 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11692 bool changed
= false;
11693 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11694 && object
->make_toc_relative(target
, &value
))
11695 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11696 && object
->make_got_relative(target
, psymval
,
11697 rela
.get_r_addend(),
11700 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11701 insn
^= (14u << 26) ^ (58u << 26);
11702 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11705 if (ok_lo_toc_insn(insn
, r_type
)
11706 && value
+ 0x8000 < 0x10000)
11708 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11710 // Transform addic to addi when we change reg.
11711 insn
&= ~((0x3f << 26) | (0x1f << 16));
11712 insn
|= (14u << 26) | (2 << 16);
11716 insn
&= ~(0x1f << 16);
11722 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11726 case elfcpp::R_PPC64_GOT_PCREL34
:
11727 if (size
== 64 && parameters
->options().toc_optimize())
11729 iview
= reinterpret_cast<Insn
*>(view
);
11730 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11732 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11733 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11734 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11737 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11739 if (relval
+ (1ULL << 33) < 1ULL << 34)
11742 // Replace with paddi
11743 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11744 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11745 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11746 pinsn
& 0xffffffff);
11752 case elfcpp::R_PPC64_PCREL34
:
11755 iview
= reinterpret_cast<Insn
*>(view
);
11756 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11758 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11759 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11760 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11761 | (14ULL << 26) /* paddi */))
11765 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11766 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11767 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11768 if (relnum
>= reloc_count
- 1)
11771 Reltype
next_rela(preloc
+ reloc_size
);
11772 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11773 != elfcpp::R_PPC64_PCREL_OPT
)
11774 || next_rela
.get_r_offset() != rela
.get_r_offset())
11777 Address off
= next_rela
.get_r_addend();
11779 off
= 8; // zero means next insn.
11780 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11783 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11784 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11786 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11788 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11790 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11791 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11792 pinsn
& 0xffffffff);
11793 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11798 case elfcpp::R_POWERPC_TPREL16_HA
:
11799 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11801 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11802 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11807 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11809 // R_PPC_TLSGD, R_PPC_TLSLD
11812 case elfcpp::R_POWERPC_TPREL16_LO
:
11813 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11815 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11816 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11817 insn
&= ~(0x1f << 16);
11818 insn
|= (size
== 32 ? 2 : 13) << 16;
11819 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11823 case elfcpp::R_PPC64_ENTRY
:
11826 value
= target
->toc_pointer();
11827 if (value
+ 0x80008000 <= 0xffffffff
11828 && !parameters
->options().output_is_position_independent())
11830 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11831 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11832 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11834 if ((insn1
& ~0xfffc) == ld_2_12
11835 && insn2
== add_2_2_12
)
11837 insn1
= lis_2
+ ha(value
);
11838 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11839 insn2
= addi_2_2
+ l(value
);
11840 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11847 if (value
+ 0x80008000 <= 0xffffffff)
11849 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11850 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11851 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11853 if ((insn1
& ~0xfffc) == ld_2_12
11854 && insn2
== add_2_2_12
)
11856 insn1
= addis_2_12
+ ha(value
);
11857 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11858 insn2
= addi_2_2
+ l(value
);
11859 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11867 case elfcpp::R_POWERPC_REL16_LO
:
11868 // If we are generating a non-PIC executable, edit
11869 // 0: addis 2,12,.TOC.-0b@ha
11870 // addi 2,2,.TOC.-0b@l
11871 // used by ELFv2 global entry points to set up r2, to
11873 // addi 2,2,.TOC.@l
11874 // if .TOC. is in range. */
11876 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11879 && target
->abiversion() >= 2
11880 && !parameters
->options().output_is_position_independent()
11881 && rela
.get_r_addend() == d_offset
+ 4
11883 && strcmp(gsym
->name(), ".TOC.") == 0)
11885 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11886 Reltype
prev_rela(preloc
- reloc_size
);
11887 if ((prev_rela
.get_r_info()
11888 == elfcpp::elf_r_info
<size
>(r_sym
,
11889 elfcpp::R_POWERPC_REL16_HA
))
11890 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11891 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11893 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11894 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11895 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11897 if ((insn1
& 0xffff0000) == addis_2_12
11898 && (insn2
& 0xffff0000) == addi_2_2
)
11900 insn1
= lis_2
+ ha(value
+ address
- 4);
11901 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11902 insn2
= addi_2_2
+ l(value
+ address
- 4);
11903 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11906 relinfo
->rr
->set_strategy(relnum
- 1,
11907 Relocatable_relocs::RELOC_SPECIAL
);
11908 relinfo
->rr
->set_strategy(relnum
,
11909 Relocatable_relocs::RELOC_SPECIAL
);
11919 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11920 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11923 case elfcpp::R_POWERPC_ADDR32
:
11924 case elfcpp::R_POWERPC_UADDR32
:
11926 overflow
= Reloc::CHECK_BITFIELD
;
11929 case elfcpp::R_POWERPC_REL32
:
11930 case elfcpp::R_POWERPC_REL16DX_HA
:
11932 overflow
= Reloc::CHECK_SIGNED
;
11935 case elfcpp::R_POWERPC_UADDR16
:
11936 overflow
= Reloc::CHECK_BITFIELD
;
11939 case elfcpp::R_POWERPC_ADDR16
:
11940 // We really should have three separate relocations,
11941 // one for 16-bit data, one for insns with 16-bit signed fields,
11942 // and one for insns with 16-bit unsigned fields.
11943 overflow
= Reloc::CHECK_BITFIELD
;
11944 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11945 overflow
= Reloc::CHECK_LOW_INSN
;
11948 case elfcpp::R_POWERPC_ADDR16_HI
:
11949 case elfcpp::R_POWERPC_ADDR16_HA
:
11950 case elfcpp::R_POWERPC_GOT16_HI
:
11951 case elfcpp::R_POWERPC_GOT16_HA
:
11952 case elfcpp::R_POWERPC_PLT16_HI
:
11953 case elfcpp::R_POWERPC_PLT16_HA
:
11954 case elfcpp::R_POWERPC_SECTOFF_HI
:
11955 case elfcpp::R_POWERPC_SECTOFF_HA
:
11956 case elfcpp::R_PPC64_TOC16_HI
:
11957 case elfcpp::R_PPC64_TOC16_HA
:
11958 case elfcpp::R_PPC64_PLTGOT16_HI
:
11959 case elfcpp::R_PPC64_PLTGOT16_HA
:
11960 case elfcpp::R_POWERPC_TPREL16_HI
:
11961 case elfcpp::R_POWERPC_TPREL16_HA
:
11962 case elfcpp::R_POWERPC_DTPREL16_HI
:
11963 case elfcpp::R_POWERPC_DTPREL16_HA
:
11964 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11965 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11966 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11967 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11968 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11969 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11970 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11971 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11972 case elfcpp::R_POWERPC_REL16_HI
:
11973 case elfcpp::R_POWERPC_REL16_HA
:
11975 overflow
= Reloc::CHECK_HIGH_INSN
;
11978 case elfcpp::R_POWERPC_REL16
:
11979 case elfcpp::R_PPC64_TOC16
:
11980 case elfcpp::R_POWERPC_GOT16
:
11981 case elfcpp::R_POWERPC_SECTOFF
:
11982 case elfcpp::R_POWERPC_TPREL16
:
11983 case elfcpp::R_POWERPC_DTPREL16
:
11984 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11985 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11986 case elfcpp::R_POWERPC_GOT_TPREL16
:
11987 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11988 overflow
= Reloc::CHECK_LOW_INSN
;
11991 case elfcpp::R_PPC64_REL24_NOTOC
:
11995 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11996 case elfcpp::R_POWERPC_ADDR24
:
11997 case elfcpp::R_POWERPC_ADDR14
:
11998 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11999 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12000 case elfcpp::R_PPC64_ADDR16_DS
:
12001 case elfcpp::R_POWERPC_REL24
:
12002 case elfcpp::R_PPC_PLTREL24
:
12003 case elfcpp::R_PPC_LOCAL24PC
:
12004 case elfcpp::R_PPC64_TPREL16_DS
:
12005 case elfcpp::R_PPC64_DTPREL16_DS
:
12006 case elfcpp::R_PPC64_TOC16_DS
:
12007 case elfcpp::R_PPC64_GOT16_DS
:
12008 case elfcpp::R_PPC64_SECTOFF_DS
:
12009 case elfcpp::R_POWERPC_REL14
:
12010 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12011 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12012 case elfcpp::R_PPC64_D34
:
12013 case elfcpp::R_PPC64_PCREL34
:
12014 case elfcpp::R_PPC64_GOT_PCREL34
:
12015 case elfcpp::R_PPC64_PLT_PCREL34
:
12016 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12017 case elfcpp::R_PPC64_D28
:
12018 case elfcpp::R_PPC64_PCREL28
:
12019 case elfcpp::R_PPC64_TPREL34
:
12020 case elfcpp::R_PPC64_DTPREL34
:
12021 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12022 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12023 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12024 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12025 overflow
= Reloc::CHECK_SIGNED
;
12029 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
12032 if (overflow
== Reloc::CHECK_LOW_INSN
12033 || overflow
== Reloc::CHECK_HIGH_INSN
)
12035 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12037 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
12038 overflow
= Reloc::CHECK_BITFIELD
;
12039 else if (overflow
== Reloc::CHECK_LOW_INSN
12040 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
12041 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
12042 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
12043 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
12044 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
12045 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
12046 overflow
= Reloc::CHECK_UNSIGNED
;
12048 overflow
= Reloc::CHECK_SIGNED
;
12051 bool maybe_dq_reloc
= false;
12052 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
12053 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
12056 case elfcpp::R_POWERPC_NONE
:
12057 case elfcpp::R_POWERPC_TLS
:
12058 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
12059 case elfcpp::R_POWERPC_GNU_VTENTRY
:
12060 case elfcpp::R_POWERPC_PLTSEQ
:
12061 case elfcpp::R_POWERPC_PLTCALL
:
12062 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
12063 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
12064 case elfcpp::R_PPC64_PCREL_OPT
:
12067 case elfcpp::R_PPC64_ADDR64
:
12068 case elfcpp::R_PPC64_REL64
:
12069 case elfcpp::R_PPC64_TOC
:
12070 case elfcpp::R_PPC64_ADDR64_LOCAL
:
12071 Reloc::addr64(view
, value
);
12074 case elfcpp::R_POWERPC_TPREL
:
12075 case elfcpp::R_POWERPC_DTPREL
:
12077 Reloc::addr64(view
, value
);
12079 status
= Reloc::addr32(view
, value
, overflow
);
12082 case elfcpp::R_PPC64_UADDR64
:
12083 Reloc::addr64_u(view
, value
);
12086 case elfcpp::R_POWERPC_ADDR32
:
12087 status
= Reloc::addr32(view
, value
, overflow
);
12090 case elfcpp::R_POWERPC_REL32
:
12091 case elfcpp::R_POWERPC_UADDR32
:
12092 status
= Reloc::addr32_u(view
, value
, overflow
);
12095 case elfcpp::R_PPC64_REL24_NOTOC
:
12097 goto unsupp
; // R_PPC_EMB_RELSDA
12099 case elfcpp::R_PPC64_REL24_P9NOTOC
:
12100 case elfcpp::R_POWERPC_ADDR24
:
12101 case elfcpp::R_POWERPC_REL24
:
12102 case elfcpp::R_PPC_PLTREL24
:
12103 case elfcpp::R_PPC_LOCAL24PC
:
12104 status
= Reloc::addr24(view
, value
, overflow
);
12107 case elfcpp::R_POWERPC_GOT_DTPREL16
:
12108 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
12109 case elfcpp::R_POWERPC_GOT_TPREL16
:
12110 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
12113 // On ppc64 these are all ds form
12114 maybe_dq_reloc
= true;
12118 case elfcpp::R_POWERPC_ADDR16
:
12119 case elfcpp::R_POWERPC_REL16
:
12120 case elfcpp::R_PPC64_TOC16
:
12121 case elfcpp::R_POWERPC_GOT16
:
12122 case elfcpp::R_POWERPC_SECTOFF
:
12123 case elfcpp::R_POWERPC_TPREL16
:
12124 case elfcpp::R_POWERPC_DTPREL16
:
12125 case elfcpp::R_POWERPC_GOT_TLSGD16
:
12126 case elfcpp::R_POWERPC_GOT_TLSLD16
:
12127 case elfcpp::R_POWERPC_ADDR16_LO
:
12128 case elfcpp::R_POWERPC_REL16_LO
:
12129 case elfcpp::R_PPC64_TOC16_LO
:
12130 case elfcpp::R_POWERPC_GOT16_LO
:
12131 case elfcpp::R_POWERPC_PLT16_LO
:
12132 case elfcpp::R_POWERPC_SECTOFF_LO
:
12133 case elfcpp::R_POWERPC_TPREL16_LO
:
12134 case elfcpp::R_POWERPC_DTPREL16_LO
:
12135 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
12136 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
12138 status
= Reloc::addr16(view
, value
, overflow
);
12140 maybe_dq_reloc
= true;
12143 case elfcpp::R_POWERPC_UADDR16
:
12144 status
= Reloc::addr16_u(view
, value
, overflow
);
12147 case elfcpp::R_PPC64_ADDR16_HIGH
:
12148 case elfcpp::R_PPC64_TPREL16_HIGH
:
12149 case elfcpp::R_PPC64_DTPREL16_HIGH
:
12151 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
12154 case elfcpp::R_POWERPC_ADDR16_HI
:
12155 case elfcpp::R_POWERPC_REL16_HI
:
12156 case elfcpp::R_PPC64_REL16_HIGH
:
12157 case elfcpp::R_PPC64_TOC16_HI
:
12158 case elfcpp::R_POWERPC_GOT16_HI
:
12159 case elfcpp::R_POWERPC_PLT16_HI
:
12160 case elfcpp::R_POWERPC_SECTOFF_HI
:
12161 case elfcpp::R_POWERPC_TPREL16_HI
:
12162 case elfcpp::R_POWERPC_DTPREL16_HI
:
12163 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
12164 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
12165 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
12166 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
12167 Reloc::addr16_hi(view
, value
);
12170 case elfcpp::R_PPC64_ADDR16_HIGHA
:
12171 case elfcpp::R_PPC64_TPREL16_HIGHA
:
12172 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
12174 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
12177 case elfcpp::R_POWERPC_ADDR16_HA
:
12178 case elfcpp::R_POWERPC_REL16_HA
:
12179 case elfcpp::R_PPC64_REL16_HIGHA
:
12180 case elfcpp::R_PPC64_TOC16_HA
:
12181 case elfcpp::R_POWERPC_GOT16_HA
:
12182 case elfcpp::R_POWERPC_PLT16_HA
:
12183 case elfcpp::R_POWERPC_SECTOFF_HA
:
12184 case elfcpp::R_POWERPC_TPREL16_HA
:
12185 case elfcpp::R_POWERPC_DTPREL16_HA
:
12186 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
12187 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
12188 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
12189 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
12190 Reloc::addr16_ha(view
, value
);
12193 case elfcpp::R_POWERPC_REL16DX_HA
:
12194 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
12197 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
12199 // R_PPC_EMB_NADDR16_LO
12202 case elfcpp::R_PPC64_ADDR16_HIGHER
:
12203 case elfcpp::R_PPC64_REL16_HIGHER
:
12204 case elfcpp::R_PPC64_TPREL16_HIGHER
:
12205 Reloc::addr16_hi2(view
, value
);
12208 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
12210 // R_PPC_EMB_NADDR16_HI
12213 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
12214 case elfcpp::R_PPC64_REL16_HIGHERA
:
12215 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
12216 Reloc::addr16_ha2(view
, value
);
12219 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
12221 // R_PPC_EMB_NADDR16_HA
12224 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
12225 case elfcpp::R_PPC64_REL16_HIGHEST
:
12226 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
12227 Reloc::addr16_hi3(view
, value
);
12230 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
12232 // R_PPC_EMB_SDAI16
12235 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
12236 case elfcpp::R_PPC64_REL16_HIGHESTA
:
12237 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
12238 Reloc::addr16_ha3(view
, value
);
12241 case elfcpp::R_PPC64_DTPREL16_DS
:
12242 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
12244 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
12247 case elfcpp::R_PPC64_TPREL16_DS
:
12248 case elfcpp::R_PPC64_TPREL16_LO_DS
:
12250 // R_PPC_TLSGD, R_PPC_TLSLD
12253 case elfcpp::R_PPC64_ADDR16_DS
:
12254 case elfcpp::R_PPC64_ADDR16_LO_DS
:
12255 case elfcpp::R_PPC64_TOC16_DS
:
12256 case elfcpp::R_PPC64_TOC16_LO_DS
:
12257 case elfcpp::R_PPC64_GOT16_DS
:
12258 case elfcpp::R_PPC64_GOT16_LO_DS
:
12259 case elfcpp::R_PPC64_PLT16_LO_DS
:
12260 case elfcpp::R_PPC64_SECTOFF_DS
:
12261 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
12262 maybe_dq_reloc
= true;
12265 case elfcpp::R_POWERPC_ADDR14
:
12266 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
12267 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12268 case elfcpp::R_POWERPC_REL14
:
12269 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12270 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12271 status
= Reloc::addr14(view
, value
, overflow
);
12274 case elfcpp::R_POWERPC_COPY
:
12275 case elfcpp::R_POWERPC_GLOB_DAT
:
12276 case elfcpp::R_POWERPC_JMP_SLOT
:
12277 case elfcpp::R_POWERPC_RELATIVE
:
12278 case elfcpp::R_POWERPC_DTPMOD
:
12279 case elfcpp::R_PPC64_JMP_IREL
:
12280 case elfcpp::R_POWERPC_IRELATIVE
:
12281 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12282 _("unexpected reloc %u in object file"),
12286 case elfcpp::R_PPC64_TOCSAVE
:
12292 Symbol_location loc
;
12293 loc
.object
= relinfo
->object
;
12294 loc
.shndx
= relinfo
->data_shndx
;
12295 loc
.offset
= rela
.get_r_offset();
12296 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12297 if (tocsave
->find(loc
) != tocsave
->end())
12299 // If we've generated plt calls using this tocsave, then
12300 // the nop needs to be changed to save r2.
12301 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12302 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12303 elfcpp::Swap
<32, big_endian
>::
12304 writeval(iview
, std_2_1
+ target
->stk_toc());
12309 case elfcpp::R_PPC_EMB_SDA2I16
:
12310 case elfcpp::R_PPC_EMB_SDA2REL
:
12313 // R_PPC64_TLSGD, R_PPC64_TLSLD
12316 case elfcpp::R_PPC64_D34
:
12317 case elfcpp::R_PPC64_D34_LO
:
12318 case elfcpp::R_PPC64_PCREL34
:
12319 case elfcpp::R_PPC64_GOT_PCREL34
:
12320 case elfcpp::R_PPC64_PLT_PCREL34
:
12321 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12322 case elfcpp::R_PPC64_TPREL34
:
12323 case elfcpp::R_PPC64_DTPREL34
:
12324 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12325 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12326 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12327 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12330 status
= Reloc::addr34(view
, value
, overflow
);
12333 case elfcpp::R_PPC64_D34_HI30
:
12336 Reloc::addr34_hi(view
, value
);
12339 case elfcpp::R_PPC64_D34_HA30
:
12342 Reloc::addr34_ha(view
, value
);
12345 case elfcpp::R_PPC64_D28
:
12346 case elfcpp::R_PPC64_PCREL28
:
12349 status
= Reloc::addr28(view
, value
, overflow
);
12352 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12353 case elfcpp::R_PPC64_REL16_HIGHER34
:
12356 Reloc::addr16_higher34(view
, value
);
12359 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12360 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12363 Reloc::addr16_highera34(view
, value
);
12366 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12367 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12370 Reloc::addr16_highest34(view
, value
);
12373 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12374 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12377 Reloc::addr16_highesta34(view
, value
);
12380 case elfcpp::R_POWERPC_PLT32
:
12381 case elfcpp::R_POWERPC_PLTREL32
:
12382 case elfcpp::R_PPC_SDAREL16
:
12383 case elfcpp::R_POWERPC_ADDR30
:
12384 case elfcpp::R_PPC64_PLT64
:
12385 case elfcpp::R_PPC64_PLTREL64
:
12386 case elfcpp::R_PPC64_PLTGOT16
:
12387 case elfcpp::R_PPC64_PLTGOT16_LO
:
12388 case elfcpp::R_PPC64_PLTGOT16_HI
:
12389 case elfcpp::R_PPC64_PLTGOT16_HA
:
12390 case elfcpp::R_PPC64_PLTGOT16_DS
:
12391 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12392 case elfcpp::R_PPC_TOC16
:
12395 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12396 _("unsupported reloc %u"),
12401 if (maybe_dq_reloc
)
12404 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12406 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12407 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12408 && (insn
& 3) == 1))
12409 status
= Reloc::addr16_dq(view
, value
, overflow
);
12410 else if (size
== 64
12411 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12412 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12413 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12414 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12415 status
= Reloc::addr16_ds(view
, value
, overflow
);
12417 status
= Reloc::addr16(view
, value
, overflow
);
12420 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12423 && gsym
->is_undefined()
12424 && is_branch_reloc
<size
>(r_type
))))
12428 name
= gsym
->demangled_name();
12430 name
= relinfo
->object
->get_symbol_name(r_sym
);
12431 if (os
->flags() & elfcpp::SHF_ALLOC
)
12433 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12434 _("reloc type %u overflow against '%s'"),
12435 r_type
, name
.c_str());
12436 if (has_stub_value
)
12437 gold_info(_("try relinking with a smaller --stub-group-size"));
12441 gold_warning_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12442 _("reloc type %u overflow against '%s'"),
12443 r_type
, name
.c_str());
12444 gold_info(_("debug info may be unreliable, compile with -gdwarf64"));
12451 // Relocate section data.
12453 template<int size
, bool big_endian
>
12455 Target_powerpc
<size
, big_endian
>::relocate_section(
12456 const Relocate_info
<size
, big_endian
>* relinfo
,
12457 unsigned int sh_type
,
12458 const unsigned char* prelocs
,
12459 size_t reloc_count
,
12460 Output_section
* output_section
,
12461 bool needs_special_offset_handling
,
12462 unsigned char* view
,
12464 section_size_type view_size
,
12465 const Reloc_symbol_changes
* reloc_symbol_changes
)
12467 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12468 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12469 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12470 Powerpc_comdat_behavior
;
12471 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12474 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12476 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12477 Powerpc_comdat_behavior
, Classify_reloc
>(
12483 needs_special_offset_handling
,
12487 reloc_symbol_changes
);
12490 template<int size
, bool big_endian
>
12491 class Powerpc_scan_relocatable_reloc
12494 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12495 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12496 static const int sh_type
= elfcpp::SHT_RELA
;
12498 // Return the symbol referred to by the relocation.
12499 static inline unsigned int
12500 get_r_sym(const Reltype
* reloc
)
12501 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12503 // Return the type of the relocation.
12504 static inline unsigned int
12505 get_r_type(const Reltype
* reloc
)
12506 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12508 // Return the strategy to use for a local symbol which is not a
12509 // section symbol, given the relocation type.
12510 inline Relocatable_relocs::Reloc_strategy
12511 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12513 if (r_type
== 0 && r_sym
== 0)
12514 return Relocatable_relocs::RELOC_DISCARD
;
12515 return Relocatable_relocs::RELOC_COPY
;
12518 // Return the strategy to use for a local symbol which is a section
12519 // symbol, given the relocation type.
12520 inline Relocatable_relocs::Reloc_strategy
12521 local_section_strategy(unsigned int, Relobj
*)
12523 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12526 // Return the strategy to use for a global symbol, given the
12527 // relocation type, the object, and the symbol index.
12528 inline Relocatable_relocs::Reloc_strategy
12529 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12532 && (r_type
== elfcpp::R_PPC_PLTREL24
12533 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12534 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12535 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12536 return Relocatable_relocs::RELOC_SPECIAL
;
12537 return Relocatable_relocs::RELOC_COPY
;
12541 // Scan the relocs during a relocatable link.
12543 template<int size
, bool big_endian
>
12545 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12546 Symbol_table
* symtab
,
12548 Sized_relobj_file
<size
, big_endian
>* object
,
12549 unsigned int data_shndx
,
12550 unsigned int sh_type
,
12551 const unsigned char* prelocs
,
12552 size_t reloc_count
,
12553 Output_section
* output_section
,
12554 bool needs_special_offset_handling
,
12555 size_t local_symbol_count
,
12556 const unsigned char* plocal_symbols
,
12557 Relocatable_relocs
* rr
)
12559 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12561 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12563 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12571 needs_special_offset_handling
,
12572 local_symbol_count
,
12577 // Scan the relocs for --emit-relocs.
12579 template<int size
, bool big_endian
>
12581 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12582 Symbol_table
* symtab
,
12584 Sized_relobj_file
<size
, big_endian
>* object
,
12585 unsigned int data_shndx
,
12586 unsigned int sh_type
,
12587 const unsigned char* prelocs
,
12588 size_t reloc_count
,
12589 Output_section
* output_section
,
12590 bool needs_special_offset_handling
,
12591 size_t local_symbol_count
,
12592 const unsigned char* plocal_syms
,
12593 Relocatable_relocs
* rr
)
12595 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12597 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12598 Emit_relocs_strategy
;
12600 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12602 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12610 needs_special_offset_handling
,
12611 local_symbol_count
,
12616 // Emit relocations for a section.
12617 // This is a modified version of the function by the same name in
12618 // target-reloc.h. Using relocate_special_relocatable for
12619 // R_PPC_PLTREL24 would require duplication of the entire body of the
12620 // loop, so we may as well duplicate the whole thing.
12622 template<int size
, bool big_endian
>
12624 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12625 const Relocate_info
<size
, big_endian
>* relinfo
,
12626 unsigned int sh_type
,
12627 const unsigned char* prelocs
,
12628 size_t reloc_count
,
12629 Output_section
* output_section
,
12630 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12632 Address view_address
,
12634 unsigned char* reloc_view
,
12635 section_size_type reloc_view_size
)
12637 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12639 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12640 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12641 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12642 // Offset from start of insn to d-field reloc.
12643 const int d_offset
= big_endian
? 2 : 0;
12645 Powerpc_relobj
<size
, big_endian
>* const object
12646 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12647 const unsigned int local_count
= object
->local_symbol_count();
12648 unsigned int got2_shndx
= object
->got2_shndx();
12649 Address got2_addend
= 0;
12650 if (got2_shndx
!= 0)
12652 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12653 gold_assert(got2_addend
!= invalid_address
);
12656 const bool relocatable
= parameters
->options().relocatable();
12658 unsigned char* pwrite
= reloc_view
;
12659 bool zap_next
= false;
12660 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12662 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12663 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12666 Reltype
reloc(prelocs
);
12667 Reltype_write
reloc_write(pwrite
);
12669 Address offset
= reloc
.get_r_offset();
12670 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12671 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12672 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12673 const unsigned int orig_r_sym
= r_sym
;
12674 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12675 = reloc
.get_r_addend();
12676 const Symbol
* gsym
= NULL
;
12680 // We could arrange to discard these and other relocs for
12681 // tls optimised sequences in the strategy methods, but for
12682 // now do as BFD ld does.
12683 r_type
= elfcpp::R_POWERPC_NONE
;
12687 // Get the new symbol index.
12688 Output_section
* os
= NULL
;
12689 if (r_sym
< local_count
)
12693 case Relocatable_relocs::RELOC_COPY
:
12694 case Relocatable_relocs::RELOC_SPECIAL
:
12697 r_sym
= object
->symtab_index(r_sym
);
12698 gold_assert(r_sym
!= -1U);
12702 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12704 // We are adjusting a section symbol. We need to find
12705 // the symbol table index of the section symbol for
12706 // the output section corresponding to input section
12707 // in which this symbol is defined.
12708 gold_assert(r_sym
< local_count
);
12710 unsigned int shndx
=
12711 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12712 gold_assert(is_ordinary
);
12713 os
= object
->output_section(shndx
);
12714 gold_assert(os
!= NULL
);
12715 gold_assert(os
->needs_symtab_index());
12716 r_sym
= os
->symtab_index();
12721 gold_unreachable();
12726 gsym
= object
->global_symbol(r_sym
);
12727 gold_assert(gsym
!= NULL
);
12728 if (gsym
->is_forwarder())
12729 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12731 gold_assert(gsym
->has_symtab_index());
12732 r_sym
= gsym
->symtab_index();
12735 // Get the new offset--the location in the output section where
12736 // this relocation should be applied.
12737 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12738 offset
+= offset_in_output_section
;
12741 section_offset_type sot_offset
=
12742 convert_types
<section_offset_type
, Address
>(offset
);
12743 section_offset_type new_sot_offset
=
12744 output_section
->output_offset(object
, relinfo
->data_shndx
,
12746 gold_assert(new_sot_offset
!= -1);
12747 offset
= new_sot_offset
;
12750 // In an object file, r_offset is an offset within the section.
12751 // In an executable or dynamic object, generated by
12752 // --emit-relocs, r_offset is an absolute address.
12755 offset
+= view_address
;
12756 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12757 offset
-= offset_in_output_section
;
12760 // Handle the reloc addend based on the strategy.
12761 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12763 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12765 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12766 addend
= psymval
->value(object
, addend
);
12767 // In a relocatable link, the symbol value is relative to
12768 // the start of the output section. For a non-relocatable
12769 // link, we need to adjust the addend.
12772 gold_assert(os
!= NULL
);
12773 addend
-= os
->address();
12776 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12780 if (addend
>= 32768)
12781 addend
+= got2_addend
;
12783 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12785 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12786 addend
-= d_offset
;
12788 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12790 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12791 addend
-= d_offset
+ 4;
12795 gold_unreachable();
12799 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12800 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12801 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12802 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12804 // First instruction of a global dynamic sequence,
12806 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12807 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12810 case tls::TLSOPT_TO_IE
:
12811 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12812 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12814 case tls::TLSOPT_TO_LE
:
12815 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12816 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12817 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12820 r_type
= elfcpp::R_POWERPC_NONE
;
12821 offset
-= d_offset
;
12828 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12829 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12830 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12831 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12833 // First instruction of a local dynamic sequence,
12835 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12836 if (tls_type
== tls::TLSOPT_TO_LE
)
12838 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12839 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12841 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12842 const Output_section
* os
= relinfo
->layout
->tls_segment()
12844 gold_assert(os
!= NULL
);
12845 gold_assert(os
->needs_symtab_index());
12846 r_sym
= os
->symtab_index();
12847 addend
= dtp_offset
;
12851 r_type
= elfcpp::R_POWERPC_NONE
;
12852 offset
-= d_offset
;
12856 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12857 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12858 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12859 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12861 // First instruction of initial exec sequence.
12862 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12863 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12865 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12866 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12867 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12870 r_type
= elfcpp::R_POWERPC_NONE
;
12871 offset
-= d_offset
;
12875 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12876 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12878 // Second instruction of a global dynamic sequence,
12879 // the __tls_get_addr call
12880 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12881 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12884 case tls::TLSOPT_TO_IE
:
12885 r_type
= elfcpp::R_POWERPC_NONE
;
12888 case tls::TLSOPT_TO_LE
:
12889 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12890 offset
+= d_offset
;
12897 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12898 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12900 // Second instruction of a local dynamic sequence,
12901 // the __tls_get_addr call
12902 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12903 if (tls_type
== tls::TLSOPT_TO_LE
)
12905 const Output_section
* os
= relinfo
->layout
->tls_segment()
12907 gold_assert(os
!= NULL
);
12908 gold_assert(os
->needs_symtab_index());
12909 r_sym
= os
->symtab_index();
12910 addend
= dtp_offset
;
12911 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12912 offset
+= d_offset
;
12916 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12918 // Second instruction of an initial exec sequence
12919 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12920 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12922 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12923 offset
+= d_offset
;
12928 reloc_write
.put_r_offset(offset
);
12929 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12930 reloc_write
.put_r_addend(addend
);
12932 pwrite
+= reloc_size
;
12935 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12936 == reloc_view_size
);
12939 // Return the value to use for a dynamic symbol which requires special
12940 // treatment. This is how we support equality comparisons of function
12941 // pointers across shared library boundaries, as described in the
12942 // processor specific ABI supplement.
12944 template<int size
, bool big_endian
>
12946 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12950 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12951 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12952 p
!= this->stub_tables_
.end();
12955 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12956 = (*p
)->find_plt_call_entry(gsym
);
12958 return (*p
)->stub_address() + ent
->off_
;
12961 else if (this->abiversion() >= 2)
12963 Address off
= this->glink_section()->find_global_entry(gsym
);
12964 if (off
!= invalid_address
)
12965 return this->glink_section()->global_entry_address() + off
;
12967 gold_unreachable();
12970 // Return the PLT address to use for a local symbol.
12971 template<int size
, bool big_endian
>
12973 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12974 const Relobj
* object
,
12975 unsigned int symndx
) const
12979 const Sized_relobj
<size
, big_endian
>* relobj
12980 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12981 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12982 p
!= this->stub_tables_
.end();
12985 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12986 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12988 return (*p
)->stub_address() + ent
->off_
;
12991 gold_unreachable();
12994 // Return the PLT address to use for a global symbol.
12995 template<int size
, bool big_endian
>
12997 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12998 const Symbol
* gsym
) const
13002 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
13003 p
!= this->stub_tables_
.end();
13006 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
13007 = (*p
)->find_plt_call_entry(gsym
);
13009 return (*p
)->stub_address() + ent
->off_
;
13012 else if (this->abiversion() >= 2)
13014 Address off
= this->glink_section()->find_global_entry(gsym
);
13015 if (off
!= invalid_address
)
13016 return this->glink_section()->global_entry_address() + off
;
13018 gold_unreachable();
13021 // Return the offset to use for the GOT_INDX'th got entry which is
13022 // for a local tls symbol specified by OBJECT, SYMNDX.
13023 template<int size
, bool big_endian
>
13025 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
13026 const Relobj
* object
,
13027 unsigned int symndx
,
13028 Output_data_got_base
* got
,
13029 unsigned int got_indx
,
13030 uint64_t addend
) const
13032 const Powerpc_relobj
<size
, big_endian
>* ppc_object
13033 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
13034 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
13036 for (Got_type got_type
= (size
== 32
13037 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13038 got_type
<= GOT_TYPE_SMALL_TPREL
;
13039 got_type
= Got_type(got_type
+ 1))
13040 if (got_type
!= GOT_TYPE_SMALL
13041 && ppc_object
->local_has_got_offset(symndx
, got_type
, addend
))
13044 = ppc_object
->local_got_offset(symndx
, got_type
, addend
);
13045 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13047 if (off
== got_indx
* (size
/ 8)
13048 && (size
== 32 || got
== this->got_section(got_type
)))
13050 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13053 return -dtp_offset
;
13057 gold_unreachable();
13060 // Return the offset to use for the GOT_INDX'th got entry which is
13061 // for global tls symbol GSYM.
13062 template<int size
, bool big_endian
>
13064 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
13066 Output_data_got_base
* got
,
13067 unsigned int got_indx
,
13068 uint64_t addend
) const
13070 if (gsym
->type() == elfcpp::STT_TLS
)
13072 for (Got_type got_type
= (size
== 32
13073 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13074 got_type
<= GOT_TYPE_SMALL_TPREL
;
13075 got_type
= Got_type(got_type
+ 1))
13076 if (got_type
!= GOT_TYPE_SMALL
13077 && gsym
->has_got_offset(got_type
, addend
))
13079 unsigned int off
= gsym
->got_offset(got_type
, addend
);
13080 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13082 if (off
== got_indx
* (size
/ 8)
13083 && (size
== 32 || got
== this->got_section(got_type
)))
13085 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13088 return -dtp_offset
;
13092 gold_unreachable();
13095 // The selector for powerpc object files.
13097 template<int size
, bool big_endian
>
13098 class Target_selector_powerpc
: public Target_selector
13101 Target_selector_powerpc()
13102 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
13105 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
13106 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
13108 ? (big_endian
? "elf64ppc" : "elf64lppc")
13109 : (big_endian
? "elf32ppc" : "elf32lppc")))
13113 do_instantiate_target()
13114 { return new Target_powerpc
<size
, big_endian
>(); }
13117 Target_selector_powerpc
<32, true> target_selector_ppc32
;
13118 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
13119 Target_selector_powerpc
<64, true> target_selector_ppc64
;
13120 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
13122 // Instantiate these constants for -O0
13123 template<int size
, bool big_endian
>
13124 const typename Output_data_glink
<size
, big_endian
>::Address
13125 Output_data_glink
<size
, big_endian
>::invalid_address
;
13126 template<int size
, bool big_endian
>
13127 const typename Stub_table
<size
, big_endian
>::Address
13128 Stub_table
<size
, big_endian
>::invalid_address
;
13129 template<int size
, bool big_endian
>
13130 const typename Target_powerpc
<size
, big_endian
>::Address
13131 Target_powerpc
<size
, big_endian
>::invalid_address
;
13133 } // End anonymous namespace.