1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2021 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
));
319 // Return offset in output GOT section that this object will use
320 // as a TOC pointer. Won't be just a constant with multi-toc support.
322 toc_base_offset() const
326 set_has_small_toc_reloc()
327 { has_small_toc_reloc_
= true; }
330 has_small_toc_reloc() const
331 { return has_small_toc_reloc_
; }
334 set_has_14bit_branch(unsigned int shndx
)
336 if (shndx
>= this->has14_
.size())
337 this->has14_
.resize(shndx
+ 1);
338 this->has14_
[shndx
] = true;
342 has_14bit_branch(unsigned int shndx
) const
343 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
346 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
348 if (shndx
>= this->stub_table_index_
.size())
349 this->stub_table_index_
.resize(shndx
+ 1, -1);
350 this->stub_table_index_
[shndx
] = stub_index
;
353 Stub_table
<size
, big_endian
>*
354 stub_table(unsigned int shndx
)
356 if (shndx
< this->stub_table_index_
.size())
358 Target_powerpc
<size
, big_endian
>* target
359 = static_cast<Target_powerpc
<size
, big_endian
>*>(
360 parameters
->sized_target
<size
, big_endian
>());
361 unsigned int indx
= this->stub_table_index_
[shndx
];
362 if (indx
< target
->stub_tables().size())
363 return target
->stub_tables()[indx
];
371 this->stub_table_index_
.clear();
376 { return this->uniq_
; }
380 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
382 // Set ABI version for input and output
384 set_abiversion(int ver
);
387 st_other (unsigned int symndx
) const
389 return this->st_other_
[symndx
];
393 ppc64_local_entry_offset(const Symbol
* sym
) const
394 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
397 ppc64_local_entry_offset(unsigned int symndx
) const
398 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
401 ppc64_needs_toc(const Symbol
* sym
) const
402 { return sym
->nonvis() > 1 << 3; }
405 ppc64_needs_toc(unsigned int symndx
) const
406 { return this->st_other_
[symndx
] > 1 << 5; }
408 // The contents of the .gnu.attributes section if there is one.
409 const Attributes_section_data
*
410 attributes_section_data() const
411 { return this->attributes_section_data_
; }
422 // Return index into opd_ent_ array for .opd entry at OFF.
423 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
424 // apart when the language doesn't use the last 8-byte word, the
425 // environment pointer. Thus dividing the entry section offset by
426 // 16 will give an index into opd_ent_ that works for either layout
427 // of .opd. (It leaves some elements of the vector unused when .opd
428 // entries are spaced 24 bytes apart, but we don't know the spacing
429 // until relocations are processed, and in any case it is possible
430 // for an object to have some entries spaced 16 bytes apart and
431 // others 24 bytes apart.)
433 opd_ent_ndx(size_t off
) const
436 // Per object unique identifier
439 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
440 unsigned int special_
;
442 // For 64-bit the .rela.toc and .toc section shdnx.
443 unsigned int relatoc_
;
446 // For 64-bit, whether this object uses small model relocs to access
448 bool has_small_toc_reloc_
;
450 // Set at the start of gc_process_relocs, when we know opd_ent_
451 // vector is valid. The flag could be made atomic and set in
452 // do_read_relocs with memory_order_release and then tested with
453 // memory_order_acquire, potentially resulting in fewer entries in
458 elfcpp::Elf_Word e_flags_
;
460 // For 64-bit, an array with one entry per 64-bit word in the .toc
461 // section, set if accesses using that word cannot be optimised.
462 std::vector
<bool> no_toc_opt_
;
464 // The first 8-byte word of an OPD entry gives the address of the
465 // entry point of the function. Relocatable object files have a
466 // relocation on this word. The following vector records the
467 // section and offset specified by these relocations.
468 std::vector
<Opd_ent
> opd_ent_
;
470 // References made to this object's .opd section when running
471 // gc_process_relocs for another object, before the opd_ent_ vector
472 // is valid for this object.
473 Access_from access_from_map_
;
475 // Whether input section has a 14-bit branch reloc.
476 std::vector
<bool> has14_
;
478 // The stub table to use for a given input section.
479 std::vector
<unsigned int> stub_table_index_
;
481 // ELF st_other field for local symbols.
482 std::vector
<unsigned char> st_other_
;
484 // Object attributes if there is a .gnu.attributes section.
485 Attributes_section_data
* attributes_section_data_
;
488 template<int size
, bool big_endian
>
489 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
492 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
494 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
495 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
496 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
497 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
498 attributes_section_data_(NULL
)
500 this->set_abiversion(0);
504 { delete this->attributes_section_data_
; }
506 // Call Sized_dynobj::do_read_symbols to read the symbols then
507 // read .opd from a dynamic object, filling in opd_ent_ vector,
509 do_read_symbols(Read_symbols_data
*);
511 // The .opd section shndx.
515 return this->opd_shndx_
;
518 // The .opd section address.
522 return this->opd_address_
;
525 // Init OPD entry arrays.
527 init_opd(size_t opd_size
)
529 size_t count
= this->opd_ent_ndx(opd_size
);
530 this->opd_ent_
.resize(count
);
533 // Return section and offset of function entry for .opd + R_OFF.
535 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
537 size_t ndx
= this->opd_ent_ndx(r_off
);
538 gold_assert(ndx
< this->opd_ent_
.size());
539 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
541 *value
= this->opd_ent_
[ndx
].off
;
542 return this->opd_ent_
[ndx
].shndx
;
545 // Set section and offset of function entry for .opd + R_OFF.
547 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
549 size_t ndx
= this->opd_ent_ndx(r_off
);
550 gold_assert(ndx
< this->opd_ent_
.size());
551 this->opd_ent_
[ndx
].shndx
= shndx
;
552 this->opd_ent_
[ndx
].off
= value
;
557 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
559 // Set ABI version for input and output.
561 set_abiversion(int ver
);
563 // The contents of the .gnu.attributes section if there is one.
564 const Attributes_section_data
*
565 attributes_section_data() const
566 { return this->attributes_section_data_
; }
569 // Used to specify extent of executable sections.
572 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
573 : start(start_
), len(len_
), shndx(shndx_
)
577 operator<(const Sec_info
& that
) const
578 { return this->start
< that
.start
; }
591 // Return index into opd_ent_ array for .opd entry at OFF.
593 opd_ent_ndx(size_t off
) const
596 // For 64-bit the .opd section shndx and address.
597 unsigned int opd_shndx_
;
598 Address opd_address_
;
601 elfcpp::Elf_Word e_flags_
;
603 // The first 8-byte word of an OPD entry gives the address of the
604 // entry point of the function. Records the section and offset
605 // corresponding to the address. Note that in dynamic objects,
606 // offset is *not* relative to the section.
607 std::vector
<Opd_ent
> opd_ent_
;
609 // Object attributes if there is a .gnu.attributes section.
610 Attributes_section_data
* attributes_section_data_
;
613 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
614 // base class will emit.
616 template<int sh_type
, int size
, bool big_endian
>
617 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
620 Powerpc_copy_relocs()
621 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
624 // Emit any saved relocations which turn out to be needed. This is
625 // called after all the relocs have been scanned.
627 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
630 template<int size
, bool big_endian
>
631 class Target_powerpc
: public Sized_target
<size
, big_endian
>
635 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
636 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
637 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
638 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
639 static const Address invalid_address
= static_cast<Address
>(0) - 1;
640 // Offset of tp and dtp pointers from start of TLS block.
641 static const Address tp_offset
= 0x7000;
642 static const Address dtp_offset
= 0x8000;
645 : Sized_target
<size
, big_endian
>(&powerpc_info
),
646 got_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
), brlt_section_(NULL
),
647 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
648 tlsld_got_offset_(-1U),
649 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
650 power10_relocs_(false), plt_thread_safe_(false), plt_localentry0_(false),
651 plt_localentry0_init_(false), has_localentry0_(false),
652 has_tls_get_addr_opt_(false), no_tprel_opt_(false),
653 relax_failed_(false), relax_fail_count_(0),
654 stub_group_size_(0), savres_section_(0),
655 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
656 attributes_section_data_(NULL
),
657 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
661 // Process the relocations to determine unreferenced sections for
662 // garbage collection.
664 gc_process_relocs(Symbol_table
* symtab
,
666 Sized_relobj_file
<size
, big_endian
>* object
,
667 unsigned int data_shndx
,
668 unsigned int sh_type
,
669 const unsigned char* prelocs
,
671 Output_section
* output_section
,
672 bool needs_special_offset_handling
,
673 size_t local_symbol_count
,
674 const unsigned char* plocal_symbols
);
676 // Scan the relocations to look for symbol adjustments.
678 scan_relocs(Symbol_table
* symtab
,
680 Sized_relobj_file
<size
, big_endian
>* object
,
681 unsigned int data_shndx
,
682 unsigned int sh_type
,
683 const unsigned char* prelocs
,
685 Output_section
* output_section
,
686 bool needs_special_offset_handling
,
687 size_t local_symbol_count
,
688 const unsigned char* plocal_symbols
);
690 // Map input .toc section to output .got section.
692 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
694 if (size
== 64 && strcmp(name
, ".toc") == 0)
702 // Provide linker defined save/restore functions.
704 define_save_restore_funcs(Layout
*, Symbol_table
*);
706 // No stubs unless a final link.
709 { return !parameters
->options().relocatable(); }
712 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
715 do_plt_fde_location(const Output_data
*, unsigned char*,
716 uint64_t*, off_t
*) const;
718 // Stash info about branches, for stub generation.
720 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
721 unsigned int data_shndx
, Address r_offset
,
722 unsigned int r_type
, unsigned int r_sym
, Address addend
)
724 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
725 this->branch_info_
.push_back(info
);
726 if (r_type
== elfcpp::R_POWERPC_REL14
727 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
728 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
729 ppc_object
->set_has_14bit_branch(data_shndx
);
732 // Return whether the last branch is a plt call, and if so, mark the
733 // branch as having an R_PPC64_TOCSAVE.
735 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
736 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
739 && !this->branch_info_
.empty()
740 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
741 r_offset
, this, symtab
));
744 // Say the given location, that of a nop in a function prologue with
745 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
746 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
748 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
749 unsigned int shndx
, Address offset
)
752 loc
.object
= ppc_object
;
755 this->tocsave_loc_
.insert(loc
);
762 return &this->tocsave_loc_
;
766 do_define_standard_symbols(Symbol_table
*, Layout
*);
768 // Finalize the sections.
770 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
772 // Return the value to use for a dynamic which requires special
775 do_dynsym_value(const Symbol
*) const;
777 // Return the PLT address to use for a local symbol.
779 do_plt_address_for_local(const Relobj
*, unsigned int) const;
781 // Return the PLT address to use for a global symbol.
783 do_plt_address_for_global(const Symbol
*) const;
785 // Return the offset to use for the GOT_INDX'th got entry which is
786 // for a local tls symbol specified by OBJECT, SYMNDX.
788 do_tls_offset_for_local(const Relobj
* object
,
790 unsigned int got_indx
) const;
792 // Return the offset to use for the GOT_INDX'th got entry which is
793 // for global tls symbol GSYM.
795 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
798 do_function_location(Symbol_location
*) const;
801 do_can_check_for_function_pointers() const
804 // Adjust -fsplit-stack code which calls non-split-stack code.
806 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
807 section_offset_type fnoffset
, section_size_type fnsize
,
808 const unsigned char* prelocs
, size_t reloc_count
,
809 unsigned char* view
, section_size_type view_size
,
810 std::string
* from
, std::string
* to
) const;
812 // Relocate a section.
814 relocate_section(const Relocate_info
<size
, big_endian
>*,
815 unsigned int sh_type
,
816 const unsigned char* prelocs
,
818 Output_section
* output_section
,
819 bool needs_special_offset_handling
,
821 Address view_address
,
822 section_size_type view_size
,
823 const Reloc_symbol_changes
*);
825 // Scan the relocs during a relocatable link.
827 scan_relocatable_relocs(Symbol_table
* symtab
,
829 Sized_relobj_file
<size
, big_endian
>* object
,
830 unsigned int data_shndx
,
831 unsigned int sh_type
,
832 const unsigned char* prelocs
,
834 Output_section
* output_section
,
835 bool needs_special_offset_handling
,
836 size_t local_symbol_count
,
837 const unsigned char* plocal_symbols
,
838 Relocatable_relocs
*);
840 // Scan the relocs for --emit-relocs.
842 emit_relocs_scan(Symbol_table
* symtab
,
844 Sized_relobj_file
<size
, big_endian
>* object
,
845 unsigned int data_shndx
,
846 unsigned int sh_type
,
847 const unsigned char* prelocs
,
849 Output_section
* output_section
,
850 bool needs_special_offset_handling
,
851 size_t local_symbol_count
,
852 const unsigned char* plocal_syms
,
853 Relocatable_relocs
* rr
);
855 // Emit relocations for a section.
857 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
858 unsigned int sh_type
,
859 const unsigned char* prelocs
,
861 Output_section
* output_section
,
862 typename
elfcpp::Elf_types
<size
>::Elf_Off
863 offset_in_output_section
,
865 Address view_address
,
867 unsigned char* reloc_view
,
868 section_size_type reloc_view_size
);
870 // Return whether SYM is defined by the ABI.
872 do_is_defined_by_abi(const Symbol
* sym
) const
874 return strcmp(sym
->name(), "__tls_get_addr") == 0;
877 // Return the size of the GOT section.
881 gold_assert(this->got_
!= NULL
);
882 return this->got_
->data_size();
885 // Get the PLT section.
886 const Output_data_plt_powerpc
<size
, big_endian
>*
889 gold_assert(this->plt_
!= NULL
);
893 // Get the IPLT section.
894 const Output_data_plt_powerpc
<size
, big_endian
>*
897 gold_assert(this->iplt_
!= NULL
);
901 // Get the LPLT section.
902 const Output_data_plt_powerpc
<size
, big_endian
>*
908 // Return the plt offset and section for the given global sym.
910 plt_off(const Symbol
* gsym
,
911 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
913 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
914 && gsym
->can_use_relative_reloc(false))
915 *sec
= this->iplt_section();
917 *sec
= this->plt_section();
918 return gsym
->plt_offset();
921 // Return the plt offset and section for the given local sym.
923 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
924 unsigned int local_sym_index
,
925 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
927 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
928 if (lsym
->is_ifunc_symbol())
929 *sec
= this->iplt_section();
931 *sec
= this->lplt_section();
932 return relobj
->local_plt_offset(local_sym_index
);
935 // Get the .glink section.
936 const Output_data_glink
<size
, big_endian
>*
937 glink_section() const
939 gold_assert(this->glink_
!= NULL
);
943 Output_data_glink
<size
, big_endian
>*
946 gold_assert(this->glink_
!= NULL
);
950 bool has_glink() const
951 { return this->glink_
!= NULL
; }
953 // Get the GOT section.
954 const Output_data_got_powerpc
<size
, big_endian
>*
957 gold_assert(this->got_
!= NULL
);
961 // Get the GOT section, creating it if necessary.
962 Output_data_got_powerpc
<size
, big_endian
>*
963 got_section(Symbol_table
*, Layout
*);
966 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
967 const elfcpp::Ehdr
<size
, big_endian
>&);
969 // Return the number of entries in the GOT.
971 got_entry_count() const
973 if (this->got_
== NULL
)
975 return this->got_size() / (size
/ 8);
978 // Return the number of entries in the PLT.
980 plt_entry_count() const;
982 // Return the offset of the first non-reserved PLT entry.
984 first_plt_entry_offset() const
988 if (this->abiversion() >= 2)
993 // Return the size of each PLT entry.
995 plt_entry_size() const
999 if (this->abiversion() >= 2)
1004 Output_data_save_res
<size
, big_endian
>*
1005 savres_section() const
1007 return this->savres_section_
;
1010 // Add any special sections for this symbol to the gc work list.
1011 // For powerpc64, this adds the code section of a function
1014 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1016 // Handle target specific gc actions when adding a gc reference from
1017 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1018 // and DST_OFF. For powerpc64, this adds a referenc to the code
1019 // section of a function descriptor.
1021 do_gc_add_reference(Symbol_table
* symtab
,
1023 unsigned int src_shndx
,
1025 unsigned int dst_shndx
,
1026 Address dst_off
) const;
1028 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1031 { return this->stub_tables_
; }
1033 const Output_data_brlt_powerpc
<size
, big_endian
>*
1034 brlt_section() const
1035 { return this->brlt_section_
; }
1038 add_branch_lookup_table(Address to
)
1040 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1041 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1045 find_branch_lookup_table(Address to
)
1047 typename
Branch_lookup_table::const_iterator p
1048 = this->branch_lookup_table_
.find(to
);
1049 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1053 write_branch_lookup_table(unsigned char *oview
)
1055 for (typename
Branch_lookup_table::const_iterator p
1056 = this->branch_lookup_table_
.begin();
1057 p
!= this->branch_lookup_table_
.end();
1060 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1064 // Wrapper used after relax to define a local symbol in output data,
1065 // from the end if value < 0.
1067 define_local(Symbol_table
* symtab
, const char* name
,
1068 Output_data
* od
, Address value
, unsigned int symsize
)
1071 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1072 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1073 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1074 static_cast<Signed_address
>(value
) < 0,
1076 // We are creating this symbol late, so need to fix up things
1077 // done early in Layout::finalize.
1078 sym
->set_dynsym_index(-1U);
1082 set_power10_relocs()
1084 this->power10_relocs_
= true;
1088 power10_stubs() const
1090 return (this->power10_relocs_
1091 && (parameters
->options().power10_stubs_enum()
1092 != General_options::POWER10_STUBS_NO
));
1096 power10_stubs_auto() const
1098 return (parameters
->options().power10_stubs_enum()
1099 == General_options::POWER10_STUBS_AUTO
);
1103 plt_thread_safe() const
1104 { return this->plt_thread_safe_
; }
1107 plt_localentry0() const
1108 { return this->plt_localentry0_
; }
1111 has_localentry0() const
1112 { return this->has_localentry0_
; }
1115 set_has_localentry0()
1117 this->has_localentry0_
= true;
1121 is_elfv2_localentry0(const Symbol
* gsym
) const
1124 && this->abiversion() >= 2
1125 && this->plt_localentry0()
1126 && gsym
->type() == elfcpp::STT_FUNC
1127 && gsym
->is_defined()
1128 && gsym
->nonvis() >> 3 == 0
1129 && !gsym
->non_zero_localentry());
1133 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1134 unsigned int r_sym
) const
1136 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1137 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1140 && this->abiversion() >= 2
1141 && this->plt_localentry0()
1142 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1144 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1146 if (!psymval
->is_ifunc_symbol()
1147 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1156 { return !this->no_tprel_opt_
&& parameters
->options().tls_optimize(); }
1160 { this->no_tprel_opt_
= true; }
1162 // Remember any symbols seen with non-zero localentry, even those
1163 // not providing a definition
1165 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1170 unsigned char st_other
= sym
.get_st_other();
1171 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1172 to
->set_non_zero_localentry();
1174 // We haven't resolved anything, continue normal processing.
1180 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1183 set_abiversion(int ver
)
1185 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1186 flags
&= ~elfcpp::EF_PPC64_ABI
;
1187 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1188 this->set_processor_specific_flags(flags
);
1192 tls_get_addr_opt() const
1193 { return this->tls_get_addr_opt_
; }
1196 tls_get_addr() const
1197 { return this->tls_get_addr_
; }
1199 // If optimizing __tls_get_addr calls, whether this is the
1200 // "__tls_get_addr" symbol.
1202 is_tls_get_addr_opt(const Symbol
* gsym
) const
1204 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1205 || gsym
== this->tls_get_addr_opt_
);
1209 replace_tls_get_addr(const Symbol
* gsym
) const
1210 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1213 set_has_tls_get_addr_opt()
1214 { this->has_tls_get_addr_opt_
= true; }
1216 // Offset to toc save stack slot
1219 { return this->abiversion() < 2 ? 40 : 24; }
1221 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1222 // so use the CR save slot. Used only by __tls_get_addr call stub,
1223 // relying on __tls_get_addr not saving CR itself.
1226 { return this->abiversion() < 2 ? 32 : 8; }
1228 // Merge object attributes from input object with those in the output.
1230 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1246 : tls_get_addr_state_(NOT_EXPECTED
),
1247 relinfo_(NULL
), relnum_(0), r_offset_(0)
1252 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1259 if (this->relinfo_
!= NULL
)
1260 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1261 _("missing expected __tls_get_addr call"));
1265 expect_tls_get_addr_call(
1266 const Relocate_info
<size
, big_endian
>* relinfo
,
1270 this->tls_get_addr_state_
= EXPECTED
;
1271 this->relinfo_
= relinfo
;
1272 this->relnum_
= relnum
;
1273 this->r_offset_
= r_offset
;
1277 expect_tls_get_addr_call()
1278 { this->tls_get_addr_state_
= EXPECTED
; }
1281 skip_next_tls_get_addr_call()
1282 {this->tls_get_addr_state_
= SKIP
; }
1285 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1286 unsigned int r_type
, const Symbol
* gsym
)
1289 = ((r_type
== elfcpp::R_POWERPC_REL24
1290 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1291 || r_type
== elfcpp::R_PPC_PLTREL24
1292 || is_plt16_reloc
<size
>(r_type
)
1293 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1294 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1295 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1296 || r_type
== elfcpp::R_POWERPC_PLTCALL
1297 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1298 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1300 && (gsym
== target
->tls_get_addr()
1301 || gsym
== target
->tls_get_addr_opt()));
1302 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1303 this->tls_get_addr_state_
= NOT_EXPECTED
;
1304 if (is_tls_call
&& last_tls
!= EXPECTED
)
1306 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1315 // What we're up to regarding calls to __tls_get_addr.
1316 // On powerpc, the branch and link insn making a call to
1317 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1318 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1319 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1320 // The marker relocation always comes first, and has the same
1321 // symbol as the reloc on the insn setting up the __tls_get_addr
1322 // argument. This ties the arg setup insn with the call insn,
1323 // allowing ld to safely optimize away the call. We check that
1324 // every call to __tls_get_addr has a marker relocation, and that
1325 // every marker relocation is on a call to __tls_get_addr.
1326 Tls_get_addr tls_get_addr_state_
;
1327 // Info about the last reloc for error message.
1328 const Relocate_info
<size
, big_endian
>* relinfo_
;
1333 // The class which scans relocations.
1334 class Scan
: protected Track_tls
1337 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1340 : Track_tls(), issued_non_pic_error_(false)
1344 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1347 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1348 Sized_relobj_file
<size
, big_endian
>* object
,
1349 unsigned int data_shndx
,
1350 Output_section
* output_section
,
1351 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1352 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1356 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1357 Sized_relobj_file
<size
, big_endian
>* object
,
1358 unsigned int data_shndx
,
1359 Output_section
* output_section
,
1360 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1364 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1366 Sized_relobj_file
<size
, big_endian
>* relobj
,
1369 const elfcpp::Rela
<size
, big_endian
>& ,
1370 unsigned int r_type
,
1371 const elfcpp::Sym
<size
, big_endian
>&)
1373 // PowerPC64 .opd is not folded, so any identical function text
1374 // may be folded and we'll still keep function addresses distinct.
1375 // That means no reloc is of concern here.
1378 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1379 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1380 if (ppcobj
->abiversion() == 1)
1383 // For 32-bit and ELFv2, conservatively assume anything but calls to
1384 // function code might be taking the address of the function.
1385 return !is_branch_reloc
<size
>(r_type
);
1389 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1391 Sized_relobj_file
<size
, big_endian
>* relobj
,
1394 const elfcpp::Rela
<size
, big_endian
>& ,
1395 unsigned int r_type
,
1401 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1402 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1403 if (ppcobj
->abiversion() == 1)
1406 return !is_branch_reloc
<size
>(r_type
);
1410 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1411 Sized_relobj_file
<size
, big_endian
>* object
,
1412 unsigned int r_type
, bool report_err
);
1416 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1417 unsigned int r_type
);
1420 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1421 unsigned int r_type
, Symbol
*);
1424 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1425 Target_powerpc
* target
);
1428 check_non_pic(Relobj
*, unsigned int r_type
);
1430 // Whether we have issued an error about a non-PIC compilation.
1431 bool issued_non_pic_error_
;
1435 symval_for_branch(const Symbol_table
* symtab
,
1436 const Sized_symbol
<size
>* gsym
,
1437 Powerpc_relobj
<size
, big_endian
>* object
,
1438 Address
*value
, unsigned int *dest_shndx
);
1440 // The class which implements relocation.
1441 class Relocate
: protected Track_tls
1444 // Use 'at' branch hints when true, 'y' when false.
1445 // FIXME maybe: set this with an option.
1446 static const bool is_isa_v2
= true;
1452 // Do a relocation. Return false if the caller should not issue
1453 // any warnings about this relocation.
1455 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1456 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1457 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1458 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1462 class Relocate_comdat_behavior
1465 // Decide what the linker should do for relocations that refer to
1466 // discarded comdat sections.
1467 inline Comdat_behavior
1468 get(const char* name
)
1470 gold::Default_comdat_behavior default_behavior
;
1471 Comdat_behavior ret
= default_behavior
.get(name
);
1472 if (ret
== CB_ERROR
)
1475 && (strcmp(name
, ".fixup") == 0
1476 || strcmp(name
, ".got2") == 0))
1479 && (strcmp(name
, ".opd") == 0
1480 || strcmp(name
, ".toc") == 0
1481 || strcmp(name
, ".toc1") == 0))
1488 // Optimize the TLS relocation type based on what we know about the
1489 // symbol. IS_FINAL is true if the final address of this symbol is
1490 // known at link time.
1492 tls::Tls_optimization
1493 optimize_tls_gd(bool is_final
)
1495 // If we are generating a shared library, then we can't do anything
1497 if (parameters
->options().shared()
1498 || !parameters
->options().tls_optimize())
1499 return tls::TLSOPT_NONE
;
1502 return tls::TLSOPT_TO_IE
;
1503 return tls::TLSOPT_TO_LE
;
1506 tls::Tls_optimization
1509 if (parameters
->options().shared()
1510 || !parameters
->options().tls_optimize())
1511 return tls::TLSOPT_NONE
;
1513 return tls::TLSOPT_TO_LE
;
1516 tls::Tls_optimization
1517 optimize_tls_ie(bool is_final
)
1520 || parameters
->options().shared()
1521 || !parameters
->options().tls_optimize())
1522 return tls::TLSOPT_NONE
;
1524 return tls::TLSOPT_TO_LE
;
1529 make_glink_section(Layout
*);
1531 // Create the PLT section.
1533 make_plt_section(Symbol_table
*, Layout
*);
1536 make_iplt_section(Symbol_table
*, Layout
*);
1539 make_lplt_section(Layout
*);
1542 make_brlt_section(Layout
*);
1544 // Create a PLT entry for a global symbol.
1546 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1548 // Create a PLT entry for a local IFUNC symbol.
1550 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1551 Sized_relobj_file
<size
, big_endian
>*,
1554 // Create a PLT entry for a local non-IFUNC symbol.
1556 make_local_plt_entry(Layout
*,
1557 Sized_relobj_file
<size
, big_endian
>*,
1561 // Create a GOT entry for local dynamic __tls_get_addr.
1563 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1564 Sized_relobj_file
<size
, big_endian
>* object
);
1567 tlsld_got_offset() const
1569 return this->tlsld_got_offset_
;
1572 // Get the dynamic reloc section, creating it if necessary.
1574 rela_dyn_section(Layout
*);
1576 // Similarly, but for ifunc symbols get the one for ifunc.
1578 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1580 // Copy a relocation against a global symbol.
1582 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1583 Sized_relobj_file
<size
, big_endian
>* object
,
1584 unsigned int shndx
, Output_section
* output_section
,
1585 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1587 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1588 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1589 symtab
->get_sized_symbol
<size
>(sym
),
1590 object
, shndx
, output_section
,
1591 r_type
, reloc
.get_r_offset(),
1592 reloc
.get_r_addend(),
1593 this->rela_dyn_section(layout
));
1596 // Look over all the input sections, deciding where to place stubs.
1598 group_sections(Layout
*, const Task
*, bool);
1600 // Sort output sections by address.
1601 struct Sort_sections
1604 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1605 { return sec1
->address() < sec2
->address(); }
1611 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1612 unsigned int data_shndx
,
1614 unsigned int r_type
,
1617 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1618 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1624 // Return whether this branch is going via a plt call stub, and if
1625 // so, mark it as having an R_PPC64_TOCSAVE.
1627 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1628 unsigned int shndx
, Address offset
,
1629 Target_powerpc
* target
, Symbol_table
* symtab
);
1631 // If this branch needs a plt call stub, or a long branch stub, make one.
1633 make_stub(Stub_table
<size
, big_endian
>*,
1634 Stub_table
<size
, big_endian
>*,
1635 Symbol_table
*) const;
1638 // The branch location..
1639 Powerpc_relobj
<size
, big_endian
>* object_
;
1640 unsigned int shndx_
;
1642 // ..and the branch type and destination.
1643 unsigned int r_type_
: 31;
1644 unsigned int tocsave_
: 1;
1645 unsigned int r_sym_
;
1649 // Information about this specific target which we pass to the
1650 // general Target structure.
1651 static Target::Target_info powerpc_info
;
1653 // The types of GOT entries needed for this platform.
1654 // These values are exposed to the ABI in an incremental link.
1655 // Do not renumber existing values without changing the version
1656 // number of the .gnu_incremental_inputs section.
1660 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1661 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1662 GOT_TYPE_TPREL
// entry for @got@tprel
1666 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1667 // The PLT section. This is a container for a table of addresses,
1668 // and their relocations. Each address in the PLT has a dynamic
1669 // relocation (R_*_JMP_SLOT) and each address will have a
1670 // corresponding entry in .glink for lazy resolution of the PLT.
1671 // ppc32 initialises the PLT to point at the .glink entry, while
1672 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1673 // linker adds a stub that loads the PLT entry into ctr then
1674 // branches to ctr. There may be more than one stub for each PLT
1675 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1676 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1677 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1678 // The IPLT section. Like plt_, this is a container for a table of
1679 // addresses and their relocations, specifically for STT_GNU_IFUNC
1680 // functions that resolve locally (STT_GNU_IFUNC functions that
1681 // don't resolve locally go in PLT). Unlike plt_, these have no
1682 // entry in .glink for lazy resolution, and the relocation section
1683 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1684 // the relocation section may contain relocations against
1685 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1686 // relocation section will appear at the end of other dynamic
1687 // relocations, so that ld.so applies these relocations after other
1688 // dynamic relocations. In a static executable, the relocation
1689 // section is emitted and marked with __rela_iplt_start and
1690 // __rela_iplt_end symbols.
1691 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1692 // A PLT style section for local, non-ifunc symbols
1693 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1694 // Section holding long branch destinations.
1695 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1696 // The .glink section.
1697 Output_data_glink
<size
, big_endian
>* glink_
;
1698 // The dynamic reloc section.
1699 Reloc_section
* rela_dyn_
;
1700 // Relocs saved to avoid a COPY reloc.
1701 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1702 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1703 unsigned int tlsld_got_offset_
;
1705 Stub_tables stub_tables_
;
1706 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1707 Branch_lookup_table branch_lookup_table_
;
1709 typedef std::vector
<Branch_info
> Branches
;
1710 Branches branch_info_
;
1711 Tocsave_loc tocsave_loc_
;
1713 bool power10_relocs_
;
1714 bool plt_thread_safe_
;
1715 bool plt_localentry0_
;
1716 bool plt_localentry0_init_
;
1717 bool has_localentry0_
;
1718 bool has_tls_get_addr_opt_
;
1722 int relax_fail_count_
;
1723 int32_t stub_group_size_
;
1725 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1727 // The "__tls_get_addr" symbol, if present
1728 Symbol
* tls_get_addr_
;
1729 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1730 Symbol
* tls_get_addr_opt_
;
1732 // Attributes in output.
1733 Attributes_section_data
* attributes_section_data_
;
1735 // Last input file to change various attribute tags
1736 const char* last_fp_
;
1737 const char* last_ld_
;
1738 const char* last_vec_
;
1739 const char* last_struct_
;
1743 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1746 true, // is_big_endian
1747 elfcpp::EM_PPC
, // machine_code
1748 false, // has_make_symbol
1749 false, // has_resolve
1750 false, // has_code_fill
1751 true, // is_default_stack_executable
1752 false, // can_icf_inline_merge_sections
1754 "/usr/lib/ld.so.1", // dynamic_linker
1755 0x10000000, // default_text_segment_address
1756 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1757 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1758 false, // isolate_execinstr
1760 elfcpp::SHN_UNDEF
, // small_common_shndx
1761 elfcpp::SHN_UNDEF
, // large_common_shndx
1762 0, // small_common_section_flags
1763 0, // large_common_section_flags
1764 NULL
, // attributes_section
1765 NULL
, // attributes_vendor
1766 "_start", // entry_symbol_name
1767 32, // hash_entry_size
1768 elfcpp::SHT_PROGBITS
, // unwind_section_type
1772 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1775 false, // is_big_endian
1776 elfcpp::EM_PPC
, // machine_code
1777 false, // has_make_symbol
1778 false, // has_resolve
1779 false, // has_code_fill
1780 true, // is_default_stack_executable
1781 false, // can_icf_inline_merge_sections
1783 "/usr/lib/ld.so.1", // dynamic_linker
1784 0x10000000, // default_text_segment_address
1785 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1786 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1787 false, // isolate_execinstr
1789 elfcpp::SHN_UNDEF
, // small_common_shndx
1790 elfcpp::SHN_UNDEF
, // large_common_shndx
1791 0, // small_common_section_flags
1792 0, // large_common_section_flags
1793 NULL
, // attributes_section
1794 NULL
, // attributes_vendor
1795 "_start", // entry_symbol_name
1796 32, // hash_entry_size
1797 elfcpp::SHT_PROGBITS
, // unwind_section_type
1801 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1804 true, // is_big_endian
1805 elfcpp::EM_PPC64
, // machine_code
1806 false, // has_make_symbol
1807 true, // has_resolve
1808 false, // has_code_fill
1809 false, // is_default_stack_executable
1810 false, // can_icf_inline_merge_sections
1812 "/usr/lib/ld.so.1", // dynamic_linker
1813 0x10000000, // default_text_segment_address
1814 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1815 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1816 false, // isolate_execinstr
1818 elfcpp::SHN_UNDEF
, // small_common_shndx
1819 elfcpp::SHN_UNDEF
, // large_common_shndx
1820 0, // small_common_section_flags
1821 0, // large_common_section_flags
1822 NULL
, // attributes_section
1823 NULL
, // attributes_vendor
1824 "_start", // entry_symbol_name
1825 32, // hash_entry_size
1826 elfcpp::SHT_PROGBITS
, // unwind_section_type
1830 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1833 false, // is_big_endian
1834 elfcpp::EM_PPC64
, // machine_code
1835 false, // has_make_symbol
1836 true, // has_resolve
1837 false, // has_code_fill
1838 false, // is_default_stack_executable
1839 false, // can_icf_inline_merge_sections
1841 "/usr/lib/ld.so.1", // dynamic_linker
1842 0x10000000, // default_text_segment_address
1843 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1844 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1845 false, // isolate_execinstr
1847 elfcpp::SHN_UNDEF
, // small_common_shndx
1848 elfcpp::SHN_UNDEF
, // large_common_shndx
1849 0, // small_common_section_flags
1850 0, // large_common_section_flags
1851 NULL
, // attributes_section
1852 NULL
, // attributes_vendor
1853 "_start", // entry_symbol_name
1854 32, // hash_entry_size
1855 elfcpp::SHT_PROGBITS
, // unwind_section_type
1860 is_branch_reloc(unsigned int r_type
)
1862 return (r_type
== elfcpp::R_POWERPC_REL24
1863 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1864 || r_type
== elfcpp::R_PPC_PLTREL24
1865 || r_type
== elfcpp::R_PPC_LOCAL24PC
1866 || r_type
== elfcpp::R_POWERPC_REL14
1867 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1868 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1869 || r_type
== elfcpp::R_POWERPC_ADDR24
1870 || r_type
== elfcpp::R_POWERPC_ADDR14
1871 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1872 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1875 // Reloc resolves to plt entry.
1878 is_plt16_reloc(unsigned int r_type
)
1880 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1881 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1882 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1883 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1886 // GOT_TYPE_STANDARD (ie. not TLS) GOT relocs
1888 is_got_reloc(unsigned int r_type
)
1890 return (r_type
== elfcpp::R_POWERPC_GOT16
1891 || r_type
== elfcpp::R_POWERPC_GOT16_LO
1892 || r_type
== elfcpp::R_POWERPC_GOT16_HI
1893 || r_type
== elfcpp::R_POWERPC_GOT16_HA
1894 || r_type
== elfcpp::R_PPC64_GOT16_DS
1895 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
1896 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
);
1899 // If INSN is an opcode that may be used with an @tls operand, return
1900 // the transformed insn for TLS optimisation, otherwise return 0. If
1901 // REG is non-zero only match an insn with RB or RA equal to REG.
1903 at_tls_transform(uint32_t insn
, unsigned int reg
)
1905 if ((insn
& (0x3f << 26)) != 31 << 26)
1909 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1910 rtra
= insn
& ((1 << 26) - (1 << 16));
1911 else if (((insn
>> 16) & 0x1f) == reg
)
1912 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1916 if ((insn
& (0x3ff << 1)) == 266 << 1)
1919 else if ((insn
& (0x1f << 1)) == 23 << 1
1920 && ((insn
& (0x1f << 6)) < 14 << 6
1921 || ((insn
& (0x1f << 6)) >= 16 << 6
1922 && (insn
& (0x1f << 6)) < 24 << 6)))
1923 // load and store indexed -> dform
1924 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1925 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1926 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1927 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1928 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1930 insn
= (58 << 26) | 2;
1938 template<int size
, bool big_endian
>
1939 class Powerpc_relocate_functions
1959 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1960 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1961 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1963 template<int valsize
>
1965 has_overflow_signed(Address value
)
1967 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1968 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1969 limit
<<= ((valsize
- 1) >> 1);
1970 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1971 return value
+ limit
> (limit
<< 1) - 1;
1974 template<int valsize
>
1976 has_overflow_unsigned(Address value
)
1978 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1979 limit
<<= ((valsize
- 1) >> 1);
1980 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1981 return value
> (limit
<< 1) - 1;
1984 template<int valsize
>
1986 has_overflow_bitfield(Address value
)
1988 return (has_overflow_unsigned
<valsize
>(value
)
1989 && has_overflow_signed
<valsize
>(value
));
1992 template<int valsize
>
1993 static inline Status
1994 overflowed(Address value
, Overflow_check overflow
)
1996 if (overflow
== CHECK_SIGNED
)
1998 if (has_overflow_signed
<valsize
>(value
))
1999 return STATUS_OVERFLOW
;
2001 else if (overflow
== CHECK_UNSIGNED
)
2003 if (has_overflow_unsigned
<valsize
>(value
))
2004 return STATUS_OVERFLOW
;
2006 else if (overflow
== CHECK_BITFIELD
)
2008 if (has_overflow_bitfield
<valsize
>(value
))
2009 return STATUS_OVERFLOW
;
2014 // Do a simple RELA relocation
2015 template<int fieldsize
, int valsize
>
2016 static inline Status
2017 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2019 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2020 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2021 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2022 return overflowed
<valsize
>(value
, overflow
);
2025 template<int fieldsize
, int valsize
>
2026 static inline Status
2027 rela(unsigned char* view
,
2028 unsigned int right_shift
,
2029 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2031 Overflow_check overflow
)
2033 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2034 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2035 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2036 if (overflow
== CHECK_SIGNED
)
2037 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2039 value
= value
>> right_shift
;
2040 Valtype reloc
= value
;
2043 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2044 return overflowed
<valsize
>(value
, overflow
);
2047 // Do a simple RELA relocation, unaligned.
2048 template<int fieldsize
, int valsize
>
2049 static inline Status
2050 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2052 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2053 return overflowed
<valsize
>(value
, overflow
);
2056 template<int fieldsize
, int valsize
>
2057 static inline Status
2058 rela_ua(unsigned char* view
,
2059 unsigned int right_shift
,
2060 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2062 Overflow_check overflow
)
2064 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2066 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2067 if (overflow
== CHECK_SIGNED
)
2068 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2070 value
= value
>> right_shift
;
2071 Valtype reloc
= value
;
2074 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2075 return overflowed
<valsize
>(value
, overflow
);
2079 // R_PPC64_ADDR64: (Symbol + Addend)
2081 addr64(unsigned char* view
, Address value
)
2082 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2084 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2086 addr64_u(unsigned char* view
, Address value
)
2087 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2089 // R_POWERPC_ADDR32: (Symbol + Addend)
2090 static inline Status
2091 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2092 { return This::template rela
<32,32>(view
, value
, overflow
); }
2094 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2095 static inline Status
2096 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2097 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2099 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2100 static inline Status
2101 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2103 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2105 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2106 stat
= STATUS_OVERFLOW
;
2110 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2111 static inline Status
2112 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2113 { return This::template rela
<16,16>(view
, value
, overflow
); }
2115 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2116 static inline Status
2117 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2118 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2120 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2121 static inline Status
2122 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2124 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2125 if ((value
& 3) != 0)
2126 stat
= STATUS_OVERFLOW
;
2130 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2131 static inline Status
2132 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2134 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2135 if ((value
& 15) != 0)
2136 stat
= STATUS_OVERFLOW
;
2140 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2142 addr16_hi(unsigned char* view
, Address value
)
2143 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2145 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2147 addr16_ha(unsigned char* view
, Address value
)
2148 { This::addr16_hi(view
, value
+ 0x8000); }
2150 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2152 addr16_hi2(unsigned char* view
, Address value
)
2153 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2155 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2157 addr16_ha2(unsigned char* view
, Address value
)
2158 { This::addr16_hi2(view
, value
+ 0x8000); }
2160 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2162 addr16_hi3(unsigned char* view
, Address value
)
2163 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2165 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2167 addr16_ha3(unsigned char* view
, Address value
)
2168 { This::addr16_hi3(view
, value
+ 0x8000); }
2170 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2171 static inline Status
2172 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2174 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2175 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2176 stat
= STATUS_OVERFLOW
;
2180 // R_POWERPC_REL16DX_HA
2181 static inline Status
2182 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2184 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2185 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2186 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2188 value
= static_cast<SignedAddress
>(value
) >> 16;
2189 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2190 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2191 return overflowed
<16>(value
, overflow
);
2195 static inline Status
2196 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2198 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2200 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2206 addr34_hi(unsigned char *view
, uint64_t value
)
2207 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2211 addr34_ha(unsigned char *view
, uint64_t value
)
2212 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2215 static inline Status
2216 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2218 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2220 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2224 // R_PPC64_ADDR16_HIGHER34
2226 addr16_higher34(unsigned char* view
, uint64_t value
)
2227 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2229 // R_PPC64_ADDR16_HIGHERA34
2231 addr16_highera34(unsigned char* view
, uint64_t value
)
2232 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2234 // R_PPC64_ADDR16_HIGHEST34
2236 addr16_highest34(unsigned char* view
, uint64_t value
)
2237 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2239 // R_PPC64_ADDR16_HIGHESTA34
2241 addr16_highesta34(unsigned char* view
, uint64_t value
)
2242 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2245 // Set ABI version for input and output.
2247 template<int size
, bool big_endian
>
2249 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2251 this->e_flags_
|= ver
;
2252 if (this->abiversion() != 0)
2254 Target_powerpc
<size
, big_endian
>* target
=
2255 static_cast<Target_powerpc
<size
, big_endian
>*>(
2256 parameters
->sized_target
<size
, big_endian
>());
2257 if (target
->abiversion() == 0)
2258 target
->set_abiversion(this->abiversion());
2259 else if (target
->abiversion() != this->abiversion())
2260 gold_error(_("%s: ABI version %d is not compatible "
2261 "with ABI version %d output"),
2262 this->name().c_str(),
2263 this->abiversion(), target
->abiversion());
2268 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2269 // relocatable object, if such sections exists.
2271 template<int size
, bool big_endian
>
2273 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2274 Read_symbols_data
* sd
)
2276 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2277 const unsigned char* namesu
= sd
->section_names
->data();
2278 const char* names
= reinterpret_cast<const char*>(namesu
);
2279 section_size_type names_size
= sd
->section_names_size
;
2280 const unsigned char* s
;
2282 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2283 size
== 32 ? ".got2" : ".opd",
2284 names
, names_size
, NULL
);
2287 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2288 this->special_
= ndx
;
2291 if (this->abiversion() == 0)
2292 this->set_abiversion(1);
2293 else if (this->abiversion() > 1)
2294 gold_error(_("%s: .opd invalid in abiv%d"),
2295 this->name().c_str(), this->abiversion());
2300 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2301 names
, names_size
, NULL
);
2304 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2305 this->relatoc_
= ndx
;
2306 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2307 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2310 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2313 // Examine .rela.opd to build info about function entry points.
2315 template<int size
, bool big_endian
>
2317 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2319 const unsigned char* prelocs
,
2320 const unsigned char* plocal_syms
)
2324 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2325 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2326 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2327 Address expected_off
= 0;
2328 bool regular
= true;
2329 unsigned int opd_ent_size
= 0;
2331 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2333 Reltype
reloc(prelocs
);
2334 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2335 = reloc
.get_r_info();
2336 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2337 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2339 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2340 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2343 if (r_sym
< this->local_symbol_count())
2345 typename
elfcpp::Sym
<size
, big_endian
>
2346 lsym(plocal_syms
+ r_sym
* sym_size
);
2347 shndx
= lsym
.get_st_shndx();
2348 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2349 value
= lsym
.get_st_value();
2352 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2354 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2355 value
+ reloc
.get_r_addend());
2358 expected_off
= reloc
.get_r_offset();
2359 opd_ent_size
= expected_off
;
2361 else if (expected_off
!= reloc
.get_r_offset())
2363 expected_off
+= opd_ent_size
;
2365 else if (r_type
== elfcpp::R_PPC64_TOC
)
2367 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2372 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2373 this->name().c_str(), r_type
);
2377 if (reloc_count
<= 2)
2378 opd_ent_size
= this->section_size(this->opd_shndx());
2379 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2383 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2384 this->name().c_str());
2390 // Returns true if a code sequence loading the TOC entry at VALUE
2391 // relative to the TOC pointer can be converted into code calculating
2392 // a TOC pointer relative offset.
2393 // If so, the TOC pointer relative offset is stored to VALUE.
2395 template<int size
, bool big_endian
>
2397 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2398 Target_powerpc
<size
, big_endian
>* target
,
2404 // With -mcmodel=medium code it is quite possible to have
2405 // toc-relative relocs referring to objects outside the TOC.
2406 // Don't try to look at a non-existent TOC.
2407 if (this->toc_shndx() == 0)
2410 // Convert VALUE back to an address by adding got_base (see below),
2411 // then to an offset in the TOC by subtracting the TOC output
2412 // section address and the TOC output offset. Since this TOC output
2413 // section and the got output section are one and the same, we can
2414 // omit adding and subtracting the output section address.
2415 Address off
= (*value
+ this->toc_base_offset()
2416 - this->output_section_offset(this->toc_shndx()));
2417 // Is this offset in the TOC? -mcmodel=medium code may be using
2418 // TOC relative access to variables outside the TOC. Those of
2419 // course can't be optimized. We also don't try to optimize code
2420 // that is using a different object's TOC.
2421 if (off
>= this->section_size(this->toc_shndx()))
2424 if (this->no_toc_opt(off
))
2427 section_size_type vlen
;
2428 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2429 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2431 Address got_base
= (target
->got_section()->output_section()->address()
2432 + this->toc_base_offset());
2434 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2441 template<int size
, bool big_endian
>
2443 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2444 Target_powerpc
<size
, big_endian
>* target
,
2445 const Symbol_value
<size
>* psymval
,
2449 Address addr
= psymval
->value(this, addend
);
2450 Address got_base
= (target
->got_section()->output_section()->address()
2451 + this->toc_base_offset());
2453 if (addr
+ 0x80008000 > 0xffffffff)
2460 // Perform the Sized_relobj_file method, then set up opd info from
2463 template<int size
, bool big_endian
>
2465 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2467 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2470 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2471 p
!= rd
->relocs
.end();
2474 if (p
->data_shndx
== this->opd_shndx())
2476 uint64_t opd_size
= this->section_size(this->opd_shndx());
2477 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2480 this->init_opd(opd_size
);
2481 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2482 rd
->local_symbols
->data());
2490 // Read the symbols then set up st_other vector.
2492 template<int size
, bool big_endian
>
2494 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2496 this->base_read_symbols(sd
);
2497 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2501 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2502 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2503 const unsigned int loccount
= this->do_local_symbol_count();
2506 this->st_other_
.resize(loccount
);
2507 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2508 off_t locsize
= loccount
* sym_size
;
2509 const unsigned int symtab_shndx
= this->symtab_shndx();
2510 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2511 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2512 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2513 locsize
, true, false);
2515 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2517 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2518 unsigned char st_other
= sym
.get_st_other();
2519 this->st_other_
[i
] = st_other
;
2520 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2522 if (this->abiversion() == 0)
2523 this->set_abiversion(2);
2524 else if (this->abiversion() < 2)
2525 gold_error(_("%s: local symbol %d has invalid st_other"
2526 " for ABI version 1"),
2527 this->name().c_str(), i
);
2533 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2534 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2535 bool merge_attributes
= false;
2536 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2538 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2539 switch (shdr
.get_sh_type())
2541 case elfcpp::SHT_GNU_ATTRIBUTES
:
2543 gold_assert(this->attributes_section_data_
== NULL
);
2544 section_offset_type section_offset
= shdr
.get_sh_offset();
2545 section_size_type section_size
=
2546 convert_to_section_size_type(shdr
.get_sh_size());
2547 const unsigned char* view
=
2548 this->get_view(section_offset
, section_size
, true, false);
2549 this->attributes_section_data_
=
2550 new Attributes_section_data(view
, section_size
);
2554 case elfcpp::SHT_SYMTAB
:
2556 // Sometimes an object has no contents except the section
2557 // name string table and an empty symbol table with the
2558 // undefined symbol. We don't want to merge
2559 // processor-specific flags from such an object.
2560 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2561 elfcpp::Elf_sizes
<size
>::sym_size
;
2562 if (shdr
.get_sh_size() > sym_size
)
2563 merge_attributes
= true;
2567 case elfcpp::SHT_STRTAB
:
2571 merge_attributes
= true;
2576 if (!merge_attributes
)
2578 // Should rarely happen.
2579 delete this->attributes_section_data_
;
2580 this->attributes_section_data_
= NULL
;
2584 template<int size
, bool big_endian
>
2586 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2588 this->e_flags_
|= ver
;
2589 if (this->abiversion() != 0)
2591 Target_powerpc
<size
, big_endian
>* target
=
2592 static_cast<Target_powerpc
<size
, big_endian
>*>(
2593 parameters
->sized_target
<size
, big_endian
>());
2594 if (target
->abiversion() == 0)
2595 target
->set_abiversion(this->abiversion());
2596 else if (target
->abiversion() != this->abiversion())
2597 gold_error(_("%s: ABI version %d is not compatible "
2598 "with ABI version %d output"),
2599 this->name().c_str(),
2600 this->abiversion(), target
->abiversion());
2605 // Call Sized_dynobj::base_read_symbols to read the symbols then
2606 // read .opd from a dynamic object, filling in opd_ent_ vector,
2608 template<int size
, bool big_endian
>
2610 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2612 this->base_read_symbols(sd
);
2613 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2614 const unsigned char* ps
=
2615 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2616 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2618 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2619 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2621 section_offset_type section_offset
= shdr
.get_sh_offset();
2622 section_size_type section_size
=
2623 convert_to_section_size_type(shdr
.get_sh_size());
2624 const unsigned char* view
=
2625 this->get_view(section_offset
, section_size
, true, false);
2626 this->attributes_section_data_
=
2627 new Attributes_section_data(view
, section_size
);
2633 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2634 const unsigned char* namesu
= sd
->section_names
->data();
2635 const char* names
= reinterpret_cast<const char*>(namesu
);
2636 const unsigned char* s
= NULL
;
2637 const unsigned char* opd
;
2638 section_size_type opd_size
;
2640 // Find and read .opd section.
2643 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2644 sd
->section_names_size
,
2649 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2650 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2651 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2653 if (this->abiversion() == 0)
2654 this->set_abiversion(1);
2655 else if (this->abiversion() > 1)
2656 gold_error(_("%s: .opd invalid in abiv%d"),
2657 this->name().c_str(), this->abiversion());
2659 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2660 this->opd_address_
= shdr
.get_sh_addr();
2661 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2662 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2668 // Build set of executable sections.
2669 // Using a set is probably overkill. There is likely to be only
2670 // a few executable sections, typically .init, .text and .fini,
2671 // and they are generally grouped together.
2672 typedef std::set
<Sec_info
> Exec_sections
;
2673 Exec_sections exec_sections
;
2675 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2677 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2678 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2679 && ((shdr
.get_sh_flags()
2680 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2681 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2682 && shdr
.get_sh_size() != 0)
2684 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2685 shdr
.get_sh_size(), i
));
2688 if (exec_sections
.empty())
2691 // Look over the OPD entries. This is complicated by the fact
2692 // that some binaries will use two-word entries while others
2693 // will use the standard three-word entries. In most cases
2694 // the third word (the environment pointer for languages like
2695 // Pascal) is unused and will be zero. If the third word is
2696 // used it should not be pointing into executable sections,
2698 this->init_opd(opd_size
);
2699 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2701 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2702 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2703 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2705 // Chances are that this is the third word of an OPD entry.
2707 typename
Exec_sections::const_iterator e
2708 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2709 if (e
!= exec_sections
.begin())
2712 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2714 // We have an address in an executable section.
2715 // VAL ought to be the function entry, set it up.
2716 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2717 // Skip second word of OPD entry, the TOC pointer.
2721 // If we didn't match any executable sections, we likely
2722 // have a non-zero third word in the OPD entry.
2727 // Relocate sections.
2729 template<int size
, bool big_endian
>
2731 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2732 const Symbol_table
* symtab
, const Layout
* layout
,
2733 const unsigned char* pshdrs
, Output_file
* of
,
2734 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2736 unsigned int start
= 1;
2738 && this->relatoc_
!= 0
2739 && !parameters
->options().relocatable())
2741 // Relocate .toc first.
2742 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2743 this->relatoc_
, this->relatoc_
);
2744 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2745 1, this->relatoc_
- 1);
2746 start
= this->relatoc_
+ 1;
2748 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2749 start
, this->shnum() - 1);
2751 if (!parameters
->options().output_is_position_independent())
2753 Target_powerpc
<size
, big_endian
>* target
2754 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2755 parameters
->sized_target
<size
, big_endian
>());
2756 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2758 const section_size_type offset
= target
->lplt_section()->offset();
2759 const section_size_type oview_size
2760 = convert_to_section_size_type(target
->lplt_section()->data_size());
2761 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2763 bool modified
= false;
2764 unsigned int nsyms
= this->local_symbol_count();
2765 for (unsigned int i
= 0; i
< nsyms
; i
++)
2766 if (this->local_has_plt_offset(i
))
2768 Address value
= this->local_symbol_value(i
, 0);
2769 size_t off
= this->local_plt_offset(i
);
2770 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2774 of
->write_output_view(offset
, oview_size
, oview
);
2779 // Set up some symbols.
2781 template<int size
, bool big_endian
>
2783 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2784 Symbol_table
* symtab
,
2789 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2790 // undefined when scanning relocs (and thus requires
2791 // non-relative dynamic relocs). The proper value will be
2793 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2794 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2796 Target_powerpc
<size
, big_endian
>* target
=
2797 static_cast<Target_powerpc
<size
, big_endian
>*>(
2798 parameters
->sized_target
<size
, big_endian
>());
2799 Output_data_got_powerpc
<size
, big_endian
>* got
2800 = target
->got_section(symtab
, layout
);
2801 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2802 Symbol_table::PREDEFINED
,
2806 elfcpp::STV_HIDDEN
, 0,
2810 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2811 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2812 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2814 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2816 = layout
->add_output_section_data(".sdata", 0,
2818 | elfcpp::SHF_WRITE
,
2819 sdata
, ORDER_SMALL_DATA
, false);
2820 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2821 Symbol_table::PREDEFINED
,
2822 os
, 32768, 0, elfcpp::STT_OBJECT
,
2823 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2829 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2830 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2831 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2833 Target_powerpc
<size
, big_endian
>* target
=
2834 static_cast<Target_powerpc
<size
, big_endian
>*>(
2835 parameters
->sized_target
<size
, big_endian
>());
2836 Output_data_got_powerpc
<size
, big_endian
>* got
2837 = target
->got_section(symtab
, layout
);
2838 symtab
->define_in_output_data(".TOC.", NULL
,
2839 Symbol_table::PREDEFINED
,
2843 elfcpp::STV_HIDDEN
, 0,
2848 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2849 if (parameters
->options().tls_get_addr_optimize()
2850 && this->tls_get_addr_
!= NULL
2851 && this->tls_get_addr_
->in_reg())
2852 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2853 if (this->tls_get_addr_opt_
!= NULL
)
2855 if (this->tls_get_addr_
->is_undefined()
2856 || this->tls_get_addr_
->is_from_dynobj())
2858 // Make it seem as if references to __tls_get_addr are
2859 // really to __tls_get_addr_opt, so the latter symbol is
2860 // made dynamic, not the former.
2861 this->tls_get_addr_
->clear_in_reg();
2862 this->tls_get_addr_opt_
->set_in_reg();
2864 // We have a non-dynamic definition for __tls_get_addr.
2865 // Make __tls_get_addr_opt the same, if it does not already have
2866 // a non-dynamic definition.
2867 else if (this->tls_get_addr_opt_
->is_undefined()
2868 || this->tls_get_addr_opt_
->is_from_dynobj())
2870 Sized_symbol
<size
>* from
2871 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2872 Sized_symbol
<size
>* to
2873 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2874 symtab
->clone
<size
>(to
, from
);
2879 // Set up PowerPC target specific relobj.
2881 template<int size
, bool big_endian
>
2883 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2884 const std::string
& name
,
2885 Input_file
* input_file
,
2886 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2888 int et
= ehdr
.get_e_type();
2889 // ET_EXEC files are valid input for --just-symbols/-R,
2890 // and we treat them as relocatable objects.
2891 if (et
== elfcpp::ET_REL
2892 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2894 Powerpc_relobj
<size
, big_endian
>* obj
=
2895 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2899 else if (et
== elfcpp::ET_DYN
)
2901 Powerpc_dynobj
<size
, big_endian
>* obj
=
2902 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2908 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2913 template<int size
, bool big_endian
>
2914 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2917 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2918 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2920 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2921 : Output_data_got
<size
, big_endian
>(),
2922 symtab_(symtab
), layout_(layout
),
2923 header_ent_cnt_(size
== 32 ? 3 : 1),
2924 header_index_(size
== 32 ? 0x2000 : 0)
2927 this->set_addralign(256);
2930 // Override all the Output_data_got methods we use so as to first call
2933 add_global(Symbol
* gsym
, unsigned int got_type
)
2935 this->reserve_ent();
2936 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2940 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2942 this->reserve_ent();
2943 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2947 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2948 { return this->add_global_plt(gsym
, got_type
); }
2951 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2952 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2954 this->reserve_ent();
2955 Output_data_got
<size
, big_endian
>::
2956 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2960 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2961 Output_data_reloc_generic
* rel_dyn
,
2962 unsigned int r_type_1
, unsigned int r_type_2
)
2964 if (gsym
->has_got_offset(got_type
))
2967 this->reserve_ent(2);
2968 Output_data_got
<size
, big_endian
>::
2969 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2973 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2975 this->reserve_ent();
2976 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2981 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2983 this->reserve_ent();
2984 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2989 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2990 { return this->add_local_plt(object
, sym_index
, got_type
); }
2993 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2994 unsigned int got_type
,
2995 Output_data_reloc_generic
* rel_dyn
,
2996 unsigned int r_type
)
2998 if (object
->local_has_got_offset(sym_index
, got_type
))
3001 this->reserve_ent(2);
3002 Output_data_got
<size
, big_endian
>::
3003 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
3007 add_constant(Valtype constant
)
3009 this->reserve_ent();
3010 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
3014 add_constant_pair(Valtype c1
, Valtype c2
)
3016 this->reserve_ent(2);
3017 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3020 // Offset of _GLOBAL_OFFSET_TABLE_.
3024 return this->got_offset(this->header_index_
);
3027 // Offset of base used to access the GOT/TOC.
3028 // The got/toc pointer reg will be set to this value.
3030 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
3033 return this->g_o_t();
3035 return (this->output_section()->address()
3036 + object
->toc_base_offset()
3040 // Ensure our GOT has a header.
3042 set_final_data_size()
3044 if (this->header_ent_cnt_
!= 0)
3045 this->make_header();
3046 Output_data_got
<size
, big_endian
>::set_final_data_size();
3049 // First word of GOT header needs some values that are not
3050 // handled by Output_data_got so poke them in here.
3051 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3053 do_write(Output_file
* of
)
3056 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3057 val
= this->layout_
->dynamic_section()->address();
3059 val
= this->output_section()->address() + 0x8000;
3060 this->replace_constant(this->header_index_
, val
);
3061 Output_data_got
<size
, big_endian
>::do_write(of
);
3066 reserve_ent(unsigned int cnt
= 1)
3068 if (this->header_ent_cnt_
== 0)
3070 if (this->num_entries() + cnt
> this->header_index_
)
3071 this->make_header();
3077 this->header_ent_cnt_
= 0;
3078 this->header_index_
= this->num_entries();
3081 Output_data_got
<size
, big_endian
>::add_constant(0);
3082 Output_data_got
<size
, big_endian
>::add_constant(0);
3083 Output_data_got
<size
, big_endian
>::add_constant(0);
3085 // Define _GLOBAL_OFFSET_TABLE_ at the header
3086 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3089 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3090 sym
->set_value(this->g_o_t());
3093 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3094 Symbol_table::PREDEFINED
,
3095 this, this->g_o_t(), 0,
3098 elfcpp::STV_HIDDEN
, 0,
3102 Output_data_got
<size
, big_endian
>::add_constant(0);
3105 // Stashed pointers.
3106 Symbol_table
* symtab_
;
3110 unsigned int header_ent_cnt_
;
3111 // GOT header index.
3112 unsigned int header_index_
;
3115 // Get the GOT section, creating it if necessary.
3117 template<int size
, bool big_endian
>
3118 Output_data_got_powerpc
<size
, big_endian
>*
3119 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3122 if (this->got_
== NULL
)
3124 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3127 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3129 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3130 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3131 this->got_
, ORDER_DATA
, false);
3137 // Get the dynamic reloc section, creating it if necessary.
3139 template<int size
, bool big_endian
>
3140 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3141 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3143 if (this->rela_dyn_
== NULL
)
3145 gold_assert(layout
!= NULL
);
3146 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3147 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3148 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3149 ORDER_DYNAMIC_RELOCS
, false);
3151 return this->rela_dyn_
;
3154 // Similarly, but for ifunc symbols get the one for ifunc.
3156 template<int size
, bool big_endian
>
3157 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3158 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3163 return this->rela_dyn_section(layout
);
3165 if (this->iplt_
== NULL
)
3166 this->make_iplt_section(symtab
, layout
);
3167 return this->iplt_
->rel_plt();
3173 // Determine the stub group size. The group size is the absolute
3174 // value of the parameter --stub-group-size. If --stub-group-size
3175 // is passed a negative value, we restrict stubs to be always after
3176 // the stubbed branches.
3177 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3178 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3179 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3180 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3181 owner_(NULL
), output_section_(NULL
)
3185 // Return true iff input section can be handled by current stub
3188 can_add_to_stub_group(Output_section
* o
,
3189 const Output_section::Input_section
* i
,
3192 const Output_section::Input_section
*
3198 { return output_section_
; }
3201 set_output_and_owner(Output_section
* o
,
3202 const Output_section::Input_section
* i
)
3204 this->output_section_
= o
;
3213 // Adding group sections before the stubs.
3214 FINDING_STUB_SECTION
,
3215 // Adding group sections after the stubs.
3219 uint32_t stub_group_size_
;
3220 bool stubs_always_after_branch_
;
3221 bool suppress_size_errors_
;
3222 // True if a stub group can serve multiple output sections.
3225 // Current max size of group. Starts at stub_group_size_ but is
3226 // reduced to stub_group_size_/1024 on seeing a section with
3227 // external conditional branches.
3228 uint32_t group_size_
;
3229 uint64_t group_start_addr_
;
3230 // owner_ and output_section_ specify the section to which stubs are
3231 // attached. The stubs are placed at the end of this section.
3232 const Output_section::Input_section
* owner_
;
3233 Output_section
* output_section_
;
3236 // Return true iff input section can be handled by current stub
3237 // group. Sections are presented to this function in order,
3238 // so the first section is the head of the group.
3241 Stub_control::can_add_to_stub_group(Output_section
* o
,
3242 const Output_section::Input_section
* i
,
3245 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3247 uint64_t start_addr
= o
->address();
3250 // .init and .fini sections are pasted together to form a single
3251 // function. We can't be adding stubs in the middle of the function.
3252 this_size
= o
->data_size();
3255 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3256 this_size
= i
->data_size();
3259 uint64_t end_addr
= start_addr
+ this_size
;
3260 uint32_t group_size
= this->stub_group_size_
;
3262 this->group_size_
= group_size
= group_size
>> 10;
3264 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3265 gold_warning(_("%s:%s exceeds group size"),
3266 i
->relobj()->name().c_str(),
3267 i
->relobj()->section_name(i
->shndx()).c_str());
3269 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3270 has14
? " 14bit" : "",
3271 i
->relobj()->name().c_str(),
3272 i
->relobj()->section_name(i
->shndx()).c_str(),
3273 (long long) this_size
,
3274 (this->state_
== NO_GROUP
3276 : (long long) end_addr
- this->group_start_addr_
));
3278 if (this->state_
== NO_GROUP
)
3280 // Only here on very first use of Stub_control
3282 this->output_section_
= o
;
3283 this->state_
= FINDING_STUB_SECTION
;
3284 this->group_size_
= group_size
;
3285 this->group_start_addr_
= start_addr
;
3288 else if (!this->multi_os_
&& this->output_section_
!= o
)
3290 else if (this->state_
== HAS_STUB_SECTION
)
3292 // Can we add this section, which is after the stubs, to the
3294 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3297 else if (this->state_
== FINDING_STUB_SECTION
)
3299 if ((whole_sec
&& this->output_section_
== o
)
3300 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3302 // Stubs are added at the end of "owner_".
3304 this->output_section_
= o
;
3307 // The group before the stubs has reached maximum size.
3308 // Now see about adding sections after the stubs to the
3309 // group. If the current section has a 14-bit branch and
3310 // the group before the stubs exceeds group_size_ (because
3311 // they didn't have 14-bit branches), don't add sections
3312 // after the stubs: The size of stubs for such a large
3313 // group may exceed the reach of a 14-bit branch.
3314 if (!this->stubs_always_after_branch_
3315 && this_size
<= this->group_size_
3316 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3318 gold_debug(DEBUG_TARGET
, "adding after stubs");
3319 this->state_
= HAS_STUB_SECTION
;
3320 this->group_start_addr_
= start_addr
;
3327 gold_debug(DEBUG_TARGET
,
3328 !this->multi_os_
&& this->output_section_
!= o
3329 ? "nope, new output section\n"
3330 : "nope, didn't fit\n");
3332 // The section fails to fit in the current group. Set up a few
3333 // things for the next group. owner_ and output_section_ will be
3334 // set later after we've retrieved those values for the current
3336 this->state_
= FINDING_STUB_SECTION
;
3337 this->group_size_
= group_size
;
3338 this->group_start_addr_
= start_addr
;
3342 // Look over all the input sections, deciding where to place stubs.
3344 template<int size
, bool big_endian
>
3346 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3348 bool no_size_errors
)
3350 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3351 parameters
->options().stub_group_multi());
3353 // Group input sections and insert stub table
3354 Stub_table_owner
* table_owner
= NULL
;
3355 std::vector
<Stub_table_owner
*> tables
;
3356 Layout::Section_list section_list
;
3357 layout
->get_executable_sections(§ion_list
);
3358 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3359 for (Layout::Section_list::iterator o
= section_list
.begin();
3360 o
!= section_list
.end();
3363 typedef Output_section::Input_section_list Input_section_list
;
3364 for (Input_section_list::const_iterator i
3365 = (*o
)->input_sections().begin();
3366 i
!= (*o
)->input_sections().end();
3369 if (i
->is_input_section()
3370 || i
->is_relaxed_input_section())
3372 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3373 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3374 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3375 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3377 table_owner
->output_section
= stub_control
.output_section();
3378 table_owner
->owner
= stub_control
.owner();
3379 stub_control
.set_output_and_owner(*o
, &*i
);
3382 if (table_owner
== NULL
)
3384 table_owner
= new Stub_table_owner
;
3385 tables
.push_back(table_owner
);
3387 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3391 if (table_owner
!= NULL
)
3393 table_owner
->output_section
= stub_control
.output_section();
3394 table_owner
->owner
= stub_control
.owner();;
3396 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3400 Stub_table
<size
, big_endian
>* stub_table
;
3402 if ((*t
)->owner
->is_input_section())
3403 stub_table
= new Stub_table
<size
, big_endian
>(this,
3404 (*t
)->output_section
,
3406 this->stub_tables_
.size());
3407 else if ((*t
)->owner
->is_relaxed_input_section())
3408 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3409 (*t
)->owner
->relaxed_input_section());
3412 this->stub_tables_
.push_back(stub_table
);
3418 static unsigned long
3419 max_branch_delta (unsigned int r_type
)
3421 if (r_type
== elfcpp::R_POWERPC_REL14
3422 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3423 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3425 if (r_type
== elfcpp::R_POWERPC_REL24
3426 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3427 || r_type
== elfcpp::R_PPC_PLTREL24
3428 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3433 // Return whether this branch is going via a plt call stub.
3435 template<int size
, bool big_endian
>
3437 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3438 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3441 Target_powerpc
* target
,
3442 Symbol_table
* symtab
)
3444 if (this->object_
!= ppc_object
3445 || this->shndx_
!= shndx
3446 || this->offset_
!= offset
)
3449 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3450 if (sym
!= NULL
&& sym
->is_forwarder())
3451 sym
= symtab
->resolve_forwards(sym
);
3452 if (target
->replace_tls_get_addr(sym
))
3453 sym
= target
->tls_get_addr_opt();
3454 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3456 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3457 && !target
->is_elfv2_localentry0(gsym
))
3458 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3459 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3467 // If this branch needs a plt call stub, or a long branch stub, make one.
3469 template<int size
, bool big_endian
>
3471 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3472 Stub_table
<size
, big_endian
>* stub_table
,
3473 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3474 Symbol_table
* symtab
) const
3476 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3477 Target_powerpc
<size
, big_endian
>* target
=
3478 static_cast<Target_powerpc
<size
, big_endian
>*>(
3479 parameters
->sized_target
<size
, big_endian
>());
3480 if (sym
!= NULL
&& sym
->is_forwarder())
3481 sym
= symtab
->resolve_forwards(sym
);
3482 if (target
->replace_tls_get_addr(sym
))
3483 sym
= target
->tls_get_addr_opt();
3484 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3488 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3489 : this->object_
->local_has_plt_offset(this->r_sym_
))
3493 && target
->abiversion() >= 2
3494 && !parameters
->options().output_is_position_independent()
3495 && !is_branch_reloc
<size
>(this->r_type_
))
3496 target
->glink_section()->add_global_entry(gsym
);
3499 if (stub_table
== NULL
3502 && !parameters
->options().output_is_position_independent()
3503 && !is_branch_reloc
<size
>(this->r_type_
)))
3504 stub_table
= this->object_
->stub_table(this->shndx_
);
3505 if (stub_table
== NULL
)
3507 // This is a ref from a data section to an ifunc symbol,
3508 // or a non-branch reloc for which we always want to use
3509 // one set of stubs for resolving function addresses.
3510 stub_table
= ifunc_stub_table
;
3512 gold_assert(stub_table
!= NULL
);
3513 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3514 if (from
!= invalid_address
)
3515 from
+= (this->object_
->output_section(this->shndx_
)->address()
3518 ok
= stub_table
->add_plt_call_entry(from
,
3519 this->object_
, gsym
,
3520 this->r_type_
, this->addend_
,
3523 ok
= stub_table
->add_plt_call_entry(from
,
3524 this->object_
, this->r_sym_
,
3525 this->r_type_
, this->addend_
,
3531 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3532 if (max_branch_offset
== 0)
3534 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3535 gold_assert(from
!= invalid_address
);
3536 from
+= (this->object_
->output_section(this->shndx_
)->address()
3539 unsigned int other
= 0;
3542 switch (gsym
->source())
3544 case Symbol::FROM_OBJECT
:
3546 Object
* symobj
= gsym
->object();
3547 if (symobj
->is_dynamic()
3548 || symobj
->pluginobj() != NULL
)
3551 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3552 if (shndx
== elfcpp::SHN_UNDEF
)
3557 case Symbol::IS_UNDEFINED
:
3563 Symbol_table::Compute_final_value_status status
;
3564 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3565 if (status
!= Symbol_table::CFVS_OK
)
3568 other
= gsym
->nonvis() >> 3;
3572 const Symbol_value
<size
>* psymval
3573 = this->object_
->local_symbol(this->r_sym_
);
3574 Symbol_value
<size
> symval
;
3575 if (psymval
->is_section_symbol())
3576 symval
.set_is_section_symbol();
3577 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3578 typename
ObjType::Compute_final_local_value_status status
3579 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3581 if (status
!= ObjType::CFLV_OK
3582 || !symval
.has_output_value())
3584 to
= symval
.value(this->object_
, 0);
3586 other
= this->object_
->st_other(this->r_sym_
) >> 5;
3588 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3589 to
+= this->addend_
;
3590 if (stub_table
== NULL
)
3591 stub_table
= this->object_
->stub_table(this->shndx_
);
3592 if (size
== 64 && target
->abiversion() < 2)
3594 unsigned int dest_shndx
;
3595 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3599 unsigned int local_ent
= 0;
3601 && this->r_type_
!= elfcpp::R_PPC64_REL24_NOTOC
)
3602 local_ent
= elfcpp::ppc64_decode_local_entry(other
);
3603 Address delta
= to
+ local_ent
- from
;
3604 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3606 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3608 ? this->object_
->ppc64_needs_toc(gsym
)
3609 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3611 if (stub_table
== NULL
)
3613 gold_warning(_("%s:%s: branch in non-executable section,"
3614 " no long branch stub for you"),
3615 this->object_
->name().c_str(),
3616 this->object_
->section_name(this->shndx_
).c_str());
3619 bool save_res
= (size
== 64
3621 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3622 && gsym
->output_data() == target
->savres_section());
3623 ok
= stub_table
->add_long_branch_entry(this->object_
,
3625 from
, to
, other
, save_res
);
3629 gold_debug(DEBUG_TARGET
,
3630 "branch at %s:%s+%#lx\n"
3631 "can't reach stub attached to %s:%s",
3632 this->object_
->name().c_str(),
3633 this->object_
->section_name(this->shndx_
).c_str(),
3634 (unsigned long) this->offset_
,
3635 stub_table
->relobj()->name().c_str(),
3636 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3641 // Relaxation hook. This is where we do stub generation.
3643 template<int size
, bool big_endian
>
3645 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3646 const Input_objects
*,
3647 Symbol_table
* symtab
,
3651 unsigned int prev_brlt_size
= 0;
3655 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3657 && this->abiversion() < 2
3659 && !parameters
->options().user_set_plt_thread_safe())
3661 static const char* const thread_starter
[] =
3665 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3667 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3668 "mq_notify", "create_timer",
3673 "GOMP_parallel_start",
3674 "GOMP_parallel_loop_static",
3675 "GOMP_parallel_loop_static_start",
3676 "GOMP_parallel_loop_dynamic",
3677 "GOMP_parallel_loop_dynamic_start",
3678 "GOMP_parallel_loop_guided",
3679 "GOMP_parallel_loop_guided_start",
3680 "GOMP_parallel_loop_runtime",
3681 "GOMP_parallel_loop_runtime_start",
3682 "GOMP_parallel_sections",
3683 "GOMP_parallel_sections_start",
3688 if (parameters
->options().shared())
3692 for (unsigned int i
= 0;
3693 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3696 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3697 thread_safe
= (sym
!= NULL
3699 && sym
->in_real_elf());
3705 this->plt_thread_safe_
= thread_safe
;
3710 this->stub_group_size_
= parameters
->options().stub_group_size();
3711 bool no_size_errors
= true;
3712 if (this->stub_group_size_
== 1)
3713 this->stub_group_size_
= 0x1c00000;
3714 else if (this->stub_group_size_
== -1)
3715 this->stub_group_size_
= -0x1e00000;
3717 no_size_errors
= false;
3718 this->group_sections(layout
, task
, no_size_errors
);
3720 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3722 this->branch_lookup_table_
.clear();
3723 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3724 p
!= this->stub_tables_
.end();
3727 (*p
)->clear_stubs(true);
3729 this->stub_tables_
.clear();
3730 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3731 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3732 program_name
, this->stub_group_size_
);
3733 this->group_sections(layout
, task
, true);
3736 // We need address of stub tables valid for make_stub.
3737 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3738 p
!= this->stub_tables_
.end();
3741 const Powerpc_relobj
<size
, big_endian
>* object
3742 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3743 Address off
= object
->get_output_section_offset((*p
)->shndx());
3744 gold_assert(off
!= invalid_address
);
3745 Output_section
* os
= (*p
)->output_section();
3746 (*p
)->set_address_and_size(os
, off
);
3751 // Clear plt call stubs, long branch stubs and branch lookup table.
3752 prev_brlt_size
= this->branch_lookup_table_
.size();
3753 this->branch_lookup_table_
.clear();
3754 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3755 p
!= this->stub_tables_
.end();
3758 (*p
)->clear_stubs(false);
3762 // Build all the stubs.
3763 this->relax_failed_
= false;
3764 Stub_table
<size
, big_endian
>* ifunc_stub_table
3765 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3766 Stub_table
<size
, big_endian
>* one_stub_table
3767 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3768 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3769 b
!= this->branch_info_
.end();
3772 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3773 && !this->relax_failed_
)
3775 this->relax_failed_
= true;
3776 this->relax_fail_count_
++;
3777 if (this->relax_fail_count_
< 3)
3781 bool do_resize
= false;
3782 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3783 p
!= this->stub_tables_
.end();
3785 if ((*p
)->need_resize())
3792 this->branch_lookup_table_
.clear();
3793 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3794 p
!= this->stub_tables_
.end();
3796 (*p
)->set_resizing(true);
3797 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3798 b
!= this->branch_info_
.end();
3801 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3802 && !this->relax_failed_
)
3804 this->relax_failed_
= true;
3805 this->relax_fail_count_
++;
3806 if (this->relax_fail_count_
< 3)
3810 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3811 p
!= this->stub_tables_
.end();
3813 (*p
)->set_resizing(false);
3816 // Did anything change size?
3817 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3818 bool again
= num_huge_branches
!= prev_brlt_size
;
3819 if (size
== 64 && num_huge_branches
!= 0)
3820 this->make_brlt_section(layout
);
3821 if (size
== 64 && again
)
3822 this->brlt_section_
->set_current_size(num_huge_branches
);
3824 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3825 p
!= this->stub_tables_
.rend();
3827 (*p
)->remove_eh_frame(layout
);
3829 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3830 p
!= this->stub_tables_
.end();
3832 (*p
)->add_eh_frame(layout
);
3834 typedef Unordered_set
<Output_section
*> Output_sections
;
3835 Output_sections os_need_update
;
3836 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3837 p
!= this->stub_tables_
.end();
3840 if ((*p
)->size_update())
3843 os_need_update
.insert((*p
)->output_section());
3847 // Set output section offsets for all input sections in an output
3848 // section that just changed size. Anything past the stubs will
3850 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3851 p
!= os_need_update
.end();
3854 Output_section
* os
= *p
;
3856 typedef Output_section::Input_section_list Input_section_list
;
3857 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3858 i
!= os
->input_sections().end();
3861 off
= align_address(off
, i
->addralign());
3862 if (i
->is_input_section() || i
->is_relaxed_input_section())
3863 i
->relobj()->set_section_offset(i
->shndx(), off
);
3864 if (i
->is_relaxed_input_section())
3866 Stub_table
<size
, big_endian
>* stub_table
3867 = static_cast<Stub_table
<size
, big_endian
>*>(
3868 i
->relaxed_input_section());
3869 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3870 off
+= stub_table_size
;
3871 // After a few iterations, set current stub table size
3872 // as min size threshold, so later stub tables can only
3875 stub_table
->set_min_size_threshold(stub_table_size
);
3878 off
+= i
->data_size();
3880 // If .branch_lt is part of this output section, then we have
3881 // just done the offset adjustment.
3882 os
->clear_section_offsets_need_adjustment();
3887 && num_huge_branches
!= 0
3888 && parameters
->options().output_is_position_independent())
3890 // Fill in the BRLT relocs.
3891 this->brlt_section_
->reset_brlt_sizes();
3892 for (typename
Branch_lookup_table::const_iterator p
3893 = this->branch_lookup_table_
.begin();
3894 p
!= this->branch_lookup_table_
.end();
3897 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3899 this->brlt_section_
->finalize_brlt_sizes();
3903 && (parameters
->options().user_set_emit_stub_syms()
3904 ? parameters
->options().emit_stub_syms()
3906 || parameters
->options().output_is_position_independent()
3907 || parameters
->options().emit_relocs())))
3909 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3910 p
!= this->stub_tables_
.end();
3912 (*p
)->define_stub_syms(symtab
);
3914 if (this->glink_
!= NULL
)
3916 int stub_size
= this->glink_
->pltresolve_size();
3917 Address value
= -stub_size
;
3923 this->define_local(symtab
, "__glink_PLTresolve",
3924 this->glink_
, value
, stub_size
);
3927 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3934 template<int size
, bool big_endian
>
3936 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3937 unsigned char* oview
,
3941 uint64_t address
= plt
->address();
3942 off_t len
= plt
->data_size();
3944 if (plt
== this->glink_
)
3946 // See Output_data_glink::do_write() for glink contents.
3949 gold_assert(parameters
->doing_static_link());
3950 // Static linking may need stubs, to support ifunc and long
3951 // branches. We need to create an output section for
3952 // .eh_frame early in the link process, to have a place to
3953 // attach stub .eh_frame info. We also need to have
3954 // registered a CIE that matches the stub CIE. Both of
3955 // these requirements are satisfied by creating an FDE and
3956 // CIE for .glink, even though static linking will leave
3957 // .glink zero length.
3958 // ??? Hopefully generating an FDE with a zero address range
3959 // won't confuse anything that consumes .eh_frame info.
3961 else if (size
== 64)
3963 // There is one word before __glink_PLTresolve
3967 else if (parameters
->options().output_is_position_independent())
3969 // There are two FDEs for a position independent glink.
3970 // The first covers the branch table, the second
3971 // __glink_PLTresolve at the end of glink.
3972 off_t resolve_size
= this->glink_
->pltresolve_size();
3973 if (oview
[9] == elfcpp::DW_CFA_nop
)
3974 len
-= resolve_size
;
3977 address
+= len
- resolve_size
;
3984 // Must be a stub table.
3985 const Stub_table
<size
, big_endian
>* stub_table
3986 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3987 uint64_t stub_address
= stub_table
->stub_address();
3988 len
-= stub_address
- address
;
3989 address
= stub_address
;
3992 *paddress
= address
;
3996 // A class to handle the PLT data.
3998 template<int size
, bool big_endian
>
3999 class Output_data_plt_powerpc
: public Output_section_data_build
4002 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4003 size
, big_endian
> Reloc_section
;
4005 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4006 Reloc_section
* plt_rel
,
4008 : Output_section_data_build(size
== 32 ? 4 : 8),
4014 // Add an entry to the PLT.
4019 add_ifunc_entry(Symbol
*);
4022 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4025 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4027 // Return the .rela.plt section data.
4034 // Return the number of PLT entries.
4038 if (this->current_data_size() == 0)
4040 return ((this->current_data_size() - this->first_plt_entry_offset())
4041 / this->plt_entry_size());
4046 do_adjust_output_section(Output_section
* os
)
4051 // Write to a map file.
4053 do_print_to_mapfile(Mapfile
* mapfile
) const
4054 { mapfile
->print_output_data(this, this->name_
); }
4057 // Return the offset of the first non-reserved PLT entry.
4059 first_plt_entry_offset() const
4061 // IPLT and LPLT have no reserved entry.
4062 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4064 return this->targ_
->first_plt_entry_offset();
4067 // Return the size of each PLT entry.
4069 plt_entry_size() const
4071 return this->targ_
->plt_entry_size();
4074 // Write out the PLT data.
4076 do_write(Output_file
*);
4078 // The reloc section.
4079 Reloc_section
* rel_
;
4080 // Allows access to .glink for do_write.
4081 Target_powerpc
<size
, big_endian
>* targ_
;
4082 // What to report in map file.
4086 // Add an entry to the PLT.
4088 template<int size
, bool big_endian
>
4090 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4092 if (!gsym
->has_plt_offset())
4094 section_size_type off
= this->current_data_size();
4096 off
+= this->first_plt_entry_offset();
4097 gsym
->set_plt_offset(off
);
4098 gsym
->set_needs_dynsym_entry();
4099 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4100 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4101 off
+= this->plt_entry_size();
4102 this->set_current_data_size(off
);
4106 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4108 template<int size
, bool big_endian
>
4110 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4112 if (!gsym
->has_plt_offset())
4114 section_size_type off
= this->current_data_size();
4115 gsym
->set_plt_offset(off
);
4116 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4117 if (size
== 64 && this->targ_
->abiversion() < 2)
4118 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4119 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4120 off
+= this->plt_entry_size();
4121 this->set_current_data_size(off
);
4125 // Add an entry for a local symbol to the PLT.
4127 template<int size
, bool big_endian
>
4129 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4130 Sized_relobj_file
<size
, big_endian
>* relobj
,
4131 unsigned int local_sym_index
)
4133 if (!relobj
->local_has_plt_offset(local_sym_index
))
4135 section_size_type off
= this->current_data_size();
4136 relobj
->set_local_plt_offset(local_sym_index
, off
);
4139 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4140 if (size
== 64 && this->targ_
->abiversion() < 2)
4141 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4142 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4143 dynrel
, this, off
, 0);
4145 off
+= this->plt_entry_size();
4146 this->set_current_data_size(off
);
4150 // Add an entry for a local ifunc symbol to the IPLT.
4152 template<int size
, bool big_endian
>
4154 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4155 Sized_relobj_file
<size
, big_endian
>* relobj
,
4156 unsigned int local_sym_index
)
4158 if (!relobj
->local_has_plt_offset(local_sym_index
))
4160 section_size_type off
= this->current_data_size();
4161 relobj
->set_local_plt_offset(local_sym_index
, off
);
4162 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4163 if (size
== 64 && this->targ_
->abiversion() < 2)
4164 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4165 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4167 off
+= this->plt_entry_size();
4168 this->set_current_data_size(off
);
4172 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4173 static const uint32_t add_2_2_11
= 0x7c425a14;
4174 static const uint32_t add_2_2_12
= 0x7c426214;
4175 static const uint32_t add_3_3_2
= 0x7c631214;
4176 static const uint32_t add_3_3_13
= 0x7c636a14;
4177 static const uint32_t add_3_12_2
= 0x7c6c1214;
4178 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4179 static const uint32_t add_11_0_11
= 0x7d605a14;
4180 static const uint32_t add_11_2_11
= 0x7d625a14;
4181 static const uint32_t add_11_11_2
= 0x7d6b1214;
4182 static const uint32_t add_12_11_12
= 0x7d8b6214;
4183 static const uint32_t addi_0_12
= 0x380c0000;
4184 static const uint32_t addi_2_2
= 0x38420000;
4185 static const uint32_t addi_3_3
= 0x38630000;
4186 static const uint32_t addi_11_11
= 0x396b0000;
4187 static const uint32_t addi_12_1
= 0x39810000;
4188 static const uint32_t addi_12_11
= 0x398b0000;
4189 static const uint32_t addi_12_12
= 0x398c0000;
4190 static const uint32_t addis_0_2
= 0x3c020000;
4191 static const uint32_t addis_0_13
= 0x3c0d0000;
4192 static const uint32_t addis_2_12
= 0x3c4c0000;
4193 static const uint32_t addis_11_2
= 0x3d620000;
4194 static const uint32_t addis_11_11
= 0x3d6b0000;
4195 static const uint32_t addis_11_30
= 0x3d7e0000;
4196 static const uint32_t addis_12_1
= 0x3d810000;
4197 static const uint32_t addis_12_2
= 0x3d820000;
4198 static const uint32_t addis_12_11
= 0x3d8b0000;
4199 static const uint32_t addis_12_12
= 0x3d8c0000;
4200 static const uint32_t b
= 0x48000000;
4201 static const uint32_t bcl_20_31
= 0x429f0005;
4202 static const uint32_t bctr
= 0x4e800420;
4203 static const uint32_t bctrl
= 0x4e800421;
4204 static const uint32_t beqlr
= 0x4d820020;
4205 static const uint32_t blr
= 0x4e800020;
4206 static const uint32_t bnectr_p4
= 0x4ce20420;
4207 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4208 static const uint32_t cmpldi_2_0
= 0x28220000;
4209 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4210 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4211 static const uint32_t cror_15_15_15
= 0x4def7b82;
4212 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4213 static const uint32_t ld_0_1
= 0xe8010000;
4214 static const uint32_t ld_0_11
= 0xe80b0000;
4215 static const uint32_t ld_0_12
= 0xe80c0000;
4216 static const uint32_t ld_2_1
= 0xe8410000;
4217 static const uint32_t ld_2_2
= 0xe8420000;
4218 static const uint32_t ld_2_11
= 0xe84b0000;
4219 static const uint32_t ld_2_12
= 0xe84c0000;
4220 static const uint32_t ld_11_1
= 0xe9610000;
4221 static const uint32_t ld_11_2
= 0xe9620000;
4222 static const uint32_t ld_11_3
= 0xe9630000;
4223 static const uint32_t ld_11_11
= 0xe96b0000;
4224 static const uint32_t ld_12_2
= 0xe9820000;
4225 static const uint32_t ld_12_3
= 0xe9830000;
4226 static const uint32_t ld_12_11
= 0xe98b0000;
4227 static const uint32_t ld_12_12
= 0xe98c0000;
4228 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4229 static const uint32_t lfd_0_1
= 0xc8010000;
4230 static const uint32_t li_0_0
= 0x38000000;
4231 static const uint32_t li_11_0
= 0x39600000;
4232 static const uint32_t li_12_0
= 0x39800000;
4233 static const uint32_t lis_0
= 0x3c000000;
4234 static const uint32_t lis_2
= 0x3c400000;
4235 static const uint32_t lis_11
= 0x3d600000;
4236 static const uint32_t lis_12
= 0x3d800000;
4237 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4238 static const uint32_t lwz_0_12
= 0x800c0000;
4239 static const uint32_t lwz_11_3
= 0x81630000;
4240 static const uint32_t lwz_11_11
= 0x816b0000;
4241 static const uint32_t lwz_11_30
= 0x817e0000;
4242 static const uint32_t lwz_12_3
= 0x81830000;
4243 static const uint32_t lwz_12_12
= 0x818c0000;
4244 static const uint32_t lwzu_0_12
= 0x840c0000;
4245 static const uint32_t mflr_0
= 0x7c0802a6;
4246 static const uint32_t mflr_11
= 0x7d6802a6;
4247 static const uint32_t mflr_12
= 0x7d8802a6;
4248 static const uint32_t mr_0_3
= 0x7c601b78;
4249 static const uint32_t mr_3_0
= 0x7c030378;
4250 static const uint32_t mtctr_0
= 0x7c0903a6;
4251 static const uint32_t mtctr_11
= 0x7d6903a6;
4252 static const uint32_t mtctr_12
= 0x7d8903a6;
4253 static const uint32_t mtlr_0
= 0x7c0803a6;
4254 static const uint32_t mtlr_11
= 0x7d6803a6;
4255 static const uint32_t mtlr_12
= 0x7d8803a6;
4256 static const uint32_t nop
= 0x60000000;
4257 static const uint32_t ori_0_0_0
= 0x60000000;
4258 static const uint32_t ori_11_11_0
= 0x616b0000;
4259 static const uint32_t ori_12_12_0
= 0x618c0000;
4260 static const uint32_t oris_12_12_0
= 0x658c0000;
4261 static const uint32_t sldi_11_11_34
= 0x796b1746;
4262 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4263 static const uint32_t srdi_0_0_2
= 0x7800f082;
4264 static const uint32_t std_0_1
= 0xf8010000;
4265 static const uint32_t std_0_12
= 0xf80c0000;
4266 static const uint32_t std_2_1
= 0xf8410000;
4267 static const uint32_t std_11_1
= 0xf9610000;
4268 static const uint32_t stfd_0_1
= 0xd8010000;
4269 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4270 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4271 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4272 static const uint32_t xor_2_12_12
= 0x7d826278;
4273 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4275 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4276 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4277 static const uint64_t pnop
= 0x0700000000000000ULL
;
4279 // Write out the PLT.
4281 template<int size
, bool big_endian
>
4283 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4285 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4287 const section_size_type offset
= this->offset();
4288 const section_size_type oview_size
4289 = convert_to_section_size_type(this->data_size());
4290 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4291 unsigned char* pov
= oview
;
4292 unsigned char* endpov
= oview
+ oview_size
;
4294 // The address of the .glink branch table
4295 const Output_data_glink
<size
, big_endian
>* glink
4296 = this->targ_
->glink_section();
4297 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4299 while (pov
< endpov
)
4301 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4306 of
->write_output_view(offset
, oview_size
, oview
);
4310 // Create the PLT section.
4312 template<int size
, bool big_endian
>
4314 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4317 if (this->plt_
== NULL
)
4319 if (this->got_
== NULL
)
4320 this->got_section(symtab
, layout
);
4322 if (this->glink_
== NULL
)
4323 make_glink_section(layout
);
4325 // Ensure that .rela.dyn always appears before .rela.plt This is
4326 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4327 // needs to include .rela.plt in its range.
4328 this->rela_dyn_section(layout
);
4330 Reloc_section
* plt_rel
= new Reloc_section(false);
4331 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4332 elfcpp::SHF_ALLOC
, plt_rel
,
4333 ORDER_DYNAMIC_PLT_RELOCS
, false);
4335 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4337 layout
->add_output_section_data(".plt",
4339 ? elfcpp::SHT_PROGBITS
4340 : elfcpp::SHT_NOBITS
),
4341 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4348 Output_section
* rela_plt_os
= plt_rel
->output_section();
4349 rela_plt_os
->set_info_section(this->plt_
->output_section());
4353 // Create the IPLT section.
4355 template<int size
, bool big_endian
>
4357 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4360 if (this->iplt_
== NULL
)
4362 this->make_plt_section(symtab
, layout
);
4363 this->make_lplt_section(layout
);
4365 Reloc_section
* iplt_rel
= new Reloc_section(false);
4366 if (this->rela_dyn_
->output_section())
4367 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4369 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4371 if (this->plt_
->output_section())
4372 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4376 // Create the LPLT section.
4378 template<int size
, bool big_endian
>
4380 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4382 if (this->lplt_
== NULL
)
4384 Reloc_section
* lplt_rel
= NULL
;
4385 if (parameters
->options().output_is_position_independent())
4387 lplt_rel
= new Reloc_section(false);
4388 this->rela_dyn_section(layout
);
4389 if (this->rela_dyn_
->output_section())
4390 this->rela_dyn_
->output_section()
4391 ->add_output_section_data(lplt_rel
);
4394 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4396 this->make_brlt_section(layout
);
4397 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4398 this->brlt_section_
->output_section()
4399 ->add_output_section_data(this->lplt_
);
4401 layout
->add_output_section_data(".branch_lt",
4402 elfcpp::SHT_PROGBITS
,
4403 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4410 // A section for huge long branch addresses, similar to plt section.
4412 template<int size
, bool big_endian
>
4413 class Output_data_brlt_powerpc
: public Output_section_data_build
4416 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4417 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4418 size
, big_endian
> Reloc_section
;
4420 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4421 Reloc_section
* brlt_rel
)
4422 : Output_section_data_build(size
== 32 ? 4 : 8),
4430 this->reset_data_size();
4431 this->rel_
->reset_data_size();
4435 finalize_brlt_sizes()
4437 this->finalize_data_size();
4438 this->rel_
->finalize_data_size();
4441 // Add a reloc for an entry in the BRLT.
4443 add_reloc(Address to
, unsigned int off
)
4444 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4446 // Update section and reloc section size.
4448 set_current_size(unsigned int num_branches
)
4450 this->reset_address_and_file_offset();
4451 this->set_current_data_size(num_branches
* 16);
4452 this->finalize_data_size();
4453 Output_section
* os
= this->output_section();
4454 os
->set_section_offsets_need_adjustment();
4455 if (this->rel_
!= NULL
)
4457 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4458 this->rel_
->reset_address_and_file_offset();
4459 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4460 this->rel_
->finalize_data_size();
4461 Output_section
* os
= this->rel_
->output_section();
4462 os
->set_section_offsets_need_adjustment();
4468 do_adjust_output_section(Output_section
* os
)
4473 // Write to a map file.
4475 do_print_to_mapfile(Mapfile
* mapfile
) const
4476 { mapfile
->print_output_data(this, "** BRLT"); }
4479 // Write out the BRLT data.
4481 do_write(Output_file
*);
4483 // The reloc section.
4484 Reloc_section
* rel_
;
4485 Target_powerpc
<size
, big_endian
>* targ_
;
4488 // Make the branch lookup table section.
4490 template<int size
, bool big_endian
>
4492 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4494 if (size
== 64 && this->brlt_section_
== NULL
)
4496 Reloc_section
* brlt_rel
= NULL
;
4497 bool is_pic
= parameters
->options().output_is_position_independent();
4500 // When PIC we can't fill in .branch_lt but must initialise at
4501 // runtime via dynamic relocations.
4502 this->rela_dyn_section(layout
);
4503 brlt_rel
= new Reloc_section(false);
4504 if (this->rela_dyn_
->output_section())
4505 this->rela_dyn_
->output_section()
4506 ->add_output_section_data(brlt_rel
);
4509 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4510 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4511 this->plt_
->output_section()
4512 ->add_output_section_data(this->brlt_section_
);
4514 layout
->add_output_section_data(".branch_lt",
4515 elfcpp::SHT_PROGBITS
,
4516 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4517 this->brlt_section_
,
4523 // Write out .branch_lt when non-PIC.
4525 template<int size
, bool big_endian
>
4527 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4529 if (size
== 64 && !parameters
->options().output_is_position_independent())
4531 const section_size_type offset
= this->offset();
4532 const section_size_type oview_size
4533 = convert_to_section_size_type(this->data_size());
4534 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4536 this->targ_
->write_branch_lookup_table(oview
);
4537 of
->write_output_view(offset
, oview_size
, oview
);
4541 static inline uint32_t
4547 static inline uint32_t
4553 static inline uint32_t
4556 return hi(a
+ 0x8000);
4559 static inline uint64_t
4562 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4565 static inline uint64_t
4568 return (v
+ (1ULL << 33)) >> 34;
4574 static const unsigned char eh_frame_cie
[12];
4578 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4581 'z', 'R', 0, // Augmentation string.
4582 4, // Code alignment.
4583 0x80 - size
/ 8 , // Data alignment.
4585 1, // Augmentation size.
4586 (elfcpp::DW_EH_PE_pcrel
4587 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4588 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4591 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4592 static const unsigned char glink_eh_frame_fde_64v1
[] =
4594 0, 0, 0, 0, // Replaced with offset to .glink.
4595 0, 0, 0, 0, // Replaced with size of .glink.
4596 0, // Augmentation size.
4597 elfcpp::DW_CFA_advance_loc
+ 2,
4598 elfcpp::DW_CFA_register
, 65, 12,
4599 elfcpp::DW_CFA_advance_loc
+ 4,
4600 elfcpp::DW_CFA_restore_extended
, 65
4603 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4604 static const unsigned char glink_eh_frame_fde_64v2
[] =
4606 0, 0, 0, 0, // Replaced with offset to .glink.
4607 0, 0, 0, 0, // Replaced with size of .glink.
4608 0, // Augmentation size.
4609 elfcpp::DW_CFA_advance_loc
+ 2,
4610 elfcpp::DW_CFA_register
, 65, 0,
4611 elfcpp::DW_CFA_advance_loc
+ 2,
4612 elfcpp::DW_CFA_restore_extended
, 65
4615 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4617 0, 0, 0, 0, // Replaced with offset to .glink.
4618 0, 0, 0, 0, // Replaced with size of .glink.
4619 0, // Augmentation size.
4620 elfcpp::DW_CFA_advance_loc
+ 3,
4621 elfcpp::DW_CFA_register
, 65, 0,
4622 elfcpp::DW_CFA_advance_loc
+ 2,
4623 elfcpp::DW_CFA_restore_extended
, 65
4626 // Describe __glink_PLTresolve use of LR, 32-bit version.
4627 static const unsigned char glink_eh_frame_fde_32
[] =
4629 0, 0, 0, 0, // Replaced with offset to .glink.
4630 0, 0, 0, 0, // Replaced with size of .glink.
4631 0, // Augmentation size.
4632 elfcpp::DW_CFA_advance_loc
+ 2,
4633 elfcpp::DW_CFA_register
, 65, 0,
4634 elfcpp::DW_CFA_advance_loc
+ 4,
4635 elfcpp::DW_CFA_restore_extended
, 65
4638 static const unsigned char default_fde
[] =
4640 0, 0, 0, 0, // Replaced with offset to stubs.
4641 0, 0, 0, 0, // Replaced with size of stubs.
4642 0, // Augmentation size.
4643 elfcpp::DW_CFA_nop
, // Pad.
4648 template<bool big_endian
>
4650 write_insn(unsigned char* p
, uint32_t v
)
4652 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4656 static inline unsigned int
4659 if (!parameters
->options().user_set_plt_align())
4660 return size
== 64 ? 32 : 8;
4661 return 1 << parameters
->options().plt_align();
4664 // Stub_table holds information about plt and long branch stubs.
4665 // Stubs are built in an area following some input section determined
4666 // by group_sections(). This input section is converted to a relaxed
4667 // input section allowing it to be resized to accommodate the stubs
4669 template<int size
, bool big_endian
>
4670 class Stub_table
: public Output_relaxed_input_section
4675 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4676 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4677 r2save_(0), localentry0_(0), tocoff_(0)
4682 unsigned int iter_
: 1;
4683 unsigned int notoc_
: 1;
4684 unsigned int toc_
: 1;
4685 unsigned int r2save_
: 1;
4686 unsigned int localentry0_
: 1;
4687 unsigned int tocoff_
: 8;
4689 struct Branch_stub_ent
4691 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4692 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4693 other_(0), tocoff_(0)
4697 unsigned int iter_
: 1;
4698 unsigned int notoc_
: 1;
4699 unsigned int toc_
: 1;
4700 unsigned int save_res_
: 1;
4701 unsigned int other_
: 3;
4702 unsigned int tocoff_
: 8;
4704 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4705 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4707 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4708 Output_section
* output_section
,
4709 const Output_section::Input_section
* owner
,
4711 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4713 ->section_addralign(owner
->shndx())),
4714 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4715 orig_data_size_(owner
->current_data_size()),
4716 plt_size_(0), last_plt_size_(0),
4717 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4718 need_save_res_(false), need_resize_(false), resizing_(false),
4721 this->set_output_section(output_section
);
4723 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4724 new_relaxed
.push_back(this);
4725 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4728 // Add a plt call stub.
4730 add_plt_call_entry(Address
,
4731 const Sized_relobj_file
<size
, big_endian
>*,
4738 add_plt_call_entry(Address
,
4739 const Sized_relobj_file
<size
, big_endian
>*,
4745 // Find a given plt call stub.
4747 find_plt_call_entry(const Symbol
*) const;
4750 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4751 unsigned int) const;
4754 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4760 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4765 // Add a long branch stub.
4767 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4768 unsigned int, Address
, Address
, unsigned int, bool);
4770 const Branch_stub_ent
*
4771 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4775 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4777 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4778 if (max_branch_offset
== 0)
4780 gold_assert(from
!= invalid_address
);
4781 Address loc
= off
+ this->stub_address();
4782 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4786 clear_stubs(bool all
)
4788 this->plt_call_stubs_
.clear();
4789 this->plt_size_
= 0;
4790 this->long_branch_stubs_
.clear();
4791 this->branch_size_
= 0;
4792 this->need_save_res_
= false;
4795 this->last_plt_size_
= 0;
4796 this->last_branch_size_
= 0;
4802 { return need_resize_
; }
4805 set_resizing(bool val
)
4807 this->resizing_
= val
;
4810 this->need_resize_
= false;
4811 this->plt_size_
= 0;
4812 this->branch_size_
= 0;
4813 this->need_save_res_
= false;
4818 set_address_and_size(const Output_section
* os
, Address off
)
4820 Address start_off
= off
;
4821 off
+= this->orig_data_size_
;
4822 Address my_size
= this->plt_size_
+ this->branch_size_
;
4823 if (this->need_save_res_
)
4824 my_size
+= this->targ_
->savres_section()->data_size();
4826 off
= align_address(off
, this->stub_align());
4827 // Include original section size and alignment padding in size
4828 my_size
+= off
- start_off
;
4829 // Ensure new size is always larger than min size
4830 // threshold. Alignment requirement is included in "my_size", so
4831 // increase "my_size" does not invalidate alignment.
4832 if (my_size
< this->min_size_threshold_
)
4833 my_size
= this->min_size_threshold_
;
4834 this->reset_address_and_file_offset();
4835 this->set_current_data_size(my_size
);
4836 this->set_address_and_file_offset(os
->address() + start_off
,
4837 os
->offset() + start_off
);
4842 stub_address() const
4844 return align_address(this->address() + this->orig_data_size_
,
4845 this->stub_align());
4851 return align_address(this->offset() + this->orig_data_size_
,
4852 this->stub_align());
4857 { return this->plt_size_
; }
4861 { return this->branch_size_
; }
4864 set_min_size_threshold(Address min_size
)
4865 { this->min_size_threshold_
= min_size
; }
4868 define_stub_syms(Symbol_table
*);
4873 Output_section
* os
= this->output_section();
4874 if (os
->addralign() < this->stub_align())
4876 os
->set_addralign(this->stub_align());
4877 // FIXME: get rid of the insane checkpointing.
4878 // We can't increase alignment of the input section to which
4879 // stubs are attached; The input section may be .init which
4880 // is pasted together with other .init sections to form a
4881 // function. Aligning might insert zero padding resulting in
4882 // sigill. However we do need to increase alignment of the
4883 // output section so that the align_address() on offset in
4884 // set_address_and_size() adds the same padding as the
4885 // align_address() on address in stub_address().
4886 // What's more, we need this alignment for the layout done in
4887 // relaxation_loop_body() so that the output section starts at
4888 // a suitably aligned address.
4889 os
->checkpoint_set_addralign(this->stub_align());
4891 if (this->last_plt_size_
!= this->plt_size_
4892 || this->last_branch_size_
!= this->branch_size_
)
4894 this->last_plt_size_
= this->plt_size_
;
4895 this->last_branch_size_
= this->branch_size_
;
4901 // Add .eh_frame info for this stub section.
4903 add_eh_frame(Layout
* layout
);
4905 // Remove .eh_frame info for this stub section.
4907 remove_eh_frame(Layout
* layout
);
4909 Target_powerpc
<size
, big_endian
>*
4915 class Plt_stub_key_hash
;
4916 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4917 Plt_stub_key_hash
> Plt_stub_entries
;
4918 class Branch_stub_key
;
4919 class Branch_stub_key_hash
;
4920 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4921 Branch_stub_key_hash
> Branch_stub_entries
;
4923 // Alignment of stub section.
4927 unsigned int min_align
= size
== 64 ? 32 : 16;
4928 unsigned int user_align
= 1 << parameters
->options().plt_align();
4929 return std::max(user_align
, min_align
);
4932 // Return the plt offset for the given call stub.
4934 plt_off(typename
Plt_stub_entries::const_iterator p
,
4935 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4937 const Symbol
* gsym
= p
->first
.sym_
;
4939 return this->targ_
->plt_off(gsym
, sec
);
4942 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4943 unsigned int local_sym_index
= p
->first
.locsym_
;
4944 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4948 // Size of a given plt call stub.
4950 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4953 plt_call_align(unsigned int bytes
) const
4955 unsigned int align
= param_plt_align
<size
>();
4956 return (bytes
+ align
- 1) & -align
;
4959 // Return long branch stub size.
4961 branch_stub_size(typename
Branch_stub_entries::iterator p
,
4965 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
4968 build_tls_opt_tail(unsigned char* p
);
4971 plt_error(const Plt_stub_key
& p
);
4975 do_write(Output_file
*);
4977 // Plt call stub keys.
4981 Plt_stub_key(const Symbol
* sym
)
4982 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4985 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4986 unsigned int locsym_index
)
4987 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4990 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4992 unsigned int r_type
,
4994 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4997 this->addend_
= addend
;
4998 else if (parameters
->options().output_is_position_independent()
4999 && (r_type
== elfcpp::R_PPC_PLTREL24
5000 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5002 this->addend_
= addend
;
5003 if (this->addend_
>= 32768)
5004 this->object_
= object
;
5008 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5009 unsigned int locsym_index
,
5010 unsigned int r_type
,
5012 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5015 this->addend_
= addend
;
5016 else if (parameters
->options().output_is_position_independent()
5017 && (r_type
== elfcpp::R_PPC_PLTREL24
5018 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5019 this->addend_
= addend
;
5022 bool operator==(const Plt_stub_key
& that
) const
5024 return (this->sym_
== that
.sym_
5025 && this->object_
== that
.object_
5026 && this->addend_
== that
.addend_
5027 && this->locsym_
== that
.locsym_
);
5031 const Sized_relobj_file
<size
, big_endian
>* object_
;
5032 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5033 unsigned int locsym_
;
5036 class Plt_stub_key_hash
5039 size_t operator()(const Plt_stub_key
& ent
) const
5041 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5042 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5048 // Long branch stub keys.
5049 class Branch_stub_key
5052 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
5053 : dest_(to
), toc_base_off_(0)
5056 toc_base_off_
= obj
->toc_base_offset();
5059 bool operator==(const Branch_stub_key
& that
) const
5061 return (this->dest_
== that
.dest_
5063 || this->toc_base_off_
== that
.toc_base_off_
));
5067 unsigned int toc_base_off_
;
5070 class Branch_stub_key_hash
5073 size_t operator()(const Branch_stub_key
& key
) const
5074 { return key
.dest_
^ key
.toc_base_off_
; }
5077 // In a sane world this would be a global.
5078 Target_powerpc
<size
, big_endian
>* targ_
;
5079 // Map sym/object/addend to stub offset.
5080 Plt_stub_entries plt_call_stubs_
;
5081 // Map destination address to stub offset.
5082 Branch_stub_entries long_branch_stubs_
;
5083 // size of input section
5084 section_size_type orig_data_size_
;
5086 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5087 // Some rare cases cause (PR/20529) fluctuation in stub table
5088 // size, which leads to an endless relax loop. This is to be fixed
5089 // by, after the first few iterations, allowing only increase of
5090 // stub table size. This variable sets the minimal possible size of
5091 // a stub table, it is zero for the first few iterations, then
5092 // increases monotonically.
5093 Address min_size_threshold_
;
5094 // Set if this stub group needs a copy of out-of-line register
5095 // save/restore functions.
5096 bool need_save_res_
;
5097 // Set when notoc_/r2save_ changes after sizing a stub
5099 // Set when resizing stubs
5101 // Per stub table unique identifier.
5105 // Add a plt call stub, if we do not already have one for this
5106 // sym/object/addend combo.
5108 template<int size
, bool big_endian
>
5110 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5112 const Sized_relobj_file
<size
, big_endian
>* object
,
5114 unsigned int r_type
,
5118 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5119 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5120 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5121 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5125 && this->targ_
->is_elfv2_localentry0(gsym
))
5127 p
.first
->second
.localentry0_
= 1;
5128 this->targ_
->set_has_localentry0();
5130 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5132 if (!p
.second
&& !p
.first
->second
.notoc_
5133 && (!this->targ_
->power10_stubs()
5134 || this->targ_
->power10_stubs_auto()))
5135 this->need_resize_
= true;
5136 p
.first
->second
.notoc_
= 1;
5140 if (!p
.second
&& !p
.first
->second
.toc_
)
5141 this->need_resize_
= true;
5142 p
.first
->second
.toc_
= 1;
5143 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5145 if (!p
.second
&& !p
.first
->second
.r2save_
)
5146 this->need_resize_
= true;
5147 p
.first
->second
.r2save_
= 1;
5151 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5153 if (this->resizing_
)
5155 p
.first
->second
.iter_
= 1;
5156 p
.first
->second
.off_
= this->plt_size_
;
5158 this->plt_size_
+= this->plt_call_size(p
.first
);
5159 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5160 this->targ_
->set_has_tls_get_addr_opt();
5161 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5163 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5166 template<int size
, bool big_endian
>
5168 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5170 const Sized_relobj_file
<size
, big_endian
>* object
,
5171 unsigned int locsym_index
,
5172 unsigned int r_type
,
5176 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5177 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5178 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5179 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5183 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5185 p
.first
->second
.localentry0_
= 1;
5186 this->targ_
->set_has_localentry0();
5188 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5190 if (!p
.second
&& !p
.first
->second
.notoc_
5191 && (!this->targ_
->power10_stubs()
5192 || this->targ_
->power10_stubs_auto()))
5193 this->need_resize_
= true;
5194 p
.first
->second
.notoc_
= 1;
5198 if (!p
.second
&& !p
.first
->second
.toc_
)
5199 this->need_resize_
= true;
5200 p
.first
->second
.toc_
= 1;
5201 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5203 if (!p
.second
&& !p
.first
->second
.r2save_
)
5204 this->need_resize_
= true;
5205 p
.first
->second
.r2save_
= 1;
5209 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5211 if (this->resizing_
)
5213 p
.first
->second
.iter_
= 1;
5214 p
.first
->second
.off_
= this->plt_size_
;
5216 this->plt_size_
+= this->plt_call_size(p
.first
);
5217 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5219 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5222 // Find a plt call stub.
5224 template<int size
, bool big_endian
>
5225 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5226 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5227 const Sized_relobj_file
<size
, big_endian
>* object
,
5229 unsigned int r_type
,
5230 Address addend
) const
5232 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5233 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5234 if (p
== this->plt_call_stubs_
.end())
5239 template<int size
, bool big_endian
>
5240 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5241 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5243 Plt_stub_key
key(gsym
);
5244 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5245 if (p
== this->plt_call_stubs_
.end())
5250 template<int size
, bool big_endian
>
5251 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5252 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5253 const Sized_relobj_file
<size
, big_endian
>* object
,
5254 unsigned int locsym_index
,
5255 unsigned int r_type
,
5256 Address addend
) const
5258 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5259 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5260 if (p
== this->plt_call_stubs_
.end())
5265 template<int size
, bool big_endian
>
5266 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5267 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5268 const Sized_relobj_file
<size
, big_endian
>* object
,
5269 unsigned int locsym_index
) const
5271 Plt_stub_key
key(object
, locsym_index
);
5272 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5273 if (p
== this->plt_call_stubs_
.end())
5278 // Add a long branch stub if we don't already have one to given
5281 template<int size
, bool big_endian
>
5283 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5284 const Powerpc_relobj
<size
, big_endian
>* object
,
5285 unsigned int r_type
,
5291 Branch_stub_key
key(object
, to
);
5292 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5293 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5294 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5295 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5298 if (!p
.second
&& !p
.first
->second
.notoc_
)
5299 this->need_resize_
= true;
5300 p
.first
->second
.notoc_
= true;
5304 if (!p
.second
&& !p
.first
->second
.toc_
)
5305 this->need_resize_
= true;
5306 p
.first
->second
.toc_
= true;
5308 if (size
== 64 && p
.first
->second
.other_
== 0)
5309 p
.first
->second
.other_
= other
;
5310 gold_assert(save_res
== p
.first
->second
.save_res_
);
5311 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5313 if (this->resizing_
)
5315 p
.first
->second
.iter_
= 1;
5316 p
.first
->second
.off_
= this->branch_size_
;
5319 this->need_save_res_
= true;
5322 bool need_lt
= false;
5323 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5324 this->branch_size_
+= stub_size
;
5325 if (size
== 64 && need_lt
)
5326 this->targ_
->add_branch_lookup_table(to
);
5329 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5332 // Find long branch stub offset.
5334 template<int size
, bool big_endian
>
5335 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5336 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5337 const Powerpc_relobj
<size
, big_endian
>* object
,
5340 Branch_stub_key
key(object
, to
);
5341 typename
Branch_stub_entries::const_iterator p
5342 = this->long_branch_stubs_
.find(key
);
5343 if (p
== this->long_branch_stubs_
.end())
5348 template<bool big_endian
>
5350 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5354 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5355 else if (delta
< 256)
5357 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5358 fde
.push_back(delta
);
5360 else if (delta
< 65536)
5362 fde
.resize(fde
.size() + 3);
5363 unsigned char *p
= &*fde
.end() - 3;
5364 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5365 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5369 fde
.resize(fde
.size() + 5);
5370 unsigned char *p
= &*fde
.end() - 5;
5371 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5372 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5376 template<typename T
>
5378 stub_sort(T s1
, T s2
)
5380 return s1
->second
.off_
< s2
->second
.off_
;
5383 // Add .eh_frame info for this stub section. Unlike other linker
5384 // generated .eh_frame this is added late in the link, because we
5385 // only want the .eh_frame info if this particular stub section is
5388 template<int size
, bool big_endian
>
5390 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5393 || !parameters
->options().ld_generated_unwind_info())
5396 // Since we add stub .eh_frame info late, it must be placed
5397 // after all other linker generated .eh_frame info so that
5398 // merge mapping need not be updated for input sections.
5399 // There is no provision to use a different CIE to that used
5401 if (!this->targ_
->has_glink())
5404 typedef typename
Plt_stub_entries::iterator plt_iter
;
5405 std::vector
<plt_iter
> calls
;
5406 if (!this->plt_call_stubs_
.empty())
5407 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5408 cs
!= this->plt_call_stubs_
.end();
5410 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5411 && cs
->second
.r2save_
5412 && !cs
->second
.localentry0_
)
5413 || (cs
->second
.notoc_
5414 && !this->targ_
->power10_stubs()))
5415 calls
.push_back(cs
);
5416 if (calls
.size() > 1)
5417 std::stable_sort(calls
.begin(), calls
.end(),
5418 stub_sort
<plt_iter
>);
5420 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5421 std::vector
<branch_iter
> branches
;
5422 if (!this->long_branch_stubs_
.empty()
5423 && !this->targ_
->power10_stubs())
5424 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5425 bs
!= this->long_branch_stubs_
.end();
5427 if (bs
->second
.notoc_
)
5428 branches
.push_back(bs
);
5429 if (branches
.size() > 1)
5430 std::stable_sort(branches
.begin(), branches
.end(),
5431 stub_sort
<branch_iter
>);
5433 if (calls
.empty() && branches
.empty())
5436 unsigned int last_eh_loc
= 0;
5437 // offset pcrel sdata4, size udata4, and augmentation size byte.
5438 std::vector
<unsigned char> fde(9, 0);
5440 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5442 plt_iter cs
= calls
[i
];
5443 unsigned int off
= cs
->second
.off_
;
5444 // The __tls_get_addr_opt call stub needs to describe where
5445 // it saves LR, to support exceptions that might be thrown
5446 // from __tls_get_addr, and to support asynchronous exceptions.
5447 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5450 if (cs
->second
.r2save_
5451 && !cs
->second
.localentry0_
)
5454 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5455 fde
.resize(fde
.size() + 6);
5456 unsigned char* p
= &*fde
.end() - 6;
5457 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5459 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5460 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5461 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5462 *p
++ = elfcpp::DW_CFA_restore_extended
;
5464 last_eh_loc
= off
+ delta
;
5468 // notoc stubs also should describe LR changes, to support
5469 // asynchronous exceptions.
5470 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5471 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5472 fde
.resize(fde
.size() + 6);
5473 unsigned char* p
= &*fde
.end() - 6;
5474 *p
++ = elfcpp::DW_CFA_register
;
5477 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5478 *p
++ = elfcpp::DW_CFA_restore_extended
;
5480 last_eh_loc
= off
+ 8;
5483 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5485 branch_iter bs
= branches
[i
];
5486 unsigned int off
= bs
->second
.off_
+ 8;
5487 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5488 fde
.resize(fde
.size() + 6);
5489 unsigned char* p
= &*fde
.end() - 6;
5490 *p
++ = elfcpp::DW_CFA_register
;
5493 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5494 *p
++ = elfcpp::DW_CFA_restore_extended
;
5496 last_eh_loc
= off
+ 8;
5499 layout
->add_eh_frame_for_plt(this,
5500 Eh_cie
<size
>::eh_frame_cie
,
5501 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5502 &*fde
.begin(), fde
.size());
5505 template<int size
, bool big_endian
>
5507 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5510 && parameters
->options().ld_generated_unwind_info()
5511 && this->targ_
->has_glink())
5512 layout
->remove_eh_frame_for_plt(this,
5513 Eh_cie
<size
>::eh_frame_cie
,
5514 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5517 // A class to handle .glink.
5519 template<int size
, bool big_endian
>
5520 class Output_data_glink
: public Output_section_data
5523 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5524 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5526 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5527 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5528 end_branch_table_(), ge_size_(0)
5532 add_eh_frame(Layout
* layout
);
5535 add_global_entry(const Symbol
*);
5538 find_global_entry(const Symbol
*) const;
5541 global_entry_align(unsigned int off
) const
5543 unsigned int align
= param_plt_align
<size
>();
5544 return (off
+ align
- 1) & -align
;
5548 global_entry_off() const
5550 return this->global_entry_align(this->end_branch_table_
);
5554 global_entry_address() const
5556 gold_assert(this->is_data_size_valid());
5557 return this->address() + this->global_entry_off();
5561 pltresolve_size() const
5565 + (this->targ_
->abiversion() < 2 ? 11 * 4
5566 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5571 // Write to a map file.
5573 do_print_to_mapfile(Mapfile
* mapfile
) const
5574 { mapfile
->print_output_data(this, _("** glink")); }
5578 set_final_data_size();
5582 do_write(Output_file
*);
5584 // Allows access to .got and .plt for do_write.
5585 Target_powerpc
<size
, big_endian
>* targ_
;
5587 // Map sym to stub offset.
5588 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5589 Global_entry_stub_entries global_entry_stubs_
;
5591 unsigned int end_branch_table_
, ge_size_
;
5594 template<int size
, bool big_endian
>
5596 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5598 if (!parameters
->options().ld_generated_unwind_info())
5603 if (this->targ_
->abiversion() < 2)
5604 layout
->add_eh_frame_for_plt(this,
5605 Eh_cie
<64>::eh_frame_cie
,
5606 sizeof (Eh_cie
<64>::eh_frame_cie
),
5607 glink_eh_frame_fde_64v1
,
5608 sizeof (glink_eh_frame_fde_64v1
));
5609 else if (this->targ_
->has_localentry0())
5610 layout
->add_eh_frame_for_plt(this,
5611 Eh_cie
<64>::eh_frame_cie
,
5612 sizeof (Eh_cie
<64>::eh_frame_cie
),
5613 glink_eh_frame_fde_64v2_localentry0
,
5614 sizeof (glink_eh_frame_fde_64v2
));
5616 layout
->add_eh_frame_for_plt(this,
5617 Eh_cie
<64>::eh_frame_cie
,
5618 sizeof (Eh_cie
<64>::eh_frame_cie
),
5619 glink_eh_frame_fde_64v2
,
5620 sizeof (glink_eh_frame_fde_64v2
));
5624 // 32-bit .glink can use the default since the CIE return
5625 // address reg, LR, is valid.
5626 layout
->add_eh_frame_for_plt(this,
5627 Eh_cie
<32>::eh_frame_cie
,
5628 sizeof (Eh_cie
<32>::eh_frame_cie
),
5630 sizeof (default_fde
));
5631 // Except where LR is used in a PIC __glink_PLTresolve.
5632 if (parameters
->options().output_is_position_independent())
5633 layout
->add_eh_frame_for_plt(this,
5634 Eh_cie
<32>::eh_frame_cie
,
5635 sizeof (Eh_cie
<32>::eh_frame_cie
),
5636 glink_eh_frame_fde_32
,
5637 sizeof (glink_eh_frame_fde_32
));
5641 template<int size
, bool big_endian
>
5643 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5645 unsigned int off
= this->global_entry_align(this->ge_size_
);
5646 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5647 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5649 this->ge_size_
= off
+ 16;
5652 template<int size
, bool big_endian
>
5653 typename Output_data_glink
<size
, big_endian
>::Address
5654 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5656 typename
Global_entry_stub_entries::const_iterator p
5657 = this->global_entry_stubs_
.find(gsym
);
5658 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5661 template<int size
, bool big_endian
>
5663 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5665 unsigned int count
= this->targ_
->plt_entry_count();
5666 section_size_type total
= 0;
5672 // space for branch table
5673 total
+= 4 * (count
- 1);
5675 total
+= -total
& 15;
5676 total
+= this->pltresolve_size();
5680 total
+= this->pltresolve_size();
5682 // space for branch table
5684 if (this->targ_
->abiversion() < 2)
5688 total
+= 4 * (count
- 0x8000);
5692 this->end_branch_table_
= total
;
5693 total
= this->global_entry_align(total
);
5694 total
+= this->ge_size_
;
5696 this->set_data_size(total
);
5699 // Define symbols on stubs, identifying the stub.
5701 template<int size
, bool big_endian
>
5703 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5705 if (!this->plt_call_stubs_
.empty())
5707 // The key for the plt call stub hash table includes addresses,
5708 // therefore traversal order depends on those addresses, which
5709 // can change between runs if gold is a PIE. Unfortunately the
5710 // output .symtab ordering depends on the order in which symbols
5711 // are added to the linker symtab. We want reproducible output
5712 // so must sort the call stub symbols.
5713 typedef typename
Plt_stub_entries::iterator plt_iter
;
5714 std::vector
<plt_iter
> sorted
;
5715 sorted
.resize(this->plt_call_stubs_
.size());
5717 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5718 cs
!= this->plt_call_stubs_
.end();
5720 sorted
[cs
->second
.indx_
] = cs
;
5722 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5724 plt_iter cs
= sorted
[i
];
5727 if (cs
->first
.addend_
!= 0)
5728 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5731 if (cs
->first
.object_
)
5733 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5734 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5735 sprintf(obj
, "%x:", ppcobj
->uniq());
5738 const char *symname
;
5739 if (cs
->first
.sym_
== NULL
)
5741 sprintf(localname
, "%x", cs
->first
.locsym_
);
5742 symname
= localname
;
5744 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5745 symname
= this->targ_
->tls_get_addr_opt()->name();
5747 symname
= cs
->first
.sym_
->name();
5748 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5749 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5751 = this->stub_address() - this->address() + cs
->second
.off_
;
5752 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5753 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5757 typedef typename
Branch_stub_entries::iterator branch_iter
;
5758 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5759 bs
!= this->long_branch_stubs_
.end();
5762 if (bs
->second
.save_res_
)
5765 char* name
= new char[8 + 13 + 16 + 1];
5766 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5767 static_cast<unsigned long long>(bs
->first
.dest_
));
5768 Address value
= (this->stub_address() - this->address()
5769 + this->plt_size_
+ bs
->second
.off_
);
5770 bool need_lt
= false;
5771 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5772 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5776 // Emit the start of a __tls_get_addr_opt plt call stub.
5778 template<int size
, bool big_endian
>
5780 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5783 unsigned char* p
= *pp
;
5786 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5788 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5790 write_insn
<big_endian
>(p
, mr_0_3
);
5792 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5794 write_insn
<big_endian
>(p
, add_3_12_13
);
5796 write_insn
<big_endian
>(p
, beqlr
);
5798 write_insn
<big_endian
>(p
, mr_3_0
);
5802 write_insn
<big_endian
>(p
, mflr_11
);
5804 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5810 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5812 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5814 write_insn
<big_endian
>(p
, mr_0_3
);
5816 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5818 write_insn
<big_endian
>(p
, add_3_12_2
);
5820 write_insn
<big_endian
>(p
, beqlr
);
5822 write_insn
<big_endian
>(p
, mr_3_0
);
5824 write_insn
<big_endian
>(p
, nop
);
5830 // Emit the tail of a __tls_get_addr_opt plt call stub.
5832 template<int size
, bool big_endian
>
5834 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5836 write_insn
<big_endian
>(p
, bctrl
);
5838 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5840 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5842 write_insn
<big_endian
>(p
, mtlr_11
);
5844 write_insn
<big_endian
>(p
, blr
);
5847 // Emit pc-relative plt call stub code.
5849 template<bool big_endian
>
5850 static unsigned char*
5851 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5854 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5859 write_insn
<big_endian
>(p
, nop
);
5867 write_insn
<big_endian
>(p
, insn
>> 32);
5869 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5871 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5874 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5878 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5881 insn
= paddi_12_pc
| d34(off
);
5882 write_insn
<big_endian
>(p
, insn
>> 32);
5884 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5888 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5892 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5894 write_insn
<big_endian
>(p
, add_12_11_12
);
5899 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5901 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5905 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5908 insn
= paddi_12_pc
| d34(off
);
5909 write_insn
<big_endian
>(p
, insn
>> 32);
5911 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5915 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5919 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5921 write_insn
<big_endian
>(p
, add_12_11_12
);
5927 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5928 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5933 // lis %r12,xxx-1b@highest
5934 // ori %r12,%r12,xxx-1b@higher
5935 // sldi %r12,%r12,32
5936 // oris %r12,%r12,xxx-1b@high
5937 // ori %r12,%r12,xxx-1b@l
5938 // add/ldx %r12,%r11,%r12
5940 template<bool big_endian
>
5941 static unsigned char*
5942 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5944 write_insn
<big_endian
>(p
, mflr_12
);
5946 write_insn
<big_endian
>(p
, bcl_20_31
);
5948 write_insn
<big_endian
>(p
, mflr_11
);
5950 write_insn
<big_endian
>(p
, mtlr_12
);
5952 if (off
+ 0x8000 < 0x10000)
5955 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5957 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5959 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5961 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5964 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5966 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5970 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5972 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5977 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5979 if (((off
>> 32) & 0xffff) != 0)
5981 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5985 if (((off
>> 32) & 0xffffffffULL
) != 0)
5987 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5992 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5997 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6001 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6003 write_insn
<big_endian
>(p
, add_12_11_12
);
6009 // Size of a given plt call stub.
6011 template<int size
, bool big_endian
>
6013 Stub_table
<size
, big_endian
>::plt_call_size(
6014 typename
Plt_stub_entries::iterator p
) const
6018 const Symbol
* gsym
= p
->first
.sym_
;
6020 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
6023 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6024 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6025 plt_addr
+= plt
->address();
6026 if (this->targ_
->power10_stubs()
6027 && this->targ_
->power10_stubs_auto())
6029 unsigned int bytes
= 0;
6030 if (p
->second
.notoc_
)
6032 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6034 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6035 uint64_t odd
= from
& 4;
6036 uint64_t off
= plt_addr
- from
;
6037 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6038 bytes
+= odd
+ 4 * 4;
6039 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6043 bytes
= this->plt_call_align(bytes
);
6045 unsigned int tail
= 0;
6048 p
->second
.tocoff_
= bytes
;
6049 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6052 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6058 if (p
->second
.r2save_
)
6061 = this->targ_
->got_section()->output_section()->address();
6062 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6063 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6064 got_addr
+= ppcobj
->toc_base_offset();
6065 uint64_t off
= plt_addr
- got_addr
;
6066 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6068 return bytes
+ tail
;
6072 unsigned int bytes
= 0;
6073 unsigned int tail
= 0;
6074 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6077 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6084 if (p
->second
.r2save_
)
6087 if (this->targ_
->power10_stubs())
6089 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6090 uint64_t odd
= from
& 4;
6091 uint64_t off
= plt_addr
- from
;
6092 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6093 bytes
+= odd
+ 4 * 4;
6094 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6098 return bytes
+ tail
;
6101 if (p
->second
.notoc_
)
6103 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6104 uint64_t off
= plt_addr
- from
;
6105 if (off
+ 0x8000 < 0x10000)
6107 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6112 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6113 && ((off
>> 32) & 0xffff) != 0)
6115 if (((off
>> 32) & 0xffffffffULL
) != 0)
6122 return bytes
+ tail
;
6125 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6126 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6127 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6128 got_addr
+= ppcobj
->toc_base_offset();
6129 uint64_t off
= plt_addr
- got_addr
;
6130 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6131 if (this->targ_
->abiversion() < 2)
6133 bool static_chain
= parameters
->options().plt_static_chain();
6134 bool thread_safe
= this->targ_
->plt_thread_safe();
6138 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6140 return bytes
+ tail
;
6144 // Return long branch stub size.
6146 template<int size
, bool big_endian
>
6148 Stub_table
<size
, big_endian
>::branch_stub_size(
6149 typename
Branch_stub_entries::iterator p
,
6152 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6155 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6157 if (parameters
->options().output_is_position_independent())
6162 uint64_t off
= p
->first
.dest_
- loc
;
6163 unsigned int bytes
= 0;
6164 if (p
->second
.notoc_
)
6166 if (this->targ_
->power10_stubs())
6168 Address odd
= loc
& 4;
6169 if (off
+ (1 << 25) < 2 << 25)
6171 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6173 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6177 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6179 p
->second
.tocoff_
= bytes
;
6184 if (off
+ 0x8000 < 0x10000)
6186 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6188 if (off
+ 24 + (1 << 25) < 2 << 25)
6194 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6195 && ((off
>> 32) & 0xffff) != 0)
6197 if (((off
>> 32) & 0xffffffffULL
) != 0)
6207 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6208 if (off
+ (1 << 25) < 2 << 25)
6210 if (!this->targ_
->power10_stubs()
6211 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6216 template<int size
, bool big_endian
>
6218 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6221 gold_error(_("linkage table error against `%s'"),
6222 p
.sym_
->demangled_name().c_str());
6224 gold_error(_("linkage table error against `%s:[local %u]'"),
6225 p
.object_
->name().c_str(),
6229 // Write out plt and long branch stub code.
6231 template<int size
, bool big_endian
>
6233 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6235 if (this->plt_call_stubs_
.empty()
6236 && this->long_branch_stubs_
.empty())
6239 const section_size_type start_off
= this->offset();
6240 const section_size_type off
= this->stub_offset();
6241 const section_size_type oview_size
=
6242 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6243 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6247 && this->targ_
->power10_stubs())
6249 const Output_data_got_powerpc
<size
, big_endian
>* got
6250 = this->targ_
->got_section();
6251 Address got_os_addr
= got
->output_section()->address();
6253 if (!this->plt_call_stubs_
.empty())
6255 // Write out plt call stubs.
6256 typename
Plt_stub_entries::const_iterator cs
;
6257 for (cs
= this->plt_call_stubs_
.begin();
6258 cs
!= this->plt_call_stubs_
.end();
6261 p
= oview
+ cs
->second
.off_
;
6262 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6263 Address pltoff
= this->plt_off(cs
, &plt
);
6264 Address plt_addr
= pltoff
+ plt
->address();
6265 if (this->targ_
->power10_stubs_auto())
6267 if (cs
->second
.notoc_
)
6269 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6270 this->build_tls_opt_head(&p
, false);
6271 Address from
= this->stub_address() + (p
- oview
);
6272 Address delta
= plt_addr
- from
;
6273 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6275 write_insn
<big_endian
>(p
, mtctr_12
);
6277 write_insn
<big_endian
>(p
, bctr
);
6279 p
= oview
+ this->plt_call_align(p
- oview
);
6281 if (cs
->second
.toc_
)
6283 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6286 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6287 this->build_tls_opt_head(&p
, save_lr
);
6289 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6290 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(
6292 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6293 Address off
= plt_addr
- got_addr
;
6295 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6296 this->plt_error(cs
->first
);
6298 if (cs
->second
.r2save_
)
6300 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6305 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6307 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6312 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6315 write_insn
<big_endian
>(p
, mtctr_12
);
6317 if (cs
->second
.r2save_
6318 && !cs
->second
.localentry0_
6319 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6320 this->build_tls_opt_tail(p
);
6322 write_insn
<big_endian
>(p
, bctr
);
6327 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6330 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6331 this->build_tls_opt_head(&p
, save_lr
);
6333 if (cs
->second
.r2save_
)
6335 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6338 Address from
= this->stub_address() + (p
- oview
);
6339 Address delta
= plt_addr
- from
;
6340 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6341 write_insn
<big_endian
>(p
, mtctr_12
);
6343 if (cs
->second
.r2save_
6344 && !cs
->second
.localentry0_
6345 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6346 this->build_tls_opt_tail(p
);
6348 write_insn
<big_endian
>(p
, bctr
);
6353 // Write out long branch stubs.
6354 typename
Branch_stub_entries::const_iterator bs
;
6355 for (bs
= this->long_branch_stubs_
.begin();
6356 bs
!= this->long_branch_stubs_
.end();
6359 if (bs
->second
.save_res_
)
6361 Address off
= this->plt_size_
+ bs
->second
.off_
;
6363 Address loc
= this->stub_address() + off
;
6364 Address delta
= bs
->first
.dest_
- loc
;
6365 if (this->targ_
->power10_stubs_auto())
6367 if (bs
->second
.notoc_
)
6369 unsigned char* startp
= p
;
6370 p
= build_power10_offset
<big_endian
>(p
, delta
,
6372 delta
-= p
- startp
;
6374 if (delta
+ (1 << 25) < 2 << 25)
6375 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6378 write_insn
<big_endian
>(p
, mtctr_12
);
6380 write_insn
<big_endian
>(p
, bctr
);
6383 delta
-= p
- startp
;
6385 if (bs
->second
.toc_
)
6387 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6388 if (delta
+ (1 << 25) >= 2 << 25)
6391 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6392 gold_assert(brlt_addr
!= invalid_address
);
6393 brlt_addr
+= this->targ_
->brlt_section()->address();
6394 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6395 Address brltoff
= brlt_addr
- got_addr
;
6396 if (ha(brltoff
) == 0)
6398 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6403 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6405 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6409 if (delta
+ (1 << 25) < 2 << 25)
6410 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6413 write_insn
<big_endian
>(p
, mtctr_12
);
6415 write_insn
<big_endian
>(p
, bctr
);
6421 if (!bs
->second
.notoc_
)
6422 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6423 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6425 unsigned char* startp
= p
;
6426 p
= build_power10_offset
<big_endian
>(p
, delta
,
6428 delta
-= p
- startp
;
6430 if (delta
+ (1 << 25) < 2 << 25)
6431 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6434 write_insn
<big_endian
>(p
, mtctr_12
);
6436 write_insn
<big_endian
>(p
, bctr
);
6441 else if (size
== 64)
6443 const Output_data_got_powerpc
<size
, big_endian
>* got
6444 = this->targ_
->got_section();
6445 Address got_os_addr
= got
->output_section()->address();
6447 if (!this->plt_call_stubs_
.empty()
6448 && this->targ_
->abiversion() >= 2)
6450 // Write out plt call stubs for ELFv2.
6451 typename
Plt_stub_entries::const_iterator cs
;
6452 for (cs
= this->plt_call_stubs_
.begin();
6453 cs
!= this->plt_call_stubs_
.end();
6456 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6457 Address pltoff
= this->plt_off(cs
, &plt
);
6458 Address plt_addr
= pltoff
+ plt
->address();
6460 p
= oview
+ cs
->second
.off_
;
6461 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6463 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6464 this->build_tls_opt_head(&p
, save_lr
);
6466 if (cs
->second
.r2save_
)
6468 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6471 if (cs
->second
.notoc_
)
6473 Address from
= this->stub_address() + (p
- oview
) + 8;
6474 Address off
= plt_addr
- from
;
6475 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6479 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6480 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6481 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6482 Address off
= plt_addr
- got_addr
;
6484 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6485 this->plt_error(cs
->first
);
6489 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6491 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6496 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6500 write_insn
<big_endian
>(p
, mtctr_12
);
6502 if (cs
->second
.r2save_
6503 && !cs
->second
.localentry0_
6504 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6505 this->build_tls_opt_tail(p
);
6507 write_insn
<big_endian
>(p
, bctr
);
6510 else if (!this->plt_call_stubs_
.empty())
6512 // Write out plt call stubs for ELFv1.
6513 typename
Plt_stub_entries::const_iterator cs
;
6514 for (cs
= this->plt_call_stubs_
.begin();
6515 cs
!= this->plt_call_stubs_
.end();
6518 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6519 Address pltoff
= this->plt_off(cs
, &plt
);
6520 Address plt_addr
= pltoff
+ plt
->address();
6521 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6522 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6523 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6524 Address off
= plt_addr
- got_addr
;
6526 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6527 || cs
->second
.notoc_
)
6528 this->plt_error(cs
->first
);
6530 bool static_chain
= parameters
->options().plt_static_chain();
6531 bool thread_safe
= this->targ_
->plt_thread_safe();
6532 bool use_fake_dep
= false;
6533 Address cmp_branch_off
= 0;
6536 unsigned int pltindex
6537 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6538 / this->targ_
->plt_entry_size());
6540 = (this->targ_
->glink_section()->pltresolve_size()
6542 if (pltindex
> 32768)
6543 glinkoff
+= (pltindex
- 32768) * 4;
6545 = this->targ_
->glink_section()->address() + glinkoff
;
6547 = (this->stub_address() + cs
->second
.off_
+ 20
6548 + 4 * cs
->second
.r2save_
6549 + 4 * (ha(off
) != 0)
6550 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6551 + 4 * static_chain
);
6552 cmp_branch_off
= to
- from
;
6553 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6556 p
= oview
+ cs
->second
.off_
;
6557 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6559 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6560 this->build_tls_opt_head(&p
, save_lr
);
6561 use_fake_dep
= thread_safe
;
6563 if (cs
->second
.r2save_
)
6565 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6570 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6572 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6574 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6576 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6580 write_insn
<big_endian
>(p
, mtctr_12
);
6584 write_insn
<big_endian
>(p
, xor_2_12_12
);
6586 write_insn
<big_endian
>(p
, add_11_11_2
);
6589 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6593 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6599 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6601 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6603 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6607 write_insn
<big_endian
>(p
, mtctr_12
);
6611 write_insn
<big_endian
>(p
, xor_11_12_12
);
6613 write_insn
<big_endian
>(p
, add_2_2_11
);
6618 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6621 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6624 if (cs
->second
.r2save_
6625 && !cs
->second
.localentry0_
6626 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6627 this->build_tls_opt_tail(p
);
6628 else if (thread_safe
&& !use_fake_dep
)
6630 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6632 write_insn
<big_endian
>(p
, bnectr_p4
);
6634 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6637 write_insn
<big_endian
>(p
, bctr
);
6641 // Write out long branch stubs.
6642 typename
Branch_stub_entries::const_iterator bs
;
6643 for (bs
= this->long_branch_stubs_
.begin();
6644 bs
!= this->long_branch_stubs_
.end();
6647 if (bs
->second
.save_res_
)
6649 Address off
= this->plt_size_
+ bs
->second
.off_
;
6651 Address loc
= this->stub_address() + off
;
6652 Address delta
= bs
->first
.dest_
- loc
;
6653 if (!bs
->second
.notoc_
)
6654 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6655 if (bs
->second
.notoc_
)
6657 unsigned char* startp
= p
;
6658 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6659 delta
-= p
- startp
;
6661 else if (delta
+ (1 << 25) >= 2 << 25)
6664 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6665 gold_assert(brlt_addr
!= invalid_address
);
6666 brlt_addr
+= this->targ_
->brlt_section()->address();
6667 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6668 Address brltoff
= brlt_addr
- got_addr
;
6669 if (ha(brltoff
) == 0)
6671 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6676 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6678 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6682 if (delta
+ (1 << 25) < 2 << 25)
6683 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6686 write_insn
<big_endian
>(p
, mtctr_12
);
6688 write_insn
<big_endian
>(p
, bctr
);
6694 if (!this->plt_call_stubs_
.empty())
6696 // The address of _GLOBAL_OFFSET_TABLE_.
6697 Address g_o_t
= invalid_address
;
6699 // Write out plt call stubs.
6700 typename
Plt_stub_entries::const_iterator cs
;
6701 for (cs
= this->plt_call_stubs_
.begin();
6702 cs
!= this->plt_call_stubs_
.end();
6705 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6706 Address plt_addr
= this->plt_off(cs
, &plt
);
6707 plt_addr
+= plt
->address();
6709 p
= oview
+ cs
->second
.off_
;
6710 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6711 this->build_tls_opt_head(&p
, false);
6712 if (parameters
->options().output_is_position_independent())
6715 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6716 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6717 (cs
->first
.object_
));
6718 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6720 unsigned int got2
= ppcobj
->got2_shndx();
6721 got_addr
= ppcobj
->get_output_section_offset(got2
);
6722 gold_assert(got_addr
!= invalid_address
);
6723 got_addr
+= (ppcobj
->output_section(got2
)->address()
6724 + cs
->first
.addend_
);
6728 if (g_o_t
== invalid_address
)
6730 const Output_data_got_powerpc
<size
, big_endian
>* got
6731 = this->targ_
->got_section();
6732 g_o_t
= got
->address() + got
->g_o_t();
6737 Address off
= plt_addr
- got_addr
;
6739 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6742 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6744 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6749 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6751 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6754 write_insn
<big_endian
>(p
, mtctr_11
);
6756 write_insn
<big_endian
>(p
, bctr
);
6760 // Write out long branch stubs.
6761 typename
Branch_stub_entries::const_iterator bs
;
6762 for (bs
= this->long_branch_stubs_
.begin();
6763 bs
!= this->long_branch_stubs_
.end();
6766 if (bs
->second
.save_res_
)
6768 Address off
= this->plt_size_
+ bs
->second
.off_
;
6770 Address loc
= this->stub_address() + off
;
6771 Address delta
= bs
->first
.dest_
- loc
;
6772 if (delta
+ (1 << 25) < 2 << 25)
6773 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6774 else if (!parameters
->options().output_is_position_independent())
6776 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6778 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6783 write_insn
<big_endian
>(p
, mflr_0
);
6785 write_insn
<big_endian
>(p
, bcl_20_31
);
6787 write_insn
<big_endian
>(p
, mflr_12
);
6789 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6791 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6793 write_insn
<big_endian
>(p
, mtlr_0
);
6796 write_insn
<big_endian
>(p
, mtctr_12
);
6798 write_insn
<big_endian
>(p
, bctr
);
6801 if (this->need_save_res_
)
6803 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6804 memcpy (p
, this->targ_
->savres_section()->contents(),
6805 this->targ_
->savres_section()->data_size());
6809 // Write out .glink.
6811 template<int size
, bool big_endian
>
6813 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6815 const section_size_type off
= this->offset();
6816 const section_size_type oview_size
=
6817 convert_to_section_size_type(this->data_size());
6818 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6821 // The base address of the .plt section.
6822 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6823 Address plt_base
= this->targ_
->plt_section()->address();
6827 if (this->end_branch_table_
!= 0)
6829 // Write pltresolve stub.
6831 Address after_bcl
= this->address() + 16;
6832 Address pltoff
= plt_base
- after_bcl
;
6834 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6836 if (this->targ_
->abiversion() < 2)
6838 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6839 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6840 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6841 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6842 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6843 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6844 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6845 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6846 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6847 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6851 if (this->targ_
->has_localentry0())
6853 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6855 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6856 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6857 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6858 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6859 if (this->targ_
->has_localentry0())
6861 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
6865 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
6867 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6868 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
6869 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
6870 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6871 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6872 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6873 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6875 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6876 gold_assert(p
== oview
+ this->pltresolve_size());
6878 // Write lazy link call stubs.
6880 while (p
< oview
+ this->end_branch_table_
)
6882 if (this->targ_
->abiversion() < 2)
6886 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6890 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6891 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6894 uint32_t branch_off
= 8 - (p
- oview
);
6895 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6900 Address plt_base
= this->targ_
->plt_section()->address();
6901 Address iplt_base
= invalid_address
;
6902 unsigned int global_entry_off
= this->global_entry_off();
6903 Address global_entry_base
= this->address() + global_entry_off
;
6904 typename
Global_entry_stub_entries::const_iterator ge
;
6905 for (ge
= this->global_entry_stubs_
.begin();
6906 ge
!= this->global_entry_stubs_
.end();
6909 p
= oview
+ global_entry_off
+ ge
->second
;
6910 Address plt_addr
= ge
->first
->plt_offset();
6911 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6912 && ge
->first
->can_use_relative_reloc(false))
6914 if (iplt_base
== invalid_address
)
6915 iplt_base
= this->targ_
->iplt_section()->address();
6916 plt_addr
+= iplt_base
;
6919 plt_addr
+= plt_base
;
6920 Address my_addr
= global_entry_base
+ ge
->second
;
6921 Address off
= plt_addr
- my_addr
;
6923 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6924 gold_error(_("linkage table error against `%s'"),
6925 ge
->first
->demangled_name().c_str());
6927 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6928 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6929 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6930 write_insn
<big_endian
>(p
, bctr
);
6935 const Output_data_got_powerpc
<size
, big_endian
>* got
6936 = this->targ_
->got_section();
6937 // The address of _GLOBAL_OFFSET_TABLE_.
6938 Address g_o_t
= got
->address() + got
->g_o_t();
6940 // Write out pltresolve branch table.
6942 unsigned int the_end
= oview_size
- this->pltresolve_size();
6943 unsigned char* end_p
= oview
+ the_end
;
6944 while (p
< end_p
- 8 * 4)
6945 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6947 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6949 // Write out pltresolve call stub.
6950 end_p
= oview
+ oview_size
;
6951 if (parameters
->options().output_is_position_independent())
6953 Address res0_off
= 0;
6954 Address after_bcl_off
= the_end
+ 12;
6955 Address bcl_res0
= after_bcl_off
- res0_off
;
6957 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6959 write_insn
<big_endian
>(p
, mflr_0
);
6961 write_insn
<big_endian
>(p
, bcl_20_31
);
6963 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6965 write_insn
<big_endian
>(p
, mflr_12
);
6967 write_insn
<big_endian
>(p
, mtlr_0
);
6969 write_insn
<big_endian
>(p
, sub_11_11_12
);
6972 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6974 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6976 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6978 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6980 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6984 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6986 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6989 write_insn
<big_endian
>(p
, mtctr_0
);
6991 write_insn
<big_endian
>(p
, add_0_11_11
);
6993 write_insn
<big_endian
>(p
, add_11_0_11
);
6997 Address res0
= this->address();
6999 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7001 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7003 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7004 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7006 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7008 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7010 write_insn
<big_endian
>(p
, mtctr_0
);
7012 write_insn
<big_endian
>(p
, add_0_11_11
);
7014 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7015 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7017 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7019 write_insn
<big_endian
>(p
, add_11_0_11
);
7022 write_insn
<big_endian
>(p
, bctr
);
7026 write_insn
<big_endian
>(p
, nop
);
7031 of
->write_output_view(off
, oview_size
, oview
);
7035 // A class to handle linker generated save/restore functions.
7037 template<int size
, bool big_endian
>
7038 class Output_data_save_res
: public Output_section_data_build
7041 Output_data_save_res(Symbol_table
* symtab
);
7043 const unsigned char*
7050 // Write to a map file.
7052 do_print_to_mapfile(Mapfile
* mapfile
) const
7053 { mapfile
->print_output_data(this, _("** save/restore")); }
7056 do_write(Output_file
*);
7059 // The maximum size of save/restore contents.
7060 static const unsigned int savres_max
= 218*4;
7063 savres_define(Symbol_table
* symtab
,
7065 unsigned int lo
, unsigned int hi
,
7066 unsigned char* write_ent(unsigned char*, int),
7067 unsigned char* write_tail(unsigned char*, int));
7069 unsigned char *contents_
;
7072 template<bool big_endian
>
7073 static unsigned char*
7074 savegpr0(unsigned char* p
, int r
)
7076 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7077 write_insn
<big_endian
>(p
, insn
);
7081 template<bool big_endian
>
7082 static unsigned char*
7083 savegpr0_tail(unsigned char* p
, int r
)
7085 p
= savegpr0
<big_endian
>(p
, r
);
7086 uint32_t insn
= std_0_1
+ 16;
7087 write_insn
<big_endian
>(p
, insn
);
7089 write_insn
<big_endian
>(p
, blr
);
7093 template<bool big_endian
>
7094 static unsigned char*
7095 restgpr0(unsigned char* p
, int r
)
7097 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7098 write_insn
<big_endian
>(p
, insn
);
7102 template<bool big_endian
>
7103 static unsigned char*
7104 restgpr0_tail(unsigned char* p
, int r
)
7106 uint32_t insn
= ld_0_1
+ 16;
7107 write_insn
<big_endian
>(p
, insn
);
7109 p
= restgpr0
<big_endian
>(p
, r
);
7110 write_insn
<big_endian
>(p
, mtlr_0
);
7114 p
= restgpr0
<big_endian
>(p
, 30);
7115 p
= restgpr0
<big_endian
>(p
, 31);
7117 write_insn
<big_endian
>(p
, blr
);
7121 template<bool big_endian
>
7122 static unsigned char*
7123 savegpr1(unsigned char* p
, int r
)
7125 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7126 write_insn
<big_endian
>(p
, insn
);
7130 template<bool big_endian
>
7131 static unsigned char*
7132 savegpr1_tail(unsigned char* p
, int r
)
7134 p
= savegpr1
<big_endian
>(p
, r
);
7135 write_insn
<big_endian
>(p
, blr
);
7139 template<bool big_endian
>
7140 static unsigned char*
7141 restgpr1(unsigned char* p
, int r
)
7143 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7144 write_insn
<big_endian
>(p
, insn
);
7148 template<bool big_endian
>
7149 static unsigned char*
7150 restgpr1_tail(unsigned char* p
, int r
)
7152 p
= restgpr1
<big_endian
>(p
, r
);
7153 write_insn
<big_endian
>(p
, blr
);
7157 template<bool big_endian
>
7158 static unsigned char*
7159 savefpr(unsigned char* p
, int r
)
7161 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7162 write_insn
<big_endian
>(p
, insn
);
7166 template<bool big_endian
>
7167 static unsigned char*
7168 savefpr0_tail(unsigned char* p
, int r
)
7170 p
= savefpr
<big_endian
>(p
, r
);
7171 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7173 write_insn
<big_endian
>(p
, blr
);
7177 template<bool big_endian
>
7178 static unsigned char*
7179 restfpr(unsigned char* p
, int r
)
7181 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7182 write_insn
<big_endian
>(p
, insn
);
7186 template<bool big_endian
>
7187 static unsigned char*
7188 restfpr0_tail(unsigned char* p
, int r
)
7190 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7192 p
= restfpr
<big_endian
>(p
, r
);
7193 write_insn
<big_endian
>(p
, mtlr_0
);
7197 p
= restfpr
<big_endian
>(p
, 30);
7198 p
= restfpr
<big_endian
>(p
, 31);
7200 write_insn
<big_endian
>(p
, blr
);
7204 template<bool big_endian
>
7205 static unsigned char*
7206 savefpr1_tail(unsigned char* p
, int r
)
7208 p
= savefpr
<big_endian
>(p
, r
);
7209 write_insn
<big_endian
>(p
, blr
);
7213 template<bool big_endian
>
7214 static unsigned char*
7215 restfpr1_tail(unsigned char* p
, int r
)
7217 p
= restfpr
<big_endian
>(p
, r
);
7218 write_insn
<big_endian
>(p
, blr
);
7222 template<bool big_endian
>
7223 static unsigned char*
7224 savevr(unsigned char* p
, int r
)
7226 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7227 write_insn
<big_endian
>(p
, insn
);
7229 insn
= stvx_0_12_0
+ (r
<< 21);
7230 write_insn
<big_endian
>(p
, insn
);
7234 template<bool big_endian
>
7235 static unsigned char*
7236 savevr_tail(unsigned char* p
, int r
)
7238 p
= savevr
<big_endian
>(p
, r
);
7239 write_insn
<big_endian
>(p
, blr
);
7243 template<bool big_endian
>
7244 static unsigned char*
7245 restvr(unsigned char* p
, int r
)
7247 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7248 write_insn
<big_endian
>(p
, insn
);
7250 insn
= lvx_0_12_0
+ (r
<< 21);
7251 write_insn
<big_endian
>(p
, insn
);
7255 template<bool big_endian
>
7256 static unsigned char*
7257 restvr_tail(unsigned char* p
, int r
)
7259 p
= restvr
<big_endian
>(p
, r
);
7260 write_insn
<big_endian
>(p
, blr
);
7265 template<int size
, bool big_endian
>
7266 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7267 Symbol_table
* symtab
)
7268 : Output_section_data_build(4),
7271 this->savres_define(symtab
,
7272 "_savegpr0_", 14, 31,
7273 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7274 this->savres_define(symtab
,
7275 "_restgpr0_", 14, 29,
7276 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7277 this->savres_define(symtab
,
7278 "_restgpr0_", 30, 31,
7279 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7280 this->savres_define(symtab
,
7281 "_savegpr1_", 14, 31,
7282 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7283 this->savres_define(symtab
,
7284 "_restgpr1_", 14, 31,
7285 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7286 this->savres_define(symtab
,
7287 "_savefpr_", 14, 31,
7288 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7289 this->savres_define(symtab
,
7290 "_restfpr_", 14, 29,
7291 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7292 this->savres_define(symtab
,
7293 "_restfpr_", 30, 31,
7294 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7295 this->savres_define(symtab
,
7297 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7298 this->savres_define(symtab
,
7300 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7301 this->savres_define(symtab
,
7303 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7304 this->savres_define(symtab
,
7306 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7309 template<int size
, bool big_endian
>
7311 Output_data_save_res
<size
, big_endian
>::savres_define(
7312 Symbol_table
* symtab
,
7314 unsigned int lo
, unsigned int hi
,
7315 unsigned char* write_ent(unsigned char*, int),
7316 unsigned char* write_tail(unsigned char*, int))
7318 size_t len
= strlen(name
);
7319 bool writing
= false;
7322 memcpy(sym
, name
, len
);
7325 for (unsigned int i
= lo
; i
<= hi
; i
++)
7327 sym
[len
+ 0] = i
/ 10 + '0';
7328 sym
[len
+ 1] = i
% 10 + '0';
7329 Symbol
* gsym
= symtab
->lookup(sym
);
7330 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7331 writing
= writing
|| refd
;
7334 if (this->contents_
== NULL
)
7335 this->contents_
= new unsigned char[this->savres_max
];
7337 section_size_type value
= this->current_data_size();
7338 unsigned char* p
= this->contents_
+ value
;
7340 p
= write_ent(p
, i
);
7342 p
= write_tail(p
, i
);
7343 section_size_type cur_size
= p
- this->contents_
;
7344 this->set_current_data_size(cur_size
);
7346 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7347 this, value
, cur_size
- value
,
7348 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7349 elfcpp::STV_HIDDEN
, 0, false, false);
7354 // Write out save/restore.
7356 template<int size
, bool big_endian
>
7358 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7360 const section_size_type off
= this->offset();
7361 const section_size_type oview_size
=
7362 convert_to_section_size_type(this->data_size());
7363 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7364 memcpy(oview
, this->contents_
, oview_size
);
7365 of
->write_output_view(off
, oview_size
, oview
);
7369 // Create the glink section.
7371 template<int size
, bool big_endian
>
7373 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7375 if (this->glink_
== NULL
)
7377 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7378 this->glink_
->add_eh_frame(layout
);
7379 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7380 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7381 this->glink_
, ORDER_TEXT
, false);
7385 // Create a PLT entry for a global symbol.
7387 template<int size
, bool big_endian
>
7389 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7393 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7394 && gsym
->can_use_relative_reloc(false))
7396 if (this->iplt_
== NULL
)
7397 this->make_iplt_section(symtab
, layout
);
7398 this->iplt_
->add_ifunc_entry(gsym
);
7402 if (this->plt_
== NULL
)
7403 this->make_plt_section(symtab
, layout
);
7404 this->plt_
->add_entry(gsym
);
7408 // Make a PLT entry for a local symbol.
7410 template<int size
, bool big_endian
>
7412 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7414 Sized_relobj_file
<size
, big_endian
>* relobj
,
7417 if (this->lplt_
== NULL
)
7418 this->make_lplt_section(layout
);
7419 this->lplt_
->add_local_entry(relobj
, r_sym
);
7422 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7424 template<int size
, bool big_endian
>
7426 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7427 Symbol_table
* symtab
,
7429 Sized_relobj_file
<size
, big_endian
>* relobj
,
7432 if (this->iplt_
== NULL
)
7433 this->make_iplt_section(symtab
, layout
);
7434 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7437 // Return the number of entries in the PLT.
7439 template<int size
, bool big_endian
>
7441 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7443 if (this->plt_
== NULL
)
7445 return this->plt_
->entry_count();
7448 // Create a GOT entry for local dynamic __tls_get_addr calls.
7450 template<int size
, bool big_endian
>
7452 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7453 Symbol_table
* symtab
,
7455 Sized_relobj_file
<size
, big_endian
>* object
)
7457 if (this->tlsld_got_offset_
== -1U)
7459 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7460 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7461 Output_data_got_powerpc
<size
, big_endian
>* got
7462 = this->got_section(symtab
, layout
);
7463 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7464 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7466 this->tlsld_got_offset_
= got_offset
;
7468 return this->tlsld_got_offset_
;
7471 // Get the Reference_flags for a particular relocation.
7473 template<int size
, bool big_endian
>
7475 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7476 unsigned int r_type
,
7477 const Target_powerpc
* target
)
7483 case elfcpp::R_POWERPC_NONE
:
7484 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7485 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7486 case elfcpp::R_PPC64_TOC
:
7487 // No symbol reference.
7490 case elfcpp::R_PPC64_ADDR64
:
7491 case elfcpp::R_PPC64_UADDR64
:
7492 case elfcpp::R_POWERPC_ADDR32
:
7493 case elfcpp::R_POWERPC_UADDR32
:
7494 case elfcpp::R_POWERPC_ADDR16
:
7495 case elfcpp::R_POWERPC_UADDR16
:
7496 case elfcpp::R_POWERPC_ADDR16_LO
:
7497 case elfcpp::R_POWERPC_ADDR16_HI
:
7498 case elfcpp::R_POWERPC_ADDR16_HA
:
7499 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7500 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7501 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7502 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7503 case elfcpp::R_PPC64_D34
:
7504 case elfcpp::R_PPC64_D34_LO
:
7505 case elfcpp::R_PPC64_D34_HI30
:
7506 case elfcpp::R_PPC64_D34_HA30
:
7507 case elfcpp::R_PPC64_D28
:
7508 ref
= Symbol::ABSOLUTE_REF
;
7511 case elfcpp::R_POWERPC_ADDR24
:
7512 case elfcpp::R_POWERPC_ADDR14
:
7513 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7514 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7515 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7518 case elfcpp::R_PPC64_REL64
:
7519 case elfcpp::R_POWERPC_REL32
:
7520 case elfcpp::R_PPC_LOCAL24PC
:
7521 case elfcpp::R_POWERPC_REL16
:
7522 case elfcpp::R_POWERPC_REL16_LO
:
7523 case elfcpp::R_POWERPC_REL16_HI
:
7524 case elfcpp::R_POWERPC_REL16_HA
:
7525 case elfcpp::R_PPC64_REL16_HIGH
:
7526 case elfcpp::R_PPC64_REL16_HIGHA
:
7527 case elfcpp::R_PPC64_REL16_HIGHER
:
7528 case elfcpp::R_PPC64_REL16_HIGHERA
:
7529 case elfcpp::R_PPC64_REL16_HIGHEST
:
7530 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7531 case elfcpp::R_PPC64_PCREL34
:
7532 case elfcpp::R_PPC64_REL16_HIGHER34
:
7533 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7534 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7535 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7536 case elfcpp::R_PPC64_PCREL28
:
7537 ref
= Symbol::RELATIVE_REF
;
7540 case elfcpp::R_PPC64_REL24_NOTOC
:
7544 case elfcpp::R_POWERPC_REL24
:
7545 case elfcpp::R_PPC_PLTREL24
:
7546 case elfcpp::R_POWERPC_REL14
:
7547 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7548 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7549 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7552 case elfcpp::R_POWERPC_GOT16
:
7553 case elfcpp::R_POWERPC_GOT16_LO
:
7554 case elfcpp::R_POWERPC_GOT16_HI
:
7555 case elfcpp::R_POWERPC_GOT16_HA
:
7556 case elfcpp::R_PPC64_GOT16_DS
:
7557 case elfcpp::R_PPC64_GOT16_LO_DS
:
7558 case elfcpp::R_PPC64_GOT_PCREL34
:
7559 case elfcpp::R_PPC64_TOC16
:
7560 case elfcpp::R_PPC64_TOC16_LO
:
7561 case elfcpp::R_PPC64_TOC16_HI
:
7562 case elfcpp::R_PPC64_TOC16_HA
:
7563 case elfcpp::R_PPC64_TOC16_DS
:
7564 case elfcpp::R_PPC64_TOC16_LO_DS
:
7565 case elfcpp::R_POWERPC_PLT16_LO
:
7566 case elfcpp::R_POWERPC_PLT16_HI
:
7567 case elfcpp::R_POWERPC_PLT16_HA
:
7568 case elfcpp::R_PPC64_PLT16_LO_DS
:
7569 case elfcpp::R_PPC64_PLT_PCREL34
:
7570 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7571 ref
= Symbol::RELATIVE_REF
;
7574 case elfcpp::R_POWERPC_GOT_TPREL16
:
7575 case elfcpp::R_POWERPC_TLS
:
7576 case elfcpp::R_PPC64_TLSGD
:
7577 case elfcpp::R_PPC64_TLSLD
:
7578 case elfcpp::R_PPC64_TPREL34
:
7579 case elfcpp::R_PPC64_DTPREL34
:
7580 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7581 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7582 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7583 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7584 ref
= Symbol::TLS_REF
;
7587 case elfcpp::R_POWERPC_COPY
:
7588 case elfcpp::R_POWERPC_GLOB_DAT
:
7589 case elfcpp::R_POWERPC_JMP_SLOT
:
7590 case elfcpp::R_POWERPC_RELATIVE
:
7591 case elfcpp::R_POWERPC_DTPMOD
:
7593 // Not expected. We will give an error later.
7597 if (size
== 64 && target
->abiversion() < 2)
7598 ref
|= Symbol::FUNC_DESC_ABI
;
7602 // Report an unsupported relocation against a local symbol.
7604 template<int size
, bool big_endian
>
7606 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7607 Sized_relobj_file
<size
, big_endian
>* object
,
7608 unsigned int r_type
)
7610 gold_error(_("%s: unsupported reloc %u against local symbol"),
7611 object
->name().c_str(), r_type
);
7614 // We are about to emit a dynamic relocation of type R_TYPE. If the
7615 // dynamic linker does not support it, issue an error.
7617 template<int size
, bool big_endian
>
7619 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7620 unsigned int r_type
)
7622 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7624 // These are the relocation types supported by glibc for both 32-bit
7625 // and 64-bit powerpc.
7628 case elfcpp::R_POWERPC_NONE
:
7629 case elfcpp::R_POWERPC_RELATIVE
:
7630 case elfcpp::R_POWERPC_GLOB_DAT
:
7631 case elfcpp::R_POWERPC_DTPMOD
:
7632 case elfcpp::R_POWERPC_DTPREL
:
7633 case elfcpp::R_POWERPC_TPREL
:
7634 case elfcpp::R_POWERPC_JMP_SLOT
:
7635 case elfcpp::R_POWERPC_COPY
:
7636 case elfcpp::R_POWERPC_IRELATIVE
:
7637 case elfcpp::R_POWERPC_ADDR32
:
7638 case elfcpp::R_POWERPC_UADDR32
:
7639 case elfcpp::R_POWERPC_ADDR24
:
7640 case elfcpp::R_POWERPC_ADDR16
:
7641 case elfcpp::R_POWERPC_UADDR16
:
7642 case elfcpp::R_POWERPC_ADDR16_LO
:
7643 case elfcpp::R_POWERPC_ADDR16_HI
:
7644 case elfcpp::R_POWERPC_ADDR16_HA
:
7645 case elfcpp::R_POWERPC_ADDR14
:
7646 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7647 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7648 case elfcpp::R_POWERPC_REL32
:
7649 case elfcpp::R_POWERPC_TPREL16
:
7650 case elfcpp::R_POWERPC_TPREL16_LO
:
7651 case elfcpp::R_POWERPC_TPREL16_HI
:
7652 case elfcpp::R_POWERPC_TPREL16_HA
:
7663 // These are the relocation types supported only on 64-bit.
7664 case elfcpp::R_PPC64_ADDR64
:
7665 case elfcpp::R_PPC64_UADDR64
:
7666 case elfcpp::R_PPC64_JMP_IREL
:
7667 case elfcpp::R_PPC64_ADDR16_DS
:
7668 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7669 case elfcpp::R_PPC64_ADDR16_HIGH
:
7670 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7671 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7672 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7673 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7674 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7675 case elfcpp::R_PPC64_REL64
:
7676 case elfcpp::R_POWERPC_ADDR30
:
7677 case elfcpp::R_PPC64_TPREL16_DS
:
7678 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7679 case elfcpp::R_PPC64_TPREL16_HIGH
:
7680 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7681 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7682 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7683 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7684 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7695 // These are the relocation types supported only on 32-bit.
7696 // ??? glibc ld.so doesn't need to support these.
7697 case elfcpp::R_POWERPC_REL24
:
7698 case elfcpp::R_POWERPC_DTPREL16
:
7699 case elfcpp::R_POWERPC_DTPREL16_LO
:
7700 case elfcpp::R_POWERPC_DTPREL16_HI
:
7701 case elfcpp::R_POWERPC_DTPREL16_HA
:
7709 // This prevents us from issuing more than one error per reloc
7710 // section. But we can still wind up issuing more than one
7711 // error per object file.
7712 if (this->issued_non_pic_error_
)
7714 gold_assert(parameters
->options().output_is_position_independent());
7715 object
->error(_("requires unsupported dynamic reloc; "
7716 "recompile with -fPIC"));
7717 this->issued_non_pic_error_
= true;
7721 // Return whether we need to make a PLT entry for a relocation of the
7722 // given type against a STT_GNU_IFUNC symbol.
7724 template<int size
, bool big_endian
>
7726 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7727 Target_powerpc
<size
, big_endian
>* target
,
7728 Sized_relobj_file
<size
, big_endian
>* object
,
7729 unsigned int r_type
,
7732 // In non-pic code any reference will resolve to the plt call stub
7733 // for the ifunc symbol.
7734 if ((size
== 32 || target
->abiversion() >= 2)
7735 && !parameters
->options().output_is_position_independent())
7740 // Word size refs from data sections are OK, but don't need a PLT entry.
7741 case elfcpp::R_POWERPC_ADDR32
:
7742 case elfcpp::R_POWERPC_UADDR32
:
7747 case elfcpp::R_PPC64_ADDR64
:
7748 case elfcpp::R_PPC64_UADDR64
:
7753 // GOT refs are good, but also don't need a PLT entry.
7754 case elfcpp::R_POWERPC_GOT16
:
7755 case elfcpp::R_POWERPC_GOT16_LO
:
7756 case elfcpp::R_POWERPC_GOT16_HI
:
7757 case elfcpp::R_POWERPC_GOT16_HA
:
7758 case elfcpp::R_PPC64_GOT16_DS
:
7759 case elfcpp::R_PPC64_GOT16_LO_DS
:
7760 case elfcpp::R_PPC64_GOT_PCREL34
:
7763 // PLT relocs are OK and need a PLT entry.
7764 case elfcpp::R_POWERPC_PLT16_LO
:
7765 case elfcpp::R_POWERPC_PLT16_HI
:
7766 case elfcpp::R_POWERPC_PLT16_HA
:
7767 case elfcpp::R_PPC64_PLT16_LO_DS
:
7768 case elfcpp::R_POWERPC_PLTSEQ
:
7769 case elfcpp::R_POWERPC_PLTCALL
:
7770 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7771 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7772 case elfcpp::R_PPC64_PLT_PCREL34
:
7773 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7777 // Function calls are good, and these do need a PLT entry.
7778 case elfcpp::R_PPC64_REL24_NOTOC
:
7782 case elfcpp::R_POWERPC_ADDR24
:
7783 case elfcpp::R_POWERPC_ADDR14
:
7784 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7785 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7786 case elfcpp::R_POWERPC_REL24
:
7787 case elfcpp::R_PPC_PLTREL24
:
7788 case elfcpp::R_POWERPC_REL14
:
7789 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7790 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7797 // Anything else is a problem.
7798 // If we are building a static executable, the libc startup function
7799 // responsible for applying indirect function relocations is going
7800 // to complain about the reloc type.
7801 // If we are building a dynamic executable, we will have a text
7802 // relocation. The dynamic loader will set the text segment
7803 // writable and non-executable to apply text relocations. So we'll
7804 // segfault when trying to run the indirection function to resolve
7807 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7808 object
->name().c_str(), r_type
);
7812 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7816 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7818 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7819 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7820 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7821 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7822 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7823 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7824 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7825 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7826 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7827 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7828 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7829 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7830 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7831 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7832 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7833 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7834 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7835 /* Exclude lfqu by testing reloc. If relocs are ever
7836 defined for the reduced D field in psq_lu then those
7837 will need testing too. */
7838 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7839 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7840 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7842 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7843 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7844 /* Exclude stfqu. psq_stu as above for psq_lu. */
7845 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7846 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7847 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7848 && (insn
& 1) == 0));
7851 // Scan a relocation for a local symbol.
7853 template<int size
, bool big_endian
>
7855 Target_powerpc
<size
, big_endian
>::Scan::local(
7856 Symbol_table
* symtab
,
7858 Target_powerpc
<size
, big_endian
>* target
,
7859 Sized_relobj_file
<size
, big_endian
>* object
,
7860 unsigned int data_shndx
,
7861 Output_section
* output_section
,
7862 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7863 unsigned int r_type
,
7864 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7867 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7869 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7870 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7872 this->expect_tls_get_addr_call();
7873 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7874 if (tls_type
!= tls::TLSOPT_NONE
)
7875 this->skip_next_tls_get_addr_call();
7877 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7878 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7880 this->expect_tls_get_addr_call();
7881 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7882 if (tls_type
!= tls::TLSOPT_NONE
)
7883 this->skip_next_tls_get_addr_call();
7886 Powerpc_relobj
<size
, big_endian
>* ppc_object
7887 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7892 && data_shndx
== ppc_object
->opd_shndx()
7893 && r_type
== elfcpp::R_PPC64_ADDR64
)
7894 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7898 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7899 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7900 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7902 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7903 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7904 r_type
, r_sym
, reloc
.get_r_addend());
7905 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7910 case elfcpp::R_POWERPC_NONE
:
7911 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7912 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7913 case elfcpp::R_POWERPC_TLS
:
7914 case elfcpp::R_PPC64_ENTRY
:
7915 case elfcpp::R_POWERPC_PLTSEQ
:
7916 case elfcpp::R_POWERPC_PLTCALL
:
7917 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7918 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7919 case elfcpp::R_PPC64_PCREL_OPT
:
7920 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7921 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7922 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7923 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7924 case elfcpp::R_PPC64_REL16_HIGHER34
:
7925 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7926 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7927 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7928 case elfcpp::R_PPC64_D34
:
7929 case elfcpp::R_PPC64_D34_LO
:
7930 case elfcpp::R_PPC64_D34_HI30
:
7931 case elfcpp::R_PPC64_D34_HA30
:
7932 case elfcpp::R_PPC64_D28
:
7933 case elfcpp::R_PPC64_PCREL34
:
7934 case elfcpp::R_PPC64_PCREL28
:
7935 case elfcpp::R_PPC64_TPREL34
:
7936 case elfcpp::R_PPC64_DTPREL34
:
7939 case elfcpp::R_PPC64_TOC
:
7941 Output_data_got_powerpc
<size
, big_endian
>* got
7942 = target
->got_section(symtab
, layout
);
7943 if (parameters
->options().output_is_position_independent())
7945 Address off
= reloc
.get_r_offset();
7947 && target
->abiversion() < 2
7948 && data_shndx
== ppc_object
->opd_shndx()
7949 && ppc_object
->get_opd_discard(off
- 8))
7952 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7953 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7954 rela_dyn
->add_output_section_relative(got
->output_section(),
7955 elfcpp::R_POWERPC_RELATIVE
,
7957 object
, data_shndx
, off
,
7958 symobj
->toc_base_offset());
7963 case elfcpp::R_PPC64_ADDR64
:
7964 case elfcpp::R_PPC64_UADDR64
:
7965 case elfcpp::R_POWERPC_ADDR32
:
7966 case elfcpp::R_POWERPC_UADDR32
:
7967 case elfcpp::R_POWERPC_ADDR24
:
7968 case elfcpp::R_POWERPC_ADDR16
:
7969 case elfcpp::R_POWERPC_ADDR16_LO
:
7970 case elfcpp::R_POWERPC_ADDR16_HI
:
7971 case elfcpp::R_POWERPC_ADDR16_HA
:
7972 case elfcpp::R_POWERPC_UADDR16
:
7973 case elfcpp::R_PPC64_ADDR16_HIGH
:
7974 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7975 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7976 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7977 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7978 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7979 case elfcpp::R_PPC64_ADDR16_DS
:
7980 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7981 case elfcpp::R_POWERPC_ADDR14
:
7982 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7983 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7984 // If building a shared library (or a position-independent
7985 // executable), we need to create a dynamic relocation for
7987 if (parameters
->options().output_is_position_independent()
7988 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7990 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7992 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7993 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7994 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7996 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7997 : elfcpp::R_POWERPC_RELATIVE
);
7998 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7999 output_section
, data_shndx
,
8000 reloc
.get_r_offset(),
8001 reloc
.get_r_addend(), false);
8003 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8005 check_non_pic(object
, r_type
);
8006 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8007 data_shndx
, reloc
.get_r_offset(),
8008 reloc
.get_r_addend());
8012 gold_assert(lsym
.get_st_value() == 0);
8013 unsigned int shndx
= lsym
.get_st_shndx();
8015 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8018 object
->error(_("section symbol %u has bad shndx %u"),
8021 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8022 output_section
, data_shndx
,
8023 reloc
.get_r_offset());
8028 case elfcpp::R_PPC64_PLT_PCREL34
:
8029 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8030 case elfcpp::R_POWERPC_PLT16_LO
:
8031 case elfcpp::R_POWERPC_PLT16_HI
:
8032 case elfcpp::R_POWERPC_PLT16_HA
:
8033 case elfcpp::R_PPC64_PLT16_LO_DS
:
8036 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8037 target
->make_local_plt_entry(layout
, object
, r_sym
);
8041 case elfcpp::R_PPC64_REL24_NOTOC
:
8045 case elfcpp::R_POWERPC_REL24
:
8046 case elfcpp::R_PPC_PLTREL24
:
8047 case elfcpp::R_PPC_LOCAL24PC
:
8048 case elfcpp::R_POWERPC_REL14
:
8049 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8050 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8053 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8054 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8055 r_type
, r_sym
, reloc
.get_r_addend());
8059 case elfcpp::R_PPC64_TOCSAVE
:
8060 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8061 // caller has already saved r2 and thus a plt call stub need not
8064 && target
->mark_pltcall(ppc_object
, data_shndx
,
8065 reloc
.get_r_offset() - 4, symtab
))
8067 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8068 unsigned int shndx
= lsym
.get_st_shndx();
8070 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8072 object
->error(_("tocsave symbol %u has bad shndx %u"),
8075 target
->add_tocsave(ppc_object
, shndx
,
8076 lsym
.get_st_value() + reloc
.get_r_addend());
8080 case elfcpp::R_PPC64_REL64
:
8081 case elfcpp::R_POWERPC_REL32
:
8082 case elfcpp::R_POWERPC_REL16
:
8083 case elfcpp::R_POWERPC_REL16_LO
:
8084 case elfcpp::R_POWERPC_REL16_HI
:
8085 case elfcpp::R_POWERPC_REL16_HA
:
8086 case elfcpp::R_POWERPC_REL16DX_HA
:
8087 case elfcpp::R_PPC64_REL16_HIGH
:
8088 case elfcpp::R_PPC64_REL16_HIGHA
:
8089 case elfcpp::R_PPC64_REL16_HIGHER
:
8090 case elfcpp::R_PPC64_REL16_HIGHERA
:
8091 case elfcpp::R_PPC64_REL16_HIGHEST
:
8092 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8093 case elfcpp::R_POWERPC_SECTOFF
:
8094 case elfcpp::R_POWERPC_SECTOFF_LO
:
8095 case elfcpp::R_POWERPC_SECTOFF_HI
:
8096 case elfcpp::R_POWERPC_SECTOFF_HA
:
8097 case elfcpp::R_PPC64_SECTOFF_DS
:
8098 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8099 case elfcpp::R_POWERPC_TPREL16
:
8100 case elfcpp::R_POWERPC_TPREL16_LO
:
8101 case elfcpp::R_POWERPC_TPREL16_HI
:
8102 case elfcpp::R_POWERPC_TPREL16_HA
:
8103 case elfcpp::R_PPC64_TPREL16_DS
:
8104 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8105 case elfcpp::R_PPC64_TPREL16_HIGH
:
8106 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8107 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8108 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8109 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8110 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8111 case elfcpp::R_POWERPC_DTPREL16
:
8112 case elfcpp::R_POWERPC_DTPREL16_LO
:
8113 case elfcpp::R_POWERPC_DTPREL16_HI
:
8114 case elfcpp::R_POWERPC_DTPREL16_HA
:
8115 case elfcpp::R_PPC64_DTPREL16_DS
:
8116 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8117 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8118 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8119 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8120 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8121 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8122 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8123 case elfcpp::R_PPC64_TLSGD
:
8124 case elfcpp::R_PPC64_TLSLD
:
8125 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8128 case elfcpp::R_PPC64_GOT_PCREL34
:
8129 case elfcpp::R_POWERPC_GOT16
:
8130 case elfcpp::R_POWERPC_GOT16_LO
:
8131 case elfcpp::R_POWERPC_GOT16_HI
:
8132 case elfcpp::R_POWERPC_GOT16_HA
:
8133 case elfcpp::R_PPC64_GOT16_DS
:
8134 case elfcpp::R_PPC64_GOT16_LO_DS
:
8136 // The symbol requires a GOT entry.
8137 Output_data_got_powerpc
<size
, big_endian
>* got
8138 = target
->got_section(symtab
, layout
);
8139 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8141 if (!parameters
->options().output_is_position_independent())
8144 && (size
== 32 || target
->abiversion() >= 2))
8145 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
8147 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
8149 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
8151 // If we are generating a shared object or a pie, this
8152 // symbol's GOT entry will be set by a dynamic relocation.
8154 off
= got
->add_constant(0);
8155 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
8157 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8159 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8160 : elfcpp::R_POWERPC_RELATIVE
);
8161 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8162 got
, off
, 0, false);
8167 case elfcpp::R_PPC64_TOC16
:
8168 case elfcpp::R_PPC64_TOC16_LO
:
8169 case elfcpp::R_PPC64_TOC16_HI
:
8170 case elfcpp::R_PPC64_TOC16_HA
:
8171 case elfcpp::R_PPC64_TOC16_DS
:
8172 case elfcpp::R_PPC64_TOC16_LO_DS
:
8173 // We need a GOT section.
8174 target
->got_section(symtab
, layout
);
8177 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8178 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8179 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8180 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8181 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8183 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8184 if (tls_type
== tls::TLSOPT_NONE
)
8186 Output_data_got_powerpc
<size
, big_endian
>* got
8187 = target
->got_section(symtab
, layout
);
8188 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8189 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8190 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
8191 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
8193 else if (tls_type
== tls::TLSOPT_TO_LE
)
8195 // no GOT relocs needed for Local Exec.
8202 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8203 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8204 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8205 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8206 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8208 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8209 if (tls_type
== tls::TLSOPT_NONE
)
8210 target
->tlsld_got_offset(symtab
, layout
, object
);
8211 else if (tls_type
== tls::TLSOPT_TO_LE
)
8213 // no GOT relocs needed for Local Exec.
8214 if (parameters
->options().emit_relocs())
8216 Output_section
* os
= layout
->tls_segment()->first_section();
8217 gold_assert(os
!= NULL
);
8218 os
->set_needs_symtab_index();
8226 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8227 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8228 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8229 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8230 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8232 Output_data_got_powerpc
<size
, big_endian
>* got
8233 = target
->got_section(symtab
, layout
);
8234 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8235 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
8239 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8240 case elfcpp::R_POWERPC_GOT_TPREL16
:
8241 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8242 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8243 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8245 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8246 if (tls_type
== tls::TLSOPT_NONE
)
8248 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8249 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
8251 Output_data_got_powerpc
<size
, big_endian
>* got
8252 = target
->got_section(symtab
, layout
);
8253 unsigned int off
= got
->add_constant(0);
8254 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
8256 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8257 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8258 elfcpp::R_POWERPC_TPREL
,
8262 else if (tls_type
== tls::TLSOPT_TO_LE
)
8264 // no GOT relocs needed for Local Exec.
8272 unsupported_reloc_local(object
, r_type
);
8277 && parameters
->options().toc_optimize())
8279 if (data_shndx
== ppc_object
->toc_shndx())
8282 if (r_type
!= elfcpp::R_PPC64_ADDR64
8283 || (is_ifunc
&& target
->abiversion() < 2))
8285 else if (parameters
->options().output_is_position_independent())
8291 unsigned int shndx
= lsym
.get_st_shndx();
8292 if (shndx
>= elfcpp::SHN_LORESERVE
8293 && shndx
!= elfcpp::SHN_XINDEX
)
8298 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8301 enum {no_check
, check_lo
, check_ha
} insn_check
;
8305 insn_check
= no_check
;
8308 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8309 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8310 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8311 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8312 case elfcpp::R_POWERPC_GOT16_HA
:
8313 case elfcpp::R_PPC64_TOC16_HA
:
8314 insn_check
= check_ha
;
8317 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8318 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8319 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8320 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8321 case elfcpp::R_POWERPC_GOT16_LO
:
8322 case elfcpp::R_PPC64_GOT16_LO_DS
:
8323 case elfcpp::R_PPC64_TOC16_LO
:
8324 case elfcpp::R_PPC64_TOC16_LO_DS
:
8325 insn_check
= check_lo
;
8329 section_size_type slen
;
8330 const unsigned char* view
= NULL
;
8331 if (insn_check
!= no_check
)
8333 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8334 section_size_type off
=
8335 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8338 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8339 if (insn_check
== check_lo
8340 ? !ok_lo_toc_insn(insn
, r_type
)
8341 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8342 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8344 ppc_object
->set_no_toc_opt();
8345 gold_warning(_("%s: toc optimization is not supported "
8346 "for %#08x instruction"),
8347 ppc_object
->name().c_str(), insn
);
8356 case elfcpp::R_PPC64_TOC16
:
8357 case elfcpp::R_PPC64_TOC16_LO
:
8358 case elfcpp::R_PPC64_TOC16_HI
:
8359 case elfcpp::R_PPC64_TOC16_HA
:
8360 case elfcpp::R_PPC64_TOC16_DS
:
8361 case elfcpp::R_PPC64_TOC16_LO_DS
:
8362 unsigned int shndx
= lsym
.get_st_shndx();
8363 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8365 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8366 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8368 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8369 if (dst_off
< ppc_object
->section_size(shndx
))
8372 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8374 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8376 // Need to check that the insn is a ld
8378 view
= ppc_object
->section_contents(data_shndx
,
8381 section_size_type off
=
8382 (convert_to_section_size_type(reloc
.get_r_offset())
8383 + (big_endian
? -2 : 3));
8385 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8389 ppc_object
->set_no_toc_opt(dst_off
);
8400 case elfcpp::R_POWERPC_REL32
:
8401 if (ppc_object
->got2_shndx() != 0
8402 && parameters
->options().output_is_position_independent())
8404 unsigned int shndx
= lsym
.get_st_shndx();
8405 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8407 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8408 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8409 && (ppc_object
->section_flags(data_shndx
)
8410 & elfcpp::SHF_EXECINSTR
) != 0)
8411 gold_error(_("%s: unsupported -mbss-plt code"),
8412 ppc_object
->name().c_str());
8422 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8423 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8424 case elfcpp::R_POWERPC_GOT_TPREL16
:
8425 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8426 case elfcpp::R_POWERPC_GOT16
:
8427 case elfcpp::R_PPC64_GOT16_DS
:
8428 case elfcpp::R_PPC64_TOC16
:
8429 case elfcpp::R_PPC64_TOC16_DS
:
8430 ppc_object
->set_has_small_toc_reloc();
8438 case elfcpp::R_PPC64_TPREL16_DS
:
8439 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8440 case elfcpp::R_PPC64_TPREL16_HIGH
:
8441 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8442 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8443 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8444 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8445 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8446 case elfcpp::R_PPC64_TPREL34
:
8450 case elfcpp::R_POWERPC_TPREL16
:
8451 case elfcpp::R_POWERPC_TPREL16_LO
:
8452 case elfcpp::R_POWERPC_TPREL16_HI
:
8453 case elfcpp::R_POWERPC_TPREL16_HA
:
8454 layout
->set_has_static_tls();
8462 case elfcpp::R_POWERPC_TPREL16_HA
:
8463 if (target
->tprel_opt())
8465 section_size_type slen
;
8466 const unsigned char* view
= NULL
;
8467 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8468 section_size_type off
8469 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8472 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8473 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8474 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8475 target
->set_no_tprel_opt();
8480 case elfcpp::R_PPC64_TPREL16_HIGH
:
8481 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8482 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8483 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8484 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8485 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8489 case elfcpp::R_POWERPC_TPREL16_HI
:
8490 target
->set_no_tprel_opt();
8498 case elfcpp::R_PPC64_D34
:
8499 case elfcpp::R_PPC64_D34_LO
:
8500 case elfcpp::R_PPC64_D34_HI30
:
8501 case elfcpp::R_PPC64_D34_HA30
:
8502 case elfcpp::R_PPC64_D28
:
8503 case elfcpp::R_PPC64_PCREL34
:
8504 case elfcpp::R_PPC64_PCREL28
:
8505 case elfcpp::R_PPC64_TPREL34
:
8506 case elfcpp::R_PPC64_DTPREL34
:
8507 case elfcpp::R_PPC64_PLT_PCREL34
:
8508 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8509 case elfcpp::R_PPC64_GOT_PCREL34
:
8510 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8511 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8512 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8513 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8514 target
->set_power10_relocs();
8521 // Report an unsupported relocation against a global symbol.
8523 template<int size
, bool big_endian
>
8525 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8526 Sized_relobj_file
<size
, big_endian
>* object
,
8527 unsigned int r_type
,
8530 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8531 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8534 // Scan a relocation for a global symbol.
8536 template<int size
, bool big_endian
>
8538 Target_powerpc
<size
, big_endian
>::Scan::global(
8539 Symbol_table
* symtab
,
8541 Target_powerpc
<size
, big_endian
>* target
,
8542 Sized_relobj_file
<size
, big_endian
>* object
,
8543 unsigned int data_shndx
,
8544 Output_section
* output_section
,
8545 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8546 unsigned int r_type
,
8549 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8553 if (target
->replace_tls_get_addr(gsym
))
8554 // Change a __tls_get_addr reference to __tls_get_addr_opt
8555 // so dynamic relocs are emitted against the latter symbol.
8556 gsym
= target
->tls_get_addr_opt();
8558 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8559 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8561 this->expect_tls_get_addr_call();
8562 const bool final
= gsym
->final_value_is_known();
8563 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8564 if (tls_type
!= tls::TLSOPT_NONE
)
8565 this->skip_next_tls_get_addr_call();
8567 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8568 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8570 this->expect_tls_get_addr_call();
8571 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8572 if (tls_type
!= tls::TLSOPT_NONE
)
8573 this->skip_next_tls_get_addr_call();
8576 Powerpc_relobj
<size
, big_endian
>* ppc_object
8577 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8579 // A STT_GNU_IFUNC symbol may require a PLT entry.
8580 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8581 bool pushed_ifunc
= false;
8582 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8584 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8585 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8586 r_type
, r_sym
, reloc
.get_r_addend());
8587 target
->make_plt_entry(symtab
, layout
, gsym
);
8588 pushed_ifunc
= true;
8593 case elfcpp::R_POWERPC_NONE
:
8594 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8595 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8596 case elfcpp::R_PPC_LOCAL24PC
:
8597 case elfcpp::R_POWERPC_TLS
:
8598 case elfcpp::R_PPC64_ENTRY
:
8599 case elfcpp::R_POWERPC_PLTSEQ
:
8600 case elfcpp::R_POWERPC_PLTCALL
:
8601 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8602 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8603 case elfcpp::R_PPC64_PCREL_OPT
:
8604 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8605 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8606 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8607 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8608 case elfcpp::R_PPC64_REL16_HIGHER34
:
8609 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8610 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8611 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8612 case elfcpp::R_PPC64_D34
:
8613 case elfcpp::R_PPC64_D34_LO
:
8614 case elfcpp::R_PPC64_D34_HI30
:
8615 case elfcpp::R_PPC64_D34_HA30
:
8616 case elfcpp::R_PPC64_D28
:
8617 case elfcpp::R_PPC64_PCREL34
:
8618 case elfcpp::R_PPC64_PCREL28
:
8619 case elfcpp::R_PPC64_TPREL34
:
8620 case elfcpp::R_PPC64_DTPREL34
:
8623 case elfcpp::R_PPC64_TOC
:
8625 Output_data_got_powerpc
<size
, big_endian
>* got
8626 = target
->got_section(symtab
, layout
);
8627 if (parameters
->options().output_is_position_independent())
8629 Address off
= reloc
.get_r_offset();
8631 && data_shndx
== ppc_object
->opd_shndx()
8632 && ppc_object
->get_opd_discard(off
- 8))
8635 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8636 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8637 if (data_shndx
!= ppc_object
->opd_shndx())
8638 symobj
= static_cast
8639 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8640 rela_dyn
->add_output_section_relative(got
->output_section(),
8641 elfcpp::R_POWERPC_RELATIVE
,
8643 object
, data_shndx
, off
,
8644 symobj
->toc_base_offset());
8649 case elfcpp::R_PPC64_ADDR64
:
8651 && target
->abiversion() < 2
8652 && data_shndx
== ppc_object
->opd_shndx()
8653 && (gsym
->is_defined_in_discarded_section()
8654 || gsym
->object() != object
))
8656 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8660 case elfcpp::R_PPC64_UADDR64
:
8661 case elfcpp::R_POWERPC_ADDR32
:
8662 case elfcpp::R_POWERPC_UADDR32
:
8663 case elfcpp::R_POWERPC_ADDR24
:
8664 case elfcpp::R_POWERPC_ADDR16
:
8665 case elfcpp::R_POWERPC_ADDR16_LO
:
8666 case elfcpp::R_POWERPC_ADDR16_HI
:
8667 case elfcpp::R_POWERPC_ADDR16_HA
:
8668 case elfcpp::R_POWERPC_UADDR16
:
8669 case elfcpp::R_PPC64_ADDR16_HIGH
:
8670 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8671 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8672 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8673 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8674 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8675 case elfcpp::R_PPC64_ADDR16_DS
:
8676 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8677 case elfcpp::R_POWERPC_ADDR14
:
8678 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8679 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8681 // Make a PLT entry if necessary.
8682 if (gsym
->needs_plt_entry())
8684 // Since this is not a PC-relative relocation, we may be
8685 // taking the address of a function. In that case we need to
8686 // set the entry in the dynamic symbol table to the address of
8687 // the PLT call stub.
8688 bool need_ifunc_plt
= false;
8689 if ((size
== 32 || target
->abiversion() >= 2)
8690 && gsym
->is_from_dynobj()
8691 && !parameters
->options().output_is_position_independent())
8693 gsym
->set_needs_dynsym_value();
8694 need_ifunc_plt
= true;
8696 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8698 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8699 target
->push_branch(ppc_object
, data_shndx
,
8700 reloc
.get_r_offset(), r_type
, r_sym
,
8701 reloc
.get_r_addend());
8702 target
->make_plt_entry(symtab
, layout
, gsym
);
8705 // Make a dynamic relocation if necessary.
8706 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8707 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8709 if (!parameters
->options().output_is_position_independent()
8710 && gsym
->may_need_copy_reloc())
8712 target
->copy_reloc(symtab
, layout
, object
,
8713 data_shndx
, output_section
, gsym
, reloc
);
8715 else if ((((size
== 32
8716 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8718 && r_type
== elfcpp::R_PPC64_ADDR64
8719 && target
->abiversion() >= 2))
8720 && gsym
->can_use_relative_reloc(false)
8721 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8722 && parameters
->options().shared()))
8724 && r_type
== elfcpp::R_PPC64_ADDR64
8725 && target
->abiversion() < 2
8726 && (gsym
->can_use_relative_reloc(false)
8727 || data_shndx
== ppc_object
->opd_shndx())))
8729 Reloc_section
* rela_dyn
8730 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8731 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8732 : elfcpp::R_POWERPC_RELATIVE
);
8733 rela_dyn
->add_symbolless_global_addend(
8734 gsym
, dynrel
, output_section
, object
, data_shndx
,
8735 reloc
.get_r_offset(), reloc
.get_r_addend());
8739 Reloc_section
* rela_dyn
8740 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8741 check_non_pic(object
, r_type
);
8742 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8744 reloc
.get_r_offset(),
8745 reloc
.get_r_addend());
8748 && parameters
->options().toc_optimize()
8749 && data_shndx
== ppc_object
->toc_shndx())
8750 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8756 case elfcpp::R_PPC64_PLT_PCREL34
:
8757 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8758 case elfcpp::R_POWERPC_PLT16_LO
:
8759 case elfcpp::R_POWERPC_PLT16_HI
:
8760 case elfcpp::R_POWERPC_PLT16_HA
:
8761 case elfcpp::R_PPC64_PLT16_LO_DS
:
8763 target
->make_plt_entry(symtab
, layout
, gsym
);
8766 case elfcpp::R_PPC64_REL24_NOTOC
:
8770 case elfcpp::R_PPC_PLTREL24
:
8771 case elfcpp::R_POWERPC_REL24
:
8774 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8775 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8776 r_type
, r_sym
, reloc
.get_r_addend());
8777 if (gsym
->needs_plt_entry()
8778 || (!gsym
->final_value_is_known()
8779 && (gsym
->is_undefined()
8780 || gsym
->is_from_dynobj()
8781 || gsym
->is_preemptible())))
8782 target
->make_plt_entry(symtab
, layout
, gsym
);
8786 case elfcpp::R_PPC64_REL64
:
8787 case elfcpp::R_POWERPC_REL32
:
8788 // Make a dynamic relocation if necessary.
8789 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8791 if (!parameters
->options().output_is_position_independent()
8792 && gsym
->may_need_copy_reloc())
8794 target
->copy_reloc(symtab
, layout
, object
,
8795 data_shndx
, output_section
, gsym
,
8800 Reloc_section
* rela_dyn
8801 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8802 check_non_pic(object
, r_type
);
8803 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8804 data_shndx
, reloc
.get_r_offset(),
8805 reloc
.get_r_addend());
8810 case elfcpp::R_POWERPC_REL14
:
8811 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8812 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8815 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8816 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8817 r_type
, r_sym
, reloc
.get_r_addend());
8821 case elfcpp::R_PPC64_TOCSAVE
:
8822 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8823 // caller has already saved r2 and thus a plt call stub need not
8826 && target
->mark_pltcall(ppc_object
, data_shndx
,
8827 reloc
.get_r_offset() - 4, symtab
))
8829 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8831 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8833 object
->error(_("tocsave symbol %u has bad shndx %u"),
8837 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8838 target
->add_tocsave(ppc_object
, shndx
,
8839 sym
->value() + reloc
.get_r_addend());
8844 case elfcpp::R_POWERPC_REL16
:
8845 case elfcpp::R_POWERPC_REL16_LO
:
8846 case elfcpp::R_POWERPC_REL16_HI
:
8847 case elfcpp::R_POWERPC_REL16_HA
:
8848 case elfcpp::R_POWERPC_REL16DX_HA
:
8849 case elfcpp::R_PPC64_REL16_HIGH
:
8850 case elfcpp::R_PPC64_REL16_HIGHA
:
8851 case elfcpp::R_PPC64_REL16_HIGHER
:
8852 case elfcpp::R_PPC64_REL16_HIGHERA
:
8853 case elfcpp::R_PPC64_REL16_HIGHEST
:
8854 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8855 case elfcpp::R_POWERPC_SECTOFF
:
8856 case elfcpp::R_POWERPC_SECTOFF_LO
:
8857 case elfcpp::R_POWERPC_SECTOFF_HI
:
8858 case elfcpp::R_POWERPC_SECTOFF_HA
:
8859 case elfcpp::R_PPC64_SECTOFF_DS
:
8860 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8861 case elfcpp::R_POWERPC_TPREL16
:
8862 case elfcpp::R_POWERPC_TPREL16_LO
:
8863 case elfcpp::R_POWERPC_TPREL16_HI
:
8864 case elfcpp::R_POWERPC_TPREL16_HA
:
8865 case elfcpp::R_PPC64_TPREL16_DS
:
8866 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8867 case elfcpp::R_PPC64_TPREL16_HIGH
:
8868 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8869 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8870 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8871 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8872 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8873 case elfcpp::R_POWERPC_DTPREL16
:
8874 case elfcpp::R_POWERPC_DTPREL16_LO
:
8875 case elfcpp::R_POWERPC_DTPREL16_HI
:
8876 case elfcpp::R_POWERPC_DTPREL16_HA
:
8877 case elfcpp::R_PPC64_DTPREL16_DS
:
8878 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8879 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8880 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8881 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8882 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8883 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8884 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8885 case elfcpp::R_PPC64_TLSGD
:
8886 case elfcpp::R_PPC64_TLSLD
:
8887 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8890 case elfcpp::R_PPC64_GOT_PCREL34
:
8891 case elfcpp::R_POWERPC_GOT16
:
8892 case elfcpp::R_POWERPC_GOT16_LO
:
8893 case elfcpp::R_POWERPC_GOT16_HI
:
8894 case elfcpp::R_POWERPC_GOT16_HA
:
8895 case elfcpp::R_PPC64_GOT16_DS
:
8896 case elfcpp::R_PPC64_GOT16_LO_DS
:
8898 // The symbol requires a GOT entry.
8899 Output_data_got_powerpc
<size
, big_endian
>* got
;
8901 got
= target
->got_section(symtab
, layout
);
8902 if (gsym
->final_value_is_known())
8905 && (size
== 32 || target
->abiversion() >= 2))
8906 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8908 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8910 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8912 // If we are generating a shared object or a pie, this
8913 // symbol's GOT entry will be set by a dynamic relocation.
8914 unsigned int off
= got
->add_constant(0);
8915 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8917 Reloc_section
* rela_dyn
8918 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8920 if (gsym
->can_use_relative_reloc(false)
8922 || target
->abiversion() >= 2)
8923 && gsym
->visibility() == elfcpp::STV_PROTECTED
8924 && parameters
->options().shared()))
8926 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8927 : elfcpp::R_POWERPC_RELATIVE
);
8928 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8932 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8933 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8939 case elfcpp::R_PPC64_TOC16
:
8940 case elfcpp::R_PPC64_TOC16_LO
:
8941 case elfcpp::R_PPC64_TOC16_HI
:
8942 case elfcpp::R_PPC64_TOC16_HA
:
8943 case elfcpp::R_PPC64_TOC16_DS
:
8944 case elfcpp::R_PPC64_TOC16_LO_DS
:
8945 // We need a GOT section.
8946 target
->got_section(symtab
, layout
);
8949 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8950 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8951 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8952 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8953 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8955 const bool final
= gsym
->final_value_is_known();
8956 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8957 if (tls_type
== tls::TLSOPT_NONE
)
8959 Output_data_got_powerpc
<size
, big_endian
>* got
8960 = target
->got_section(symtab
, layout
);
8961 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8962 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8963 elfcpp::R_POWERPC_DTPMOD
,
8964 elfcpp::R_POWERPC_DTPREL
);
8966 else if (tls_type
== tls::TLSOPT_TO_IE
)
8968 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8970 Output_data_got_powerpc
<size
, big_endian
>* got
8971 = target
->got_section(symtab
, layout
);
8972 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8973 if (gsym
->is_undefined()
8974 || gsym
->is_from_dynobj())
8976 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8977 elfcpp::R_POWERPC_TPREL
);
8981 unsigned int off
= got
->add_constant(0);
8982 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8983 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8984 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8989 else if (tls_type
== tls::TLSOPT_TO_LE
)
8991 // no GOT relocs needed for Local Exec.
8998 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8999 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9000 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9001 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9002 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9004 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9005 if (tls_type
== tls::TLSOPT_NONE
)
9006 target
->tlsld_got_offset(symtab
, layout
, object
);
9007 else if (tls_type
== tls::TLSOPT_TO_LE
)
9009 // no GOT relocs needed for Local Exec.
9010 if (parameters
->options().emit_relocs())
9012 Output_section
* os
= layout
->tls_segment()->first_section();
9013 gold_assert(os
!= NULL
);
9014 os
->set_needs_symtab_index();
9022 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9023 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9024 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9025 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9026 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9028 Output_data_got_powerpc
<size
, big_endian
>* got
9029 = target
->got_section(symtab
, layout
);
9030 if (!gsym
->final_value_is_known()
9031 && (gsym
->is_from_dynobj()
9032 || gsym
->is_undefined()
9033 || gsym
->is_preemptible()))
9034 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
9035 target
->rela_dyn_section(layout
),
9036 elfcpp::R_POWERPC_DTPREL
);
9038 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
9042 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9043 case elfcpp::R_POWERPC_GOT_TPREL16
:
9044 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9045 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9046 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9048 const bool final
= gsym
->final_value_is_known();
9049 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9050 if (tls_type
== tls::TLSOPT_NONE
)
9052 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
9054 Output_data_got_powerpc
<size
, big_endian
>* got
9055 = target
->got_section(symtab
, layout
);
9056 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9057 if (gsym
->is_undefined()
9058 || gsym
->is_from_dynobj())
9060 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
9061 elfcpp::R_POWERPC_TPREL
);
9065 unsigned int off
= got
->add_constant(0);
9066 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
9067 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9068 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9073 else if (tls_type
== tls::TLSOPT_TO_LE
)
9075 // no GOT relocs needed for Local Exec.
9083 unsupported_reloc_global(object
, r_type
, gsym
);
9088 && parameters
->options().toc_optimize())
9090 if (data_shndx
== ppc_object
->toc_shndx())
9093 if (r_type
!= elfcpp::R_PPC64_ADDR64
9094 || (is_ifunc
&& target
->abiversion() < 2))
9096 else if (parameters
->options().output_is_position_independent()
9097 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9100 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9103 enum {no_check
, check_lo
, check_ha
} insn_check
;
9107 insn_check
= no_check
;
9110 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9111 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9112 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9113 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9114 case elfcpp::R_POWERPC_GOT16_HA
:
9115 case elfcpp::R_PPC64_TOC16_HA
:
9116 insn_check
= check_ha
;
9119 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9120 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9121 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9122 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9123 case elfcpp::R_POWERPC_GOT16_LO
:
9124 case elfcpp::R_PPC64_GOT16_LO_DS
:
9125 case elfcpp::R_PPC64_TOC16_LO
:
9126 case elfcpp::R_PPC64_TOC16_LO_DS
:
9127 insn_check
= check_lo
;
9131 section_size_type slen
;
9132 const unsigned char* view
= NULL
;
9133 if (insn_check
!= no_check
)
9135 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9136 section_size_type off
=
9137 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9140 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9141 if (insn_check
== check_lo
9142 ? !ok_lo_toc_insn(insn
, r_type
)
9143 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9144 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9146 ppc_object
->set_no_toc_opt();
9147 gold_warning(_("%s: toc optimization is not supported "
9148 "for %#08x instruction"),
9149 ppc_object
->name().c_str(), insn
);
9158 case elfcpp::R_PPC64_TOC16
:
9159 case elfcpp::R_PPC64_TOC16_LO
:
9160 case elfcpp::R_PPC64_TOC16_HI
:
9161 case elfcpp::R_PPC64_TOC16_HA
:
9162 case elfcpp::R_PPC64_TOC16_DS
:
9163 case elfcpp::R_PPC64_TOC16_LO_DS
:
9164 if (gsym
->source() == Symbol::FROM_OBJECT
9165 && !gsym
->object()->is_dynamic())
9167 Powerpc_relobj
<size
, big_endian
>* sym_object
9168 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9170 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9171 if (shndx
== sym_object
->toc_shndx())
9173 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9174 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9175 if (dst_off
< sym_object
->section_size(shndx
))
9178 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9180 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9182 // Need to check that the insn is a ld
9184 view
= ppc_object
->section_contents(data_shndx
,
9187 section_size_type off
=
9188 (convert_to_section_size_type(reloc
.get_r_offset())
9189 + (big_endian
? -2 : 3));
9191 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9195 sym_object
->set_no_toc_opt(dst_off
);
9207 case elfcpp::R_PPC_LOCAL24PC
:
9208 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9209 gold_error(_("%s: unsupported -mbss-plt code"),
9210 ppc_object
->name().c_str());
9219 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9220 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9221 case elfcpp::R_POWERPC_GOT_TPREL16
:
9222 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9223 case elfcpp::R_POWERPC_GOT16
:
9224 case elfcpp::R_PPC64_GOT16_DS
:
9225 case elfcpp::R_PPC64_TOC16
:
9226 case elfcpp::R_PPC64_TOC16_DS
:
9227 ppc_object
->set_has_small_toc_reloc();
9235 case elfcpp::R_PPC64_TPREL16_DS
:
9236 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9237 case elfcpp::R_PPC64_TPREL16_HIGH
:
9238 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9239 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9240 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9241 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9242 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9243 case elfcpp::R_PPC64_TPREL34
:
9247 case elfcpp::R_POWERPC_TPREL16
:
9248 case elfcpp::R_POWERPC_TPREL16_LO
:
9249 case elfcpp::R_POWERPC_TPREL16_HI
:
9250 case elfcpp::R_POWERPC_TPREL16_HA
:
9251 layout
->set_has_static_tls();
9259 case elfcpp::R_POWERPC_TPREL16_HA
:
9260 if (target
->tprel_opt())
9262 section_size_type slen
;
9263 const unsigned char* view
= NULL
;
9264 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9265 section_size_type off
9266 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9269 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9270 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9271 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9272 target
->set_no_tprel_opt();
9277 case elfcpp::R_PPC64_TPREL16_HIGH
:
9278 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9279 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9280 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9281 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9282 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9286 case elfcpp::R_POWERPC_TPREL16_HI
:
9287 target
->set_no_tprel_opt();
9295 case elfcpp::R_PPC64_D34
:
9296 case elfcpp::R_PPC64_D34_LO
:
9297 case elfcpp::R_PPC64_D34_HI30
:
9298 case elfcpp::R_PPC64_D34_HA30
:
9299 case elfcpp::R_PPC64_D28
:
9300 case elfcpp::R_PPC64_PCREL34
:
9301 case elfcpp::R_PPC64_PCREL28
:
9302 case elfcpp::R_PPC64_TPREL34
:
9303 case elfcpp::R_PPC64_DTPREL34
:
9304 case elfcpp::R_PPC64_PLT_PCREL34
:
9305 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9306 case elfcpp::R_PPC64_GOT_PCREL34
:
9307 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9308 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9309 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9310 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9311 target
->set_power10_relocs();
9318 // Process relocations for gc.
9320 template<int size
, bool big_endian
>
9322 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9323 Symbol_table
* symtab
,
9325 Sized_relobj_file
<size
, big_endian
>* object
,
9326 unsigned int data_shndx
,
9328 const unsigned char* prelocs
,
9330 Output_section
* output_section
,
9331 bool needs_special_offset_handling
,
9332 size_t local_symbol_count
,
9333 const unsigned char* plocal_symbols
)
9335 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9336 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9339 Powerpc_relobj
<size
, big_endian
>* ppc_object
9340 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9342 ppc_object
->set_opd_valid();
9343 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9345 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9346 for (p
= ppc_object
->access_from_map()->begin();
9347 p
!= ppc_object
->access_from_map()->end();
9350 Address dst_off
= p
->first
;
9351 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9352 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9353 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9355 Relobj
* src_obj
= s
->first
;
9356 unsigned int src_indx
= s
->second
;
9357 symtab
->gc()->add_reference(src_obj
, src_indx
,
9358 ppc_object
, dst_indx
);
9362 ppc_object
->access_from_map()->clear();
9363 ppc_object
->process_gc_mark(symtab
);
9364 // Don't look at .opd relocs as .opd will reference everything.
9368 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9377 needs_special_offset_handling
,
9382 // Handle target specific gc actions when adding a gc reference from
9383 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9384 // and DST_OFF. For powerpc64, this adds a referenc to the code
9385 // section of a function descriptor.
9387 template<int size
, bool big_endian
>
9389 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9390 Symbol_table
* symtab
,
9392 unsigned int src_shndx
,
9394 unsigned int dst_shndx
,
9395 Address dst_off
) const
9397 if (size
!= 64 || dst_obj
->is_dynamic())
9400 Powerpc_relobj
<size
, big_endian
>* ppc_object
9401 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9402 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9404 if (ppc_object
->opd_valid())
9406 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9407 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9411 // If we haven't run scan_opd_relocs, we must delay
9412 // processing this function descriptor reference.
9413 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9418 // Add any special sections for this symbol to the gc work list.
9419 // For powerpc64, this adds the code section of a function
9422 template<int size
, bool big_endian
>
9424 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9425 Symbol_table
* symtab
,
9428 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9430 Powerpc_relobj
<size
, big_endian
>* ppc_object
9431 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9433 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9434 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9436 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9437 Address dst_off
= gsym
->value();
9438 if (ppc_object
->opd_valid())
9440 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9441 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9445 ppc_object
->add_gc_mark(dst_off
);
9450 // For a symbol location in .opd, set LOC to the location of the
9453 template<int size
, bool big_endian
>
9455 Target_powerpc
<size
, big_endian
>::do_function_location(
9456 Symbol_location
* loc
) const
9458 if (size
== 64 && loc
->shndx
!= 0)
9460 if (loc
->object
->is_dynamic())
9462 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9463 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9464 if (loc
->shndx
== ppc_object
->opd_shndx())
9467 Address off
= loc
->offset
- ppc_object
->opd_address();
9468 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9469 loc
->offset
= dest_off
;
9474 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9475 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9476 if (loc
->shndx
== ppc_object
->opd_shndx())
9479 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9480 loc
->offset
= dest_off
;
9486 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9487 // compiled with -fsplit-stack. The function calls non-split-stack
9488 // code. Change the function to ensure it has enough stack space to
9489 // call some random function.
9491 template<int size
, bool big_endian
>
9493 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9496 section_offset_type fnoffset
,
9497 section_size_type fnsize
,
9498 const unsigned char* prelocs
,
9500 unsigned char* view
,
9501 section_size_type view_size
,
9503 std::string
* to
) const
9505 // 32-bit not supported.
9509 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9510 prelocs
, reloc_count
, view
, view_size
,
9515 // The function always starts with
9516 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9517 // addis %r12,%r1,-allocate@ha
9518 // addi %r12,%r12,-allocate@l
9520 // but note that the addis or addi may be replaced with a nop
9522 unsigned char *entry
= view
+ fnoffset
;
9523 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9525 if ((insn
& 0xffff0000) == addis_2_12
)
9527 /* Skip ELFv2 global entry code. */
9529 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9532 unsigned char *pinsn
= entry
;
9534 const uint32_t ld_private_ss
= 0xe80d8fc0;
9535 if (insn
== ld_private_ss
)
9537 int32_t allocate
= 0;
9541 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9542 if ((insn
& 0xffff0000) == addis_12_1
)
9543 allocate
+= (insn
& 0xffff) << 16;
9544 else if ((insn
& 0xffff0000) == addi_12_1
9545 || (insn
& 0xffff0000) == addi_12_12
)
9546 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9547 else if (insn
!= nop
)
9550 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9552 int extra
= parameters
->options().split_stack_adjust_size();
9554 if (allocate
>= 0 || extra
< 0)
9556 object
->error(_("split-stack stack size overflow at "
9557 "section %u offset %0zx"),
9558 shndx
, static_cast<size_t>(fnoffset
));
9562 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9563 if (insn
!= addis_12_1
)
9565 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9567 insn
= addi_12_12
| (allocate
& 0xffff);
9568 if (insn
!= addi_12_12
)
9570 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9576 insn
= addi_12_1
| (allocate
& 0xffff);
9577 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9580 if (pinsn
!= entry
+ 12)
9581 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9589 if (!object
->has_no_split_stack())
9590 object
->error(_("failed to match split-stack sequence at "
9591 "section %u offset %0zx"),
9592 shndx
, static_cast<size_t>(fnoffset
));
9596 // Scan relocations for a section.
9598 template<int size
, bool big_endian
>
9600 Target_powerpc
<size
, big_endian
>::scan_relocs(
9601 Symbol_table
* symtab
,
9603 Sized_relobj_file
<size
, big_endian
>* object
,
9604 unsigned int data_shndx
,
9605 unsigned int sh_type
,
9606 const unsigned char* prelocs
,
9608 Output_section
* output_section
,
9609 bool needs_special_offset_handling
,
9610 size_t local_symbol_count
,
9611 const unsigned char* plocal_symbols
)
9613 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9614 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9617 if (!this->plt_localentry0_init_
)
9619 bool plt_localentry0
= false;
9621 && this->abiversion() >= 2)
9623 if (parameters
->options().user_set_plt_localentry())
9624 plt_localentry0
= parameters
->options().plt_localentry();
9626 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9627 gold_warning(_("--plt-localentry is especially dangerous without "
9628 "ld.so support to detect ABI violations"));
9630 this->plt_localentry0_
= plt_localentry0
;
9631 this->plt_localentry0_init_
= true;
9634 if (sh_type
== elfcpp::SHT_REL
)
9636 gold_error(_("%s: unsupported REL reloc section"),
9637 object
->name().c_str());
9641 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9650 needs_special_offset_handling
,
9654 if (this->plt_localentry0_
&& this->power10_relocs_
)
9656 gold_warning(_("--plt-localentry is incompatible with "
9657 "power10 pc-relative code"));
9658 this->plt_localentry0_
= false;
9662 // Functor class for processing the global symbol table.
9663 // Removes symbols defined on discarded opd entries.
9665 template<bool big_endian
>
9666 class Global_symbol_visitor_opd
9669 Global_symbol_visitor_opd()
9673 operator()(Sized_symbol
<64>* sym
)
9675 if (sym
->has_symtab_index()
9676 || sym
->source() != Symbol::FROM_OBJECT
9677 || !sym
->in_real_elf())
9680 if (sym
->object()->is_dynamic())
9683 Powerpc_relobj
<64, big_endian
>* symobj
9684 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9685 if (symobj
->opd_shndx() == 0)
9689 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9690 if (shndx
== symobj
->opd_shndx()
9691 && symobj
->get_opd_discard(sym
->value()))
9693 sym
->set_undefined();
9694 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9695 sym
->set_is_defined_in_discarded_section();
9696 sym
->set_symtab_index(-1U);
9701 template<int size
, bool big_endian
>
9703 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9705 Symbol_table
* symtab
)
9709 Output_data_save_res
<size
, big_endian
>* savres
9710 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9711 this->savres_section_
= savres
;
9712 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9713 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9714 savres
, ORDER_TEXT
, false);
9718 // Sort linker created .got section first (for the header), then input
9719 // sections belonging to files using small model code.
9721 template<bool big_endian
>
9722 class Sort_toc_sections
9726 operator()(const Output_section::Input_section
& is1
,
9727 const Output_section::Input_section
& is2
) const
9729 if (!is1
.is_input_section() && is2
.is_input_section())
9732 = (is1
.is_input_section()
9733 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9734 ->has_small_toc_reloc()));
9736 = (is2
.is_input_section()
9737 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9738 ->has_small_toc_reloc()));
9739 return small1
&& !small2
;
9743 // Finalize the sections.
9745 template<int size
, bool big_endian
>
9747 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9749 const Input_objects
* input_objects
,
9750 Symbol_table
* symtab
)
9752 if (parameters
->doing_static_link())
9754 // At least some versions of glibc elf-init.o have a strong
9755 // reference to __rela_iplt marker syms. A weak ref would be
9757 if (this->iplt_
!= NULL
)
9759 Reloc_section
* rel
= this->iplt_
->rel_plt();
9760 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9761 Symbol_table::PREDEFINED
, rel
, 0, 0,
9762 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9763 elfcpp::STV_HIDDEN
, 0, false, true);
9764 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9765 Symbol_table::PREDEFINED
, rel
, 0, 0,
9766 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9767 elfcpp::STV_HIDDEN
, 0, true, true);
9771 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9772 Symbol_table::PREDEFINED
, 0, 0,
9773 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9774 elfcpp::STV_HIDDEN
, 0, true, false);
9775 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9776 Symbol_table::PREDEFINED
, 0, 0,
9777 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9778 elfcpp::STV_HIDDEN
, 0, true, false);
9784 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9785 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9787 if (!parameters
->options().relocatable())
9789 this->define_save_restore_funcs(layout
, symtab
);
9791 // Annoyingly, we need to make these sections now whether or
9792 // not we need them. If we delay until do_relax then we
9793 // need to mess with the relaxation machinery checkpointing.
9794 this->got_section(symtab
, layout
);
9795 this->make_brlt_section(layout
);
9797 if (parameters
->options().toc_sort())
9799 Output_section
* os
= this->got_
->output_section();
9800 if (os
!= NULL
&& os
->input_sections().size() > 1)
9801 std::stable_sort(os
->input_sections().begin(),
9802 os
->input_sections().end(),
9803 Sort_toc_sections
<big_endian
>());
9808 // Fill in some more dynamic tags.
9809 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9812 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9814 : this->plt_
->rel_plt());
9815 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9816 this->rela_dyn_
, true, size
== 32);
9820 if (this->got_
!= NULL
)
9822 this->got_
->finalize_data_size();
9823 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9824 this->got_
, this->got_
->g_o_t());
9826 if (this->has_tls_get_addr_opt_
)
9827 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9831 if (this->glink_
!= NULL
)
9833 this->glink_
->finalize_data_size();
9834 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9836 (this->glink_
->pltresolve_size()
9839 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9840 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9841 ((this->has_localentry0_
9842 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9843 | (this->has_tls_get_addr_opt_
9844 ? elfcpp::PPC64_OPT_TLS
: 0)));
9848 // Emit any relocs we saved in an attempt to avoid generating COPY
9850 if (this->copy_relocs_
.any_saved_relocs())
9851 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9853 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9854 p
!= input_objects
->relobj_end();
9857 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9858 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9859 if (ppc_relobj
->attributes_section_data())
9860 this->merge_object_attributes(ppc_relobj
,
9861 ppc_relobj
->attributes_section_data());
9863 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9864 p
!= input_objects
->dynobj_end();
9867 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9868 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9869 if (ppc_dynobj
->attributes_section_data())
9870 this->merge_object_attributes(ppc_dynobj
,
9871 ppc_dynobj
->attributes_section_data());
9874 // Create a .gnu.attributes section if we have merged any attributes
9876 if (this->attributes_section_data_
!= NULL
9877 && this->attributes_section_data_
->size() != 0)
9879 Output_attributes_section_data
* attributes_section
9880 = new Output_attributes_section_data(*this->attributes_section_data_
);
9881 layout
->add_output_section_data(".gnu.attributes",
9882 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9883 attributes_section
, ORDER_INVALID
, false);
9887 // Merge object attributes from input file called NAME with those of the
9888 // output. The input object attributes are in the object pointed by PASD.
9890 template<int size
, bool big_endian
>
9892 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9894 const Attributes_section_data
* pasd
)
9896 // Return if there is no attributes section data.
9900 // Create output object attributes.
9901 if (this->attributes_section_data_
== NULL
)
9902 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9904 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9905 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9906 Object_attribute
* out_attr
9907 = this->attributes_section_data_
->known_attributes(vendor
);
9909 const char* name
= obj
->name().c_str();
9913 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9914 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9915 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9916 bool warn_only
= obj
->is_dynamic();
9917 if (in_fp
!= out_fp
)
9920 if ((in_fp
& 3) == 0)
9922 else if ((out_fp
& 3) == 0)
9926 out_fp
|= in_fp
& 3;
9927 out_attr
[tag
].set_int_value(out_fp
);
9928 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9929 this->last_fp_
= name
;
9932 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9934 err
= N_("%s uses hard float, %s uses soft float");
9935 first
= this->last_fp_
;
9938 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9940 err
= N_("%s uses hard float, %s uses soft float");
9942 second
= this->last_fp_
;
9944 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9946 err
= N_("%s uses double-precision hard float, "
9947 "%s uses single-precision hard float");
9948 first
= this->last_fp_
;
9951 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9953 err
= N_("%s uses double-precision hard float, "
9954 "%s uses single-precision hard float");
9956 second
= this->last_fp_
;
9959 if (err
|| (in_fp
& 0xc) == 0)
9961 else if ((out_fp
& 0xc) == 0)
9965 out_fp
|= in_fp
& 0xc;
9966 out_attr
[tag
].set_int_value(out_fp
);
9967 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9968 this->last_ld_
= name
;
9971 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9973 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9975 second
= this->last_ld_
;
9977 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9979 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9980 first
= this->last_ld_
;
9983 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9985 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9986 first
= this->last_ld_
;
9989 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9991 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9993 second
= this->last_ld_
;
9998 if (parameters
->options().warn_mismatch())
10001 gold_warning(_(err
), first
, second
);
10003 gold_error(_(err
), first
, second
);
10005 // Arrange for this attribute to be deleted. It's better to
10006 // say "don't know" about a file than to wrongly claim compliance.
10008 out_attr
[tag
].set_type(0);
10014 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10015 int in_vec
= in_attr
[tag
].int_value() & 3;
10016 int out_vec
= out_attr
[tag
].int_value() & 3;
10017 if (in_vec
!= out_vec
)
10022 else if (out_vec
== 0)
10025 out_attr
[tag
].set_int_value(out_vec
);
10026 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10027 this->last_vec_
= name
;
10029 // For now, allow generic to transition to AltiVec or SPE
10030 // without a warning. If GCC marked files with their stack
10031 // alignment and used don't-care markings for files which are
10032 // not affected by the vector ABI, we could warn about this
10034 else if (in_vec
== 1)
10036 else if (out_vec
== 1)
10039 out_attr
[tag
].set_int_value(out_vec
);
10040 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10041 this->last_vec_
= name
;
10043 else if (out_vec
< in_vec
)
10045 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10046 first
= this->last_vec_
;
10049 else if (out_vec
> in_vec
)
10051 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10053 second
= this->last_vec_
;
10057 if (parameters
->options().warn_mismatch())
10058 gold_error(_(err
), first
, second
);
10059 out_attr
[tag
].set_type(0);
10063 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10064 int in_struct
= in_attr
[tag
].int_value() & 3;
10065 int out_struct
= out_attr
[tag
].int_value() & 3;
10066 if (in_struct
!= out_struct
)
10069 if (in_struct
== 0 || in_struct
== 3)
10071 else if (out_struct
== 0)
10073 out_struct
= in_struct
;
10074 out_attr
[tag
].set_int_value(out_struct
);
10075 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10076 this->last_struct_
= name
;
10078 else if (out_struct
< in_struct
)
10080 err
= N_("%s uses r3/r4 for small structure returns, "
10082 first
= this->last_struct_
;
10085 else if (out_struct
> in_struct
)
10087 err
= N_("%s uses r3/r4 for small structure returns, "
10090 second
= this->last_struct_
;
10094 if (parameters
->options().warn_mismatch())
10095 gold_error(_(err
), first
, second
);
10096 out_attr
[tag
].set_type(0);
10101 // Merge Tag_compatibility attributes and any common GNU ones.
10102 this->attributes_section_data_
->merge(name
, pasd
);
10105 // Emit any saved relocs, and mark toc entries using any of these
10106 // relocs as not optimizable.
10108 template<int sh_type
, int size
, bool big_endian
>
10110 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10111 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10114 && parameters
->options().toc_optimize())
10116 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10117 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10118 p
!= this->entries_
.end();
10121 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10124 // If the symbol is no longer defined in a dynamic object,
10125 // then we emitted a COPY relocation. If it is still
10126 // dynamic then we'll need dynamic relocations and thus
10127 // can't optimize toc entries.
10128 if (entry
.sym_
->is_from_dynobj())
10130 Powerpc_relobj
<size
, big_endian
>* ppc_object
10131 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10132 if (entry
.shndx_
== ppc_object
->toc_shndx())
10133 ppc_object
->set_no_toc_opt(entry
.address_
);
10138 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10141 // Return the value to use for a branch relocation.
10143 template<int size
, bool big_endian
>
10145 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10146 const Symbol_table
* symtab
,
10147 const Sized_symbol
<size
>* gsym
,
10148 Powerpc_relobj
<size
, big_endian
>* object
,
10150 unsigned int *dest_shndx
)
10152 if (size
== 32 || this->abiversion() >= 2)
10153 gold_unreachable();
10156 // If the symbol is defined in an opd section, ie. is a function
10157 // descriptor, use the function descriptor code entry address
10158 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10160 && (gsym
->source() != Symbol::FROM_OBJECT
10161 || gsym
->object()->is_dynamic()))
10164 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10165 unsigned int shndx
= symobj
->opd_shndx();
10168 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10169 if (opd_addr
== invalid_address
)
10171 opd_addr
+= symobj
->output_section_address(shndx
);
10172 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10175 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10176 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10179 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10180 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10181 *dest_shndx
= folded
.second
;
10183 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10184 if (sec_addr
== invalid_address
)
10187 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10188 *value
= sec_addr
+ sec_off
;
10195 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10197 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10200 if (gsym
->is_from_dynobj()
10201 || gsym
->is_undefined()
10202 || gsym
->is_preemptible())
10205 if (gsym
->is_absolute())
10206 return !parameters
->options().output_is_position_independent();
10213 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10215 if (psymval
->is_ifunc_symbol())
10219 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10221 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10224 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10225 // pld ra,symbol@got@pcrel
10226 // load/store rt,0(ra)
10228 // pla ra,symbol@pcrel
10229 // load/store rt,0(ra)
10230 // may be translated to
10231 // pload/pstore rt,symbol@pcrel
10233 // This function returns true if the optimization is possible, placing
10234 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10236 // On entry to this function, the linker has already determined that
10237 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10238 // while *PINSN2 is the second instruction.
10241 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10243 uint32_t insn2
= *pinsn2
>> 32;
10246 // Check that regs match.
10247 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10250 switch ((insn2
>> 26) & 63)
10266 // These are the PMLS cases, where we just need to tack a prefix
10267 // on the insn. Check that the D field is zero.
10268 if ((insn2
& 0xffff) != 0)
10270 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10271 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10274 case 58: // lwa, ld
10275 if ((insn2
& 0xfffd) != 0)
10277 i1new
= ((1ULL << 58) | (1ULL << 52)
10278 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10279 | (insn2
& (31ULL << 21)));
10282 case 57: // lxsd, lxssp
10283 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10285 i1new
= ((1ULL << 58) | (1ULL << 52)
10286 | ((40ULL | (insn2
& 3)) << 26)
10287 | (insn2
& (31ULL << 21)));
10290 case 61: // stxsd, stxssp, lxv, stxv
10291 if ((insn2
& 3) == 0)
10293 else if ((insn2
& 3) >= 2)
10295 if ((insn2
& 0xfffc) != 0)
10297 i1new
= ((1ULL << 58) | (1ULL << 52)
10298 | ((44ULL | (insn2
& 3)) << 26)
10299 | (insn2
& (31ULL << 21)));
10303 if ((insn2
& 0xfff0) != 0)
10305 i1new
= ((1ULL << 58) | (1ULL << 52)
10306 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10307 | (insn2
& (31ULL << 21)));
10312 if ((insn2
& 0xffff) != 0)
10314 i1new
= ((1ULL << 58) | (1ULL << 52)
10315 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10318 case 62: // std, stq
10319 if ((insn2
& 0xfffd) != 0)
10321 i1new
= ((1ULL << 58) | (1ULL << 52)
10322 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10323 | (insn2
& (31ULL << 21)));
10328 *pinsn2
= (uint64_t) nop
<< 32;
10332 // Perform a relocation.
10334 template<int size
, bool big_endian
>
10336 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10337 const Relocate_info
<size
, big_endian
>* relinfo
,
10339 Target_powerpc
* target
,
10340 Output_section
* os
,
10342 const unsigned char* preloc
,
10343 const Sized_symbol
<size
>* gsym
,
10344 const Symbol_value
<size
>* psymval
,
10345 unsigned char* view
,
10347 section_size_type view_size
)
10349 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10350 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10351 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10356 if (target
->replace_tls_get_addr(gsym
))
10357 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10359 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10360 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10361 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10363 case Track_tls::NOT_EXPECTED
:
10364 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10365 _("__tls_get_addr call lacks marker reloc"));
10367 case Track_tls::EXPECTED
:
10368 // We have already complained.
10370 case Track_tls::SKIP
:
10371 if (is_plt16_reloc
<size
>(r_type
)
10372 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10373 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10375 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10376 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10378 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10380 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10381 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10383 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10384 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10386 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10387 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10388 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10391 case Track_tls::NORMAL
:
10395 // Offset from start of insn to d-field reloc.
10396 const int d_offset
= big_endian
? 2 : 0;
10398 Powerpc_relobj
<size
, big_endian
>* const object
10399 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10401 bool has_stub_value
= false;
10402 bool localentry0
= false;
10403 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10404 bool has_plt_offset
10406 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10407 : object
->local_has_plt_offset(r_sym
));
10409 && !is_got_reloc(r_type
)
10410 && !is_plt16_reloc
<size
>(r_type
)
10411 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10412 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10413 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10414 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10415 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10416 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10417 && (!psymval
->is_ifunc_symbol()
10418 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10422 && target
->abiversion() >= 2
10423 && !parameters
->options().output_is_position_independent()
10424 && !is_branch_reloc
<size
>(r_type
))
10426 Address off
= target
->glink_section()->find_global_entry(gsym
);
10427 if (off
!= invalid_address
)
10429 value
= target
->glink_section()->global_entry_address() + off
;
10430 has_stub_value
= true;
10435 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10436 if (target
->stub_tables().size() == 1)
10437 stub_table
= target
->stub_tables()[0];
10438 if (stub_table
== NULL
10441 && !parameters
->options().output_is_position_independent()
10442 && !is_branch_reloc
<size
>(r_type
)))
10443 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10444 if (stub_table
== NULL
)
10446 // This is a ref from a data section to an ifunc symbol,
10447 // or a non-branch reloc for which we always want to use
10448 // one set of stubs for resolving function addresses.
10449 if (target
->stub_tables().size() != 0)
10450 stub_table
= target
->stub_tables()[0];
10452 if (stub_table
!= NULL
)
10454 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10456 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10457 rela
.get_r_addend());
10459 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10460 rela
.get_r_addend());
10463 value
= stub_table
->stub_address() + ent
->off_
;
10464 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10465 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10466 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10468 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10469 value
+= ent
->tocoff_
;
10473 && target
->is_tls_get_addr_opt(gsym
)))
10475 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10477 if (!(target
->power10_stubs()
10478 && target
->power10_stubs_auto()))
10481 else if (relnum
< reloc_count
- 1)
10483 Reltype
next_rela(preloc
+ reloc_size
);
10484 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10485 == elfcpp::R_PPC64_TOCSAVE
10486 && (next_rela
.get_r_offset()
10487 == rela
.get_r_offset() + 4))
10491 localentry0
= ent
->localentry0_
;
10492 has_stub_value
= true;
10496 // We don't care too much about bogus debug references to
10497 // non-local functions, but otherwise there had better be a plt
10498 // call stub or global entry stub as appropriate.
10499 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10502 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10503 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10504 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10506 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10508 value
= target
->plt_off(gsym
, &plt
);
10510 value
= target
->plt_off(object
, r_sym
, &plt
);
10511 value
+= plt
->address();
10515 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10516 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10517 value
-= (target
->got_section()->output_section()->address()
10518 + object
->toc_base_offset());
10520 else if (parameters
->options().output_is_position_independent())
10522 if (rela
.get_r_addend() >= 32768)
10524 unsigned int got2
= object
->got2_shndx();
10525 value
-= (object
->get_output_section_offset(got2
)
10526 + object
->output_section(got2
)->address()
10527 + rela
.get_r_addend());
10530 value
-= (target
->got_section()->address()
10531 + target
->got_section()->g_o_t());
10534 else if (!has_plt_offset
10535 && (is_plt16_reloc
<size
>(r_type
)
10536 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10537 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10539 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10540 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10541 r_type
= elfcpp::R_POWERPC_NONE
;
10543 else if (!has_plt_offset
10544 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10545 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10547 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10548 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10549 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10550 r_type
= elfcpp::R_POWERPC_NONE
;
10552 else if (is_got_reloc(r_type
))
10556 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10557 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10561 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10562 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10564 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10565 value
+= target
->got_section()->address();
10567 value
-= target
->got_section()->got_base_offset(object
);
10569 else if (r_type
== elfcpp::R_PPC64_TOC
)
10571 value
= (target
->got_section()->output_section()->address()
10572 + object
->toc_base_offset());
10574 else if (gsym
!= NULL
10575 && (r_type
== elfcpp::R_POWERPC_REL24
10576 || r_type
== elfcpp::R_PPC_PLTREL24
)
10581 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10582 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10583 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10584 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10586 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10587 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10588 if ((insn
& 1) != 0
10590 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10592 elfcpp::Swap
<32, big_endian
>::
10593 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10594 can_plt_call
= true;
10599 // If we don't have a branch and link followed by a nop,
10600 // we can't go via the plt because there is no place to
10601 // put a toc restoring instruction.
10602 // Unless we know we won't be returning.
10603 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10604 can_plt_call
= true;
10608 // g++ as of 20130507 emits self-calls without a
10609 // following nop. This is arguably wrong since we have
10610 // conflicting information. On the one hand a global
10611 // symbol and on the other a local call sequence, but
10612 // don't error for this special case.
10613 // It isn't possible to cheaply verify we have exactly
10614 // such a call. Allow all calls to the same section.
10616 Address code
= value
;
10617 if (gsym
->source() == Symbol::FROM_OBJECT
10618 && gsym
->object() == object
)
10620 unsigned int dest_shndx
= 0;
10621 if (target
->abiversion() < 2)
10623 Address addend
= rela
.get_r_addend();
10624 code
= psymval
->value(object
, addend
);
10625 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10626 &code
, &dest_shndx
);
10629 if (dest_shndx
== 0)
10630 dest_shndx
= gsym
->shndx(&is_ordinary
);
10631 ok
= dest_shndx
== relinfo
->data_shndx
;
10635 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10636 _("call lacks nop, can't restore toc; "
10637 "recompile with -fPIC"));
10643 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10644 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10645 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10646 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10647 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10649 // First instruction of a global dynamic sequence, arg setup insn.
10650 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10651 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10652 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10653 if (tls_type
== tls::TLSOPT_NONE
)
10654 got_type
= GOT_TYPE_TLSGD
;
10655 else if (tls_type
== tls::TLSOPT_TO_IE
)
10656 got_type
= GOT_TYPE_TPREL
;
10657 if (got_type
!= GOT_TYPE_STANDARD
)
10661 gold_assert(gsym
->has_got_offset(got_type
));
10662 value
= gsym
->got_offset(got_type
);
10666 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10667 value
= object
->local_got_offset(r_sym
, got_type
);
10669 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10670 value
+= target
->got_section()->address();
10672 value
-= target
->got_section()->got_base_offset(object
);
10674 if (tls_type
== tls::TLSOPT_TO_IE
)
10676 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10678 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10679 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10681 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10683 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10684 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10685 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10686 pinsn
& 0xffffffff);
10687 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10691 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10692 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10694 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10695 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10696 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10698 insn
|= 32 << 26; // lwz
10700 insn
|= 58 << 26; // ld
10701 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10703 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10704 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10707 else if (tls_type
== tls::TLSOPT_TO_LE
)
10709 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10711 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10712 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10714 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10715 // pla pcrel -> paddi r13
10716 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10717 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10718 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10719 pinsn
& 0xffffffff);
10720 r_type
= elfcpp::R_PPC64_TPREL34
;
10721 value
= psymval
->value(object
, rela
.get_r_addend());
10725 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10726 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10728 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10729 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10730 insn
&= (1 << 26) - (1 << 21); // extract rt
10734 insn
|= addis_0_13
;
10735 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10736 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10737 value
= psymval
->value(object
, rela
.get_r_addend());
10741 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10743 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10744 r_type
= elfcpp::R_POWERPC_NONE
;
10749 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10750 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10751 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10752 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10753 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10755 // First instruction of a local dynamic sequence, arg setup insn.
10756 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10757 if (tls_type
== tls::TLSOPT_NONE
)
10759 value
= target
->tlsld_got_offset();
10760 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10761 value
+= target
->got_section()->address();
10763 value
-= target
->got_section()->got_base_offset(object
);
10767 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10768 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10770 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10771 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10773 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10774 // pla pcrel -> paddi r13
10775 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10776 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10777 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10778 pinsn
& 0xffffffff);
10779 r_type
= elfcpp::R_PPC64_TPREL34
;
10780 value
= dtp_offset
;
10782 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10783 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10785 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10786 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10787 insn
&= (1 << 26) - (1 << 21); // extract rt
10791 insn
|= addis_0_13
;
10792 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10793 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10794 value
= dtp_offset
;
10798 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10800 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10801 r_type
= elfcpp::R_POWERPC_NONE
;
10805 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10806 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10807 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10808 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10809 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10811 // Accesses relative to a local dynamic sequence address,
10812 // no optimisation here.
10815 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10816 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10820 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10821 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10823 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10824 value
+= target
->got_section()->address();
10826 value
-= target
->got_section()->got_base_offset(object
);
10828 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10829 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10830 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10831 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10832 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10834 // First instruction of initial exec sequence.
10835 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10836 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10837 if (tls_type
== tls::TLSOPT_NONE
)
10841 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10842 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10846 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10847 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10849 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10850 value
+= target
->got_section()->address();
10852 value
-= target
->got_section()->got_base_offset(object
);
10856 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10857 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10859 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10860 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10862 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10863 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10864 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10865 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10866 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10867 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10868 pinsn
& 0xffffffff);
10869 r_type
= elfcpp::R_PPC64_TPREL34
;
10870 value
= psymval
->value(object
, rela
.get_r_addend());
10872 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10873 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10875 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10876 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10877 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10881 insn
|= addis_0_13
;
10882 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10883 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10884 value
= psymval
->value(object
, rela
.get_r_addend());
10888 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10890 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10891 r_type
= elfcpp::R_POWERPC_NONE
;
10895 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10896 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10898 // Second instruction of a global dynamic sequence,
10899 // the __tls_get_addr call
10900 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10901 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10902 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10903 if (tls_type
!= tls::TLSOPT_NONE
)
10905 if (tls_type
== tls::TLSOPT_TO_IE
)
10907 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10908 Insn insn
= add_3_3_13
;
10911 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10912 r_type
= elfcpp::R_POWERPC_NONE
;
10916 bool is_pcrel
= false;
10917 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10918 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10919 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10920 if (relnum
< reloc_count
- 1)
10922 Reltype
next_rela(preloc
+ reloc_size
);
10923 unsigned int r_type2
10924 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10925 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10926 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10927 && next_rela
.get_r_offset() == rela
.get_r_offset())
10930 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10933 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10934 r_type
= elfcpp::R_POWERPC_NONE
;
10938 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10939 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10941 value
= psymval
->value(object
, rela
.get_r_addend());
10944 this->skip_next_tls_get_addr_call();
10947 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10948 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10950 // Second instruction of a local dynamic sequence,
10951 // the __tls_get_addr call
10952 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10953 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10954 if (tls_type
== tls::TLSOPT_TO_LE
)
10956 bool is_pcrel
= false;
10957 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10958 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10959 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10960 if (relnum
< reloc_count
- 1)
10962 Reltype
next_rela(preloc
+ reloc_size
);
10963 unsigned int r_type2
10964 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10965 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10966 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10967 && next_rela
.get_r_offset() == rela
.get_r_offset())
10970 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10973 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10974 r_type
= elfcpp::R_POWERPC_NONE
;
10978 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10979 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10981 value
= dtp_offset
;
10983 this->skip_next_tls_get_addr_call();
10986 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10988 // Second instruction of an initial exec sequence
10989 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10990 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10991 if (tls_type
== tls::TLSOPT_TO_LE
)
10993 Address roff
= rela
.get_r_offset() & 3;
10994 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
10995 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10996 unsigned int reg
= size
== 32 ? 2 : 13;
10997 insn
= at_tls_transform(insn
, reg
);
10998 gold_assert(insn
!= 0);
11001 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11002 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11004 value
= psymval
->value(object
, rela
.get_r_addend());
11006 else if (roff
== 1)
11008 // For pcrel IE to LE we already have the full offset
11009 // and thus don't need an addi here. A nop or mr will do.
11010 if ((insn
& (0x3f << 26)) == 14 << 26)
11012 // Extract regs from addi rt,ra,si.
11013 unsigned int rt
= (insn
>> 21) & 0x1f;
11014 unsigned int ra
= (insn
>> 16) & 0x1f;
11019 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11020 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11021 insn
|= (31u << 26) | (444u << 1);
11024 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11025 r_type
= elfcpp::R_POWERPC_NONE
;
11029 else if (!has_stub_value
)
11031 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11032 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11034 // PLTCALL without plt entry => convert to direct call
11035 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11036 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11037 insn
= (insn
& 1) | b
;
11038 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11040 r_type
= elfcpp::R_PPC_PLTREL24
;
11041 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11042 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11044 r_type
= elfcpp::R_POWERPC_REL24
;
11046 Address addend
= 0;
11048 && (r_type
== elfcpp::R_PPC_PLTREL24
11049 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11050 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11051 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11052 addend
= rela
.get_r_addend();
11053 value
= psymval
->value(object
, addend
);
11054 unsigned int local_ent
= 0;
11055 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11057 if (target
->abiversion() >= 2)
11060 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11062 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11066 unsigned int dest_shndx
;
11067 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11068 &value
, &dest_shndx
);
11071 Address max_branch
= max_branch_delta
<size
>(r_type
);
11072 if (max_branch
!= 0
11073 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11075 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
11077 ? object
->ppc64_needs_toc(gsym
)
11078 : object
->ppc64_needs_toc(r_sym
)))))
11080 Stub_table
<size
, big_endian
>* stub_table
11081 = object
->stub_table(relinfo
->data_shndx
);
11082 if (stub_table
!= NULL
)
11084 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11085 = stub_table
->find_long_branch_entry(object
, value
);
11088 if (ent
->save_res_
)
11089 value
= (value
- target
->savres_section()->address()
11090 + stub_table
->branch_size());
11093 value
= (stub_table
->stub_address()
11094 + stub_table
->plt_size()
11097 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
11098 value
+= ent
->tocoff_
;
11100 has_stub_value
= true;
11104 if (!has_stub_value
)
11105 value
+= local_ent
;
11110 case elfcpp::R_PPC64_REL24_NOTOC
:
11114 case elfcpp::R_PPC64_REL64
:
11115 case elfcpp::R_POWERPC_REL32
:
11116 case elfcpp::R_POWERPC_REL24
:
11117 case elfcpp::R_PPC_PLTREL24
:
11118 case elfcpp::R_PPC_LOCAL24PC
:
11119 case elfcpp::R_POWERPC_REL16
:
11120 case elfcpp::R_POWERPC_REL16_LO
:
11121 case elfcpp::R_POWERPC_REL16_HI
:
11122 case elfcpp::R_POWERPC_REL16_HA
:
11123 case elfcpp::R_POWERPC_REL16DX_HA
:
11124 case elfcpp::R_PPC64_REL16_HIGH
:
11125 case elfcpp::R_PPC64_REL16_HIGHA
:
11126 case elfcpp::R_PPC64_REL16_HIGHER
:
11127 case elfcpp::R_PPC64_REL16_HIGHERA
:
11128 case elfcpp::R_PPC64_REL16_HIGHEST
:
11129 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11130 case elfcpp::R_POWERPC_REL14
:
11131 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11132 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11133 case elfcpp::R_PPC64_PCREL34
:
11134 case elfcpp::R_PPC64_GOT_PCREL34
:
11135 case elfcpp::R_PPC64_PLT_PCREL34
:
11136 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11137 case elfcpp::R_PPC64_PCREL28
:
11138 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11139 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11140 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11141 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11142 case elfcpp::R_PPC64_REL16_HIGHER34
:
11143 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11144 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11145 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11149 case elfcpp::R_PPC64_TOC16
:
11150 case elfcpp::R_PPC64_TOC16_LO
:
11151 case elfcpp::R_PPC64_TOC16_HI
:
11152 case elfcpp::R_PPC64_TOC16_HA
:
11153 case elfcpp::R_PPC64_TOC16_DS
:
11154 case elfcpp::R_PPC64_TOC16_LO_DS
:
11155 // Subtract the TOC base address.
11156 value
-= (target
->got_section()->output_section()->address()
11157 + object
->toc_base_offset());
11160 case elfcpp::R_POWERPC_SECTOFF
:
11161 case elfcpp::R_POWERPC_SECTOFF_LO
:
11162 case elfcpp::R_POWERPC_SECTOFF_HI
:
11163 case elfcpp::R_POWERPC_SECTOFF_HA
:
11164 case elfcpp::R_PPC64_SECTOFF_DS
:
11165 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11167 value
-= os
->address();
11170 case elfcpp::R_PPC64_TPREL16_DS
:
11171 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11172 case elfcpp::R_PPC64_TPREL16_HIGH
:
11173 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11175 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11178 case elfcpp::R_POWERPC_TPREL16
:
11179 case elfcpp::R_POWERPC_TPREL16_LO
:
11180 case elfcpp::R_POWERPC_TPREL16_HI
:
11181 case elfcpp::R_POWERPC_TPREL16_HA
:
11182 case elfcpp::R_POWERPC_TPREL
:
11183 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11184 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11185 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11186 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11187 case elfcpp::R_PPC64_TPREL34
:
11188 // tls symbol values are relative to tls_segment()->vaddr()
11189 value
-= tp_offset
;
11192 case elfcpp::R_PPC64_DTPREL16_DS
:
11193 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11194 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11195 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11196 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11197 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11199 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11200 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11203 case elfcpp::R_POWERPC_DTPREL16
:
11204 case elfcpp::R_POWERPC_DTPREL16_LO
:
11205 case elfcpp::R_POWERPC_DTPREL16_HI
:
11206 case elfcpp::R_POWERPC_DTPREL16_HA
:
11207 case elfcpp::R_POWERPC_DTPREL
:
11208 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11209 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11210 case elfcpp::R_PPC64_DTPREL34
:
11211 // tls symbol values are relative to tls_segment()->vaddr()
11212 value
-= dtp_offset
;
11215 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11217 value
+= object
->ppc64_local_entry_offset(gsym
);
11219 value
+= object
->ppc64_local_entry_offset(r_sym
);
11226 Insn branch_bit
= 0;
11229 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11230 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11231 branch_bit
= 1 << 21;
11233 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11234 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11236 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11237 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11238 insn
&= ~(1 << 21);
11239 insn
|= branch_bit
;
11240 if (this->is_isa_v2
)
11242 // Set 'a' bit. This is 0b00010 in BO field for branch
11243 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11244 // for branch on CTR insns (BO == 1a00t or 1a01t).
11245 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11246 insn
|= 0x02 << 21;
11247 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11248 insn
|= 0x08 << 21;
11254 // Invert 'y' bit if not the default.
11255 if (static_cast<Signed_address
>(value
) < 0)
11258 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11262 case elfcpp::R_POWERPC_PLT16_HA
:
11264 && !parameters
->options().output_is_position_independent())
11266 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11267 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11269 // Convert addis to lis.
11270 if ((insn
& (0x3f << 26)) == 15u << 26
11271 && (insn
& (0x1f << 16)) != 0)
11273 insn
&= ~(0x1f << 16);
11274 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11284 ? relative_value_is_known(gsym
)
11285 : relative_value_is_known(psymval
))
11290 uint64_t pinsn
, pinsn2
;
11297 // Multi-instruction sequences that access the GOT/TOC can
11298 // be optimized, eg.
11299 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11300 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11302 // addis ra,r2,0; addi rb,ra,x@toc@l;
11303 // to nop; addi rb,r2,x@toc;
11304 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11305 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11306 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11307 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11308 case elfcpp::R_POWERPC_GOT16_HA
:
11309 case elfcpp::R_PPC64_TOC16_HA
:
11310 if (size
== 64 && parameters
->options().toc_optimize())
11312 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11313 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11314 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11315 && object
->make_toc_relative(target
, &value
))
11316 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11317 && object
->make_got_relative(target
, psymval
,
11318 rela
.get_r_addend(),
11321 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11322 == ((15u << 26) | (2 << 16)));
11324 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11325 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11326 && value
+ 0x8000 < 0x10000)
11328 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11334 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11335 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11336 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11337 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11338 case elfcpp::R_POWERPC_GOT16_LO
:
11339 case elfcpp::R_PPC64_GOT16_LO_DS
:
11340 case elfcpp::R_PPC64_TOC16_LO
:
11341 case elfcpp::R_PPC64_TOC16_LO_DS
:
11342 if (size
== 64 && parameters
->options().toc_optimize())
11344 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11345 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11346 bool changed
= false;
11347 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11348 && object
->make_toc_relative(target
, &value
))
11349 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11350 && object
->make_got_relative(target
, psymval
,
11351 rela
.get_r_addend(),
11354 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11355 insn
^= (14u << 26) ^ (58u << 26);
11356 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11359 if (ok_lo_toc_insn(insn
, r_type
)
11360 && value
+ 0x8000 < 0x10000)
11362 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11364 // Transform addic to addi when we change reg.
11365 insn
&= ~((0x3f << 26) | (0x1f << 16));
11366 insn
|= (14u << 26) | (2 << 16);
11370 insn
&= ~(0x1f << 16);
11376 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11380 case elfcpp::R_PPC64_GOT_PCREL34
:
11381 if (size
== 64 && parameters
->options().toc_optimize())
11383 iview
= reinterpret_cast<Insn
*>(view
);
11384 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11386 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11387 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11388 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11391 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11393 if (relval
+ (1ULL << 33) < 1ULL << 34)
11396 // Replace with paddi
11397 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11398 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11399 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11400 pinsn
& 0xffffffff);
11406 case elfcpp::R_PPC64_PCREL34
:
11409 iview
= reinterpret_cast<Insn
*>(view
);
11410 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11412 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11413 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11414 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11415 | (14ULL << 26) /* paddi */))
11419 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11420 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11421 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11422 if (relnum
>= reloc_count
- 1)
11425 Reltype
next_rela(preloc
+ reloc_size
);
11426 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11427 != elfcpp::R_PPC64_PCREL_OPT
)
11428 || next_rela
.get_r_offset() != rela
.get_r_offset())
11431 Address off
= next_rela
.get_r_addend();
11433 off
= 8; // zero means next insn.
11434 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11437 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11438 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11440 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11442 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11444 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11445 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11446 pinsn
& 0xffffffff);
11447 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11452 case elfcpp::R_POWERPC_TPREL16_HA
:
11453 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11455 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11456 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11461 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11463 // R_PPC_TLSGD, R_PPC_TLSLD
11466 case elfcpp::R_POWERPC_TPREL16_LO
:
11467 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11469 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11470 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11471 insn
&= ~(0x1f << 16);
11472 insn
|= (size
== 32 ? 2 : 13) << 16;
11473 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11477 case elfcpp::R_PPC64_ENTRY
:
11480 value
= (target
->got_section()->output_section()->address()
11481 + object
->toc_base_offset());
11482 if (value
+ 0x80008000 <= 0xffffffff
11483 && !parameters
->options().output_is_position_independent())
11485 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11486 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11487 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11489 if ((insn1
& ~0xfffc) == ld_2_12
11490 && insn2
== add_2_2_12
)
11492 insn1
= lis_2
+ ha(value
);
11493 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11494 insn2
= addi_2_2
+ l(value
);
11495 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11502 if (value
+ 0x80008000 <= 0xffffffff)
11504 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11505 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11506 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11508 if ((insn1
& ~0xfffc) == ld_2_12
11509 && insn2
== add_2_2_12
)
11511 insn1
= addis_2_12
+ ha(value
);
11512 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11513 insn2
= addi_2_2
+ l(value
);
11514 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11522 case elfcpp::R_POWERPC_REL16_LO
:
11523 // If we are generating a non-PIC executable, edit
11524 // 0: addis 2,12,.TOC.-0b@ha
11525 // addi 2,2,.TOC.-0b@l
11526 // used by ELFv2 global entry points to set up r2, to
11528 // addi 2,2,.TOC.@l
11529 // if .TOC. is in range. */
11531 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11534 && target
->abiversion() >= 2
11535 && !parameters
->options().output_is_position_independent()
11536 && rela
.get_r_addend() == d_offset
+ 4
11538 && strcmp(gsym
->name(), ".TOC.") == 0)
11540 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11541 Reltype
prev_rela(preloc
- reloc_size
);
11542 if ((prev_rela
.get_r_info()
11543 == elfcpp::elf_r_info
<size
>(r_sym
,
11544 elfcpp::R_POWERPC_REL16_HA
))
11545 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11546 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11548 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11549 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11550 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11552 if ((insn1
& 0xffff0000) == addis_2_12
11553 && (insn2
& 0xffff0000) == addi_2_2
)
11555 insn1
= lis_2
+ ha(value
+ address
- 4);
11556 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11557 insn2
= addi_2_2
+ l(value
+ address
- 4);
11558 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11561 relinfo
->rr
->set_strategy(relnum
- 1,
11562 Relocatable_relocs::RELOC_SPECIAL
);
11563 relinfo
->rr
->set_strategy(relnum
,
11564 Relocatable_relocs::RELOC_SPECIAL
);
11574 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11575 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11578 case elfcpp::R_POWERPC_ADDR32
:
11579 case elfcpp::R_POWERPC_UADDR32
:
11581 overflow
= Reloc::CHECK_BITFIELD
;
11584 case elfcpp::R_POWERPC_REL32
:
11585 case elfcpp::R_POWERPC_REL16DX_HA
:
11587 overflow
= Reloc::CHECK_SIGNED
;
11590 case elfcpp::R_POWERPC_UADDR16
:
11591 overflow
= Reloc::CHECK_BITFIELD
;
11594 case elfcpp::R_POWERPC_ADDR16
:
11595 // We really should have three separate relocations,
11596 // one for 16-bit data, one for insns with 16-bit signed fields,
11597 // and one for insns with 16-bit unsigned fields.
11598 overflow
= Reloc::CHECK_BITFIELD
;
11599 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11600 overflow
= Reloc::CHECK_LOW_INSN
;
11603 case elfcpp::R_POWERPC_ADDR16_HI
:
11604 case elfcpp::R_POWERPC_ADDR16_HA
:
11605 case elfcpp::R_POWERPC_GOT16_HI
:
11606 case elfcpp::R_POWERPC_GOT16_HA
:
11607 case elfcpp::R_POWERPC_PLT16_HI
:
11608 case elfcpp::R_POWERPC_PLT16_HA
:
11609 case elfcpp::R_POWERPC_SECTOFF_HI
:
11610 case elfcpp::R_POWERPC_SECTOFF_HA
:
11611 case elfcpp::R_PPC64_TOC16_HI
:
11612 case elfcpp::R_PPC64_TOC16_HA
:
11613 case elfcpp::R_PPC64_PLTGOT16_HI
:
11614 case elfcpp::R_PPC64_PLTGOT16_HA
:
11615 case elfcpp::R_POWERPC_TPREL16_HI
:
11616 case elfcpp::R_POWERPC_TPREL16_HA
:
11617 case elfcpp::R_POWERPC_DTPREL16_HI
:
11618 case elfcpp::R_POWERPC_DTPREL16_HA
:
11619 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11620 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11621 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11622 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11623 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11624 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11625 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11626 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11627 case elfcpp::R_POWERPC_REL16_HI
:
11628 case elfcpp::R_POWERPC_REL16_HA
:
11630 overflow
= Reloc::CHECK_HIGH_INSN
;
11633 case elfcpp::R_POWERPC_REL16
:
11634 case elfcpp::R_PPC64_TOC16
:
11635 case elfcpp::R_POWERPC_GOT16
:
11636 case elfcpp::R_POWERPC_SECTOFF
:
11637 case elfcpp::R_POWERPC_TPREL16
:
11638 case elfcpp::R_POWERPC_DTPREL16
:
11639 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11640 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11641 case elfcpp::R_POWERPC_GOT_TPREL16
:
11642 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11643 overflow
= Reloc::CHECK_LOW_INSN
;
11646 case elfcpp::R_PPC64_REL24_NOTOC
:
11650 case elfcpp::R_POWERPC_ADDR24
:
11651 case elfcpp::R_POWERPC_ADDR14
:
11652 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11653 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11654 case elfcpp::R_PPC64_ADDR16_DS
:
11655 case elfcpp::R_POWERPC_REL24
:
11656 case elfcpp::R_PPC_PLTREL24
:
11657 case elfcpp::R_PPC_LOCAL24PC
:
11658 case elfcpp::R_PPC64_TPREL16_DS
:
11659 case elfcpp::R_PPC64_DTPREL16_DS
:
11660 case elfcpp::R_PPC64_TOC16_DS
:
11661 case elfcpp::R_PPC64_GOT16_DS
:
11662 case elfcpp::R_PPC64_SECTOFF_DS
:
11663 case elfcpp::R_POWERPC_REL14
:
11664 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11665 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11666 case elfcpp::R_PPC64_D34
:
11667 case elfcpp::R_PPC64_PCREL34
:
11668 case elfcpp::R_PPC64_GOT_PCREL34
:
11669 case elfcpp::R_PPC64_PLT_PCREL34
:
11670 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11671 case elfcpp::R_PPC64_D28
:
11672 case elfcpp::R_PPC64_PCREL28
:
11673 case elfcpp::R_PPC64_TPREL34
:
11674 case elfcpp::R_PPC64_DTPREL34
:
11675 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11676 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11677 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11678 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11679 overflow
= Reloc::CHECK_SIGNED
;
11683 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11686 if (overflow
== Reloc::CHECK_LOW_INSN
11687 || overflow
== Reloc::CHECK_HIGH_INSN
)
11689 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11691 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11692 overflow
= Reloc::CHECK_BITFIELD
;
11693 else if (overflow
== Reloc::CHECK_LOW_INSN
11694 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11695 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11696 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11697 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11698 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11699 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11700 overflow
= Reloc::CHECK_UNSIGNED
;
11702 overflow
= Reloc::CHECK_SIGNED
;
11705 bool maybe_dq_reloc
= false;
11706 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11707 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11710 case elfcpp::R_POWERPC_NONE
:
11711 case elfcpp::R_POWERPC_TLS
:
11712 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11713 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11714 case elfcpp::R_POWERPC_PLTSEQ
:
11715 case elfcpp::R_POWERPC_PLTCALL
:
11716 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11717 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11718 case elfcpp::R_PPC64_PCREL_OPT
:
11721 case elfcpp::R_PPC64_ADDR64
:
11722 case elfcpp::R_PPC64_REL64
:
11723 case elfcpp::R_PPC64_TOC
:
11724 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11725 Reloc::addr64(view
, value
);
11728 case elfcpp::R_POWERPC_TPREL
:
11729 case elfcpp::R_POWERPC_DTPREL
:
11731 Reloc::addr64(view
, value
);
11733 status
= Reloc::addr32(view
, value
, overflow
);
11736 case elfcpp::R_PPC64_UADDR64
:
11737 Reloc::addr64_u(view
, value
);
11740 case elfcpp::R_POWERPC_ADDR32
:
11741 status
= Reloc::addr32(view
, value
, overflow
);
11744 case elfcpp::R_POWERPC_REL32
:
11745 case elfcpp::R_POWERPC_UADDR32
:
11746 status
= Reloc::addr32_u(view
, value
, overflow
);
11749 case elfcpp::R_PPC64_REL24_NOTOC
:
11751 goto unsupp
; // R_PPC_EMB_RELSDA
11753 case elfcpp::R_POWERPC_ADDR24
:
11754 case elfcpp::R_POWERPC_REL24
:
11755 case elfcpp::R_PPC_PLTREL24
:
11756 case elfcpp::R_PPC_LOCAL24PC
:
11757 status
= Reloc::addr24(view
, value
, overflow
);
11760 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11761 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11762 case elfcpp::R_POWERPC_GOT_TPREL16
:
11763 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11766 // On ppc64 these are all ds form
11767 maybe_dq_reloc
= true;
11771 case elfcpp::R_POWERPC_ADDR16
:
11772 case elfcpp::R_POWERPC_REL16
:
11773 case elfcpp::R_PPC64_TOC16
:
11774 case elfcpp::R_POWERPC_GOT16
:
11775 case elfcpp::R_POWERPC_SECTOFF
:
11776 case elfcpp::R_POWERPC_TPREL16
:
11777 case elfcpp::R_POWERPC_DTPREL16
:
11778 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11779 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11780 case elfcpp::R_POWERPC_ADDR16_LO
:
11781 case elfcpp::R_POWERPC_REL16_LO
:
11782 case elfcpp::R_PPC64_TOC16_LO
:
11783 case elfcpp::R_POWERPC_GOT16_LO
:
11784 case elfcpp::R_POWERPC_PLT16_LO
:
11785 case elfcpp::R_POWERPC_SECTOFF_LO
:
11786 case elfcpp::R_POWERPC_TPREL16_LO
:
11787 case elfcpp::R_POWERPC_DTPREL16_LO
:
11788 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11789 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11791 status
= Reloc::addr16(view
, value
, overflow
);
11793 maybe_dq_reloc
= true;
11796 case elfcpp::R_POWERPC_UADDR16
:
11797 status
= Reloc::addr16_u(view
, value
, overflow
);
11800 case elfcpp::R_PPC64_ADDR16_HIGH
:
11801 case elfcpp::R_PPC64_TPREL16_HIGH
:
11802 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11804 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11807 case elfcpp::R_POWERPC_ADDR16_HI
:
11808 case elfcpp::R_POWERPC_REL16_HI
:
11809 case elfcpp::R_PPC64_REL16_HIGH
:
11810 case elfcpp::R_PPC64_TOC16_HI
:
11811 case elfcpp::R_POWERPC_GOT16_HI
:
11812 case elfcpp::R_POWERPC_PLT16_HI
:
11813 case elfcpp::R_POWERPC_SECTOFF_HI
:
11814 case elfcpp::R_POWERPC_TPREL16_HI
:
11815 case elfcpp::R_POWERPC_DTPREL16_HI
:
11816 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11817 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11818 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11819 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11820 Reloc::addr16_hi(view
, value
);
11823 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11824 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11825 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11827 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11830 case elfcpp::R_POWERPC_ADDR16_HA
:
11831 case elfcpp::R_POWERPC_REL16_HA
:
11832 case elfcpp::R_PPC64_REL16_HIGHA
:
11833 case elfcpp::R_PPC64_TOC16_HA
:
11834 case elfcpp::R_POWERPC_GOT16_HA
:
11835 case elfcpp::R_POWERPC_PLT16_HA
:
11836 case elfcpp::R_POWERPC_SECTOFF_HA
:
11837 case elfcpp::R_POWERPC_TPREL16_HA
:
11838 case elfcpp::R_POWERPC_DTPREL16_HA
:
11839 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11840 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11841 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11842 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11843 Reloc::addr16_ha(view
, value
);
11846 case elfcpp::R_POWERPC_REL16DX_HA
:
11847 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11850 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11852 // R_PPC_EMB_NADDR16_LO
11855 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11856 case elfcpp::R_PPC64_REL16_HIGHER
:
11857 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11858 Reloc::addr16_hi2(view
, value
);
11861 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11863 // R_PPC_EMB_NADDR16_HI
11866 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11867 case elfcpp::R_PPC64_REL16_HIGHERA
:
11868 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11869 Reloc::addr16_ha2(view
, value
);
11872 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11874 // R_PPC_EMB_NADDR16_HA
11877 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11878 case elfcpp::R_PPC64_REL16_HIGHEST
:
11879 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11880 Reloc::addr16_hi3(view
, value
);
11883 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11885 // R_PPC_EMB_SDAI16
11888 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11889 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11890 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11891 Reloc::addr16_ha3(view
, value
);
11894 case elfcpp::R_PPC64_DTPREL16_DS
:
11895 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11897 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11900 case elfcpp::R_PPC64_TPREL16_DS
:
11901 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11903 // R_PPC_TLSGD, R_PPC_TLSLD
11906 case elfcpp::R_PPC64_ADDR16_DS
:
11907 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11908 case elfcpp::R_PPC64_TOC16_DS
:
11909 case elfcpp::R_PPC64_TOC16_LO_DS
:
11910 case elfcpp::R_PPC64_GOT16_DS
:
11911 case elfcpp::R_PPC64_GOT16_LO_DS
:
11912 case elfcpp::R_PPC64_PLT16_LO_DS
:
11913 case elfcpp::R_PPC64_SECTOFF_DS
:
11914 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11915 maybe_dq_reloc
= true;
11918 case elfcpp::R_POWERPC_ADDR14
:
11919 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11920 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11921 case elfcpp::R_POWERPC_REL14
:
11922 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11923 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11924 status
= Reloc::addr14(view
, value
, overflow
);
11927 case elfcpp::R_POWERPC_COPY
:
11928 case elfcpp::R_POWERPC_GLOB_DAT
:
11929 case elfcpp::R_POWERPC_JMP_SLOT
:
11930 case elfcpp::R_POWERPC_RELATIVE
:
11931 case elfcpp::R_POWERPC_DTPMOD
:
11932 case elfcpp::R_PPC64_JMP_IREL
:
11933 case elfcpp::R_POWERPC_IRELATIVE
:
11934 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11935 _("unexpected reloc %u in object file"),
11939 case elfcpp::R_PPC64_TOCSAVE
:
11945 Symbol_location loc
;
11946 loc
.object
= relinfo
->object
;
11947 loc
.shndx
= relinfo
->data_shndx
;
11948 loc
.offset
= rela
.get_r_offset();
11949 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
11950 if (tocsave
->find(loc
) != tocsave
->end())
11952 // If we've generated plt calls using this tocsave, then
11953 // the nop needs to be changed to save r2.
11954 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11955 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11956 elfcpp::Swap
<32, big_endian
>::
11957 writeval(iview
, std_2_1
+ target
->stk_toc());
11962 case elfcpp::R_PPC_EMB_SDA2I16
:
11963 case elfcpp::R_PPC_EMB_SDA2REL
:
11966 // R_PPC64_TLSGD, R_PPC64_TLSLD
11969 case elfcpp::R_PPC64_D34
:
11970 case elfcpp::R_PPC64_D34_LO
:
11971 case elfcpp::R_PPC64_PCREL34
:
11972 case elfcpp::R_PPC64_GOT_PCREL34
:
11973 case elfcpp::R_PPC64_PLT_PCREL34
:
11974 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11975 case elfcpp::R_PPC64_TPREL34
:
11976 case elfcpp::R_PPC64_DTPREL34
:
11977 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11978 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11979 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11980 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11983 status
= Reloc::addr34(view
, value
, overflow
);
11986 case elfcpp::R_PPC64_D34_HI30
:
11989 Reloc::addr34_hi(view
, value
);
11992 case elfcpp::R_PPC64_D34_HA30
:
11995 Reloc::addr34_ha(view
, value
);
11998 case elfcpp::R_PPC64_D28
:
11999 case elfcpp::R_PPC64_PCREL28
:
12002 status
= Reloc::addr28(view
, value
, overflow
);
12005 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12006 case elfcpp::R_PPC64_REL16_HIGHER34
:
12009 Reloc::addr16_higher34(view
, value
);
12012 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12013 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12016 Reloc::addr16_highera34(view
, value
);
12019 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12020 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12023 Reloc::addr16_highest34(view
, value
);
12026 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12027 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12030 Reloc::addr16_highesta34(view
, value
);
12033 case elfcpp::R_POWERPC_PLT32
:
12034 case elfcpp::R_POWERPC_PLTREL32
:
12035 case elfcpp::R_PPC_SDAREL16
:
12036 case elfcpp::R_POWERPC_ADDR30
:
12037 case elfcpp::R_PPC64_PLT64
:
12038 case elfcpp::R_PPC64_PLTREL64
:
12039 case elfcpp::R_PPC64_PLTGOT16
:
12040 case elfcpp::R_PPC64_PLTGOT16_LO
:
12041 case elfcpp::R_PPC64_PLTGOT16_HI
:
12042 case elfcpp::R_PPC64_PLTGOT16_HA
:
12043 case elfcpp::R_PPC64_PLTGOT16_DS
:
12044 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12045 case elfcpp::R_PPC_TOC16
:
12048 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12049 _("unsupported reloc %u"),
12054 if (maybe_dq_reloc
)
12057 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12059 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12060 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12061 && (insn
& 3) == 1))
12062 status
= Reloc::addr16_dq(view
, value
, overflow
);
12063 else if (size
== 64
12064 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12065 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12066 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12067 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12068 status
= Reloc::addr16_ds(view
, value
, overflow
);
12070 status
= Reloc::addr16(view
, value
, overflow
);
12073 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12076 && gsym
->is_undefined()
12077 && is_branch_reloc
<size
>(r_type
))))
12079 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12080 _("relocation overflow"));
12081 if (has_stub_value
)
12082 gold_info(_("try relinking with a smaller --stub-group-size"));
12088 // Relocate section data.
12090 template<int size
, bool big_endian
>
12092 Target_powerpc
<size
, big_endian
>::relocate_section(
12093 const Relocate_info
<size
, big_endian
>* relinfo
,
12094 unsigned int sh_type
,
12095 const unsigned char* prelocs
,
12096 size_t reloc_count
,
12097 Output_section
* output_section
,
12098 bool needs_special_offset_handling
,
12099 unsigned char* view
,
12101 section_size_type view_size
,
12102 const Reloc_symbol_changes
* reloc_symbol_changes
)
12104 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12105 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12106 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12107 Powerpc_comdat_behavior
;
12108 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12111 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12113 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12114 Powerpc_comdat_behavior
, Classify_reloc
>(
12120 needs_special_offset_handling
,
12124 reloc_symbol_changes
);
12127 template<int size
, bool big_endian
>
12128 class Powerpc_scan_relocatable_reloc
12131 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12132 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12133 static const int sh_type
= elfcpp::SHT_RELA
;
12135 // Return the symbol referred to by the relocation.
12136 static inline unsigned int
12137 get_r_sym(const Reltype
* reloc
)
12138 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12140 // Return the type of the relocation.
12141 static inline unsigned int
12142 get_r_type(const Reltype
* reloc
)
12143 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12145 // Return the strategy to use for a local symbol which is not a
12146 // section symbol, given the relocation type.
12147 inline Relocatable_relocs::Reloc_strategy
12148 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12150 if (r_type
== 0 && r_sym
== 0)
12151 return Relocatable_relocs::RELOC_DISCARD
;
12152 return Relocatable_relocs::RELOC_COPY
;
12155 // Return the strategy to use for a local symbol which is a section
12156 // symbol, given the relocation type.
12157 inline Relocatable_relocs::Reloc_strategy
12158 local_section_strategy(unsigned int, Relobj
*)
12160 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12163 // Return the strategy to use for a global symbol, given the
12164 // relocation type, the object, and the symbol index.
12165 inline Relocatable_relocs::Reloc_strategy
12166 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12169 && (r_type
== elfcpp::R_PPC_PLTREL24
12170 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12171 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12172 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12173 return Relocatable_relocs::RELOC_SPECIAL
;
12174 return Relocatable_relocs::RELOC_COPY
;
12178 // Scan the relocs during a relocatable link.
12180 template<int size
, bool big_endian
>
12182 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12183 Symbol_table
* symtab
,
12185 Sized_relobj_file
<size
, big_endian
>* object
,
12186 unsigned int data_shndx
,
12187 unsigned int sh_type
,
12188 const unsigned char* prelocs
,
12189 size_t reloc_count
,
12190 Output_section
* output_section
,
12191 bool needs_special_offset_handling
,
12192 size_t local_symbol_count
,
12193 const unsigned char* plocal_symbols
,
12194 Relocatable_relocs
* rr
)
12196 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12198 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12200 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12208 needs_special_offset_handling
,
12209 local_symbol_count
,
12214 // Scan the relocs for --emit-relocs.
12216 template<int size
, bool big_endian
>
12218 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12219 Symbol_table
* symtab
,
12221 Sized_relobj_file
<size
, big_endian
>* object
,
12222 unsigned int data_shndx
,
12223 unsigned int sh_type
,
12224 const unsigned char* prelocs
,
12225 size_t reloc_count
,
12226 Output_section
* output_section
,
12227 bool needs_special_offset_handling
,
12228 size_t local_symbol_count
,
12229 const unsigned char* plocal_syms
,
12230 Relocatable_relocs
* rr
)
12232 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12234 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12235 Emit_relocs_strategy
;
12237 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12239 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12247 needs_special_offset_handling
,
12248 local_symbol_count
,
12253 // Emit relocations for a section.
12254 // This is a modified version of the function by the same name in
12255 // target-reloc.h. Using relocate_special_relocatable for
12256 // R_PPC_PLTREL24 would require duplication of the entire body of the
12257 // loop, so we may as well duplicate the whole thing.
12259 template<int size
, bool big_endian
>
12261 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12262 const Relocate_info
<size
, big_endian
>* relinfo
,
12263 unsigned int sh_type
,
12264 const unsigned char* prelocs
,
12265 size_t reloc_count
,
12266 Output_section
* output_section
,
12267 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12269 Address view_address
,
12271 unsigned char* reloc_view
,
12272 section_size_type reloc_view_size
)
12274 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12276 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12277 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12278 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12279 // Offset from start of insn to d-field reloc.
12280 const int d_offset
= big_endian
? 2 : 0;
12282 Powerpc_relobj
<size
, big_endian
>* const object
12283 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12284 const unsigned int local_count
= object
->local_symbol_count();
12285 unsigned int got2_shndx
= object
->got2_shndx();
12286 Address got2_addend
= 0;
12287 if (got2_shndx
!= 0)
12289 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12290 gold_assert(got2_addend
!= invalid_address
);
12293 const bool relocatable
= parameters
->options().relocatable();
12295 unsigned char* pwrite
= reloc_view
;
12296 bool zap_next
= false;
12297 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12299 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12300 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12303 Reltype
reloc(prelocs
);
12304 Reltype_write
reloc_write(pwrite
);
12306 Address offset
= reloc
.get_r_offset();
12307 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12308 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12309 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12310 const unsigned int orig_r_sym
= r_sym
;
12311 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12312 = reloc
.get_r_addend();
12313 const Symbol
* gsym
= NULL
;
12317 // We could arrange to discard these and other relocs for
12318 // tls optimised sequences in the strategy methods, but for
12319 // now do as BFD ld does.
12320 r_type
= elfcpp::R_POWERPC_NONE
;
12324 // Get the new symbol index.
12325 Output_section
* os
= NULL
;
12326 if (r_sym
< local_count
)
12330 case Relocatable_relocs::RELOC_COPY
:
12331 case Relocatable_relocs::RELOC_SPECIAL
:
12334 r_sym
= object
->symtab_index(r_sym
);
12335 gold_assert(r_sym
!= -1U);
12339 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12341 // We are adjusting a section symbol. We need to find
12342 // the symbol table index of the section symbol for
12343 // the output section corresponding to input section
12344 // in which this symbol is defined.
12345 gold_assert(r_sym
< local_count
);
12347 unsigned int shndx
=
12348 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12349 gold_assert(is_ordinary
);
12350 os
= object
->output_section(shndx
);
12351 gold_assert(os
!= NULL
);
12352 gold_assert(os
->needs_symtab_index());
12353 r_sym
= os
->symtab_index();
12358 gold_unreachable();
12363 gsym
= object
->global_symbol(r_sym
);
12364 gold_assert(gsym
!= NULL
);
12365 if (gsym
->is_forwarder())
12366 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12368 gold_assert(gsym
->has_symtab_index());
12369 r_sym
= gsym
->symtab_index();
12372 // Get the new offset--the location in the output section where
12373 // this relocation should be applied.
12374 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12375 offset
+= offset_in_output_section
;
12378 section_offset_type sot_offset
=
12379 convert_types
<section_offset_type
, Address
>(offset
);
12380 section_offset_type new_sot_offset
=
12381 output_section
->output_offset(object
, relinfo
->data_shndx
,
12383 gold_assert(new_sot_offset
!= -1);
12384 offset
= new_sot_offset
;
12387 // In an object file, r_offset is an offset within the section.
12388 // In an executable or dynamic object, generated by
12389 // --emit-relocs, r_offset is an absolute address.
12392 offset
+= view_address
;
12393 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12394 offset
-= offset_in_output_section
;
12397 // Handle the reloc addend based on the strategy.
12398 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12400 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12402 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12403 addend
= psymval
->value(object
, addend
);
12404 // In a relocatable link, the symbol value is relative to
12405 // the start of the output section. For a non-relocatable
12406 // link, we need to adjust the addend.
12409 gold_assert(os
!= NULL
);
12410 addend
-= os
->address();
12413 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12417 if (addend
>= 32768)
12418 addend
+= got2_addend
;
12420 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12422 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12423 addend
-= d_offset
;
12425 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12427 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12428 addend
-= d_offset
+ 4;
12432 gold_unreachable();
12436 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12437 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12438 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12439 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12441 // First instruction of a global dynamic sequence,
12443 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12444 switch (this->optimize_tls_gd(final
))
12446 case tls::TLSOPT_TO_IE
:
12447 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12448 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12450 case tls::TLSOPT_TO_LE
:
12451 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12452 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12453 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12456 r_type
= elfcpp::R_POWERPC_NONE
;
12457 offset
-= d_offset
;
12464 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12465 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12466 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12467 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12469 // First instruction of a local dynamic sequence,
12471 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12473 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12474 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12476 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12477 const Output_section
* os
= relinfo
->layout
->tls_segment()
12479 gold_assert(os
!= NULL
);
12480 gold_assert(os
->needs_symtab_index());
12481 r_sym
= os
->symtab_index();
12482 addend
= dtp_offset
;
12486 r_type
= elfcpp::R_POWERPC_NONE
;
12487 offset
-= d_offset
;
12491 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12492 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12493 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12494 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12496 // First instruction of initial exec sequence.
12497 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12498 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12500 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12501 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12502 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12505 r_type
= elfcpp::R_POWERPC_NONE
;
12506 offset
-= d_offset
;
12510 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12511 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12513 // Second instruction of a global dynamic sequence,
12514 // the __tls_get_addr call
12515 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12516 switch (this->optimize_tls_gd(final
))
12518 case tls::TLSOPT_TO_IE
:
12519 r_type
= elfcpp::R_POWERPC_NONE
;
12522 case tls::TLSOPT_TO_LE
:
12523 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12524 offset
+= d_offset
;
12531 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12532 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12534 // Second instruction of a local dynamic sequence,
12535 // the __tls_get_addr call
12536 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12538 const Output_section
* os
= relinfo
->layout
->tls_segment()
12540 gold_assert(os
!= NULL
);
12541 gold_assert(os
->needs_symtab_index());
12542 r_sym
= os
->symtab_index();
12543 addend
= dtp_offset
;
12544 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12545 offset
+= d_offset
;
12549 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12551 // Second instruction of an initial exec sequence
12552 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12553 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12555 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12556 offset
+= d_offset
;
12561 reloc_write
.put_r_offset(offset
);
12562 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12563 reloc_write
.put_r_addend(addend
);
12565 pwrite
+= reloc_size
;
12568 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12569 == reloc_view_size
);
12572 // Return the value to use for a dynamic symbol which requires special
12573 // treatment. This is how we support equality comparisons of function
12574 // pointers across shared library boundaries, as described in the
12575 // processor specific ABI supplement.
12577 template<int size
, bool big_endian
>
12579 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12583 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12584 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12585 p
!= this->stub_tables_
.end();
12588 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12589 = (*p
)->find_plt_call_entry(gsym
);
12591 return (*p
)->stub_address() + ent
->off_
;
12594 else if (this->abiversion() >= 2)
12596 Address off
= this->glink_section()->find_global_entry(gsym
);
12597 if (off
!= invalid_address
)
12598 return this->glink_section()->global_entry_address() + off
;
12600 gold_unreachable();
12603 // Return the PLT address to use for a local symbol.
12604 template<int size
, bool big_endian
>
12606 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12607 const Relobj
* object
,
12608 unsigned int symndx
) const
12612 const Sized_relobj
<size
, big_endian
>* relobj
12613 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12614 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12615 p
!= this->stub_tables_
.end();
12618 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12619 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12621 return (*p
)->stub_address() + ent
->off_
;
12624 gold_unreachable();
12627 // Return the PLT address to use for a global symbol.
12628 template<int size
, bool big_endian
>
12630 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12631 const Symbol
* gsym
) const
12635 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12636 p
!= this->stub_tables_
.end();
12639 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12640 = (*p
)->find_plt_call_entry(gsym
);
12642 return (*p
)->stub_address() + ent
->off_
;
12645 else if (this->abiversion() >= 2)
12647 Address off
= this->glink_section()->find_global_entry(gsym
);
12648 if (off
!= invalid_address
)
12649 return this->glink_section()->global_entry_address() + off
;
12651 gold_unreachable();
12654 // Return the offset to use for the GOT_INDX'th got entry which is
12655 // for a local tls symbol specified by OBJECT, SYMNDX.
12656 template<int size
, bool big_endian
>
12658 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12659 const Relobj
* object
,
12660 unsigned int symndx
,
12661 unsigned int got_indx
) const
12663 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12664 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12665 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12667 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12668 got_type
<= GOT_TYPE_TPREL
;
12669 got_type
= Got_type(got_type
+ 1))
12670 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12672 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12673 if (got_type
== GOT_TYPE_TLSGD
)
12675 if (off
== got_indx
* (size
/ 8))
12677 if (got_type
== GOT_TYPE_TPREL
)
12680 return -dtp_offset
;
12684 gold_unreachable();
12687 // Return the offset to use for the GOT_INDX'th got entry which is
12688 // for global tls symbol GSYM.
12689 template<int size
, bool big_endian
>
12691 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12693 unsigned int got_indx
) const
12695 if (gsym
->type() == elfcpp::STT_TLS
)
12697 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12698 got_type
<= GOT_TYPE_TPREL
;
12699 got_type
= Got_type(got_type
+ 1))
12700 if (gsym
->has_got_offset(got_type
))
12702 unsigned int off
= gsym
->got_offset(got_type
);
12703 if (got_type
== GOT_TYPE_TLSGD
)
12705 if (off
== got_indx
* (size
/ 8))
12707 if (got_type
== GOT_TYPE_TPREL
)
12710 return -dtp_offset
;
12714 gold_unreachable();
12717 // The selector for powerpc object files.
12719 template<int size
, bool big_endian
>
12720 class Target_selector_powerpc
: public Target_selector
12723 Target_selector_powerpc()
12724 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12727 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12728 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12730 ? (big_endian
? "elf64ppc" : "elf64lppc")
12731 : (big_endian
? "elf32ppc" : "elf32lppc")))
12735 do_instantiate_target()
12736 { return new Target_powerpc
<size
, big_endian
>(); }
12739 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12740 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12741 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12742 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12744 // Instantiate these constants for -O0
12745 template<int size
, bool big_endian
>
12746 const typename Output_data_glink
<size
, big_endian
>::Address
12747 Output_data_glink
<size
, big_endian
>::invalid_address
;
12748 template<int size
, bool big_endian
>
12749 const typename Stub_table
<size
, big_endian
>::Address
12750 Stub_table
<size
, big_endian
>::invalid_address
;
12751 template<int size
, bool big_endian
>
12752 const typename Target_powerpc
<size
, big_endian
>::Address
12753 Target_powerpc
<size
, big_endian
>::invalid_address
;
12755 } // End anonymous namespace.