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()
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
)
3567 other
= gsym
->nonvis() >> 3;
3571 const Symbol_value
<size
>* psymval
3572 = this->object_
->local_symbol(this->r_sym_
);
3573 Symbol_value
<size
> symval
;
3574 if (psymval
->is_section_symbol())
3575 symval
.set_is_section_symbol();
3576 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3577 typename
ObjType::Compute_final_local_value_status status
3578 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3580 if (status
!= ObjType::CFLV_OK
3581 || !symval
.has_output_value())
3583 to
= symval
.value(this->object_
, 0);
3584 other
= this->object_
->st_other(this->r_sym_
) >> 5;
3586 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3587 to
+= this->addend_
;
3588 if (stub_table
== NULL
)
3589 stub_table
= this->object_
->stub_table(this->shndx_
);
3590 if (size
== 64 && target
->abiversion() < 2)
3592 unsigned int dest_shndx
;
3593 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3597 unsigned int local_ent
= 0;
3599 && this->r_type_
!= elfcpp::R_PPC64_REL24_NOTOC
)
3600 local_ent
= elfcpp::ppc64_decode_local_entry(other
);
3601 Address delta
= to
+ local_ent
- from
;
3602 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3604 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3606 ? this->object_
->ppc64_needs_toc(gsym
)
3607 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3609 if (stub_table
== NULL
)
3611 gold_warning(_("%s:%s: branch in non-executable section,"
3612 " no long branch stub for you"),
3613 this->object_
->name().c_str(),
3614 this->object_
->section_name(this->shndx_
).c_str());
3617 bool save_res
= (size
== 64
3619 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3620 && gsym
->output_data() == target
->savres_section());
3621 ok
= stub_table
->add_long_branch_entry(this->object_
,
3623 from
, to
, other
, save_res
);
3627 gold_debug(DEBUG_TARGET
,
3628 "branch at %s:%s+%#lx\n"
3629 "can't reach stub attached to %s:%s",
3630 this->object_
->name().c_str(),
3631 this->object_
->section_name(this->shndx_
).c_str(),
3632 (unsigned long) this->offset_
,
3633 stub_table
->relobj()->name().c_str(),
3634 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3639 // Relaxation hook. This is where we do stub generation.
3641 template<int size
, bool big_endian
>
3643 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3644 const Input_objects
*,
3645 Symbol_table
* symtab
,
3649 unsigned int prev_brlt_size
= 0;
3653 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3655 && this->abiversion() < 2
3657 && !parameters
->options().user_set_plt_thread_safe())
3659 static const char* const thread_starter
[] =
3663 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3665 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3666 "mq_notify", "create_timer",
3671 "GOMP_parallel_start",
3672 "GOMP_parallel_loop_static",
3673 "GOMP_parallel_loop_static_start",
3674 "GOMP_parallel_loop_dynamic",
3675 "GOMP_parallel_loop_dynamic_start",
3676 "GOMP_parallel_loop_guided",
3677 "GOMP_parallel_loop_guided_start",
3678 "GOMP_parallel_loop_runtime",
3679 "GOMP_parallel_loop_runtime_start",
3680 "GOMP_parallel_sections",
3681 "GOMP_parallel_sections_start",
3686 if (parameters
->options().shared())
3690 for (unsigned int i
= 0;
3691 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3694 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3695 thread_safe
= (sym
!= NULL
3697 && sym
->in_real_elf());
3703 this->plt_thread_safe_
= thread_safe
;
3708 this->stub_group_size_
= parameters
->options().stub_group_size();
3709 bool no_size_errors
= true;
3710 if (this->stub_group_size_
== 1)
3711 this->stub_group_size_
= 0x1c00000;
3712 else if (this->stub_group_size_
== -1)
3713 this->stub_group_size_
= -0x1e00000;
3715 no_size_errors
= false;
3716 this->group_sections(layout
, task
, no_size_errors
);
3718 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3720 this->branch_lookup_table_
.clear();
3721 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3722 p
!= this->stub_tables_
.end();
3725 (*p
)->clear_stubs(true);
3727 this->stub_tables_
.clear();
3728 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3729 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3730 program_name
, this->stub_group_size_
);
3731 this->group_sections(layout
, task
, true);
3734 // We need address of stub tables valid for make_stub.
3735 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3736 p
!= this->stub_tables_
.end();
3739 const Powerpc_relobj
<size
, big_endian
>* object
3740 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3741 Address off
= object
->get_output_section_offset((*p
)->shndx());
3742 gold_assert(off
!= invalid_address
);
3743 Output_section
* os
= (*p
)->output_section();
3744 (*p
)->set_address_and_size(os
, off
);
3749 // Clear plt call stubs, long branch stubs and branch lookup table.
3750 prev_brlt_size
= this->branch_lookup_table_
.size();
3751 this->branch_lookup_table_
.clear();
3752 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3753 p
!= this->stub_tables_
.end();
3756 (*p
)->clear_stubs(false);
3760 // Build all the stubs.
3761 this->relax_failed_
= false;
3762 Stub_table
<size
, big_endian
>* ifunc_stub_table
3763 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3764 Stub_table
<size
, big_endian
>* one_stub_table
3765 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3766 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3767 b
!= this->branch_info_
.end();
3770 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3771 && !this->relax_failed_
)
3773 this->relax_failed_
= true;
3774 this->relax_fail_count_
++;
3775 if (this->relax_fail_count_
< 3)
3779 bool do_resize
= false;
3780 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3781 p
!= this->stub_tables_
.end();
3783 if ((*p
)->need_resize())
3790 this->branch_lookup_table_
.clear();
3791 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3792 p
!= this->stub_tables_
.end();
3794 (*p
)->set_resizing(true);
3795 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3796 b
!= this->branch_info_
.end();
3799 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3800 && !this->relax_failed_
)
3802 this->relax_failed_
= true;
3803 this->relax_fail_count_
++;
3804 if (this->relax_fail_count_
< 3)
3808 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3809 p
!= this->stub_tables_
.end();
3811 (*p
)->set_resizing(false);
3814 // Did anything change size?
3815 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3816 bool again
= num_huge_branches
!= prev_brlt_size
;
3817 if (size
== 64 && num_huge_branches
!= 0)
3818 this->make_brlt_section(layout
);
3819 if (size
== 64 && again
)
3820 this->brlt_section_
->set_current_size(num_huge_branches
);
3822 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3823 p
!= this->stub_tables_
.rend();
3825 (*p
)->remove_eh_frame(layout
);
3827 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3828 p
!= this->stub_tables_
.end();
3830 (*p
)->add_eh_frame(layout
);
3832 typedef Unordered_set
<Output_section
*> Output_sections
;
3833 Output_sections os_need_update
;
3834 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3835 p
!= this->stub_tables_
.end();
3838 if ((*p
)->size_update())
3841 os_need_update
.insert((*p
)->output_section());
3845 // Set output section offsets for all input sections in an output
3846 // section that just changed size. Anything past the stubs will
3848 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3849 p
!= os_need_update
.end();
3852 Output_section
* os
= *p
;
3854 typedef Output_section::Input_section_list Input_section_list
;
3855 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3856 i
!= os
->input_sections().end();
3859 off
= align_address(off
, i
->addralign());
3860 if (i
->is_input_section() || i
->is_relaxed_input_section())
3861 i
->relobj()->set_section_offset(i
->shndx(), off
);
3862 if (i
->is_relaxed_input_section())
3864 Stub_table
<size
, big_endian
>* stub_table
3865 = static_cast<Stub_table
<size
, big_endian
>*>(
3866 i
->relaxed_input_section());
3867 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3868 off
+= stub_table_size
;
3869 // After a few iterations, set current stub table size
3870 // as min size threshold, so later stub tables can only
3873 stub_table
->set_min_size_threshold(stub_table_size
);
3876 off
+= i
->data_size();
3878 // If .branch_lt is part of this output section, then we have
3879 // just done the offset adjustment.
3880 os
->clear_section_offsets_need_adjustment();
3885 && num_huge_branches
!= 0
3886 && parameters
->options().output_is_position_independent())
3888 // Fill in the BRLT relocs.
3889 this->brlt_section_
->reset_brlt_sizes();
3890 for (typename
Branch_lookup_table::const_iterator p
3891 = this->branch_lookup_table_
.begin();
3892 p
!= this->branch_lookup_table_
.end();
3895 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3897 this->brlt_section_
->finalize_brlt_sizes();
3901 && (parameters
->options().user_set_emit_stub_syms()
3902 ? parameters
->options().emit_stub_syms()
3904 || parameters
->options().output_is_position_independent()
3905 || parameters
->options().emit_relocs())))
3907 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3908 p
!= this->stub_tables_
.end();
3910 (*p
)->define_stub_syms(symtab
);
3912 if (this->glink_
!= NULL
)
3914 int stub_size
= this->glink_
->pltresolve_size();
3915 Address value
= -stub_size
;
3921 this->define_local(symtab
, "__glink_PLTresolve",
3922 this->glink_
, value
, stub_size
);
3925 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3932 template<int size
, bool big_endian
>
3934 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3935 unsigned char* oview
,
3939 uint64_t address
= plt
->address();
3940 off_t len
= plt
->data_size();
3942 if (plt
== this->glink_
)
3944 // See Output_data_glink::do_write() for glink contents.
3947 gold_assert(parameters
->doing_static_link());
3948 // Static linking may need stubs, to support ifunc and long
3949 // branches. We need to create an output section for
3950 // .eh_frame early in the link process, to have a place to
3951 // attach stub .eh_frame info. We also need to have
3952 // registered a CIE that matches the stub CIE. Both of
3953 // these requirements are satisfied by creating an FDE and
3954 // CIE for .glink, even though static linking will leave
3955 // .glink zero length.
3956 // ??? Hopefully generating an FDE with a zero address range
3957 // won't confuse anything that consumes .eh_frame info.
3959 else if (size
== 64)
3961 // There is one word before __glink_PLTresolve
3965 else if (parameters
->options().output_is_position_independent())
3967 // There are two FDEs for a position independent glink.
3968 // The first covers the branch table, the second
3969 // __glink_PLTresolve at the end of glink.
3970 off_t resolve_size
= this->glink_
->pltresolve_size();
3971 if (oview
[9] == elfcpp::DW_CFA_nop
)
3972 len
-= resolve_size
;
3975 address
+= len
- resolve_size
;
3982 // Must be a stub table.
3983 const Stub_table
<size
, big_endian
>* stub_table
3984 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3985 uint64_t stub_address
= stub_table
->stub_address();
3986 len
-= stub_address
- address
;
3987 address
= stub_address
;
3990 *paddress
= address
;
3994 // A class to handle the PLT data.
3996 template<int size
, bool big_endian
>
3997 class Output_data_plt_powerpc
: public Output_section_data_build
4000 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4001 size
, big_endian
> Reloc_section
;
4003 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4004 Reloc_section
* plt_rel
,
4006 : Output_section_data_build(size
== 32 ? 4 : 8),
4012 // Add an entry to the PLT.
4017 add_ifunc_entry(Symbol
*);
4020 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4023 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4025 // Return the .rela.plt section data.
4032 // Return the number of PLT entries.
4036 if (this->current_data_size() == 0)
4038 return ((this->current_data_size() - this->first_plt_entry_offset())
4039 / this->plt_entry_size());
4044 do_adjust_output_section(Output_section
* os
)
4049 // Write to a map file.
4051 do_print_to_mapfile(Mapfile
* mapfile
) const
4052 { mapfile
->print_output_data(this, this->name_
); }
4055 // Return the offset of the first non-reserved PLT entry.
4057 first_plt_entry_offset() const
4059 // IPLT and LPLT have no reserved entry.
4060 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4062 return this->targ_
->first_plt_entry_offset();
4065 // Return the size of each PLT entry.
4067 plt_entry_size() const
4069 return this->targ_
->plt_entry_size();
4072 // Write out the PLT data.
4074 do_write(Output_file
*);
4076 // The reloc section.
4077 Reloc_section
* rel_
;
4078 // Allows access to .glink for do_write.
4079 Target_powerpc
<size
, big_endian
>* targ_
;
4080 // What to report in map file.
4084 // Add an entry to the PLT.
4086 template<int size
, bool big_endian
>
4088 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4090 if (!gsym
->has_plt_offset())
4092 section_size_type off
= this->current_data_size();
4094 off
+= this->first_plt_entry_offset();
4095 gsym
->set_plt_offset(off
);
4096 gsym
->set_needs_dynsym_entry();
4097 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4098 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4099 off
+= this->plt_entry_size();
4100 this->set_current_data_size(off
);
4104 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4106 template<int size
, bool big_endian
>
4108 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4110 if (!gsym
->has_plt_offset())
4112 section_size_type off
= this->current_data_size();
4113 gsym
->set_plt_offset(off
);
4114 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4115 if (size
== 64 && this->targ_
->abiversion() < 2)
4116 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4117 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4118 off
+= this->plt_entry_size();
4119 this->set_current_data_size(off
);
4123 // Add an entry for a local symbol to the PLT.
4125 template<int size
, bool big_endian
>
4127 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4128 Sized_relobj_file
<size
, big_endian
>* relobj
,
4129 unsigned int local_sym_index
)
4131 if (!relobj
->local_has_plt_offset(local_sym_index
))
4133 section_size_type off
= this->current_data_size();
4134 relobj
->set_local_plt_offset(local_sym_index
, off
);
4137 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4138 if (size
== 64 && this->targ_
->abiversion() < 2)
4139 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4140 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4141 dynrel
, this, off
, 0);
4143 off
+= this->plt_entry_size();
4144 this->set_current_data_size(off
);
4148 // Add an entry for a local ifunc symbol to the IPLT.
4150 template<int size
, bool big_endian
>
4152 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4153 Sized_relobj_file
<size
, big_endian
>* relobj
,
4154 unsigned int local_sym_index
)
4156 if (!relobj
->local_has_plt_offset(local_sym_index
))
4158 section_size_type off
= this->current_data_size();
4159 relobj
->set_local_plt_offset(local_sym_index
, off
);
4160 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4161 if (size
== 64 && this->targ_
->abiversion() < 2)
4162 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4163 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4165 off
+= this->plt_entry_size();
4166 this->set_current_data_size(off
);
4170 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4171 static const uint32_t add_2_2_11
= 0x7c425a14;
4172 static const uint32_t add_2_2_12
= 0x7c426214;
4173 static const uint32_t add_3_3_2
= 0x7c631214;
4174 static const uint32_t add_3_3_13
= 0x7c636a14;
4175 static const uint32_t add_3_12_2
= 0x7c6c1214;
4176 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4177 static const uint32_t add_11_0_11
= 0x7d605a14;
4178 static const uint32_t add_11_2_11
= 0x7d625a14;
4179 static const uint32_t add_11_11_2
= 0x7d6b1214;
4180 static const uint32_t add_12_11_12
= 0x7d8b6214;
4181 static const uint32_t addi_0_12
= 0x380c0000;
4182 static const uint32_t addi_2_2
= 0x38420000;
4183 static const uint32_t addi_3_3
= 0x38630000;
4184 static const uint32_t addi_11_11
= 0x396b0000;
4185 static const uint32_t addi_12_1
= 0x39810000;
4186 static const uint32_t addi_12_11
= 0x398b0000;
4187 static const uint32_t addi_12_12
= 0x398c0000;
4188 static const uint32_t addis_0_2
= 0x3c020000;
4189 static const uint32_t addis_0_13
= 0x3c0d0000;
4190 static const uint32_t addis_2_12
= 0x3c4c0000;
4191 static const uint32_t addis_11_2
= 0x3d620000;
4192 static const uint32_t addis_11_11
= 0x3d6b0000;
4193 static const uint32_t addis_11_30
= 0x3d7e0000;
4194 static const uint32_t addis_12_1
= 0x3d810000;
4195 static const uint32_t addis_12_2
= 0x3d820000;
4196 static const uint32_t addis_12_11
= 0x3d8b0000;
4197 static const uint32_t addis_12_12
= 0x3d8c0000;
4198 static const uint32_t b
= 0x48000000;
4199 static const uint32_t bcl_20_31
= 0x429f0005;
4200 static const uint32_t bctr
= 0x4e800420;
4201 static const uint32_t bctrl
= 0x4e800421;
4202 static const uint32_t beqlr
= 0x4d820020;
4203 static const uint32_t blr
= 0x4e800020;
4204 static const uint32_t bnectr_p4
= 0x4ce20420;
4205 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4206 static const uint32_t cmpldi_2_0
= 0x28220000;
4207 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4208 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4209 static const uint32_t cror_15_15_15
= 0x4def7b82;
4210 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4211 static const uint32_t ld_0_1
= 0xe8010000;
4212 static const uint32_t ld_0_11
= 0xe80b0000;
4213 static const uint32_t ld_0_12
= 0xe80c0000;
4214 static const uint32_t ld_2_1
= 0xe8410000;
4215 static const uint32_t ld_2_2
= 0xe8420000;
4216 static const uint32_t ld_2_11
= 0xe84b0000;
4217 static const uint32_t ld_2_12
= 0xe84c0000;
4218 static const uint32_t ld_11_1
= 0xe9610000;
4219 static const uint32_t ld_11_2
= 0xe9620000;
4220 static const uint32_t ld_11_3
= 0xe9630000;
4221 static const uint32_t ld_11_11
= 0xe96b0000;
4222 static const uint32_t ld_12_2
= 0xe9820000;
4223 static const uint32_t ld_12_3
= 0xe9830000;
4224 static const uint32_t ld_12_11
= 0xe98b0000;
4225 static const uint32_t ld_12_12
= 0xe98c0000;
4226 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4227 static const uint32_t lfd_0_1
= 0xc8010000;
4228 static const uint32_t li_0_0
= 0x38000000;
4229 static const uint32_t li_11_0
= 0x39600000;
4230 static const uint32_t li_12_0
= 0x39800000;
4231 static const uint32_t lis_0
= 0x3c000000;
4232 static const uint32_t lis_2
= 0x3c400000;
4233 static const uint32_t lis_11
= 0x3d600000;
4234 static const uint32_t lis_12
= 0x3d800000;
4235 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4236 static const uint32_t lwz_0_12
= 0x800c0000;
4237 static const uint32_t lwz_11_3
= 0x81630000;
4238 static const uint32_t lwz_11_11
= 0x816b0000;
4239 static const uint32_t lwz_11_30
= 0x817e0000;
4240 static const uint32_t lwz_12_3
= 0x81830000;
4241 static const uint32_t lwz_12_12
= 0x818c0000;
4242 static const uint32_t lwzu_0_12
= 0x840c0000;
4243 static const uint32_t mflr_0
= 0x7c0802a6;
4244 static const uint32_t mflr_11
= 0x7d6802a6;
4245 static const uint32_t mflr_12
= 0x7d8802a6;
4246 static const uint32_t mr_0_3
= 0x7c601b78;
4247 static const uint32_t mr_3_0
= 0x7c030378;
4248 static const uint32_t mtctr_0
= 0x7c0903a6;
4249 static const uint32_t mtctr_11
= 0x7d6903a6;
4250 static const uint32_t mtctr_12
= 0x7d8903a6;
4251 static const uint32_t mtlr_0
= 0x7c0803a6;
4252 static const uint32_t mtlr_11
= 0x7d6803a6;
4253 static const uint32_t mtlr_12
= 0x7d8803a6;
4254 static const uint32_t nop
= 0x60000000;
4255 static const uint32_t ori_0_0_0
= 0x60000000;
4256 static const uint32_t ori_11_11_0
= 0x616b0000;
4257 static const uint32_t ori_12_12_0
= 0x618c0000;
4258 static const uint32_t oris_12_12_0
= 0x658c0000;
4259 static const uint32_t sldi_11_11_34
= 0x796b1746;
4260 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4261 static const uint32_t srdi_0_0_2
= 0x7800f082;
4262 static const uint32_t std_0_1
= 0xf8010000;
4263 static const uint32_t std_0_12
= 0xf80c0000;
4264 static const uint32_t std_2_1
= 0xf8410000;
4265 static const uint32_t std_11_1
= 0xf9610000;
4266 static const uint32_t stfd_0_1
= 0xd8010000;
4267 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4268 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4269 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4270 static const uint32_t xor_2_12_12
= 0x7d826278;
4271 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4273 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4274 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4275 static const uint64_t pnop
= 0x0700000000000000ULL
;
4277 // Write out the PLT.
4279 template<int size
, bool big_endian
>
4281 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4283 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4285 const section_size_type offset
= this->offset();
4286 const section_size_type oview_size
4287 = convert_to_section_size_type(this->data_size());
4288 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4289 unsigned char* pov
= oview
;
4290 unsigned char* endpov
= oview
+ oview_size
;
4292 // The address of the .glink branch table
4293 const Output_data_glink
<size
, big_endian
>* glink
4294 = this->targ_
->glink_section();
4295 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4297 while (pov
< endpov
)
4299 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4304 of
->write_output_view(offset
, oview_size
, oview
);
4308 // Create the PLT section.
4310 template<int size
, bool big_endian
>
4312 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4315 if (this->plt_
== NULL
)
4317 if (this->got_
== NULL
)
4318 this->got_section(symtab
, layout
);
4320 if (this->glink_
== NULL
)
4321 make_glink_section(layout
);
4323 // Ensure that .rela.dyn always appears before .rela.plt This is
4324 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4325 // needs to include .rela.plt in its range.
4326 this->rela_dyn_section(layout
);
4328 Reloc_section
* plt_rel
= new Reloc_section(false);
4329 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4330 elfcpp::SHF_ALLOC
, plt_rel
,
4331 ORDER_DYNAMIC_PLT_RELOCS
, false);
4333 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4335 layout
->add_output_section_data(".plt",
4337 ? elfcpp::SHT_PROGBITS
4338 : elfcpp::SHT_NOBITS
),
4339 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4346 Output_section
* rela_plt_os
= plt_rel
->output_section();
4347 rela_plt_os
->set_info_section(this->plt_
->output_section());
4351 // Create the IPLT section.
4353 template<int size
, bool big_endian
>
4355 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4358 if (this->iplt_
== NULL
)
4360 this->make_plt_section(symtab
, layout
);
4361 this->make_lplt_section(layout
);
4363 Reloc_section
* iplt_rel
= new Reloc_section(false);
4364 if (this->rela_dyn_
->output_section())
4365 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4367 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4369 if (this->plt_
->output_section())
4370 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4374 // Create the LPLT section.
4376 template<int size
, bool big_endian
>
4378 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4380 if (this->lplt_
== NULL
)
4382 Reloc_section
* lplt_rel
= NULL
;
4383 if (parameters
->options().output_is_position_independent())
4385 lplt_rel
= new Reloc_section(false);
4386 this->rela_dyn_section(layout
);
4387 if (this->rela_dyn_
->output_section())
4388 this->rela_dyn_
->output_section()
4389 ->add_output_section_data(lplt_rel
);
4392 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4394 this->make_brlt_section(layout
);
4395 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4396 this->brlt_section_
->output_section()
4397 ->add_output_section_data(this->lplt_
);
4399 layout
->add_output_section_data(".branch_lt",
4400 elfcpp::SHT_PROGBITS
,
4401 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4408 // A section for huge long branch addresses, similar to plt section.
4410 template<int size
, bool big_endian
>
4411 class Output_data_brlt_powerpc
: public Output_section_data_build
4414 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4415 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4416 size
, big_endian
> Reloc_section
;
4418 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4419 Reloc_section
* brlt_rel
)
4420 : Output_section_data_build(size
== 32 ? 4 : 8),
4428 this->reset_data_size();
4429 this->rel_
->reset_data_size();
4433 finalize_brlt_sizes()
4435 this->finalize_data_size();
4436 this->rel_
->finalize_data_size();
4439 // Add a reloc for an entry in the BRLT.
4441 add_reloc(Address to
, unsigned int off
)
4442 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4444 // Update section and reloc section size.
4446 set_current_size(unsigned int num_branches
)
4448 this->reset_address_and_file_offset();
4449 this->set_current_data_size(num_branches
* 16);
4450 this->finalize_data_size();
4451 Output_section
* os
= this->output_section();
4452 os
->set_section_offsets_need_adjustment();
4453 if (this->rel_
!= NULL
)
4455 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4456 this->rel_
->reset_address_and_file_offset();
4457 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4458 this->rel_
->finalize_data_size();
4459 Output_section
* os
= this->rel_
->output_section();
4460 os
->set_section_offsets_need_adjustment();
4466 do_adjust_output_section(Output_section
* os
)
4471 // Write to a map file.
4473 do_print_to_mapfile(Mapfile
* mapfile
) const
4474 { mapfile
->print_output_data(this, "** BRLT"); }
4477 // Write out the BRLT data.
4479 do_write(Output_file
*);
4481 // The reloc section.
4482 Reloc_section
* rel_
;
4483 Target_powerpc
<size
, big_endian
>* targ_
;
4486 // Make the branch lookup table section.
4488 template<int size
, bool big_endian
>
4490 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4492 if (size
== 64 && this->brlt_section_
== NULL
)
4494 Reloc_section
* brlt_rel
= NULL
;
4495 bool is_pic
= parameters
->options().output_is_position_independent();
4498 // When PIC we can't fill in .branch_lt but must initialise at
4499 // runtime via dynamic relocations.
4500 this->rela_dyn_section(layout
);
4501 brlt_rel
= new Reloc_section(false);
4502 if (this->rela_dyn_
->output_section())
4503 this->rela_dyn_
->output_section()
4504 ->add_output_section_data(brlt_rel
);
4507 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4508 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4509 this->plt_
->output_section()
4510 ->add_output_section_data(this->brlt_section_
);
4512 layout
->add_output_section_data(".branch_lt",
4513 elfcpp::SHT_PROGBITS
,
4514 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4515 this->brlt_section_
,
4521 // Write out .branch_lt when non-PIC.
4523 template<int size
, bool big_endian
>
4525 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4527 if (size
== 64 && !parameters
->options().output_is_position_independent())
4529 const section_size_type offset
= this->offset();
4530 const section_size_type oview_size
4531 = convert_to_section_size_type(this->data_size());
4532 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4534 this->targ_
->write_branch_lookup_table(oview
);
4535 of
->write_output_view(offset
, oview_size
, oview
);
4539 static inline uint32_t
4545 static inline uint32_t
4551 static inline uint32_t
4554 return hi(a
+ 0x8000);
4557 static inline uint64_t
4560 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4563 static inline uint64_t
4566 return (v
+ (1ULL << 33)) >> 34;
4572 static const unsigned char eh_frame_cie
[12];
4576 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4579 'z', 'R', 0, // Augmentation string.
4580 4, // Code alignment.
4581 0x80 - size
/ 8 , // Data alignment.
4583 1, // Augmentation size.
4584 (elfcpp::DW_EH_PE_pcrel
4585 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4586 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4589 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4590 static const unsigned char glink_eh_frame_fde_64v1
[] =
4592 0, 0, 0, 0, // Replaced with offset to .glink.
4593 0, 0, 0, 0, // Replaced with size of .glink.
4594 0, // Augmentation size.
4595 elfcpp::DW_CFA_advance_loc
+ 2,
4596 elfcpp::DW_CFA_register
, 65, 12,
4597 elfcpp::DW_CFA_advance_loc
+ 4,
4598 elfcpp::DW_CFA_restore_extended
, 65
4601 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4602 static const unsigned char glink_eh_frame_fde_64v2
[] =
4604 0, 0, 0, 0, // Replaced with offset to .glink.
4605 0, 0, 0, 0, // Replaced with size of .glink.
4606 0, // Augmentation size.
4607 elfcpp::DW_CFA_advance_loc
+ 2,
4608 elfcpp::DW_CFA_register
, 65, 0,
4609 elfcpp::DW_CFA_advance_loc
+ 2,
4610 elfcpp::DW_CFA_restore_extended
, 65
4613 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4615 0, 0, 0, 0, // Replaced with offset to .glink.
4616 0, 0, 0, 0, // Replaced with size of .glink.
4617 0, // Augmentation size.
4618 elfcpp::DW_CFA_advance_loc
+ 3,
4619 elfcpp::DW_CFA_register
, 65, 0,
4620 elfcpp::DW_CFA_advance_loc
+ 2,
4621 elfcpp::DW_CFA_restore_extended
, 65
4624 // Describe __glink_PLTresolve use of LR, 32-bit version.
4625 static const unsigned char glink_eh_frame_fde_32
[] =
4627 0, 0, 0, 0, // Replaced with offset to .glink.
4628 0, 0, 0, 0, // Replaced with size of .glink.
4629 0, // Augmentation size.
4630 elfcpp::DW_CFA_advance_loc
+ 2,
4631 elfcpp::DW_CFA_register
, 65, 0,
4632 elfcpp::DW_CFA_advance_loc
+ 4,
4633 elfcpp::DW_CFA_restore_extended
, 65
4636 static const unsigned char default_fde
[] =
4638 0, 0, 0, 0, // Replaced with offset to stubs.
4639 0, 0, 0, 0, // Replaced with size of stubs.
4640 0, // Augmentation size.
4641 elfcpp::DW_CFA_nop
, // Pad.
4646 template<bool big_endian
>
4648 write_insn(unsigned char* p
, uint32_t v
)
4650 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4654 static inline unsigned int
4657 if (!parameters
->options().user_set_plt_align())
4658 return size
== 64 ? 32 : 8;
4659 return 1 << parameters
->options().plt_align();
4662 // Stub_table holds information about plt and long branch stubs.
4663 // Stubs are built in an area following some input section determined
4664 // by group_sections(). This input section is converted to a relaxed
4665 // input section allowing it to be resized to accommodate the stubs
4667 template<int size
, bool big_endian
>
4668 class Stub_table
: public Output_relaxed_input_section
4673 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4674 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4675 r2save_(0), localentry0_(0), tocoff_(0)
4680 unsigned int iter_
: 1;
4681 unsigned int notoc_
: 1;
4682 unsigned int toc_
: 1;
4683 unsigned int r2save_
: 1;
4684 unsigned int localentry0_
: 1;
4685 unsigned int tocoff_
: 8;
4687 struct Branch_stub_ent
4689 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4690 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4691 other_(0), tocoff_(0)
4695 unsigned int iter_
: 1;
4696 unsigned int notoc_
: 1;
4697 unsigned int toc_
: 1;
4698 unsigned int save_res_
: 1;
4699 unsigned int other_
: 3;
4700 unsigned int tocoff_
: 8;
4702 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4703 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4705 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4706 Output_section
* output_section
,
4707 const Output_section::Input_section
* owner
,
4709 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4711 ->section_addralign(owner
->shndx())),
4712 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4713 orig_data_size_(owner
->current_data_size()),
4714 plt_size_(0), last_plt_size_(0),
4715 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4716 need_save_res_(false), need_resize_(false), resizing_(false),
4719 this->set_output_section(output_section
);
4721 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4722 new_relaxed
.push_back(this);
4723 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4726 // Add a plt call stub.
4728 add_plt_call_entry(Address
,
4729 const Sized_relobj_file
<size
, big_endian
>*,
4736 add_plt_call_entry(Address
,
4737 const Sized_relobj_file
<size
, big_endian
>*,
4743 // Find a given plt call stub.
4745 find_plt_call_entry(const Symbol
*) const;
4748 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4749 unsigned int) const;
4752 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4758 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4763 // Add a long branch stub.
4765 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4766 unsigned int, Address
, Address
, unsigned int, bool);
4768 const Branch_stub_ent
*
4769 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4773 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4775 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4776 if (max_branch_offset
== 0)
4778 gold_assert(from
!= invalid_address
);
4779 Address loc
= off
+ this->stub_address();
4780 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4784 clear_stubs(bool all
)
4786 this->plt_call_stubs_
.clear();
4787 this->plt_size_
= 0;
4788 this->long_branch_stubs_
.clear();
4789 this->branch_size_
= 0;
4790 this->need_save_res_
= false;
4793 this->last_plt_size_
= 0;
4794 this->last_branch_size_
= 0;
4800 { return need_resize_
; }
4803 set_resizing(bool val
)
4805 this->resizing_
= val
;
4808 this->need_resize_
= false;
4809 this->plt_size_
= 0;
4810 this->branch_size_
= 0;
4811 this->need_save_res_
= false;
4816 set_address_and_size(const Output_section
* os
, Address off
)
4818 Address start_off
= off
;
4819 off
+= this->orig_data_size_
;
4820 Address my_size
= this->plt_size_
+ this->branch_size_
;
4821 if (this->need_save_res_
)
4822 my_size
+= this->targ_
->savres_section()->data_size();
4824 off
= align_address(off
, this->stub_align());
4825 // Include original section size and alignment padding in size
4826 my_size
+= off
- start_off
;
4827 // Ensure new size is always larger than min size
4828 // threshold. Alignment requirement is included in "my_size", so
4829 // increase "my_size" does not invalidate alignment.
4830 if (my_size
< this->min_size_threshold_
)
4831 my_size
= this->min_size_threshold_
;
4832 this->reset_address_and_file_offset();
4833 this->set_current_data_size(my_size
);
4834 this->set_address_and_file_offset(os
->address() + start_off
,
4835 os
->offset() + start_off
);
4840 stub_address() const
4842 return align_address(this->address() + this->orig_data_size_
,
4843 this->stub_align());
4849 return align_address(this->offset() + this->orig_data_size_
,
4850 this->stub_align());
4855 { return this->plt_size_
; }
4859 { return this->branch_size_
; }
4862 set_min_size_threshold(Address min_size
)
4863 { this->min_size_threshold_
= min_size
; }
4866 define_stub_syms(Symbol_table
*);
4871 Output_section
* os
= this->output_section();
4872 if (os
->addralign() < this->stub_align())
4874 os
->set_addralign(this->stub_align());
4875 // FIXME: get rid of the insane checkpointing.
4876 // We can't increase alignment of the input section to which
4877 // stubs are attached; The input section may be .init which
4878 // is pasted together with other .init sections to form a
4879 // function. Aligning might insert zero padding resulting in
4880 // sigill. However we do need to increase alignment of the
4881 // output section so that the align_address() on offset in
4882 // set_address_and_size() adds the same padding as the
4883 // align_address() on address in stub_address().
4884 // What's more, we need this alignment for the layout done in
4885 // relaxation_loop_body() so that the output section starts at
4886 // a suitably aligned address.
4887 os
->checkpoint_set_addralign(this->stub_align());
4889 if (this->last_plt_size_
!= this->plt_size_
4890 || this->last_branch_size_
!= this->branch_size_
)
4892 this->last_plt_size_
= this->plt_size_
;
4893 this->last_branch_size_
= this->branch_size_
;
4899 // Add .eh_frame info for this stub section.
4901 add_eh_frame(Layout
* layout
);
4903 // Remove .eh_frame info for this stub section.
4905 remove_eh_frame(Layout
* layout
);
4907 Target_powerpc
<size
, big_endian
>*
4913 class Plt_stub_key_hash
;
4914 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4915 Plt_stub_key_hash
> Plt_stub_entries
;
4916 class Branch_stub_key
;
4917 class Branch_stub_key_hash
;
4918 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4919 Branch_stub_key_hash
> Branch_stub_entries
;
4921 // Alignment of stub section.
4925 unsigned int min_align
= size
== 64 ? 32 : 16;
4926 unsigned int user_align
= 1 << parameters
->options().plt_align();
4927 return std::max(user_align
, min_align
);
4930 // Return the plt offset for the given call stub.
4932 plt_off(typename
Plt_stub_entries::const_iterator p
,
4933 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4935 const Symbol
* gsym
= p
->first
.sym_
;
4937 return this->targ_
->plt_off(gsym
, sec
);
4940 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4941 unsigned int local_sym_index
= p
->first
.locsym_
;
4942 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4946 // Size of a given plt call stub.
4948 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4951 plt_call_align(unsigned int bytes
) const
4953 unsigned int align
= param_plt_align
<size
>();
4954 return (bytes
+ align
- 1) & -align
;
4957 // Return long branch stub size.
4959 branch_stub_size(typename
Branch_stub_entries::iterator p
,
4963 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
4966 build_tls_opt_tail(unsigned char* p
);
4969 plt_error(const Plt_stub_key
& p
);
4973 do_write(Output_file
*);
4975 // Plt call stub keys.
4979 Plt_stub_key(const Symbol
* sym
)
4980 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4983 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4984 unsigned int locsym_index
)
4985 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4988 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4990 unsigned int r_type
,
4992 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4995 this->addend_
= addend
;
4996 else if (parameters
->options().output_is_position_independent()
4997 && (r_type
== elfcpp::R_PPC_PLTREL24
4998 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5000 this->addend_
= addend
;
5001 if (this->addend_
>= 32768)
5002 this->object_
= object
;
5006 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5007 unsigned int locsym_index
,
5008 unsigned int r_type
,
5010 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5013 this->addend_
= addend
;
5014 else if (parameters
->options().output_is_position_independent()
5015 && (r_type
== elfcpp::R_PPC_PLTREL24
5016 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5017 this->addend_
= addend
;
5020 bool operator==(const Plt_stub_key
& that
) const
5022 return (this->sym_
== that
.sym_
5023 && this->object_
== that
.object_
5024 && this->addend_
== that
.addend_
5025 && this->locsym_
== that
.locsym_
);
5029 const Sized_relobj_file
<size
, big_endian
>* object_
;
5030 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5031 unsigned int locsym_
;
5034 class Plt_stub_key_hash
5037 size_t operator()(const Plt_stub_key
& ent
) const
5039 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5040 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5046 // Long branch stub keys.
5047 class Branch_stub_key
5050 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
5051 : dest_(to
), toc_base_off_(0)
5054 toc_base_off_
= obj
->toc_base_offset();
5057 bool operator==(const Branch_stub_key
& that
) const
5059 return (this->dest_
== that
.dest_
5061 || this->toc_base_off_
== that
.toc_base_off_
));
5065 unsigned int toc_base_off_
;
5068 class Branch_stub_key_hash
5071 size_t operator()(const Branch_stub_key
& key
) const
5072 { return key
.dest_
^ key
.toc_base_off_
; }
5075 // In a sane world this would be a global.
5076 Target_powerpc
<size
, big_endian
>* targ_
;
5077 // Map sym/object/addend to stub offset.
5078 Plt_stub_entries plt_call_stubs_
;
5079 // Map destination address to stub offset.
5080 Branch_stub_entries long_branch_stubs_
;
5081 // size of input section
5082 section_size_type orig_data_size_
;
5084 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5085 // Some rare cases cause (PR/20529) fluctuation in stub table
5086 // size, which leads to an endless relax loop. This is to be fixed
5087 // by, after the first few iterations, allowing only increase of
5088 // stub table size. This variable sets the minimal possible size of
5089 // a stub table, it is zero for the first few iterations, then
5090 // increases monotonically.
5091 Address min_size_threshold_
;
5092 // Set if this stub group needs a copy of out-of-line register
5093 // save/restore functions.
5094 bool need_save_res_
;
5095 // Set when notoc_/r2save_ changes after sizing a stub
5097 // Set when resizing stubs
5099 // Per stub table unique identifier.
5103 // Add a plt call stub, if we do not already have one for this
5104 // sym/object/addend combo.
5106 template<int size
, bool big_endian
>
5108 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5110 const Sized_relobj_file
<size
, big_endian
>* object
,
5112 unsigned int r_type
,
5116 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5117 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5118 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5119 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5123 && this->targ_
->is_elfv2_localentry0(gsym
))
5125 p
.first
->second
.localentry0_
= 1;
5126 this->targ_
->set_has_localentry0();
5128 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5130 if (!p
.second
&& !p
.first
->second
.notoc_
5131 && (!this->targ_
->power10_stubs()
5132 || this->targ_
->power10_stubs_auto()))
5133 this->need_resize_
= true;
5134 p
.first
->second
.notoc_
= 1;
5138 if (!p
.second
&& !p
.first
->second
.toc_
)
5139 this->need_resize_
= true;
5140 p
.first
->second
.toc_
= 1;
5141 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5143 if (!p
.second
&& !p
.first
->second
.r2save_
)
5144 this->need_resize_
= true;
5145 p
.first
->second
.r2save_
= 1;
5149 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5151 if (this->resizing_
)
5153 p
.first
->second
.iter_
= 1;
5154 p
.first
->second
.off_
= this->plt_size_
;
5156 this->plt_size_
+= this->plt_call_size(p
.first
);
5157 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5158 this->targ_
->set_has_tls_get_addr_opt();
5159 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5161 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5164 template<int size
, bool big_endian
>
5166 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5168 const Sized_relobj_file
<size
, big_endian
>* object
,
5169 unsigned int locsym_index
,
5170 unsigned int r_type
,
5174 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5175 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5176 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5177 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5181 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5183 p
.first
->second
.localentry0_
= 1;
5184 this->targ_
->set_has_localentry0();
5186 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5188 if (!p
.second
&& !p
.first
->second
.notoc_
5189 && (!this->targ_
->power10_stubs()
5190 || this->targ_
->power10_stubs_auto()))
5191 this->need_resize_
= true;
5192 p
.first
->second
.notoc_
= 1;
5196 if (!p
.second
&& !p
.first
->second
.toc_
)
5197 this->need_resize_
= true;
5198 p
.first
->second
.toc_
= 1;
5199 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5201 if (!p
.second
&& !p
.first
->second
.r2save_
)
5202 this->need_resize_
= true;
5203 p
.first
->second
.r2save_
= 1;
5207 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5209 if (this->resizing_
)
5211 p
.first
->second
.iter_
= 1;
5212 p
.first
->second
.off_
= this->plt_size_
;
5214 this->plt_size_
+= this->plt_call_size(p
.first
);
5215 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5217 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5220 // Find a plt call stub.
5222 template<int size
, bool big_endian
>
5223 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5224 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5225 const Sized_relobj_file
<size
, big_endian
>* object
,
5227 unsigned int r_type
,
5228 Address addend
) const
5230 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5231 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5232 if (p
== this->plt_call_stubs_
.end())
5237 template<int size
, bool big_endian
>
5238 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5239 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5241 Plt_stub_key
key(gsym
);
5242 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5243 if (p
== this->plt_call_stubs_
.end())
5248 template<int size
, bool big_endian
>
5249 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5250 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5251 const Sized_relobj_file
<size
, big_endian
>* object
,
5252 unsigned int locsym_index
,
5253 unsigned int r_type
,
5254 Address addend
) const
5256 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5257 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5258 if (p
== this->plt_call_stubs_
.end())
5263 template<int size
, bool big_endian
>
5264 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5265 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5266 const Sized_relobj_file
<size
, big_endian
>* object
,
5267 unsigned int locsym_index
) const
5269 Plt_stub_key
key(object
, locsym_index
);
5270 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5271 if (p
== this->plt_call_stubs_
.end())
5276 // Add a long branch stub if we don't already have one to given
5279 template<int size
, bool big_endian
>
5281 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5282 const Powerpc_relobj
<size
, big_endian
>* object
,
5283 unsigned int r_type
,
5289 Branch_stub_key
key(object
, to
);
5290 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5291 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5292 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5293 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5296 if (!p
.second
&& !p
.first
->second
.notoc_
)
5297 this->need_resize_
= true;
5298 p
.first
->second
.notoc_
= true;
5302 if (!p
.second
&& !p
.first
->second
.toc_
)
5303 this->need_resize_
= true;
5304 p
.first
->second
.toc_
= true;
5306 if (p
.first
->second
.other_
== 0)
5307 p
.first
->second
.other_
= other
;
5308 gold_assert(save_res
== p
.first
->second
.save_res_
);
5309 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5311 if (this->resizing_
)
5313 p
.first
->second
.iter_
= 1;
5314 p
.first
->second
.off_
= this->branch_size_
;
5317 this->need_save_res_
= true;
5320 bool need_lt
= false;
5321 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5322 this->branch_size_
+= stub_size
;
5323 if (size
== 64 && need_lt
)
5324 this->targ_
->add_branch_lookup_table(to
);
5327 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5330 // Find long branch stub offset.
5332 template<int size
, bool big_endian
>
5333 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5334 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5335 const Powerpc_relobj
<size
, big_endian
>* object
,
5338 Branch_stub_key
key(object
, to
);
5339 typename
Branch_stub_entries::const_iterator p
5340 = this->long_branch_stubs_
.find(key
);
5341 if (p
== this->long_branch_stubs_
.end())
5346 template<bool big_endian
>
5348 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5352 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5353 else if (delta
< 256)
5355 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5356 fde
.push_back(delta
);
5358 else if (delta
< 65536)
5360 fde
.resize(fde
.size() + 3);
5361 unsigned char *p
= &*fde
.end() - 3;
5362 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5363 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5367 fde
.resize(fde
.size() + 5);
5368 unsigned char *p
= &*fde
.end() - 5;
5369 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5370 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5374 template<typename T
>
5376 stub_sort(T s1
, T s2
)
5378 return s1
->second
.off_
< s2
->second
.off_
;
5381 // Add .eh_frame info for this stub section. Unlike other linker
5382 // generated .eh_frame this is added late in the link, because we
5383 // only want the .eh_frame info if this particular stub section is
5386 template<int size
, bool big_endian
>
5388 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5391 || !parameters
->options().ld_generated_unwind_info())
5394 // Since we add stub .eh_frame info late, it must be placed
5395 // after all other linker generated .eh_frame info so that
5396 // merge mapping need not be updated for input sections.
5397 // There is no provision to use a different CIE to that used
5399 if (!this->targ_
->has_glink())
5402 typedef typename
Plt_stub_entries::iterator plt_iter
;
5403 std::vector
<plt_iter
> calls
;
5404 if (!this->plt_call_stubs_
.empty())
5405 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5406 cs
!= this->plt_call_stubs_
.end();
5408 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5409 && cs
->second
.r2save_
5410 && !cs
->second
.localentry0_
)
5411 || (cs
->second
.notoc_
5412 && !this->targ_
->power10_stubs()))
5413 calls
.push_back(cs
);
5414 if (calls
.size() > 1)
5415 std::stable_sort(calls
.begin(), calls
.end(),
5416 stub_sort
<plt_iter
>);
5418 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5419 std::vector
<branch_iter
> branches
;
5420 if (!this->long_branch_stubs_
.empty()
5421 && !this->targ_
->power10_stubs())
5422 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5423 bs
!= this->long_branch_stubs_
.end();
5425 if (bs
->second
.notoc_
)
5426 branches
.push_back(bs
);
5427 if (branches
.size() > 1)
5428 std::stable_sort(branches
.begin(), branches
.end(),
5429 stub_sort
<branch_iter
>);
5431 if (calls
.empty() && branches
.empty())
5434 unsigned int last_eh_loc
= 0;
5435 // offset pcrel sdata4, size udata4, and augmentation size byte.
5436 std::vector
<unsigned char> fde(9, 0);
5438 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5440 plt_iter cs
= calls
[i
];
5441 unsigned int off
= cs
->second
.off_
;
5442 // The __tls_get_addr_opt call stub needs to describe where
5443 // it saves LR, to support exceptions that might be thrown
5444 // from __tls_get_addr, and to support asynchronous exceptions.
5445 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5448 if (cs
->second
.r2save_
5449 && !cs
->second
.localentry0_
)
5452 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5453 fde
.resize(fde
.size() + 6);
5454 unsigned char* p
= &*fde
.end() - 6;
5455 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5457 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5458 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5459 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5460 *p
++ = elfcpp::DW_CFA_restore_extended
;
5462 last_eh_loc
= off
+ delta
;
5466 // notoc stubs also should describe LR changes, to support
5467 // asynchronous exceptions.
5468 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5469 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5470 fde
.resize(fde
.size() + 6);
5471 unsigned char* p
= &*fde
.end() - 6;
5472 *p
++ = elfcpp::DW_CFA_register
;
5475 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5476 *p
++ = elfcpp::DW_CFA_restore_extended
;
5478 last_eh_loc
= off
+ 8;
5481 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5483 branch_iter bs
= branches
[i
];
5484 unsigned int off
= bs
->second
.off_
+ 8;
5485 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5486 fde
.resize(fde
.size() + 6);
5487 unsigned char* p
= &*fde
.end() - 6;
5488 *p
++ = elfcpp::DW_CFA_register
;
5491 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5492 *p
++ = elfcpp::DW_CFA_restore_extended
;
5494 last_eh_loc
= off
+ 8;
5497 layout
->add_eh_frame_for_plt(this,
5498 Eh_cie
<size
>::eh_frame_cie
,
5499 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5500 &*fde
.begin(), fde
.size());
5503 template<int size
, bool big_endian
>
5505 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5508 && parameters
->options().ld_generated_unwind_info()
5509 && this->targ_
->has_glink())
5510 layout
->remove_eh_frame_for_plt(this,
5511 Eh_cie
<size
>::eh_frame_cie
,
5512 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5515 // A class to handle .glink.
5517 template<int size
, bool big_endian
>
5518 class Output_data_glink
: public Output_section_data
5521 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5522 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5524 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5525 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5526 end_branch_table_(), ge_size_(0)
5530 add_eh_frame(Layout
* layout
);
5533 add_global_entry(const Symbol
*);
5536 find_global_entry(const Symbol
*) const;
5539 global_entry_align(unsigned int off
) const
5541 unsigned int align
= param_plt_align
<size
>();
5542 return (off
+ align
- 1) & -align
;
5546 global_entry_off() const
5548 return this->global_entry_align(this->end_branch_table_
);
5552 global_entry_address() const
5554 gold_assert(this->is_data_size_valid());
5555 return this->address() + this->global_entry_off();
5559 pltresolve_size() const
5563 + (this->targ_
->abiversion() < 2 ? 11 * 4
5564 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5569 // Write to a map file.
5571 do_print_to_mapfile(Mapfile
* mapfile
) const
5572 { mapfile
->print_output_data(this, _("** glink")); }
5576 set_final_data_size();
5580 do_write(Output_file
*);
5582 // Allows access to .got and .plt for do_write.
5583 Target_powerpc
<size
, big_endian
>* targ_
;
5585 // Map sym to stub offset.
5586 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5587 Global_entry_stub_entries global_entry_stubs_
;
5589 unsigned int end_branch_table_
, ge_size_
;
5592 template<int size
, bool big_endian
>
5594 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5596 if (!parameters
->options().ld_generated_unwind_info())
5601 if (this->targ_
->abiversion() < 2)
5602 layout
->add_eh_frame_for_plt(this,
5603 Eh_cie
<64>::eh_frame_cie
,
5604 sizeof (Eh_cie
<64>::eh_frame_cie
),
5605 glink_eh_frame_fde_64v1
,
5606 sizeof (glink_eh_frame_fde_64v1
));
5607 else if (this->targ_
->has_localentry0())
5608 layout
->add_eh_frame_for_plt(this,
5609 Eh_cie
<64>::eh_frame_cie
,
5610 sizeof (Eh_cie
<64>::eh_frame_cie
),
5611 glink_eh_frame_fde_64v2_localentry0
,
5612 sizeof (glink_eh_frame_fde_64v2
));
5614 layout
->add_eh_frame_for_plt(this,
5615 Eh_cie
<64>::eh_frame_cie
,
5616 sizeof (Eh_cie
<64>::eh_frame_cie
),
5617 glink_eh_frame_fde_64v2
,
5618 sizeof (glink_eh_frame_fde_64v2
));
5622 // 32-bit .glink can use the default since the CIE return
5623 // address reg, LR, is valid.
5624 layout
->add_eh_frame_for_plt(this,
5625 Eh_cie
<32>::eh_frame_cie
,
5626 sizeof (Eh_cie
<32>::eh_frame_cie
),
5628 sizeof (default_fde
));
5629 // Except where LR is used in a PIC __glink_PLTresolve.
5630 if (parameters
->options().output_is_position_independent())
5631 layout
->add_eh_frame_for_plt(this,
5632 Eh_cie
<32>::eh_frame_cie
,
5633 sizeof (Eh_cie
<32>::eh_frame_cie
),
5634 glink_eh_frame_fde_32
,
5635 sizeof (glink_eh_frame_fde_32
));
5639 template<int size
, bool big_endian
>
5641 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5643 unsigned int off
= this->global_entry_align(this->ge_size_
);
5644 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5645 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5647 this->ge_size_
= off
+ 16;
5650 template<int size
, bool big_endian
>
5651 typename Output_data_glink
<size
, big_endian
>::Address
5652 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5654 typename
Global_entry_stub_entries::const_iterator p
5655 = this->global_entry_stubs_
.find(gsym
);
5656 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5659 template<int size
, bool big_endian
>
5661 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5663 unsigned int count
= this->targ_
->plt_entry_count();
5664 section_size_type total
= 0;
5670 // space for branch table
5671 total
+= 4 * (count
- 1);
5673 total
+= -total
& 15;
5674 total
+= this->pltresolve_size();
5678 total
+= this->pltresolve_size();
5680 // space for branch table
5682 if (this->targ_
->abiversion() < 2)
5686 total
+= 4 * (count
- 0x8000);
5690 this->end_branch_table_
= total
;
5691 total
= this->global_entry_align(total
);
5692 total
+= this->ge_size_
;
5694 this->set_data_size(total
);
5697 // Define symbols on stubs, identifying the stub.
5699 template<int size
, bool big_endian
>
5701 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5703 if (!this->plt_call_stubs_
.empty())
5705 // The key for the plt call stub hash table includes addresses,
5706 // therefore traversal order depends on those addresses, which
5707 // can change between runs if gold is a PIE. Unfortunately the
5708 // output .symtab ordering depends on the order in which symbols
5709 // are added to the linker symtab. We want reproducible output
5710 // so must sort the call stub symbols.
5711 typedef typename
Plt_stub_entries::iterator plt_iter
;
5712 std::vector
<plt_iter
> sorted
;
5713 sorted
.resize(this->plt_call_stubs_
.size());
5715 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5716 cs
!= this->plt_call_stubs_
.end();
5718 sorted
[cs
->second
.indx_
] = cs
;
5720 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5722 plt_iter cs
= sorted
[i
];
5725 if (cs
->first
.addend_
!= 0)
5726 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5729 if (cs
->first
.object_
)
5731 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5732 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5733 sprintf(obj
, "%x:", ppcobj
->uniq());
5736 const char *symname
;
5737 if (cs
->first
.sym_
== NULL
)
5739 sprintf(localname
, "%x", cs
->first
.locsym_
);
5740 symname
= localname
;
5742 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5743 symname
= this->targ_
->tls_get_addr_opt()->name();
5745 symname
= cs
->first
.sym_
->name();
5746 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5747 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5749 = this->stub_address() - this->address() + cs
->second
.off_
;
5750 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5751 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5755 typedef typename
Branch_stub_entries::iterator branch_iter
;
5756 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5757 bs
!= this->long_branch_stubs_
.end();
5760 if (bs
->second
.save_res_
)
5763 char* name
= new char[8 + 13 + 16 + 1];
5764 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5765 static_cast<unsigned long long>(bs
->first
.dest_
));
5766 Address value
= (this->stub_address() - this->address()
5767 + this->plt_size_
+ bs
->second
.off_
);
5768 bool need_lt
= false;
5769 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5770 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5774 // Emit the start of a __tls_get_addr_opt plt call stub.
5776 template<int size
, bool big_endian
>
5778 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5781 unsigned char* p
= *pp
;
5784 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5786 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5788 write_insn
<big_endian
>(p
, mr_0_3
);
5790 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5792 write_insn
<big_endian
>(p
, add_3_12_13
);
5794 write_insn
<big_endian
>(p
, beqlr
);
5796 write_insn
<big_endian
>(p
, mr_3_0
);
5800 write_insn
<big_endian
>(p
, mflr_11
);
5802 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5808 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5810 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5812 write_insn
<big_endian
>(p
, mr_0_3
);
5814 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5816 write_insn
<big_endian
>(p
, add_3_12_2
);
5818 write_insn
<big_endian
>(p
, beqlr
);
5820 write_insn
<big_endian
>(p
, mr_3_0
);
5822 write_insn
<big_endian
>(p
, nop
);
5828 // Emit the tail of a __tls_get_addr_opt plt call stub.
5830 template<int size
, bool big_endian
>
5832 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5834 write_insn
<big_endian
>(p
, bctrl
);
5836 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5838 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5840 write_insn
<big_endian
>(p
, mtlr_11
);
5842 write_insn
<big_endian
>(p
, blr
);
5845 // Emit pc-relative plt call stub code.
5847 template<bool big_endian
>
5848 static unsigned char*
5849 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5852 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5857 write_insn
<big_endian
>(p
, nop
);
5865 write_insn
<big_endian
>(p
, insn
>> 32);
5867 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5869 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5872 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5876 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5879 insn
= paddi_12_pc
| d34(off
);
5880 write_insn
<big_endian
>(p
, insn
>> 32);
5882 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5886 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5890 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5892 write_insn
<big_endian
>(p
, add_12_11_12
);
5897 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5899 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5903 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5906 insn
= paddi_12_pc
| d34(off
);
5907 write_insn
<big_endian
>(p
, insn
>> 32);
5909 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5913 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5917 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5919 write_insn
<big_endian
>(p
, add_12_11_12
);
5925 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5926 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5931 // lis %r12,xxx-1b@highest
5932 // ori %r12,%r12,xxx-1b@higher
5933 // sldi %r12,%r12,32
5934 // oris %r12,%r12,xxx-1b@high
5935 // ori %r12,%r12,xxx-1b@l
5936 // add/ldx %r12,%r11,%r12
5938 template<bool big_endian
>
5939 static unsigned char*
5940 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5942 write_insn
<big_endian
>(p
, mflr_12
);
5944 write_insn
<big_endian
>(p
, bcl_20_31
);
5946 write_insn
<big_endian
>(p
, mflr_11
);
5948 write_insn
<big_endian
>(p
, mtlr_12
);
5950 if (off
+ 0x8000 < 0x10000)
5953 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5955 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5957 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5959 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5962 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5964 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5968 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5970 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5975 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5977 if (((off
>> 32) & 0xffff) != 0)
5979 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5983 if (((off
>> 32) & 0xffffffffULL
) != 0)
5985 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5990 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5995 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5999 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6001 write_insn
<big_endian
>(p
, add_12_11_12
);
6007 // Size of a given plt call stub.
6009 template<int size
, bool big_endian
>
6011 Stub_table
<size
, big_endian
>::plt_call_size(
6012 typename
Plt_stub_entries::iterator p
) const
6016 const Symbol
* gsym
= p
->first
.sym_
;
6018 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
6021 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6022 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6023 plt_addr
+= plt
->address();
6024 if (this->targ_
->power10_stubs()
6025 && this->targ_
->power10_stubs_auto())
6027 unsigned int bytes
= 0;
6028 if (p
->second
.notoc_
)
6030 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6032 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6033 uint64_t odd
= from
& 4;
6034 uint64_t off
= plt_addr
- from
;
6035 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6036 bytes
+= odd
+ 4 * 4;
6037 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6041 bytes
= this->plt_call_align(bytes
);
6043 unsigned int tail
= 0;
6046 p
->second
.tocoff_
= bytes
;
6047 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6050 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6056 if (p
->second
.r2save_
)
6059 = this->targ_
->got_section()->output_section()->address();
6060 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6061 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6062 got_addr
+= ppcobj
->toc_base_offset();
6063 uint64_t off
= plt_addr
- got_addr
;
6064 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6066 return bytes
+ tail
;
6070 unsigned int bytes
= 0;
6071 unsigned int tail
= 0;
6072 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6075 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6082 if (p
->second
.r2save_
)
6085 if (this->targ_
->power10_stubs())
6087 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6088 uint64_t odd
= from
& 4;
6089 uint64_t off
= plt_addr
- from
;
6090 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6091 bytes
+= odd
+ 4 * 4;
6092 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6096 return bytes
+ tail
;
6099 if (p
->second
.notoc_
)
6101 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6102 uint64_t off
= plt_addr
- from
;
6103 if (off
+ 0x8000 < 0x10000)
6105 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6110 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6111 && ((off
>> 32) & 0xffff) != 0)
6113 if (((off
>> 32) & 0xffffffffULL
) != 0)
6120 return bytes
+ tail
;
6123 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6124 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6125 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6126 got_addr
+= ppcobj
->toc_base_offset();
6127 uint64_t off
= plt_addr
- got_addr
;
6128 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6129 if (this->targ_
->abiversion() < 2)
6131 bool static_chain
= parameters
->options().plt_static_chain();
6132 bool thread_safe
= this->targ_
->plt_thread_safe();
6136 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6138 return bytes
+ tail
;
6142 // Return long branch stub size.
6144 template<int size
, bool big_endian
>
6146 Stub_table
<size
, big_endian
>::branch_stub_size(
6147 typename
Branch_stub_entries::iterator p
,
6150 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6153 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6155 if (parameters
->options().output_is_position_independent())
6160 uint64_t off
= p
->first
.dest_
- loc
;
6161 unsigned int bytes
= 0;
6162 if (p
->second
.notoc_
)
6164 if (this->targ_
->power10_stubs())
6166 Address odd
= loc
& 4;
6167 if (off
+ (1 << 25) < 2 << 25)
6169 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6171 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6175 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6177 p
->second
.tocoff_
= bytes
;
6182 if (off
+ 0x8000 < 0x10000)
6184 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6186 if (off
+ 24 + (1 << 25) < 2 << 25)
6192 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6193 && ((off
>> 32) & 0xffff) != 0)
6195 if (((off
>> 32) & 0xffffffffULL
) != 0)
6205 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6206 if (off
+ (1 << 25) < 2 << 25)
6208 if (!this->targ_
->power10_stubs()
6209 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6214 template<int size
, bool big_endian
>
6216 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6219 gold_error(_("linkage table error against `%s'"),
6220 p
.sym_
->demangled_name().c_str());
6222 gold_error(_("linkage table error against `%s:[local %u]'"),
6223 p
.object_
->name().c_str(),
6227 // Write out plt and long branch stub code.
6229 template<int size
, bool big_endian
>
6231 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6233 if (this->plt_call_stubs_
.empty()
6234 && this->long_branch_stubs_
.empty())
6237 const section_size_type start_off
= this->offset();
6238 const section_size_type off
= this->stub_offset();
6239 const section_size_type oview_size
=
6240 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6241 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6245 && this->targ_
->power10_stubs())
6247 const Output_data_got_powerpc
<size
, big_endian
>* got
6248 = this->targ_
->got_section();
6249 Address got_os_addr
= got
->output_section()->address();
6251 if (!this->plt_call_stubs_
.empty())
6253 // Write out plt call stubs.
6254 typename
Plt_stub_entries::const_iterator cs
;
6255 for (cs
= this->plt_call_stubs_
.begin();
6256 cs
!= this->plt_call_stubs_
.end();
6259 p
= oview
+ cs
->second
.off_
;
6260 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6261 Address pltoff
= this->plt_off(cs
, &plt
);
6262 Address plt_addr
= pltoff
+ plt
->address();
6263 if (this->targ_
->power10_stubs_auto())
6265 if (cs
->second
.notoc_
)
6267 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6268 this->build_tls_opt_head(&p
, false);
6269 Address from
= this->stub_address() + (p
- oview
);
6270 Address delta
= plt_addr
- from
;
6271 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6273 write_insn
<big_endian
>(p
, mtctr_12
);
6275 write_insn
<big_endian
>(p
, bctr
);
6277 p
= oview
+ this->plt_call_align(p
- oview
);
6279 if (cs
->second
.toc_
)
6281 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6284 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6285 this->build_tls_opt_head(&p
, save_lr
);
6287 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6288 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(
6290 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6291 Address off
= plt_addr
- got_addr
;
6293 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6294 this->plt_error(cs
->first
);
6296 if (cs
->second
.r2save_
)
6298 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6303 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6305 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6310 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6313 write_insn
<big_endian
>(p
, mtctr_12
);
6315 if (cs
->second
.r2save_
6316 && !cs
->second
.localentry0_
6317 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6318 this->build_tls_opt_tail(p
);
6320 write_insn
<big_endian
>(p
, bctr
);
6325 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6328 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6329 this->build_tls_opt_head(&p
, save_lr
);
6331 if (cs
->second
.r2save_
)
6333 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6336 Address from
= this->stub_address() + (p
- oview
);
6337 Address delta
= plt_addr
- from
;
6338 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6339 write_insn
<big_endian
>(p
, mtctr_12
);
6341 if (cs
->second
.r2save_
6342 && !cs
->second
.localentry0_
6343 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6344 this->build_tls_opt_tail(p
);
6346 write_insn
<big_endian
>(p
, bctr
);
6351 // Write out long branch stubs.
6352 typename
Branch_stub_entries::const_iterator bs
;
6353 for (bs
= this->long_branch_stubs_
.begin();
6354 bs
!= this->long_branch_stubs_
.end();
6357 if (bs
->second
.save_res_
)
6359 Address off
= this->plt_size_
+ bs
->second
.off_
;
6361 Address loc
= this->stub_address() + off
;
6362 Address delta
= bs
->first
.dest_
- loc
;
6363 if (this->targ_
->power10_stubs_auto())
6365 if (bs
->second
.notoc_
)
6367 unsigned char* startp
= p
;
6368 p
= build_power10_offset
<big_endian
>(p
, delta
,
6370 delta
-= p
- startp
;
6372 if (delta
+ (1 << 25) < 2 << 25)
6373 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6376 write_insn
<big_endian
>(p
, mtctr_12
);
6378 write_insn
<big_endian
>(p
, bctr
);
6381 delta
-= p
- startp
;
6383 if (bs
->second
.toc_
)
6385 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6386 if (delta
+ (1 << 25) >= 2 << 25)
6389 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6390 gold_assert(brlt_addr
!= invalid_address
);
6391 brlt_addr
+= this->targ_
->brlt_section()->address();
6392 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6393 Address brltoff
= brlt_addr
- got_addr
;
6394 if (ha(brltoff
) == 0)
6396 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6401 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6403 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6407 if (delta
+ (1 << 25) < 2 << 25)
6408 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6411 write_insn
<big_endian
>(p
, mtctr_12
);
6413 write_insn
<big_endian
>(p
, bctr
);
6419 if (!bs
->second
.notoc_
)
6420 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6421 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6423 unsigned char* startp
= p
;
6424 p
= build_power10_offset
<big_endian
>(p
, delta
,
6426 delta
-= p
- startp
;
6428 if (delta
+ (1 << 25) < 2 << 25)
6429 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6432 write_insn
<big_endian
>(p
, mtctr_12
);
6434 write_insn
<big_endian
>(p
, bctr
);
6439 else if (size
== 64)
6441 const Output_data_got_powerpc
<size
, big_endian
>* got
6442 = this->targ_
->got_section();
6443 Address got_os_addr
= got
->output_section()->address();
6445 if (!this->plt_call_stubs_
.empty()
6446 && this->targ_
->abiversion() >= 2)
6448 // Write out plt call stubs for ELFv2.
6449 typename
Plt_stub_entries::const_iterator cs
;
6450 for (cs
= this->plt_call_stubs_
.begin();
6451 cs
!= this->plt_call_stubs_
.end();
6454 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6455 Address pltoff
= this->plt_off(cs
, &plt
);
6456 Address plt_addr
= pltoff
+ plt
->address();
6458 p
= oview
+ cs
->second
.off_
;
6459 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6461 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6462 this->build_tls_opt_head(&p
, save_lr
);
6464 if (cs
->second
.r2save_
)
6466 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6469 if (cs
->second
.notoc_
)
6471 Address from
= this->stub_address() + (p
- oview
) + 8;
6472 Address off
= plt_addr
- from
;
6473 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6477 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6478 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6479 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6480 Address off
= plt_addr
- got_addr
;
6482 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6483 this->plt_error(cs
->first
);
6487 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6489 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6494 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6498 write_insn
<big_endian
>(p
, mtctr_12
);
6500 if (cs
->second
.r2save_
6501 && !cs
->second
.localentry0_
6502 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6503 this->build_tls_opt_tail(p
);
6505 write_insn
<big_endian
>(p
, bctr
);
6508 else if (!this->plt_call_stubs_
.empty())
6510 // Write out plt call stubs for ELFv1.
6511 typename
Plt_stub_entries::const_iterator cs
;
6512 for (cs
= this->plt_call_stubs_
.begin();
6513 cs
!= this->plt_call_stubs_
.end();
6516 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6517 Address pltoff
= this->plt_off(cs
, &plt
);
6518 Address plt_addr
= pltoff
+ plt
->address();
6519 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6520 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6521 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6522 Address off
= plt_addr
- got_addr
;
6524 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6525 || cs
->second
.notoc_
)
6526 this->plt_error(cs
->first
);
6528 bool static_chain
= parameters
->options().plt_static_chain();
6529 bool thread_safe
= this->targ_
->plt_thread_safe();
6530 bool use_fake_dep
= false;
6531 Address cmp_branch_off
= 0;
6534 unsigned int pltindex
6535 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6536 / this->targ_
->plt_entry_size());
6538 = (this->targ_
->glink_section()->pltresolve_size()
6540 if (pltindex
> 32768)
6541 glinkoff
+= (pltindex
- 32768) * 4;
6543 = this->targ_
->glink_section()->address() + glinkoff
;
6545 = (this->stub_address() + cs
->second
.off_
+ 20
6546 + 4 * cs
->second
.r2save_
6547 + 4 * (ha(off
) != 0)
6548 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6549 + 4 * static_chain
);
6550 cmp_branch_off
= to
- from
;
6551 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6554 p
= oview
+ cs
->second
.off_
;
6555 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6557 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6558 this->build_tls_opt_head(&p
, save_lr
);
6559 use_fake_dep
= thread_safe
;
6561 if (cs
->second
.r2save_
)
6563 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6568 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6570 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6572 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6574 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6578 write_insn
<big_endian
>(p
, mtctr_12
);
6582 write_insn
<big_endian
>(p
, xor_2_12_12
);
6584 write_insn
<big_endian
>(p
, add_11_11_2
);
6587 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6591 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6597 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6599 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6601 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6605 write_insn
<big_endian
>(p
, mtctr_12
);
6609 write_insn
<big_endian
>(p
, xor_11_12_12
);
6611 write_insn
<big_endian
>(p
, add_2_2_11
);
6616 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6619 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6622 if (cs
->second
.r2save_
6623 && !cs
->second
.localentry0_
6624 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6625 this->build_tls_opt_tail(p
);
6626 else if (thread_safe
&& !use_fake_dep
)
6628 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6630 write_insn
<big_endian
>(p
, bnectr_p4
);
6632 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6635 write_insn
<big_endian
>(p
, bctr
);
6639 // Write out long branch stubs.
6640 typename
Branch_stub_entries::const_iterator bs
;
6641 for (bs
= this->long_branch_stubs_
.begin();
6642 bs
!= this->long_branch_stubs_
.end();
6645 if (bs
->second
.save_res_
)
6647 Address off
= this->plt_size_
+ bs
->second
.off_
;
6649 Address loc
= this->stub_address() + off
;
6650 Address delta
= bs
->first
.dest_
- loc
;
6651 if (!bs
->second
.notoc_
)
6652 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6653 if (bs
->second
.notoc_
)
6655 unsigned char* startp
= p
;
6656 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6657 delta
-= p
- startp
;
6659 else if (delta
+ (1 << 25) >= 2 << 25)
6662 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6663 gold_assert(brlt_addr
!= invalid_address
);
6664 brlt_addr
+= this->targ_
->brlt_section()->address();
6665 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6666 Address brltoff
= brlt_addr
- got_addr
;
6667 if (ha(brltoff
) == 0)
6669 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6674 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6676 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6680 if (delta
+ (1 << 25) < 2 << 25)
6681 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6684 write_insn
<big_endian
>(p
, mtctr_12
);
6686 write_insn
<big_endian
>(p
, bctr
);
6692 if (!this->plt_call_stubs_
.empty())
6694 // The address of _GLOBAL_OFFSET_TABLE_.
6695 Address g_o_t
= invalid_address
;
6697 // Write out plt call stubs.
6698 typename
Plt_stub_entries::const_iterator cs
;
6699 for (cs
= this->plt_call_stubs_
.begin();
6700 cs
!= this->plt_call_stubs_
.end();
6703 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6704 Address plt_addr
= this->plt_off(cs
, &plt
);
6705 plt_addr
+= plt
->address();
6707 p
= oview
+ cs
->second
.off_
;
6708 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6709 this->build_tls_opt_head(&p
, false);
6710 if (parameters
->options().output_is_position_independent())
6713 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6714 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6715 (cs
->first
.object_
));
6716 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6718 unsigned int got2
= ppcobj
->got2_shndx();
6719 got_addr
= ppcobj
->get_output_section_offset(got2
);
6720 gold_assert(got_addr
!= invalid_address
);
6721 got_addr
+= (ppcobj
->output_section(got2
)->address()
6722 + cs
->first
.addend_
);
6726 if (g_o_t
== invalid_address
)
6728 const Output_data_got_powerpc
<size
, big_endian
>* got
6729 = this->targ_
->got_section();
6730 g_o_t
= got
->address() + got
->g_o_t();
6735 Address off
= plt_addr
- got_addr
;
6737 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6740 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6742 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6747 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6749 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6752 write_insn
<big_endian
>(p
, mtctr_11
);
6754 write_insn
<big_endian
>(p
, bctr
);
6758 // Write out long branch stubs.
6759 typename
Branch_stub_entries::const_iterator bs
;
6760 for (bs
= this->long_branch_stubs_
.begin();
6761 bs
!= this->long_branch_stubs_
.end();
6764 if (bs
->second
.save_res_
)
6766 Address off
= this->plt_size_
+ bs
->second
.off_
;
6768 Address loc
= this->stub_address() + off
;
6769 Address delta
= bs
->first
.dest_
- loc
;
6770 if (delta
+ (1 << 25) < 2 << 25)
6771 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6772 else if (!parameters
->options().output_is_position_independent())
6774 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6776 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6781 write_insn
<big_endian
>(p
, mflr_0
);
6783 write_insn
<big_endian
>(p
, bcl_20_31
);
6785 write_insn
<big_endian
>(p
, mflr_12
);
6787 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6789 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6791 write_insn
<big_endian
>(p
, mtlr_0
);
6794 write_insn
<big_endian
>(p
, mtctr_12
);
6796 write_insn
<big_endian
>(p
, bctr
);
6799 if (this->need_save_res_
)
6801 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6802 memcpy (p
, this->targ_
->savres_section()->contents(),
6803 this->targ_
->savres_section()->data_size());
6807 // Write out .glink.
6809 template<int size
, bool big_endian
>
6811 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6813 const section_size_type off
= this->offset();
6814 const section_size_type oview_size
=
6815 convert_to_section_size_type(this->data_size());
6816 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6819 // The base address of the .plt section.
6820 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6821 Address plt_base
= this->targ_
->plt_section()->address();
6825 if (this->end_branch_table_
!= 0)
6827 // Write pltresolve stub.
6829 Address after_bcl
= this->address() + 16;
6830 Address pltoff
= plt_base
- after_bcl
;
6832 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6834 if (this->targ_
->abiversion() < 2)
6836 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6837 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6838 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6839 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6840 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6841 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6842 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6843 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6844 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6845 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6849 if (this->targ_
->has_localentry0())
6851 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6853 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6854 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6855 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6856 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6857 if (this->targ_
->has_localentry0())
6859 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
6863 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
6865 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6866 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
6867 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
6868 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6869 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6870 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6871 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6873 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6874 gold_assert(p
== oview
+ this->pltresolve_size());
6876 // Write lazy link call stubs.
6878 while (p
< oview
+ this->end_branch_table_
)
6880 if (this->targ_
->abiversion() < 2)
6884 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6888 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6889 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6892 uint32_t branch_off
= 8 - (p
- oview
);
6893 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6898 Address plt_base
= this->targ_
->plt_section()->address();
6899 Address iplt_base
= invalid_address
;
6900 unsigned int global_entry_off
= this->global_entry_off();
6901 Address global_entry_base
= this->address() + global_entry_off
;
6902 typename
Global_entry_stub_entries::const_iterator ge
;
6903 for (ge
= this->global_entry_stubs_
.begin();
6904 ge
!= this->global_entry_stubs_
.end();
6907 p
= oview
+ global_entry_off
+ ge
->second
;
6908 Address plt_addr
= ge
->first
->plt_offset();
6909 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6910 && ge
->first
->can_use_relative_reloc(false))
6912 if (iplt_base
== invalid_address
)
6913 iplt_base
= this->targ_
->iplt_section()->address();
6914 plt_addr
+= iplt_base
;
6917 plt_addr
+= plt_base
;
6918 Address my_addr
= global_entry_base
+ ge
->second
;
6919 Address off
= plt_addr
- my_addr
;
6921 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6922 gold_error(_("linkage table error against `%s'"),
6923 ge
->first
->demangled_name().c_str());
6925 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6926 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6927 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6928 write_insn
<big_endian
>(p
, bctr
);
6933 const Output_data_got_powerpc
<size
, big_endian
>* got
6934 = this->targ_
->got_section();
6935 // The address of _GLOBAL_OFFSET_TABLE_.
6936 Address g_o_t
= got
->address() + got
->g_o_t();
6938 // Write out pltresolve branch table.
6940 unsigned int the_end
= oview_size
- this->pltresolve_size();
6941 unsigned char* end_p
= oview
+ the_end
;
6942 while (p
< end_p
- 8 * 4)
6943 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6945 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6947 // Write out pltresolve call stub.
6948 end_p
= oview
+ oview_size
;
6949 if (parameters
->options().output_is_position_independent())
6951 Address res0_off
= 0;
6952 Address after_bcl_off
= the_end
+ 12;
6953 Address bcl_res0
= after_bcl_off
- res0_off
;
6955 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6957 write_insn
<big_endian
>(p
, mflr_0
);
6959 write_insn
<big_endian
>(p
, bcl_20_31
);
6961 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6963 write_insn
<big_endian
>(p
, mflr_12
);
6965 write_insn
<big_endian
>(p
, mtlr_0
);
6967 write_insn
<big_endian
>(p
, sub_11_11_12
);
6970 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6972 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6974 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6976 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6978 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6982 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6984 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6987 write_insn
<big_endian
>(p
, mtctr_0
);
6989 write_insn
<big_endian
>(p
, add_0_11_11
);
6991 write_insn
<big_endian
>(p
, add_11_0_11
);
6995 Address res0
= this->address();
6997 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6999 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7001 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7002 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7004 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7006 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7008 write_insn
<big_endian
>(p
, mtctr_0
);
7010 write_insn
<big_endian
>(p
, add_0_11_11
);
7012 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7013 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7015 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7017 write_insn
<big_endian
>(p
, add_11_0_11
);
7020 write_insn
<big_endian
>(p
, bctr
);
7024 write_insn
<big_endian
>(p
, nop
);
7029 of
->write_output_view(off
, oview_size
, oview
);
7033 // A class to handle linker generated save/restore functions.
7035 template<int size
, bool big_endian
>
7036 class Output_data_save_res
: public Output_section_data_build
7039 Output_data_save_res(Symbol_table
* symtab
);
7041 const unsigned char*
7048 // Write to a map file.
7050 do_print_to_mapfile(Mapfile
* mapfile
) const
7051 { mapfile
->print_output_data(this, _("** save/restore")); }
7054 do_write(Output_file
*);
7057 // The maximum size of save/restore contents.
7058 static const unsigned int savres_max
= 218*4;
7061 savres_define(Symbol_table
* symtab
,
7063 unsigned int lo
, unsigned int hi
,
7064 unsigned char* write_ent(unsigned char*, int),
7065 unsigned char* write_tail(unsigned char*, int));
7067 unsigned char *contents_
;
7070 template<bool big_endian
>
7071 static unsigned char*
7072 savegpr0(unsigned char* p
, int r
)
7074 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7075 write_insn
<big_endian
>(p
, insn
);
7079 template<bool big_endian
>
7080 static unsigned char*
7081 savegpr0_tail(unsigned char* p
, int r
)
7083 p
= savegpr0
<big_endian
>(p
, r
);
7084 uint32_t insn
= std_0_1
+ 16;
7085 write_insn
<big_endian
>(p
, insn
);
7087 write_insn
<big_endian
>(p
, blr
);
7091 template<bool big_endian
>
7092 static unsigned char*
7093 restgpr0(unsigned char* p
, int r
)
7095 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7096 write_insn
<big_endian
>(p
, insn
);
7100 template<bool big_endian
>
7101 static unsigned char*
7102 restgpr0_tail(unsigned char* p
, int r
)
7104 uint32_t insn
= ld_0_1
+ 16;
7105 write_insn
<big_endian
>(p
, insn
);
7107 p
= restgpr0
<big_endian
>(p
, r
);
7108 write_insn
<big_endian
>(p
, mtlr_0
);
7112 p
= restgpr0
<big_endian
>(p
, 30);
7113 p
= restgpr0
<big_endian
>(p
, 31);
7115 write_insn
<big_endian
>(p
, blr
);
7119 template<bool big_endian
>
7120 static unsigned char*
7121 savegpr1(unsigned char* p
, int r
)
7123 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7124 write_insn
<big_endian
>(p
, insn
);
7128 template<bool big_endian
>
7129 static unsigned char*
7130 savegpr1_tail(unsigned char* p
, int r
)
7132 p
= savegpr1
<big_endian
>(p
, r
);
7133 write_insn
<big_endian
>(p
, blr
);
7137 template<bool big_endian
>
7138 static unsigned char*
7139 restgpr1(unsigned char* p
, int r
)
7141 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7142 write_insn
<big_endian
>(p
, insn
);
7146 template<bool big_endian
>
7147 static unsigned char*
7148 restgpr1_tail(unsigned char* p
, int r
)
7150 p
= restgpr1
<big_endian
>(p
, r
);
7151 write_insn
<big_endian
>(p
, blr
);
7155 template<bool big_endian
>
7156 static unsigned char*
7157 savefpr(unsigned char* p
, int r
)
7159 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7160 write_insn
<big_endian
>(p
, insn
);
7164 template<bool big_endian
>
7165 static unsigned char*
7166 savefpr0_tail(unsigned char* p
, int r
)
7168 p
= savefpr
<big_endian
>(p
, r
);
7169 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7171 write_insn
<big_endian
>(p
, blr
);
7175 template<bool big_endian
>
7176 static unsigned char*
7177 restfpr(unsigned char* p
, int r
)
7179 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7180 write_insn
<big_endian
>(p
, insn
);
7184 template<bool big_endian
>
7185 static unsigned char*
7186 restfpr0_tail(unsigned char* p
, int r
)
7188 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7190 p
= restfpr
<big_endian
>(p
, r
);
7191 write_insn
<big_endian
>(p
, mtlr_0
);
7195 p
= restfpr
<big_endian
>(p
, 30);
7196 p
= restfpr
<big_endian
>(p
, 31);
7198 write_insn
<big_endian
>(p
, blr
);
7202 template<bool big_endian
>
7203 static unsigned char*
7204 savefpr1_tail(unsigned char* p
, int r
)
7206 p
= savefpr
<big_endian
>(p
, r
);
7207 write_insn
<big_endian
>(p
, blr
);
7211 template<bool big_endian
>
7212 static unsigned char*
7213 restfpr1_tail(unsigned char* p
, int r
)
7215 p
= restfpr
<big_endian
>(p
, r
);
7216 write_insn
<big_endian
>(p
, blr
);
7220 template<bool big_endian
>
7221 static unsigned char*
7222 savevr(unsigned char* p
, int r
)
7224 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7225 write_insn
<big_endian
>(p
, insn
);
7227 insn
= stvx_0_12_0
+ (r
<< 21);
7228 write_insn
<big_endian
>(p
, insn
);
7232 template<bool big_endian
>
7233 static unsigned char*
7234 savevr_tail(unsigned char* p
, int r
)
7236 p
= savevr
<big_endian
>(p
, r
);
7237 write_insn
<big_endian
>(p
, blr
);
7241 template<bool big_endian
>
7242 static unsigned char*
7243 restvr(unsigned char* p
, int r
)
7245 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7246 write_insn
<big_endian
>(p
, insn
);
7248 insn
= lvx_0_12_0
+ (r
<< 21);
7249 write_insn
<big_endian
>(p
, insn
);
7253 template<bool big_endian
>
7254 static unsigned char*
7255 restvr_tail(unsigned char* p
, int r
)
7257 p
= restvr
<big_endian
>(p
, r
);
7258 write_insn
<big_endian
>(p
, blr
);
7263 template<int size
, bool big_endian
>
7264 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7265 Symbol_table
* symtab
)
7266 : Output_section_data_build(4),
7269 this->savres_define(symtab
,
7270 "_savegpr0_", 14, 31,
7271 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7272 this->savres_define(symtab
,
7273 "_restgpr0_", 14, 29,
7274 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7275 this->savres_define(symtab
,
7276 "_restgpr0_", 30, 31,
7277 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7278 this->savres_define(symtab
,
7279 "_savegpr1_", 14, 31,
7280 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7281 this->savres_define(symtab
,
7282 "_restgpr1_", 14, 31,
7283 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7284 this->savres_define(symtab
,
7285 "_savefpr_", 14, 31,
7286 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7287 this->savres_define(symtab
,
7288 "_restfpr_", 14, 29,
7289 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7290 this->savres_define(symtab
,
7291 "_restfpr_", 30, 31,
7292 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7293 this->savres_define(symtab
,
7295 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7296 this->savres_define(symtab
,
7298 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7299 this->savres_define(symtab
,
7301 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7302 this->savres_define(symtab
,
7304 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7307 template<int size
, bool big_endian
>
7309 Output_data_save_res
<size
, big_endian
>::savres_define(
7310 Symbol_table
* symtab
,
7312 unsigned int lo
, unsigned int hi
,
7313 unsigned char* write_ent(unsigned char*, int),
7314 unsigned char* write_tail(unsigned char*, int))
7316 size_t len
= strlen(name
);
7317 bool writing
= false;
7320 memcpy(sym
, name
, len
);
7323 for (unsigned int i
= lo
; i
<= hi
; i
++)
7325 sym
[len
+ 0] = i
/ 10 + '0';
7326 sym
[len
+ 1] = i
% 10 + '0';
7327 Symbol
* gsym
= symtab
->lookup(sym
);
7328 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7329 writing
= writing
|| refd
;
7332 if (this->contents_
== NULL
)
7333 this->contents_
= new unsigned char[this->savres_max
];
7335 section_size_type value
= this->current_data_size();
7336 unsigned char* p
= this->contents_
+ value
;
7338 p
= write_ent(p
, i
);
7340 p
= write_tail(p
, i
);
7341 section_size_type cur_size
= p
- this->contents_
;
7342 this->set_current_data_size(cur_size
);
7344 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7345 this, value
, cur_size
- value
,
7346 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7347 elfcpp::STV_HIDDEN
, 0, false, false);
7352 // Write out save/restore.
7354 template<int size
, bool big_endian
>
7356 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7358 const section_size_type off
= this->offset();
7359 const section_size_type oview_size
=
7360 convert_to_section_size_type(this->data_size());
7361 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7362 memcpy(oview
, this->contents_
, oview_size
);
7363 of
->write_output_view(off
, oview_size
, oview
);
7367 // Create the glink section.
7369 template<int size
, bool big_endian
>
7371 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7373 if (this->glink_
== NULL
)
7375 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7376 this->glink_
->add_eh_frame(layout
);
7377 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7378 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7379 this->glink_
, ORDER_TEXT
, false);
7383 // Create a PLT entry for a global symbol.
7385 template<int size
, bool big_endian
>
7387 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7391 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7392 && gsym
->can_use_relative_reloc(false))
7394 if (this->iplt_
== NULL
)
7395 this->make_iplt_section(symtab
, layout
);
7396 this->iplt_
->add_ifunc_entry(gsym
);
7400 if (this->plt_
== NULL
)
7401 this->make_plt_section(symtab
, layout
);
7402 this->plt_
->add_entry(gsym
);
7406 // Make a PLT entry for a local symbol.
7408 template<int size
, bool big_endian
>
7410 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7412 Sized_relobj_file
<size
, big_endian
>* relobj
,
7415 if (this->lplt_
== NULL
)
7416 this->make_lplt_section(layout
);
7417 this->lplt_
->add_local_entry(relobj
, r_sym
);
7420 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7422 template<int size
, bool big_endian
>
7424 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7425 Symbol_table
* symtab
,
7427 Sized_relobj_file
<size
, big_endian
>* relobj
,
7430 if (this->iplt_
== NULL
)
7431 this->make_iplt_section(symtab
, layout
);
7432 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7435 // Return the number of entries in the PLT.
7437 template<int size
, bool big_endian
>
7439 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7441 if (this->plt_
== NULL
)
7443 return this->plt_
->entry_count();
7446 // Create a GOT entry for local dynamic __tls_get_addr calls.
7448 template<int size
, bool big_endian
>
7450 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7451 Symbol_table
* symtab
,
7453 Sized_relobj_file
<size
, big_endian
>* object
)
7455 if (this->tlsld_got_offset_
== -1U)
7457 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7458 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7459 Output_data_got_powerpc
<size
, big_endian
>* got
7460 = this->got_section(symtab
, layout
);
7461 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7462 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7464 this->tlsld_got_offset_
= got_offset
;
7466 return this->tlsld_got_offset_
;
7469 // Get the Reference_flags for a particular relocation.
7471 template<int size
, bool big_endian
>
7473 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7474 unsigned int r_type
,
7475 const Target_powerpc
* target
)
7481 case elfcpp::R_POWERPC_NONE
:
7482 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7483 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7484 case elfcpp::R_PPC64_TOC
:
7485 // No symbol reference.
7488 case elfcpp::R_PPC64_ADDR64
:
7489 case elfcpp::R_PPC64_UADDR64
:
7490 case elfcpp::R_POWERPC_ADDR32
:
7491 case elfcpp::R_POWERPC_UADDR32
:
7492 case elfcpp::R_POWERPC_ADDR16
:
7493 case elfcpp::R_POWERPC_UADDR16
:
7494 case elfcpp::R_POWERPC_ADDR16_LO
:
7495 case elfcpp::R_POWERPC_ADDR16_HI
:
7496 case elfcpp::R_POWERPC_ADDR16_HA
:
7497 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7498 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7499 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7500 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7501 case elfcpp::R_PPC64_D34
:
7502 case elfcpp::R_PPC64_D34_LO
:
7503 case elfcpp::R_PPC64_D34_HI30
:
7504 case elfcpp::R_PPC64_D34_HA30
:
7505 case elfcpp::R_PPC64_D28
:
7506 ref
= Symbol::ABSOLUTE_REF
;
7509 case elfcpp::R_POWERPC_ADDR24
:
7510 case elfcpp::R_POWERPC_ADDR14
:
7511 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7512 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7513 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7516 case elfcpp::R_PPC64_REL64
:
7517 case elfcpp::R_POWERPC_REL32
:
7518 case elfcpp::R_PPC_LOCAL24PC
:
7519 case elfcpp::R_POWERPC_REL16
:
7520 case elfcpp::R_POWERPC_REL16_LO
:
7521 case elfcpp::R_POWERPC_REL16_HI
:
7522 case elfcpp::R_POWERPC_REL16_HA
:
7523 case elfcpp::R_PPC64_REL16_HIGH
:
7524 case elfcpp::R_PPC64_REL16_HIGHA
:
7525 case elfcpp::R_PPC64_REL16_HIGHER
:
7526 case elfcpp::R_PPC64_REL16_HIGHERA
:
7527 case elfcpp::R_PPC64_REL16_HIGHEST
:
7528 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7529 case elfcpp::R_PPC64_PCREL34
:
7530 case elfcpp::R_PPC64_REL16_HIGHER34
:
7531 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7532 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7533 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7534 case elfcpp::R_PPC64_PCREL28
:
7535 ref
= Symbol::RELATIVE_REF
;
7538 case elfcpp::R_PPC64_REL24_NOTOC
:
7542 case elfcpp::R_POWERPC_REL24
:
7543 case elfcpp::R_PPC_PLTREL24
:
7544 case elfcpp::R_POWERPC_REL14
:
7545 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7546 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7547 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7550 case elfcpp::R_POWERPC_GOT16
:
7551 case elfcpp::R_POWERPC_GOT16_LO
:
7552 case elfcpp::R_POWERPC_GOT16_HI
:
7553 case elfcpp::R_POWERPC_GOT16_HA
:
7554 case elfcpp::R_PPC64_GOT16_DS
:
7555 case elfcpp::R_PPC64_GOT16_LO_DS
:
7556 case elfcpp::R_PPC64_GOT_PCREL34
:
7557 case elfcpp::R_PPC64_TOC16
:
7558 case elfcpp::R_PPC64_TOC16_LO
:
7559 case elfcpp::R_PPC64_TOC16_HI
:
7560 case elfcpp::R_PPC64_TOC16_HA
:
7561 case elfcpp::R_PPC64_TOC16_DS
:
7562 case elfcpp::R_PPC64_TOC16_LO_DS
:
7563 case elfcpp::R_POWERPC_PLT16_LO
:
7564 case elfcpp::R_POWERPC_PLT16_HI
:
7565 case elfcpp::R_POWERPC_PLT16_HA
:
7566 case elfcpp::R_PPC64_PLT16_LO_DS
:
7567 case elfcpp::R_PPC64_PLT_PCREL34
:
7568 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7569 ref
= Symbol::RELATIVE_REF
;
7572 case elfcpp::R_POWERPC_GOT_TPREL16
:
7573 case elfcpp::R_POWERPC_TLS
:
7574 case elfcpp::R_PPC64_TLSGD
:
7575 case elfcpp::R_PPC64_TLSLD
:
7576 case elfcpp::R_PPC64_TPREL34
:
7577 case elfcpp::R_PPC64_DTPREL34
:
7578 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7579 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7580 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7581 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7582 ref
= Symbol::TLS_REF
;
7585 case elfcpp::R_POWERPC_COPY
:
7586 case elfcpp::R_POWERPC_GLOB_DAT
:
7587 case elfcpp::R_POWERPC_JMP_SLOT
:
7588 case elfcpp::R_POWERPC_RELATIVE
:
7589 case elfcpp::R_POWERPC_DTPMOD
:
7591 // Not expected. We will give an error later.
7595 if (size
== 64 && target
->abiversion() < 2)
7596 ref
|= Symbol::FUNC_DESC_ABI
;
7600 // Report an unsupported relocation against a local symbol.
7602 template<int size
, bool big_endian
>
7604 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7605 Sized_relobj_file
<size
, big_endian
>* object
,
7606 unsigned int r_type
)
7608 gold_error(_("%s: unsupported reloc %u against local symbol"),
7609 object
->name().c_str(), r_type
);
7612 // We are about to emit a dynamic relocation of type R_TYPE. If the
7613 // dynamic linker does not support it, issue an error.
7615 template<int size
, bool big_endian
>
7617 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7618 unsigned int r_type
)
7620 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7622 // These are the relocation types supported by glibc for both 32-bit
7623 // and 64-bit powerpc.
7626 case elfcpp::R_POWERPC_NONE
:
7627 case elfcpp::R_POWERPC_RELATIVE
:
7628 case elfcpp::R_POWERPC_GLOB_DAT
:
7629 case elfcpp::R_POWERPC_DTPMOD
:
7630 case elfcpp::R_POWERPC_DTPREL
:
7631 case elfcpp::R_POWERPC_TPREL
:
7632 case elfcpp::R_POWERPC_JMP_SLOT
:
7633 case elfcpp::R_POWERPC_COPY
:
7634 case elfcpp::R_POWERPC_IRELATIVE
:
7635 case elfcpp::R_POWERPC_ADDR32
:
7636 case elfcpp::R_POWERPC_UADDR32
:
7637 case elfcpp::R_POWERPC_ADDR24
:
7638 case elfcpp::R_POWERPC_ADDR16
:
7639 case elfcpp::R_POWERPC_UADDR16
:
7640 case elfcpp::R_POWERPC_ADDR16_LO
:
7641 case elfcpp::R_POWERPC_ADDR16_HI
:
7642 case elfcpp::R_POWERPC_ADDR16_HA
:
7643 case elfcpp::R_POWERPC_ADDR14
:
7644 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7645 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7646 case elfcpp::R_POWERPC_REL32
:
7647 case elfcpp::R_POWERPC_TPREL16
:
7648 case elfcpp::R_POWERPC_TPREL16_LO
:
7649 case elfcpp::R_POWERPC_TPREL16_HI
:
7650 case elfcpp::R_POWERPC_TPREL16_HA
:
7661 // These are the relocation types supported only on 64-bit.
7662 case elfcpp::R_PPC64_ADDR64
:
7663 case elfcpp::R_PPC64_UADDR64
:
7664 case elfcpp::R_PPC64_JMP_IREL
:
7665 case elfcpp::R_PPC64_ADDR16_DS
:
7666 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7667 case elfcpp::R_PPC64_ADDR16_HIGH
:
7668 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7669 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7670 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7671 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7672 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7673 case elfcpp::R_PPC64_REL64
:
7674 case elfcpp::R_POWERPC_ADDR30
:
7675 case elfcpp::R_PPC64_TPREL16_DS
:
7676 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7677 case elfcpp::R_PPC64_TPREL16_HIGH
:
7678 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7679 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7680 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7681 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7682 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7693 // These are the relocation types supported only on 32-bit.
7694 // ??? glibc ld.so doesn't need to support these.
7695 case elfcpp::R_POWERPC_REL24
:
7696 case elfcpp::R_POWERPC_DTPREL16
:
7697 case elfcpp::R_POWERPC_DTPREL16_LO
:
7698 case elfcpp::R_POWERPC_DTPREL16_HI
:
7699 case elfcpp::R_POWERPC_DTPREL16_HA
:
7707 // This prevents us from issuing more than one error per reloc
7708 // section. But we can still wind up issuing more than one
7709 // error per object file.
7710 if (this->issued_non_pic_error_
)
7712 gold_assert(parameters
->options().output_is_position_independent());
7713 object
->error(_("requires unsupported dynamic reloc; "
7714 "recompile with -fPIC"));
7715 this->issued_non_pic_error_
= true;
7719 // Return whether we need to make a PLT entry for a relocation of the
7720 // given type against a STT_GNU_IFUNC symbol.
7722 template<int size
, bool big_endian
>
7724 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7725 Target_powerpc
<size
, big_endian
>* target
,
7726 Sized_relobj_file
<size
, big_endian
>* object
,
7727 unsigned int r_type
,
7730 // In non-pic code any reference will resolve to the plt call stub
7731 // for the ifunc symbol.
7732 if ((size
== 32 || target
->abiversion() >= 2)
7733 && !parameters
->options().output_is_position_independent())
7738 // Word size refs from data sections are OK, but don't need a PLT entry.
7739 case elfcpp::R_POWERPC_ADDR32
:
7740 case elfcpp::R_POWERPC_UADDR32
:
7745 case elfcpp::R_PPC64_ADDR64
:
7746 case elfcpp::R_PPC64_UADDR64
:
7751 // GOT refs are good, but also don't need a PLT entry.
7752 case elfcpp::R_POWERPC_GOT16
:
7753 case elfcpp::R_POWERPC_GOT16_LO
:
7754 case elfcpp::R_POWERPC_GOT16_HI
:
7755 case elfcpp::R_POWERPC_GOT16_HA
:
7756 case elfcpp::R_PPC64_GOT16_DS
:
7757 case elfcpp::R_PPC64_GOT16_LO_DS
:
7758 case elfcpp::R_PPC64_GOT_PCREL34
:
7761 // PLT relocs are OK and need a PLT entry.
7762 case elfcpp::R_POWERPC_PLT16_LO
:
7763 case elfcpp::R_POWERPC_PLT16_HI
:
7764 case elfcpp::R_POWERPC_PLT16_HA
:
7765 case elfcpp::R_PPC64_PLT16_LO_DS
:
7766 case elfcpp::R_POWERPC_PLTSEQ
:
7767 case elfcpp::R_POWERPC_PLTCALL
:
7768 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7769 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7770 case elfcpp::R_PPC64_PLT_PCREL34
:
7771 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7775 // Function calls are good, and these do need a PLT entry.
7776 case elfcpp::R_PPC64_REL24_NOTOC
:
7780 case elfcpp::R_POWERPC_ADDR24
:
7781 case elfcpp::R_POWERPC_ADDR14
:
7782 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7783 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7784 case elfcpp::R_POWERPC_REL24
:
7785 case elfcpp::R_PPC_PLTREL24
:
7786 case elfcpp::R_POWERPC_REL14
:
7787 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7788 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7795 // Anything else is a problem.
7796 // If we are building a static executable, the libc startup function
7797 // responsible for applying indirect function relocations is going
7798 // to complain about the reloc type.
7799 // If we are building a dynamic executable, we will have a text
7800 // relocation. The dynamic loader will set the text segment
7801 // writable and non-executable to apply text relocations. So we'll
7802 // segfault when trying to run the indirection function to resolve
7805 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7806 object
->name().c_str(), r_type
);
7810 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7814 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7816 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7817 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7818 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7819 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7820 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7821 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7822 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7823 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7824 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7825 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7826 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7827 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7828 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7829 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7830 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7831 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7832 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7833 /* Exclude lfqu by testing reloc. If relocs are ever
7834 defined for the reduced D field in psq_lu then those
7835 will need testing too. */
7836 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7837 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7838 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7840 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7841 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7842 /* Exclude stfqu. psq_stu as above for psq_lu. */
7843 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7844 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7845 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7846 && (insn
& 1) == 0));
7849 // Scan a relocation for a local symbol.
7851 template<int size
, bool big_endian
>
7853 Target_powerpc
<size
, big_endian
>::Scan::local(
7854 Symbol_table
* symtab
,
7856 Target_powerpc
<size
, big_endian
>* target
,
7857 Sized_relobj_file
<size
, big_endian
>* object
,
7858 unsigned int data_shndx
,
7859 Output_section
* output_section
,
7860 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7861 unsigned int r_type
,
7862 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7865 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7867 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7868 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7870 this->expect_tls_get_addr_call();
7871 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7872 if (tls_type
!= tls::TLSOPT_NONE
)
7873 this->skip_next_tls_get_addr_call();
7875 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7876 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7878 this->expect_tls_get_addr_call();
7879 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7880 if (tls_type
!= tls::TLSOPT_NONE
)
7881 this->skip_next_tls_get_addr_call();
7884 Powerpc_relobj
<size
, big_endian
>* ppc_object
7885 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7890 && data_shndx
== ppc_object
->opd_shndx()
7891 && r_type
== elfcpp::R_PPC64_ADDR64
)
7892 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7896 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7897 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7898 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7900 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7901 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7902 r_type
, r_sym
, reloc
.get_r_addend());
7903 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7908 case elfcpp::R_POWERPC_NONE
:
7909 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7910 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7911 case elfcpp::R_POWERPC_TLS
:
7912 case elfcpp::R_PPC64_ENTRY
:
7913 case elfcpp::R_POWERPC_PLTSEQ
:
7914 case elfcpp::R_POWERPC_PLTCALL
:
7915 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7916 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7917 case elfcpp::R_PPC64_PCREL_OPT
:
7918 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7919 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7920 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7921 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7922 case elfcpp::R_PPC64_REL16_HIGHER34
:
7923 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7924 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7925 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7926 case elfcpp::R_PPC64_D34
:
7927 case elfcpp::R_PPC64_D34_LO
:
7928 case elfcpp::R_PPC64_D34_HI30
:
7929 case elfcpp::R_PPC64_D34_HA30
:
7930 case elfcpp::R_PPC64_D28
:
7931 case elfcpp::R_PPC64_PCREL34
:
7932 case elfcpp::R_PPC64_PCREL28
:
7933 case elfcpp::R_PPC64_TPREL34
:
7934 case elfcpp::R_PPC64_DTPREL34
:
7937 case elfcpp::R_PPC64_TOC
:
7939 Output_data_got_powerpc
<size
, big_endian
>* got
7940 = target
->got_section(symtab
, layout
);
7941 if (parameters
->options().output_is_position_independent())
7943 Address off
= reloc
.get_r_offset();
7945 && target
->abiversion() < 2
7946 && data_shndx
== ppc_object
->opd_shndx()
7947 && ppc_object
->get_opd_discard(off
- 8))
7950 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7951 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7952 rela_dyn
->add_output_section_relative(got
->output_section(),
7953 elfcpp::R_POWERPC_RELATIVE
,
7955 object
, data_shndx
, off
,
7956 symobj
->toc_base_offset());
7961 case elfcpp::R_PPC64_ADDR64
:
7962 case elfcpp::R_PPC64_UADDR64
:
7963 case elfcpp::R_POWERPC_ADDR32
:
7964 case elfcpp::R_POWERPC_UADDR32
:
7965 case elfcpp::R_POWERPC_ADDR24
:
7966 case elfcpp::R_POWERPC_ADDR16
:
7967 case elfcpp::R_POWERPC_ADDR16_LO
:
7968 case elfcpp::R_POWERPC_ADDR16_HI
:
7969 case elfcpp::R_POWERPC_ADDR16_HA
:
7970 case elfcpp::R_POWERPC_UADDR16
:
7971 case elfcpp::R_PPC64_ADDR16_HIGH
:
7972 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7973 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7974 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7975 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7976 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7977 case elfcpp::R_PPC64_ADDR16_DS
:
7978 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7979 case elfcpp::R_POWERPC_ADDR14
:
7980 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7981 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7982 // If building a shared library (or a position-independent
7983 // executable), we need to create a dynamic relocation for
7985 if (parameters
->options().output_is_position_independent()
7986 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7988 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7990 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7991 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7992 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7994 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7995 : elfcpp::R_POWERPC_RELATIVE
);
7996 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7997 output_section
, data_shndx
,
7998 reloc
.get_r_offset(),
7999 reloc
.get_r_addend(), false);
8001 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8003 check_non_pic(object
, r_type
);
8004 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8005 data_shndx
, reloc
.get_r_offset(),
8006 reloc
.get_r_addend());
8010 gold_assert(lsym
.get_st_value() == 0);
8011 unsigned int shndx
= lsym
.get_st_shndx();
8013 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8016 object
->error(_("section symbol %u has bad shndx %u"),
8019 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8020 output_section
, data_shndx
,
8021 reloc
.get_r_offset());
8026 case elfcpp::R_PPC64_PLT_PCREL34
:
8027 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8028 case elfcpp::R_POWERPC_PLT16_LO
:
8029 case elfcpp::R_POWERPC_PLT16_HI
:
8030 case elfcpp::R_POWERPC_PLT16_HA
:
8031 case elfcpp::R_PPC64_PLT16_LO_DS
:
8034 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8035 target
->make_local_plt_entry(layout
, object
, r_sym
);
8039 case elfcpp::R_PPC64_REL24_NOTOC
:
8043 case elfcpp::R_POWERPC_REL24
:
8044 case elfcpp::R_PPC_PLTREL24
:
8045 case elfcpp::R_PPC_LOCAL24PC
:
8046 case elfcpp::R_POWERPC_REL14
:
8047 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8048 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8051 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8052 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8053 r_type
, r_sym
, reloc
.get_r_addend());
8057 case elfcpp::R_PPC64_TOCSAVE
:
8058 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8059 // caller has already saved r2 and thus a plt call stub need not
8062 && target
->mark_pltcall(ppc_object
, data_shndx
,
8063 reloc
.get_r_offset() - 4, symtab
))
8065 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8066 unsigned int shndx
= lsym
.get_st_shndx();
8068 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8070 object
->error(_("tocsave symbol %u has bad shndx %u"),
8073 target
->add_tocsave(ppc_object
, shndx
,
8074 lsym
.get_st_value() + reloc
.get_r_addend());
8078 case elfcpp::R_PPC64_REL64
:
8079 case elfcpp::R_POWERPC_REL32
:
8080 case elfcpp::R_POWERPC_REL16
:
8081 case elfcpp::R_POWERPC_REL16_LO
:
8082 case elfcpp::R_POWERPC_REL16_HI
:
8083 case elfcpp::R_POWERPC_REL16_HA
:
8084 case elfcpp::R_POWERPC_REL16DX_HA
:
8085 case elfcpp::R_PPC64_REL16_HIGH
:
8086 case elfcpp::R_PPC64_REL16_HIGHA
:
8087 case elfcpp::R_PPC64_REL16_HIGHER
:
8088 case elfcpp::R_PPC64_REL16_HIGHERA
:
8089 case elfcpp::R_PPC64_REL16_HIGHEST
:
8090 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8091 case elfcpp::R_POWERPC_SECTOFF
:
8092 case elfcpp::R_POWERPC_SECTOFF_LO
:
8093 case elfcpp::R_POWERPC_SECTOFF_HI
:
8094 case elfcpp::R_POWERPC_SECTOFF_HA
:
8095 case elfcpp::R_PPC64_SECTOFF_DS
:
8096 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8097 case elfcpp::R_POWERPC_TPREL16
:
8098 case elfcpp::R_POWERPC_TPREL16_LO
:
8099 case elfcpp::R_POWERPC_TPREL16_HI
:
8100 case elfcpp::R_POWERPC_TPREL16_HA
:
8101 case elfcpp::R_PPC64_TPREL16_DS
:
8102 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8103 case elfcpp::R_PPC64_TPREL16_HIGH
:
8104 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8105 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8106 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8107 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8108 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8109 case elfcpp::R_POWERPC_DTPREL16
:
8110 case elfcpp::R_POWERPC_DTPREL16_LO
:
8111 case elfcpp::R_POWERPC_DTPREL16_HI
:
8112 case elfcpp::R_POWERPC_DTPREL16_HA
:
8113 case elfcpp::R_PPC64_DTPREL16_DS
:
8114 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8115 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8116 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8117 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8118 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8119 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8120 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8121 case elfcpp::R_PPC64_TLSGD
:
8122 case elfcpp::R_PPC64_TLSLD
:
8123 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8126 case elfcpp::R_PPC64_GOT_PCREL34
:
8127 case elfcpp::R_POWERPC_GOT16
:
8128 case elfcpp::R_POWERPC_GOT16_LO
:
8129 case elfcpp::R_POWERPC_GOT16_HI
:
8130 case elfcpp::R_POWERPC_GOT16_HA
:
8131 case elfcpp::R_PPC64_GOT16_DS
:
8132 case elfcpp::R_PPC64_GOT16_LO_DS
:
8134 // The symbol requires a GOT entry.
8135 Output_data_got_powerpc
<size
, big_endian
>* got
8136 = target
->got_section(symtab
, layout
);
8137 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8139 if (!parameters
->options().output_is_position_independent())
8142 && (size
== 32 || target
->abiversion() >= 2))
8143 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
8145 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
8147 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
8149 // If we are generating a shared object or a pie, this
8150 // symbol's GOT entry will be set by a dynamic relocation.
8152 off
= got
->add_constant(0);
8153 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
8155 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8157 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8158 : elfcpp::R_POWERPC_RELATIVE
);
8159 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8160 got
, off
, 0, false);
8165 case elfcpp::R_PPC64_TOC16
:
8166 case elfcpp::R_PPC64_TOC16_LO
:
8167 case elfcpp::R_PPC64_TOC16_HI
:
8168 case elfcpp::R_PPC64_TOC16_HA
:
8169 case elfcpp::R_PPC64_TOC16_DS
:
8170 case elfcpp::R_PPC64_TOC16_LO_DS
:
8171 // We need a GOT section.
8172 target
->got_section(symtab
, layout
);
8175 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8176 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8177 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8178 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8179 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8181 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8182 if (tls_type
== tls::TLSOPT_NONE
)
8184 Output_data_got_powerpc
<size
, big_endian
>* got
8185 = target
->got_section(symtab
, layout
);
8186 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8187 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8188 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
8189 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
8191 else if (tls_type
== tls::TLSOPT_TO_LE
)
8193 // no GOT relocs needed for Local Exec.
8200 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8201 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8202 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8203 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8204 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8206 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8207 if (tls_type
== tls::TLSOPT_NONE
)
8208 target
->tlsld_got_offset(symtab
, layout
, object
);
8209 else if (tls_type
== tls::TLSOPT_TO_LE
)
8211 // no GOT relocs needed for Local Exec.
8212 if (parameters
->options().emit_relocs())
8214 Output_section
* os
= layout
->tls_segment()->first_section();
8215 gold_assert(os
!= NULL
);
8216 os
->set_needs_symtab_index();
8224 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8225 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8226 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8227 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8228 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8230 Output_data_got_powerpc
<size
, big_endian
>* got
8231 = target
->got_section(symtab
, layout
);
8232 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8233 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
8237 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8238 case elfcpp::R_POWERPC_GOT_TPREL16
:
8239 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8240 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8241 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8243 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8244 if (tls_type
== tls::TLSOPT_NONE
)
8246 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8247 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
8249 Output_data_got_powerpc
<size
, big_endian
>* got
8250 = target
->got_section(symtab
, layout
);
8251 unsigned int off
= got
->add_constant(0);
8252 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
8254 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8255 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8256 elfcpp::R_POWERPC_TPREL
,
8260 else if (tls_type
== tls::TLSOPT_TO_LE
)
8262 // no GOT relocs needed for Local Exec.
8270 unsupported_reloc_local(object
, r_type
);
8275 && parameters
->options().toc_optimize())
8277 if (data_shndx
== ppc_object
->toc_shndx())
8280 if (r_type
!= elfcpp::R_PPC64_ADDR64
8281 || (is_ifunc
&& target
->abiversion() < 2))
8283 else if (parameters
->options().output_is_position_independent())
8289 unsigned int shndx
= lsym
.get_st_shndx();
8290 if (shndx
>= elfcpp::SHN_LORESERVE
8291 && shndx
!= elfcpp::SHN_XINDEX
)
8296 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8299 enum {no_check
, check_lo
, check_ha
} insn_check
;
8303 insn_check
= no_check
;
8306 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8307 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8308 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8309 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8310 case elfcpp::R_POWERPC_GOT16_HA
:
8311 case elfcpp::R_PPC64_TOC16_HA
:
8312 insn_check
= check_ha
;
8315 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8316 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8317 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8318 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8319 case elfcpp::R_POWERPC_GOT16_LO
:
8320 case elfcpp::R_PPC64_GOT16_LO_DS
:
8321 case elfcpp::R_PPC64_TOC16_LO
:
8322 case elfcpp::R_PPC64_TOC16_LO_DS
:
8323 insn_check
= check_lo
;
8327 section_size_type slen
;
8328 const unsigned char* view
= NULL
;
8329 if (insn_check
!= no_check
)
8331 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8332 section_size_type off
=
8333 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8336 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8337 if (insn_check
== check_lo
8338 ? !ok_lo_toc_insn(insn
, r_type
)
8339 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8340 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8342 ppc_object
->set_no_toc_opt();
8343 gold_warning(_("%s: toc optimization is not supported "
8344 "for %#08x instruction"),
8345 ppc_object
->name().c_str(), insn
);
8354 case elfcpp::R_PPC64_TOC16
:
8355 case elfcpp::R_PPC64_TOC16_LO
:
8356 case elfcpp::R_PPC64_TOC16_HI
:
8357 case elfcpp::R_PPC64_TOC16_HA
:
8358 case elfcpp::R_PPC64_TOC16_DS
:
8359 case elfcpp::R_PPC64_TOC16_LO_DS
:
8360 unsigned int shndx
= lsym
.get_st_shndx();
8361 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8363 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8364 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8366 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8367 if (dst_off
< ppc_object
->section_size(shndx
))
8370 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8372 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8374 // Need to check that the insn is a ld
8376 view
= ppc_object
->section_contents(data_shndx
,
8379 section_size_type off
=
8380 (convert_to_section_size_type(reloc
.get_r_offset())
8381 + (big_endian
? -2 : 3));
8383 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8387 ppc_object
->set_no_toc_opt(dst_off
);
8398 case elfcpp::R_POWERPC_REL32
:
8399 if (ppc_object
->got2_shndx() != 0
8400 && parameters
->options().output_is_position_independent())
8402 unsigned int shndx
= lsym
.get_st_shndx();
8403 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8405 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8406 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8407 && (ppc_object
->section_flags(data_shndx
)
8408 & elfcpp::SHF_EXECINSTR
) != 0)
8409 gold_error(_("%s: unsupported -mbss-plt code"),
8410 ppc_object
->name().c_str());
8420 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8421 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8422 case elfcpp::R_POWERPC_GOT_TPREL16
:
8423 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8424 case elfcpp::R_POWERPC_GOT16
:
8425 case elfcpp::R_PPC64_GOT16_DS
:
8426 case elfcpp::R_PPC64_TOC16
:
8427 case elfcpp::R_PPC64_TOC16_DS
:
8428 ppc_object
->set_has_small_toc_reloc();
8436 case elfcpp::R_PPC64_TPREL16_DS
:
8437 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8438 case elfcpp::R_PPC64_TPREL16_HIGH
:
8439 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8440 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8441 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8442 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8443 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8444 case elfcpp::R_PPC64_TPREL34
:
8448 case elfcpp::R_POWERPC_TPREL16
:
8449 case elfcpp::R_POWERPC_TPREL16_LO
:
8450 case elfcpp::R_POWERPC_TPREL16_HI
:
8451 case elfcpp::R_POWERPC_TPREL16_HA
:
8452 layout
->set_has_static_tls();
8460 case elfcpp::R_POWERPC_TPREL16_HA
:
8461 if (target
->tprel_opt())
8463 section_size_type slen
;
8464 const unsigned char* view
= NULL
;
8465 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8466 section_size_type off
8467 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8470 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8471 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8472 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8473 target
->set_no_tprel_opt();
8478 case elfcpp::R_PPC64_TPREL16_HIGH
:
8479 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8480 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8481 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8482 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8483 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8487 case elfcpp::R_POWERPC_TPREL16_HI
:
8488 target
->set_no_tprel_opt();
8496 case elfcpp::R_PPC64_D34
:
8497 case elfcpp::R_PPC64_D34_LO
:
8498 case elfcpp::R_PPC64_D34_HI30
:
8499 case elfcpp::R_PPC64_D34_HA30
:
8500 case elfcpp::R_PPC64_D28
:
8501 case elfcpp::R_PPC64_PCREL34
:
8502 case elfcpp::R_PPC64_PCREL28
:
8503 case elfcpp::R_PPC64_TPREL34
:
8504 case elfcpp::R_PPC64_DTPREL34
:
8505 case elfcpp::R_PPC64_PLT_PCREL34
:
8506 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8507 case elfcpp::R_PPC64_GOT_PCREL34
:
8508 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8509 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8510 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8511 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8512 target
->set_power10_relocs();
8519 // Report an unsupported relocation against a global symbol.
8521 template<int size
, bool big_endian
>
8523 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8524 Sized_relobj_file
<size
, big_endian
>* object
,
8525 unsigned int r_type
,
8528 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8529 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8532 // Scan a relocation for a global symbol.
8534 template<int size
, bool big_endian
>
8536 Target_powerpc
<size
, big_endian
>::Scan::global(
8537 Symbol_table
* symtab
,
8539 Target_powerpc
<size
, big_endian
>* target
,
8540 Sized_relobj_file
<size
, big_endian
>* object
,
8541 unsigned int data_shndx
,
8542 Output_section
* output_section
,
8543 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8544 unsigned int r_type
,
8547 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8551 if (target
->replace_tls_get_addr(gsym
))
8552 // Change a __tls_get_addr reference to __tls_get_addr_opt
8553 // so dynamic relocs are emitted against the latter symbol.
8554 gsym
= target
->tls_get_addr_opt();
8556 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8557 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8559 this->expect_tls_get_addr_call();
8560 const bool final
= gsym
->final_value_is_known();
8561 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8562 if (tls_type
!= tls::TLSOPT_NONE
)
8563 this->skip_next_tls_get_addr_call();
8565 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8566 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8568 this->expect_tls_get_addr_call();
8569 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8570 if (tls_type
!= tls::TLSOPT_NONE
)
8571 this->skip_next_tls_get_addr_call();
8574 Powerpc_relobj
<size
, big_endian
>* ppc_object
8575 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8577 // A STT_GNU_IFUNC symbol may require a PLT entry.
8578 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8579 bool pushed_ifunc
= false;
8580 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8582 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8583 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8584 r_type
, r_sym
, reloc
.get_r_addend());
8585 target
->make_plt_entry(symtab
, layout
, gsym
);
8586 pushed_ifunc
= true;
8591 case elfcpp::R_POWERPC_NONE
:
8592 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8593 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8594 case elfcpp::R_PPC_LOCAL24PC
:
8595 case elfcpp::R_POWERPC_TLS
:
8596 case elfcpp::R_PPC64_ENTRY
:
8597 case elfcpp::R_POWERPC_PLTSEQ
:
8598 case elfcpp::R_POWERPC_PLTCALL
:
8599 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8600 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8601 case elfcpp::R_PPC64_PCREL_OPT
:
8602 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8603 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8604 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8605 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8606 case elfcpp::R_PPC64_REL16_HIGHER34
:
8607 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8608 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8609 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8610 case elfcpp::R_PPC64_D34
:
8611 case elfcpp::R_PPC64_D34_LO
:
8612 case elfcpp::R_PPC64_D34_HI30
:
8613 case elfcpp::R_PPC64_D34_HA30
:
8614 case elfcpp::R_PPC64_D28
:
8615 case elfcpp::R_PPC64_PCREL34
:
8616 case elfcpp::R_PPC64_PCREL28
:
8617 case elfcpp::R_PPC64_TPREL34
:
8618 case elfcpp::R_PPC64_DTPREL34
:
8621 case elfcpp::R_PPC64_TOC
:
8623 Output_data_got_powerpc
<size
, big_endian
>* got
8624 = target
->got_section(symtab
, layout
);
8625 if (parameters
->options().output_is_position_independent())
8627 Address off
= reloc
.get_r_offset();
8629 && data_shndx
== ppc_object
->opd_shndx()
8630 && ppc_object
->get_opd_discard(off
- 8))
8633 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8634 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8635 if (data_shndx
!= ppc_object
->opd_shndx())
8636 symobj
= static_cast
8637 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8638 rela_dyn
->add_output_section_relative(got
->output_section(),
8639 elfcpp::R_POWERPC_RELATIVE
,
8641 object
, data_shndx
, off
,
8642 symobj
->toc_base_offset());
8647 case elfcpp::R_PPC64_ADDR64
:
8649 && target
->abiversion() < 2
8650 && data_shndx
== ppc_object
->opd_shndx()
8651 && (gsym
->is_defined_in_discarded_section()
8652 || gsym
->object() != object
))
8654 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8658 case elfcpp::R_PPC64_UADDR64
:
8659 case elfcpp::R_POWERPC_ADDR32
:
8660 case elfcpp::R_POWERPC_UADDR32
:
8661 case elfcpp::R_POWERPC_ADDR24
:
8662 case elfcpp::R_POWERPC_ADDR16
:
8663 case elfcpp::R_POWERPC_ADDR16_LO
:
8664 case elfcpp::R_POWERPC_ADDR16_HI
:
8665 case elfcpp::R_POWERPC_ADDR16_HA
:
8666 case elfcpp::R_POWERPC_UADDR16
:
8667 case elfcpp::R_PPC64_ADDR16_HIGH
:
8668 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8669 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8670 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8671 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8672 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8673 case elfcpp::R_PPC64_ADDR16_DS
:
8674 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8675 case elfcpp::R_POWERPC_ADDR14
:
8676 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8677 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8679 // Make a PLT entry if necessary.
8680 if (gsym
->needs_plt_entry())
8682 // Since this is not a PC-relative relocation, we may be
8683 // taking the address of a function. In that case we need to
8684 // set the entry in the dynamic symbol table to the address of
8685 // the PLT call stub.
8686 bool need_ifunc_plt
= false;
8687 if ((size
== 32 || target
->abiversion() >= 2)
8688 && gsym
->is_from_dynobj()
8689 && !parameters
->options().output_is_position_independent())
8691 gsym
->set_needs_dynsym_value();
8692 need_ifunc_plt
= true;
8694 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8696 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8697 target
->push_branch(ppc_object
, data_shndx
,
8698 reloc
.get_r_offset(), r_type
, r_sym
,
8699 reloc
.get_r_addend());
8700 target
->make_plt_entry(symtab
, layout
, gsym
);
8703 // Make a dynamic relocation if necessary.
8704 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8705 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8707 if (!parameters
->options().output_is_position_independent()
8708 && gsym
->may_need_copy_reloc())
8710 target
->copy_reloc(symtab
, layout
, object
,
8711 data_shndx
, output_section
, gsym
, reloc
);
8713 else if ((((size
== 32
8714 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8716 && r_type
== elfcpp::R_PPC64_ADDR64
8717 && target
->abiversion() >= 2))
8718 && gsym
->can_use_relative_reloc(false)
8719 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8720 && parameters
->options().shared()))
8722 && r_type
== elfcpp::R_PPC64_ADDR64
8723 && target
->abiversion() < 2
8724 && (gsym
->can_use_relative_reloc(false)
8725 || data_shndx
== ppc_object
->opd_shndx())))
8727 Reloc_section
* rela_dyn
8728 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8729 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8730 : elfcpp::R_POWERPC_RELATIVE
);
8731 rela_dyn
->add_symbolless_global_addend(
8732 gsym
, dynrel
, output_section
, object
, data_shndx
,
8733 reloc
.get_r_offset(), reloc
.get_r_addend());
8737 Reloc_section
* rela_dyn
8738 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8739 check_non_pic(object
, r_type
);
8740 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8742 reloc
.get_r_offset(),
8743 reloc
.get_r_addend());
8746 && parameters
->options().toc_optimize()
8747 && data_shndx
== ppc_object
->toc_shndx())
8748 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8754 case elfcpp::R_PPC64_PLT_PCREL34
:
8755 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8756 case elfcpp::R_POWERPC_PLT16_LO
:
8757 case elfcpp::R_POWERPC_PLT16_HI
:
8758 case elfcpp::R_POWERPC_PLT16_HA
:
8759 case elfcpp::R_PPC64_PLT16_LO_DS
:
8761 target
->make_plt_entry(symtab
, layout
, gsym
);
8764 case elfcpp::R_PPC64_REL24_NOTOC
:
8768 case elfcpp::R_PPC_PLTREL24
:
8769 case elfcpp::R_POWERPC_REL24
:
8772 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8773 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8774 r_type
, r_sym
, reloc
.get_r_addend());
8775 if (gsym
->needs_plt_entry()
8776 || (!gsym
->final_value_is_known()
8777 && (gsym
->is_undefined()
8778 || gsym
->is_from_dynobj()
8779 || gsym
->is_preemptible())))
8780 target
->make_plt_entry(symtab
, layout
, gsym
);
8784 case elfcpp::R_PPC64_REL64
:
8785 case elfcpp::R_POWERPC_REL32
:
8786 // Make a dynamic relocation if necessary.
8787 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8789 if (!parameters
->options().output_is_position_independent()
8790 && gsym
->may_need_copy_reloc())
8792 target
->copy_reloc(symtab
, layout
, object
,
8793 data_shndx
, output_section
, gsym
,
8798 Reloc_section
* rela_dyn
8799 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8800 check_non_pic(object
, r_type
);
8801 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8802 data_shndx
, reloc
.get_r_offset(),
8803 reloc
.get_r_addend());
8808 case elfcpp::R_POWERPC_REL14
:
8809 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8810 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8813 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8814 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8815 r_type
, r_sym
, reloc
.get_r_addend());
8819 case elfcpp::R_PPC64_TOCSAVE
:
8820 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8821 // caller has already saved r2 and thus a plt call stub need not
8824 && target
->mark_pltcall(ppc_object
, data_shndx
,
8825 reloc
.get_r_offset() - 4, symtab
))
8827 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8829 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8831 object
->error(_("tocsave symbol %u has bad shndx %u"),
8835 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8836 target
->add_tocsave(ppc_object
, shndx
,
8837 sym
->value() + reloc
.get_r_addend());
8842 case elfcpp::R_POWERPC_REL16
:
8843 case elfcpp::R_POWERPC_REL16_LO
:
8844 case elfcpp::R_POWERPC_REL16_HI
:
8845 case elfcpp::R_POWERPC_REL16_HA
:
8846 case elfcpp::R_POWERPC_REL16DX_HA
:
8847 case elfcpp::R_PPC64_REL16_HIGH
:
8848 case elfcpp::R_PPC64_REL16_HIGHA
:
8849 case elfcpp::R_PPC64_REL16_HIGHER
:
8850 case elfcpp::R_PPC64_REL16_HIGHERA
:
8851 case elfcpp::R_PPC64_REL16_HIGHEST
:
8852 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8853 case elfcpp::R_POWERPC_SECTOFF
:
8854 case elfcpp::R_POWERPC_SECTOFF_LO
:
8855 case elfcpp::R_POWERPC_SECTOFF_HI
:
8856 case elfcpp::R_POWERPC_SECTOFF_HA
:
8857 case elfcpp::R_PPC64_SECTOFF_DS
:
8858 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8859 case elfcpp::R_POWERPC_TPREL16
:
8860 case elfcpp::R_POWERPC_TPREL16_LO
:
8861 case elfcpp::R_POWERPC_TPREL16_HI
:
8862 case elfcpp::R_POWERPC_TPREL16_HA
:
8863 case elfcpp::R_PPC64_TPREL16_DS
:
8864 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8865 case elfcpp::R_PPC64_TPREL16_HIGH
:
8866 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8867 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8868 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8869 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8870 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8871 case elfcpp::R_POWERPC_DTPREL16
:
8872 case elfcpp::R_POWERPC_DTPREL16_LO
:
8873 case elfcpp::R_POWERPC_DTPREL16_HI
:
8874 case elfcpp::R_POWERPC_DTPREL16_HA
:
8875 case elfcpp::R_PPC64_DTPREL16_DS
:
8876 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8877 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8878 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8879 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8880 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8881 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8882 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8883 case elfcpp::R_PPC64_TLSGD
:
8884 case elfcpp::R_PPC64_TLSLD
:
8885 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8888 case elfcpp::R_PPC64_GOT_PCREL34
:
8889 case elfcpp::R_POWERPC_GOT16
:
8890 case elfcpp::R_POWERPC_GOT16_LO
:
8891 case elfcpp::R_POWERPC_GOT16_HI
:
8892 case elfcpp::R_POWERPC_GOT16_HA
:
8893 case elfcpp::R_PPC64_GOT16_DS
:
8894 case elfcpp::R_PPC64_GOT16_LO_DS
:
8896 // The symbol requires a GOT entry.
8897 Output_data_got_powerpc
<size
, big_endian
>* got
;
8899 got
= target
->got_section(symtab
, layout
);
8900 if (gsym
->final_value_is_known())
8903 && (size
== 32 || target
->abiversion() >= 2))
8904 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8906 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8908 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8910 // If we are generating a shared object or a pie, this
8911 // symbol's GOT entry will be set by a dynamic relocation.
8912 unsigned int off
= got
->add_constant(0);
8913 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8915 Reloc_section
* rela_dyn
8916 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8918 if (gsym
->can_use_relative_reloc(false)
8920 || target
->abiversion() >= 2)
8921 && gsym
->visibility() == elfcpp::STV_PROTECTED
8922 && parameters
->options().shared()))
8924 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8925 : elfcpp::R_POWERPC_RELATIVE
);
8926 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8930 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8931 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8937 case elfcpp::R_PPC64_TOC16
:
8938 case elfcpp::R_PPC64_TOC16_LO
:
8939 case elfcpp::R_PPC64_TOC16_HI
:
8940 case elfcpp::R_PPC64_TOC16_HA
:
8941 case elfcpp::R_PPC64_TOC16_DS
:
8942 case elfcpp::R_PPC64_TOC16_LO_DS
:
8943 // We need a GOT section.
8944 target
->got_section(symtab
, layout
);
8947 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8948 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8949 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8950 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8951 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8953 const bool final
= gsym
->final_value_is_known();
8954 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8955 if (tls_type
== tls::TLSOPT_NONE
)
8957 Output_data_got_powerpc
<size
, big_endian
>* got
8958 = target
->got_section(symtab
, layout
);
8959 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8960 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8961 elfcpp::R_POWERPC_DTPMOD
,
8962 elfcpp::R_POWERPC_DTPREL
);
8964 else if (tls_type
== tls::TLSOPT_TO_IE
)
8966 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8968 Output_data_got_powerpc
<size
, big_endian
>* got
8969 = target
->got_section(symtab
, layout
);
8970 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8971 if (gsym
->is_undefined()
8972 || gsym
->is_from_dynobj())
8974 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8975 elfcpp::R_POWERPC_TPREL
);
8979 unsigned int off
= got
->add_constant(0);
8980 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8981 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8982 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8987 else if (tls_type
== tls::TLSOPT_TO_LE
)
8989 // no GOT relocs needed for Local Exec.
8996 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8997 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8998 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8999 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9000 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9002 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9003 if (tls_type
== tls::TLSOPT_NONE
)
9004 target
->tlsld_got_offset(symtab
, layout
, object
);
9005 else if (tls_type
== tls::TLSOPT_TO_LE
)
9007 // no GOT relocs needed for Local Exec.
9008 if (parameters
->options().emit_relocs())
9010 Output_section
* os
= layout
->tls_segment()->first_section();
9011 gold_assert(os
!= NULL
);
9012 os
->set_needs_symtab_index();
9020 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9021 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9022 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9023 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9024 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9026 Output_data_got_powerpc
<size
, big_endian
>* got
9027 = target
->got_section(symtab
, layout
);
9028 if (!gsym
->final_value_is_known()
9029 && (gsym
->is_from_dynobj()
9030 || gsym
->is_undefined()
9031 || gsym
->is_preemptible()))
9032 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
9033 target
->rela_dyn_section(layout
),
9034 elfcpp::R_POWERPC_DTPREL
);
9036 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
9040 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9041 case elfcpp::R_POWERPC_GOT_TPREL16
:
9042 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9043 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9044 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9046 const bool final
= gsym
->final_value_is_known();
9047 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9048 if (tls_type
== tls::TLSOPT_NONE
)
9050 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
9052 Output_data_got_powerpc
<size
, big_endian
>* got
9053 = target
->got_section(symtab
, layout
);
9054 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9055 if (gsym
->is_undefined()
9056 || gsym
->is_from_dynobj())
9058 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
9059 elfcpp::R_POWERPC_TPREL
);
9063 unsigned int off
= got
->add_constant(0);
9064 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
9065 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9066 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9071 else if (tls_type
== tls::TLSOPT_TO_LE
)
9073 // no GOT relocs needed for Local Exec.
9081 unsupported_reloc_global(object
, r_type
, gsym
);
9086 && parameters
->options().toc_optimize())
9088 if (data_shndx
== ppc_object
->toc_shndx())
9091 if (r_type
!= elfcpp::R_PPC64_ADDR64
9092 || (is_ifunc
&& target
->abiversion() < 2))
9094 else if (parameters
->options().output_is_position_independent()
9095 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9098 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9101 enum {no_check
, check_lo
, check_ha
} insn_check
;
9105 insn_check
= no_check
;
9108 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9109 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9110 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9111 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9112 case elfcpp::R_POWERPC_GOT16_HA
:
9113 case elfcpp::R_PPC64_TOC16_HA
:
9114 insn_check
= check_ha
;
9117 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9118 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9119 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9120 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9121 case elfcpp::R_POWERPC_GOT16_LO
:
9122 case elfcpp::R_PPC64_GOT16_LO_DS
:
9123 case elfcpp::R_PPC64_TOC16_LO
:
9124 case elfcpp::R_PPC64_TOC16_LO_DS
:
9125 insn_check
= check_lo
;
9129 section_size_type slen
;
9130 const unsigned char* view
= NULL
;
9131 if (insn_check
!= no_check
)
9133 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9134 section_size_type off
=
9135 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9138 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9139 if (insn_check
== check_lo
9140 ? !ok_lo_toc_insn(insn
, r_type
)
9141 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9142 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9144 ppc_object
->set_no_toc_opt();
9145 gold_warning(_("%s: toc optimization is not supported "
9146 "for %#08x instruction"),
9147 ppc_object
->name().c_str(), insn
);
9156 case elfcpp::R_PPC64_TOC16
:
9157 case elfcpp::R_PPC64_TOC16_LO
:
9158 case elfcpp::R_PPC64_TOC16_HI
:
9159 case elfcpp::R_PPC64_TOC16_HA
:
9160 case elfcpp::R_PPC64_TOC16_DS
:
9161 case elfcpp::R_PPC64_TOC16_LO_DS
:
9162 if (gsym
->source() == Symbol::FROM_OBJECT
9163 && !gsym
->object()->is_dynamic())
9165 Powerpc_relobj
<size
, big_endian
>* sym_object
9166 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9168 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9169 if (shndx
== sym_object
->toc_shndx())
9171 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9172 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9173 if (dst_off
< sym_object
->section_size(shndx
))
9176 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9178 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9180 // Need to check that the insn is a ld
9182 view
= ppc_object
->section_contents(data_shndx
,
9185 section_size_type off
=
9186 (convert_to_section_size_type(reloc
.get_r_offset())
9187 + (big_endian
? -2 : 3));
9189 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9193 sym_object
->set_no_toc_opt(dst_off
);
9205 case elfcpp::R_PPC_LOCAL24PC
:
9206 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9207 gold_error(_("%s: unsupported -mbss-plt code"),
9208 ppc_object
->name().c_str());
9217 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9218 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9219 case elfcpp::R_POWERPC_GOT_TPREL16
:
9220 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9221 case elfcpp::R_POWERPC_GOT16
:
9222 case elfcpp::R_PPC64_GOT16_DS
:
9223 case elfcpp::R_PPC64_TOC16
:
9224 case elfcpp::R_PPC64_TOC16_DS
:
9225 ppc_object
->set_has_small_toc_reloc();
9233 case elfcpp::R_PPC64_TPREL16_DS
:
9234 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9235 case elfcpp::R_PPC64_TPREL16_HIGH
:
9236 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9237 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9238 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9239 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9240 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9241 case elfcpp::R_PPC64_TPREL34
:
9245 case elfcpp::R_POWERPC_TPREL16
:
9246 case elfcpp::R_POWERPC_TPREL16_LO
:
9247 case elfcpp::R_POWERPC_TPREL16_HI
:
9248 case elfcpp::R_POWERPC_TPREL16_HA
:
9249 layout
->set_has_static_tls();
9257 case elfcpp::R_POWERPC_TPREL16_HA
:
9258 if (target
->tprel_opt())
9260 section_size_type slen
;
9261 const unsigned char* view
= NULL
;
9262 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9263 section_size_type off
9264 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9267 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9268 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9269 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9270 target
->set_no_tprel_opt();
9275 case elfcpp::R_PPC64_TPREL16_HIGH
:
9276 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9277 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9278 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9279 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9280 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9284 case elfcpp::R_POWERPC_TPREL16_HI
:
9285 target
->set_no_tprel_opt();
9293 case elfcpp::R_PPC64_D34
:
9294 case elfcpp::R_PPC64_D34_LO
:
9295 case elfcpp::R_PPC64_D34_HI30
:
9296 case elfcpp::R_PPC64_D34_HA30
:
9297 case elfcpp::R_PPC64_D28
:
9298 case elfcpp::R_PPC64_PCREL34
:
9299 case elfcpp::R_PPC64_PCREL28
:
9300 case elfcpp::R_PPC64_TPREL34
:
9301 case elfcpp::R_PPC64_DTPREL34
:
9302 case elfcpp::R_PPC64_PLT_PCREL34
:
9303 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9304 case elfcpp::R_PPC64_GOT_PCREL34
:
9305 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9306 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9307 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9308 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9309 target
->set_power10_relocs();
9316 // Process relocations for gc.
9318 template<int size
, bool big_endian
>
9320 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9321 Symbol_table
* symtab
,
9323 Sized_relobj_file
<size
, big_endian
>* object
,
9324 unsigned int data_shndx
,
9326 const unsigned char* prelocs
,
9328 Output_section
* output_section
,
9329 bool needs_special_offset_handling
,
9330 size_t local_symbol_count
,
9331 const unsigned char* plocal_symbols
)
9333 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9334 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9337 Powerpc_relobj
<size
, big_endian
>* ppc_object
9338 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9340 ppc_object
->set_opd_valid();
9341 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9343 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9344 for (p
= ppc_object
->access_from_map()->begin();
9345 p
!= ppc_object
->access_from_map()->end();
9348 Address dst_off
= p
->first
;
9349 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9350 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9351 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9353 Relobj
* src_obj
= s
->first
;
9354 unsigned int src_indx
= s
->second
;
9355 symtab
->gc()->add_reference(src_obj
, src_indx
,
9356 ppc_object
, dst_indx
);
9360 ppc_object
->access_from_map()->clear();
9361 ppc_object
->process_gc_mark(symtab
);
9362 // Don't look at .opd relocs as .opd will reference everything.
9366 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9375 needs_special_offset_handling
,
9380 // Handle target specific gc actions when adding a gc reference from
9381 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9382 // and DST_OFF. For powerpc64, this adds a referenc to the code
9383 // section of a function descriptor.
9385 template<int size
, bool big_endian
>
9387 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9388 Symbol_table
* symtab
,
9390 unsigned int src_shndx
,
9392 unsigned int dst_shndx
,
9393 Address dst_off
) const
9395 if (size
!= 64 || dst_obj
->is_dynamic())
9398 Powerpc_relobj
<size
, big_endian
>* ppc_object
9399 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9400 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9402 if (ppc_object
->opd_valid())
9404 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9405 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9409 // If we haven't run scan_opd_relocs, we must delay
9410 // processing this function descriptor reference.
9411 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9416 // Add any special sections for this symbol to the gc work list.
9417 // For powerpc64, this adds the code section of a function
9420 template<int size
, bool big_endian
>
9422 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9423 Symbol_table
* symtab
,
9426 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9428 Powerpc_relobj
<size
, big_endian
>* ppc_object
9429 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9431 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9432 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9434 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9435 Address dst_off
= gsym
->value();
9436 if (ppc_object
->opd_valid())
9438 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9439 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9443 ppc_object
->add_gc_mark(dst_off
);
9448 // For a symbol location in .opd, set LOC to the location of the
9451 template<int size
, bool big_endian
>
9453 Target_powerpc
<size
, big_endian
>::do_function_location(
9454 Symbol_location
* loc
) const
9456 if (size
== 64 && loc
->shndx
!= 0)
9458 if (loc
->object
->is_dynamic())
9460 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9461 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9462 if (loc
->shndx
== ppc_object
->opd_shndx())
9465 Address off
= loc
->offset
- ppc_object
->opd_address();
9466 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9467 loc
->offset
= dest_off
;
9472 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9473 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9474 if (loc
->shndx
== ppc_object
->opd_shndx())
9477 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9478 loc
->offset
= dest_off
;
9484 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9485 // compiled with -fsplit-stack. The function calls non-split-stack
9486 // code. Change the function to ensure it has enough stack space to
9487 // call some random function.
9489 template<int size
, bool big_endian
>
9491 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9494 section_offset_type fnoffset
,
9495 section_size_type fnsize
,
9496 const unsigned char* prelocs
,
9498 unsigned char* view
,
9499 section_size_type view_size
,
9501 std::string
* to
) const
9503 // 32-bit not supported.
9507 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9508 prelocs
, reloc_count
, view
, view_size
,
9513 // The function always starts with
9514 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9515 // addis %r12,%r1,-allocate@ha
9516 // addi %r12,%r12,-allocate@l
9518 // but note that the addis or addi may be replaced with a nop
9520 unsigned char *entry
= view
+ fnoffset
;
9521 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9523 if ((insn
& 0xffff0000) == addis_2_12
)
9525 /* Skip ELFv2 global entry code. */
9527 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9530 unsigned char *pinsn
= entry
;
9532 const uint32_t ld_private_ss
= 0xe80d8fc0;
9533 if (insn
== ld_private_ss
)
9535 int32_t allocate
= 0;
9539 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9540 if ((insn
& 0xffff0000) == addis_12_1
)
9541 allocate
+= (insn
& 0xffff) << 16;
9542 else if ((insn
& 0xffff0000) == addi_12_1
9543 || (insn
& 0xffff0000) == addi_12_12
)
9544 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9545 else if (insn
!= nop
)
9548 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9550 int extra
= parameters
->options().split_stack_adjust_size();
9552 if (allocate
>= 0 || extra
< 0)
9554 object
->error(_("split-stack stack size overflow at "
9555 "section %u offset %0zx"),
9556 shndx
, static_cast<size_t>(fnoffset
));
9560 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9561 if (insn
!= addis_12_1
)
9563 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9565 insn
= addi_12_12
| (allocate
& 0xffff);
9566 if (insn
!= addi_12_12
)
9568 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9574 insn
= addi_12_1
| (allocate
& 0xffff);
9575 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9578 if (pinsn
!= entry
+ 12)
9579 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9587 if (!object
->has_no_split_stack())
9588 object
->error(_("failed to match split-stack sequence at "
9589 "section %u offset %0zx"),
9590 shndx
, static_cast<size_t>(fnoffset
));
9594 // Scan relocations for a section.
9596 template<int size
, bool big_endian
>
9598 Target_powerpc
<size
, big_endian
>::scan_relocs(
9599 Symbol_table
* symtab
,
9601 Sized_relobj_file
<size
, big_endian
>* object
,
9602 unsigned int data_shndx
,
9603 unsigned int sh_type
,
9604 const unsigned char* prelocs
,
9606 Output_section
* output_section
,
9607 bool needs_special_offset_handling
,
9608 size_t local_symbol_count
,
9609 const unsigned char* plocal_symbols
)
9611 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9612 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9615 if (!this->plt_localentry0_init_
)
9617 bool plt_localentry0
= false;
9619 && this->abiversion() >= 2)
9621 if (parameters
->options().user_set_plt_localentry())
9622 plt_localentry0
= parameters
->options().plt_localentry();
9624 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9625 gold_warning(_("--plt-localentry is especially dangerous without "
9626 "ld.so support to detect ABI violations"));
9628 this->plt_localentry0_
= plt_localentry0
;
9629 this->plt_localentry0_init_
= true;
9632 if (sh_type
== elfcpp::SHT_REL
)
9634 gold_error(_("%s: unsupported REL reloc section"),
9635 object
->name().c_str());
9639 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9648 needs_special_offset_handling
,
9652 if (this->plt_localentry0_
&& this->power10_relocs_
)
9654 gold_warning(_("--plt-localentry is incompatible with "
9655 "power10 pc-relative code"));
9656 this->plt_localentry0_
= false;
9660 // Functor class for processing the global symbol table.
9661 // Removes symbols defined on discarded opd entries.
9663 template<bool big_endian
>
9664 class Global_symbol_visitor_opd
9667 Global_symbol_visitor_opd()
9671 operator()(Sized_symbol
<64>* sym
)
9673 if (sym
->has_symtab_index()
9674 || sym
->source() != Symbol::FROM_OBJECT
9675 || !sym
->in_real_elf())
9678 if (sym
->object()->is_dynamic())
9681 Powerpc_relobj
<64, big_endian
>* symobj
9682 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9683 if (symobj
->opd_shndx() == 0)
9687 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9688 if (shndx
== symobj
->opd_shndx()
9689 && symobj
->get_opd_discard(sym
->value()))
9691 sym
->set_undefined();
9692 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9693 sym
->set_is_defined_in_discarded_section();
9694 sym
->set_symtab_index(-1U);
9699 template<int size
, bool big_endian
>
9701 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9703 Symbol_table
* symtab
)
9707 Output_data_save_res
<size
, big_endian
>* savres
9708 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9709 this->savres_section_
= savres
;
9710 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9711 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9712 savres
, ORDER_TEXT
, false);
9716 // Sort linker created .got section first (for the header), then input
9717 // sections belonging to files using small model code.
9719 template<bool big_endian
>
9720 class Sort_toc_sections
9724 operator()(const Output_section::Input_section
& is1
,
9725 const Output_section::Input_section
& is2
) const
9727 if (!is1
.is_input_section() && is2
.is_input_section())
9730 = (is1
.is_input_section()
9731 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9732 ->has_small_toc_reloc()));
9734 = (is2
.is_input_section()
9735 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9736 ->has_small_toc_reloc()));
9737 return small1
&& !small2
;
9741 // Finalize the sections.
9743 template<int size
, bool big_endian
>
9745 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9747 const Input_objects
* input_objects
,
9748 Symbol_table
* symtab
)
9750 if (parameters
->doing_static_link())
9752 // At least some versions of glibc elf-init.o have a strong
9753 // reference to __rela_iplt marker syms. A weak ref would be
9755 if (this->iplt_
!= NULL
)
9757 Reloc_section
* rel
= this->iplt_
->rel_plt();
9758 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9759 Symbol_table::PREDEFINED
, rel
, 0, 0,
9760 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9761 elfcpp::STV_HIDDEN
, 0, false, true);
9762 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9763 Symbol_table::PREDEFINED
, rel
, 0, 0,
9764 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9765 elfcpp::STV_HIDDEN
, 0, true, true);
9769 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9770 Symbol_table::PREDEFINED
, 0, 0,
9771 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9772 elfcpp::STV_HIDDEN
, 0, true, false);
9773 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9774 Symbol_table::PREDEFINED
, 0, 0,
9775 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9776 elfcpp::STV_HIDDEN
, 0, true, false);
9782 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9783 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9785 if (!parameters
->options().relocatable())
9787 this->define_save_restore_funcs(layout
, symtab
);
9789 // Annoyingly, we need to make these sections now whether or
9790 // not we need them. If we delay until do_relax then we
9791 // need to mess with the relaxation machinery checkpointing.
9792 this->got_section(symtab
, layout
);
9793 this->make_brlt_section(layout
);
9795 if (parameters
->options().toc_sort())
9797 Output_section
* os
= this->got_
->output_section();
9798 if (os
!= NULL
&& os
->input_sections().size() > 1)
9799 std::stable_sort(os
->input_sections().begin(),
9800 os
->input_sections().end(),
9801 Sort_toc_sections
<big_endian
>());
9806 // Fill in some more dynamic tags.
9807 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9810 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9812 : this->plt_
->rel_plt());
9813 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9814 this->rela_dyn_
, true, size
== 32);
9818 if (this->got_
!= NULL
)
9820 this->got_
->finalize_data_size();
9821 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9822 this->got_
, this->got_
->g_o_t());
9824 if (this->has_tls_get_addr_opt_
)
9825 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9829 if (this->glink_
!= NULL
)
9831 this->glink_
->finalize_data_size();
9832 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9834 (this->glink_
->pltresolve_size()
9837 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9838 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9839 ((this->has_localentry0_
9840 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9841 | (this->has_tls_get_addr_opt_
9842 ? elfcpp::PPC64_OPT_TLS
: 0)));
9846 // Emit any relocs we saved in an attempt to avoid generating COPY
9848 if (this->copy_relocs_
.any_saved_relocs())
9849 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9851 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9852 p
!= input_objects
->relobj_end();
9855 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9856 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9857 if (ppc_relobj
->attributes_section_data())
9858 this->merge_object_attributes(ppc_relobj
,
9859 ppc_relobj
->attributes_section_data());
9861 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9862 p
!= input_objects
->dynobj_end();
9865 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9866 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9867 if (ppc_dynobj
->attributes_section_data())
9868 this->merge_object_attributes(ppc_dynobj
,
9869 ppc_dynobj
->attributes_section_data());
9872 // Create a .gnu.attributes section if we have merged any attributes
9874 if (this->attributes_section_data_
!= NULL
9875 && this->attributes_section_data_
->size() != 0)
9877 Output_attributes_section_data
* attributes_section
9878 = new Output_attributes_section_data(*this->attributes_section_data_
);
9879 layout
->add_output_section_data(".gnu.attributes",
9880 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9881 attributes_section
, ORDER_INVALID
, false);
9885 // Merge object attributes from input file called NAME with those of the
9886 // output. The input object attributes are in the object pointed by PASD.
9888 template<int size
, bool big_endian
>
9890 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9892 const Attributes_section_data
* pasd
)
9894 // Return if there is no attributes section data.
9898 // Create output object attributes.
9899 if (this->attributes_section_data_
== NULL
)
9900 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9902 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9903 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9904 Object_attribute
* out_attr
9905 = this->attributes_section_data_
->known_attributes(vendor
);
9907 const char* name
= obj
->name().c_str();
9911 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9912 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9913 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9914 bool warn_only
= obj
->is_dynamic();
9915 if (in_fp
!= out_fp
)
9918 if ((in_fp
& 3) == 0)
9920 else if ((out_fp
& 3) == 0)
9924 out_fp
|= in_fp
& 3;
9925 out_attr
[tag
].set_int_value(out_fp
);
9926 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9927 this->last_fp_
= name
;
9930 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9932 err
= N_("%s uses hard float, %s uses soft float");
9933 first
= this->last_fp_
;
9936 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9938 err
= N_("%s uses hard float, %s uses soft float");
9940 second
= this->last_fp_
;
9942 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9944 err
= N_("%s uses double-precision hard float, "
9945 "%s uses single-precision hard float");
9946 first
= this->last_fp_
;
9949 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9951 err
= N_("%s uses double-precision hard float, "
9952 "%s uses single-precision hard float");
9954 second
= this->last_fp_
;
9957 if (err
|| (in_fp
& 0xc) == 0)
9959 else if ((out_fp
& 0xc) == 0)
9963 out_fp
|= in_fp
& 0xc;
9964 out_attr
[tag
].set_int_value(out_fp
);
9965 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9966 this->last_ld_
= name
;
9969 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9971 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9973 second
= this->last_ld_
;
9975 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9977 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9978 first
= this->last_ld_
;
9981 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9983 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9984 first
= this->last_ld_
;
9987 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9989 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9991 second
= this->last_ld_
;
9996 if (parameters
->options().warn_mismatch())
9999 gold_warning(_(err
), first
, second
);
10001 gold_error(_(err
), first
, second
);
10003 // Arrange for this attribute to be deleted. It's better to
10004 // say "don't know" about a file than to wrongly claim compliance.
10006 out_attr
[tag
].set_type(0);
10012 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10013 int in_vec
= in_attr
[tag
].int_value() & 3;
10014 int out_vec
= out_attr
[tag
].int_value() & 3;
10015 if (in_vec
!= out_vec
)
10020 else if (out_vec
== 0)
10023 out_attr
[tag
].set_int_value(out_vec
);
10024 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10025 this->last_vec_
= name
;
10027 // For now, allow generic to transition to AltiVec or SPE
10028 // without a warning. If GCC marked files with their stack
10029 // alignment and used don't-care markings for files which are
10030 // not affected by the vector ABI, we could warn about this
10032 else if (in_vec
== 1)
10034 else if (out_vec
== 1)
10037 out_attr
[tag
].set_int_value(out_vec
);
10038 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10039 this->last_vec_
= name
;
10041 else if (out_vec
< in_vec
)
10043 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10044 first
= this->last_vec_
;
10047 else if (out_vec
> in_vec
)
10049 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10051 second
= this->last_vec_
;
10055 if (parameters
->options().warn_mismatch())
10056 gold_error(_(err
), first
, second
);
10057 out_attr
[tag
].set_type(0);
10061 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10062 int in_struct
= in_attr
[tag
].int_value() & 3;
10063 int out_struct
= out_attr
[tag
].int_value() & 3;
10064 if (in_struct
!= out_struct
)
10067 if (in_struct
== 0 || in_struct
== 3)
10069 else if (out_struct
== 0)
10071 out_struct
= in_struct
;
10072 out_attr
[tag
].set_int_value(out_struct
);
10073 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10074 this->last_struct_
= name
;
10076 else if (out_struct
< in_struct
)
10078 err
= N_("%s uses r3/r4 for small structure returns, "
10080 first
= this->last_struct_
;
10083 else if (out_struct
> in_struct
)
10085 err
= N_("%s uses r3/r4 for small structure returns, "
10088 second
= this->last_struct_
;
10092 if (parameters
->options().warn_mismatch())
10093 gold_error(_(err
), first
, second
);
10094 out_attr
[tag
].set_type(0);
10099 // Merge Tag_compatibility attributes and any common GNU ones.
10100 this->attributes_section_data_
->merge(name
, pasd
);
10103 // Emit any saved relocs, and mark toc entries using any of these
10104 // relocs as not optimizable.
10106 template<int sh_type
, int size
, bool big_endian
>
10108 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10109 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10112 && parameters
->options().toc_optimize())
10114 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10115 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10116 p
!= this->entries_
.end();
10119 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10122 // If the symbol is no longer defined in a dynamic object,
10123 // then we emitted a COPY relocation. If it is still
10124 // dynamic then we'll need dynamic relocations and thus
10125 // can't optimize toc entries.
10126 if (entry
.sym_
->is_from_dynobj())
10128 Powerpc_relobj
<size
, big_endian
>* ppc_object
10129 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10130 if (entry
.shndx_
== ppc_object
->toc_shndx())
10131 ppc_object
->set_no_toc_opt(entry
.address_
);
10136 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10139 // Return the value to use for a branch relocation.
10141 template<int size
, bool big_endian
>
10143 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10144 const Symbol_table
* symtab
,
10145 const Sized_symbol
<size
>* gsym
,
10146 Powerpc_relobj
<size
, big_endian
>* object
,
10148 unsigned int *dest_shndx
)
10150 if (size
== 32 || this->abiversion() >= 2)
10151 gold_unreachable();
10154 // If the symbol is defined in an opd section, ie. is a function
10155 // descriptor, use the function descriptor code entry address
10156 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10158 && (gsym
->source() != Symbol::FROM_OBJECT
10159 || gsym
->object()->is_dynamic()))
10162 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10163 unsigned int shndx
= symobj
->opd_shndx();
10166 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10167 if (opd_addr
== invalid_address
)
10169 opd_addr
+= symobj
->output_section_address(shndx
);
10170 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10173 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10174 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10177 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10178 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10179 *dest_shndx
= folded
.second
;
10181 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10182 if (sec_addr
== invalid_address
)
10185 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10186 *value
= sec_addr
+ sec_off
;
10193 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10195 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10198 if (gsym
->is_from_dynobj()
10199 || gsym
->is_undefined()
10200 || gsym
->is_preemptible())
10203 if (gsym
->is_absolute())
10204 return !parameters
->options().output_is_position_independent();
10211 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10213 if (psymval
->is_ifunc_symbol())
10217 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10219 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10222 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10223 // pld ra,symbol@got@pcrel
10224 // load/store rt,0(ra)
10226 // pla ra,symbol@pcrel
10227 // load/store rt,0(ra)
10228 // may be translated to
10229 // pload/pstore rt,symbol@pcrel
10231 // This function returns true if the optimization is possible, placing
10232 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10234 // On entry to this function, the linker has already determined that
10235 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10236 // while *PINSN2 is the second instruction.
10239 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10241 uint32_t insn2
= *pinsn2
>> 32;
10244 // Check that regs match.
10245 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10248 switch ((insn2
>> 26) & 63)
10264 // These are the PMLS cases, where we just need to tack a prefix
10265 // on the insn. Check that the D field is zero.
10266 if ((insn2
& 0xffff) != 0)
10268 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10269 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10272 case 58: // lwa, ld
10273 if ((insn2
& 0xfffd) != 0)
10275 i1new
= ((1ULL << 58) | (1ULL << 52)
10276 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10277 | (insn2
& (31ULL << 21)));
10280 case 57: // lxsd, lxssp
10281 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10283 i1new
= ((1ULL << 58) | (1ULL << 52)
10284 | ((40ULL | (insn2
& 3)) << 26)
10285 | (insn2
& (31ULL << 21)));
10288 case 61: // stxsd, stxssp, lxv, stxv
10289 if ((insn2
& 3) == 0)
10291 else if ((insn2
& 3) >= 2)
10293 if ((insn2
& 0xfffc) != 0)
10295 i1new
= ((1ULL << 58) | (1ULL << 52)
10296 | ((44ULL | (insn2
& 3)) << 26)
10297 | (insn2
& (31ULL << 21)));
10301 if ((insn2
& 0xfff0) != 0)
10303 i1new
= ((1ULL << 58) | (1ULL << 52)
10304 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10305 | (insn2
& (31ULL << 21)));
10310 if ((insn2
& 0xffff) != 0)
10312 i1new
= ((1ULL << 58) | (1ULL << 52)
10313 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10316 case 62: // std, stq
10317 if ((insn2
& 0xfffd) != 0)
10319 i1new
= ((1ULL << 58) | (1ULL << 52)
10320 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10321 | (insn2
& (31ULL << 21)));
10326 *pinsn2
= (uint64_t) nop
<< 32;
10330 // Perform a relocation.
10332 template<int size
, bool big_endian
>
10334 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10335 const Relocate_info
<size
, big_endian
>* relinfo
,
10337 Target_powerpc
* target
,
10338 Output_section
* os
,
10340 const unsigned char* preloc
,
10341 const Sized_symbol
<size
>* gsym
,
10342 const Symbol_value
<size
>* psymval
,
10343 unsigned char* view
,
10345 section_size_type view_size
)
10347 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10348 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10349 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10354 if (target
->replace_tls_get_addr(gsym
))
10355 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10357 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10358 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10359 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10361 case Track_tls::NOT_EXPECTED
:
10362 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10363 _("__tls_get_addr call lacks marker reloc"));
10365 case Track_tls::EXPECTED
:
10366 // We have already complained.
10368 case Track_tls::SKIP
:
10369 if (is_plt16_reloc
<size
>(r_type
)
10370 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10371 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10373 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10374 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10376 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10378 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10379 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10381 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10382 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10384 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10385 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10386 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10389 case Track_tls::NORMAL
:
10393 // Offset from start of insn to d-field reloc.
10394 const int d_offset
= big_endian
? 2 : 0;
10396 Powerpc_relobj
<size
, big_endian
>* const object
10397 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10399 bool has_stub_value
= false;
10400 bool localentry0
= false;
10401 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10402 bool has_plt_offset
10404 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10405 : object
->local_has_plt_offset(r_sym
));
10407 && !is_got_reloc(r_type
)
10408 && !is_plt16_reloc
<size
>(r_type
)
10409 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10410 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10411 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10412 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10413 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10414 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10415 && (!psymval
->is_ifunc_symbol()
10416 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10420 && target
->abiversion() >= 2
10421 && !parameters
->options().output_is_position_independent()
10422 && !is_branch_reloc
<size
>(r_type
))
10424 Address off
= target
->glink_section()->find_global_entry(gsym
);
10425 if (off
!= invalid_address
)
10427 value
= target
->glink_section()->global_entry_address() + off
;
10428 has_stub_value
= true;
10433 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10434 if (target
->stub_tables().size() == 1)
10435 stub_table
= target
->stub_tables()[0];
10436 if (stub_table
== NULL
10439 && !parameters
->options().output_is_position_independent()
10440 && !is_branch_reloc
<size
>(r_type
)))
10441 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10442 if (stub_table
== NULL
)
10444 // This is a ref from a data section to an ifunc symbol,
10445 // or a non-branch reloc for which we always want to use
10446 // one set of stubs for resolving function addresses.
10447 if (target
->stub_tables().size() != 0)
10448 stub_table
= target
->stub_tables()[0];
10450 if (stub_table
!= NULL
)
10452 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10454 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10455 rela
.get_r_addend());
10457 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10458 rela
.get_r_addend());
10461 value
= stub_table
->stub_address() + ent
->off_
;
10462 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10463 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10464 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10466 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10467 value
+= ent
->tocoff_
;
10471 && target
->is_tls_get_addr_opt(gsym
)))
10473 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10475 if (!(target
->power10_stubs()
10476 && target
->power10_stubs_auto()))
10479 else if (relnum
< reloc_count
- 1)
10481 Reltype
next_rela(preloc
+ reloc_size
);
10482 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10483 == elfcpp::R_PPC64_TOCSAVE
10484 && (next_rela
.get_r_offset()
10485 == rela
.get_r_offset() + 4))
10489 localentry0
= ent
->localentry0_
;
10490 has_stub_value
= true;
10494 // We don't care too much about bogus debug references to
10495 // non-local functions, but otherwise there had better be a plt
10496 // call stub or global entry stub as appropriate.
10497 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10500 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10501 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10502 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10504 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10506 value
= target
->plt_off(gsym
, &plt
);
10508 value
= target
->plt_off(object
, r_sym
, &plt
);
10509 value
+= plt
->address();
10513 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10514 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10515 value
-= (target
->got_section()->output_section()->address()
10516 + object
->toc_base_offset());
10518 else if (parameters
->options().output_is_position_independent())
10520 if (rela
.get_r_addend() >= 32768)
10522 unsigned int got2
= object
->got2_shndx();
10523 value
-= (object
->get_output_section_offset(got2
)
10524 + object
->output_section(got2
)->address()
10525 + rela
.get_r_addend());
10528 value
-= (target
->got_section()->address()
10529 + target
->got_section()->g_o_t());
10532 else if (!has_plt_offset
10533 && (is_plt16_reloc
<size
>(r_type
)
10534 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10535 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10537 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10538 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10539 r_type
= elfcpp::R_POWERPC_NONE
;
10541 else if (!has_plt_offset
10542 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10543 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10545 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10546 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10547 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10548 r_type
= elfcpp::R_POWERPC_NONE
;
10550 else if (is_got_reloc(r_type
))
10554 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10555 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10559 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10560 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10562 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10563 value
+= target
->got_section()->address();
10565 value
-= target
->got_section()->got_base_offset(object
);
10567 else if (r_type
== elfcpp::R_PPC64_TOC
)
10569 value
= (target
->got_section()->output_section()->address()
10570 + object
->toc_base_offset());
10572 else if (gsym
!= NULL
10573 && (r_type
== elfcpp::R_POWERPC_REL24
10574 || r_type
== elfcpp::R_PPC_PLTREL24
)
10579 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10580 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10581 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10582 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10584 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10585 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10586 if ((insn
& 1) != 0
10588 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10590 elfcpp::Swap
<32, big_endian
>::
10591 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10592 can_plt_call
= true;
10597 // If we don't have a branch and link followed by a nop,
10598 // we can't go via the plt because there is no place to
10599 // put a toc restoring instruction.
10600 // Unless we know we won't be returning.
10601 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10602 can_plt_call
= true;
10606 // g++ as of 20130507 emits self-calls without a
10607 // following nop. This is arguably wrong since we have
10608 // conflicting information. On the one hand a global
10609 // symbol and on the other a local call sequence, but
10610 // don't error for this special case.
10611 // It isn't possible to cheaply verify we have exactly
10612 // such a call. Allow all calls to the same section.
10614 Address code
= value
;
10615 if (gsym
->source() == Symbol::FROM_OBJECT
10616 && gsym
->object() == object
)
10618 unsigned int dest_shndx
= 0;
10619 if (target
->abiversion() < 2)
10621 Address addend
= rela
.get_r_addend();
10622 code
= psymval
->value(object
, addend
);
10623 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10624 &code
, &dest_shndx
);
10627 if (dest_shndx
== 0)
10628 dest_shndx
= gsym
->shndx(&is_ordinary
);
10629 ok
= dest_shndx
== relinfo
->data_shndx
;
10633 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10634 _("call lacks nop, can't restore toc; "
10635 "recompile with -fPIC"));
10641 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10642 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10643 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10644 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10645 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10647 // First instruction of a global dynamic sequence, arg setup insn.
10648 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10649 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10650 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10651 if (tls_type
== tls::TLSOPT_NONE
)
10652 got_type
= GOT_TYPE_TLSGD
;
10653 else if (tls_type
== tls::TLSOPT_TO_IE
)
10654 got_type
= GOT_TYPE_TPREL
;
10655 if (got_type
!= GOT_TYPE_STANDARD
)
10659 gold_assert(gsym
->has_got_offset(got_type
));
10660 value
= gsym
->got_offset(got_type
);
10664 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10665 value
= object
->local_got_offset(r_sym
, got_type
);
10667 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10668 value
+= target
->got_section()->address();
10670 value
-= target
->got_section()->got_base_offset(object
);
10672 if (tls_type
== tls::TLSOPT_TO_IE
)
10674 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10676 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10677 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10679 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10681 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10682 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10683 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10684 pinsn
& 0xffffffff);
10685 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10689 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10690 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10692 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10693 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10694 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10696 insn
|= 32 << 26; // lwz
10698 insn
|= 58 << 26; // ld
10699 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10701 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10702 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10705 else if (tls_type
== tls::TLSOPT_TO_LE
)
10707 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10709 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10710 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10712 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10713 // pla pcrel -> paddi r13
10714 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10715 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10716 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10717 pinsn
& 0xffffffff);
10718 r_type
= elfcpp::R_PPC64_TPREL34
;
10719 value
= psymval
->value(object
, rela
.get_r_addend());
10723 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10724 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10726 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10727 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10728 insn
&= (1 << 26) - (1 << 21); // extract rt
10732 insn
|= addis_0_13
;
10733 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10734 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10735 value
= psymval
->value(object
, rela
.get_r_addend());
10739 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10741 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10742 r_type
= elfcpp::R_POWERPC_NONE
;
10747 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10748 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10749 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10750 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10751 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10753 // First instruction of a local dynamic sequence, arg setup insn.
10754 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10755 if (tls_type
== tls::TLSOPT_NONE
)
10757 value
= target
->tlsld_got_offset();
10758 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10759 value
+= target
->got_section()->address();
10761 value
-= target
->got_section()->got_base_offset(object
);
10765 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10766 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10768 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10769 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10771 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10772 // pla pcrel -> paddi r13
10773 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10774 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10775 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10776 pinsn
& 0xffffffff);
10777 r_type
= elfcpp::R_PPC64_TPREL34
;
10778 value
= dtp_offset
;
10780 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10781 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10783 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10784 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10785 insn
&= (1 << 26) - (1 << 21); // extract rt
10789 insn
|= addis_0_13
;
10790 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10791 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10792 value
= dtp_offset
;
10796 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10798 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10799 r_type
= elfcpp::R_POWERPC_NONE
;
10803 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10804 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10805 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10806 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10807 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10809 // Accesses relative to a local dynamic sequence address,
10810 // no optimisation here.
10813 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10814 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10818 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10819 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10821 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10822 value
+= target
->got_section()->address();
10824 value
-= target
->got_section()->got_base_offset(object
);
10826 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10827 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10828 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10829 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10830 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10832 // First instruction of initial exec sequence.
10833 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10834 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10835 if (tls_type
== tls::TLSOPT_NONE
)
10839 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10840 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10844 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10845 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10847 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10848 value
+= target
->got_section()->address();
10850 value
-= target
->got_section()->got_base_offset(object
);
10854 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10855 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10857 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10858 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10860 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10861 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10862 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10863 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10864 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10865 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10866 pinsn
& 0xffffffff);
10867 r_type
= elfcpp::R_PPC64_TPREL34
;
10868 value
= psymval
->value(object
, rela
.get_r_addend());
10870 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10871 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10873 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10874 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10875 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10879 insn
|= addis_0_13
;
10880 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10881 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10882 value
= psymval
->value(object
, rela
.get_r_addend());
10886 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10888 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10889 r_type
= elfcpp::R_POWERPC_NONE
;
10893 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10894 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10896 // Second instruction of a global dynamic sequence,
10897 // the __tls_get_addr call
10898 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10899 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10900 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10901 if (tls_type
!= tls::TLSOPT_NONE
)
10903 if (tls_type
== tls::TLSOPT_TO_IE
)
10905 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10906 Insn insn
= add_3_3_13
;
10909 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10910 r_type
= elfcpp::R_POWERPC_NONE
;
10914 bool is_pcrel
= false;
10915 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10916 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10917 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10918 if (relnum
< reloc_count
- 1)
10920 Reltype
next_rela(preloc
+ reloc_size
);
10921 unsigned int r_type2
10922 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10923 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10924 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10925 && next_rela
.get_r_offset() == rela
.get_r_offset())
10928 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10931 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10932 r_type
= elfcpp::R_POWERPC_NONE
;
10936 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10937 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10939 value
= psymval
->value(object
, rela
.get_r_addend());
10942 this->skip_next_tls_get_addr_call();
10945 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10946 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10948 // Second instruction of a local dynamic sequence,
10949 // the __tls_get_addr call
10950 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10951 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10952 if (tls_type
== tls::TLSOPT_TO_LE
)
10954 bool is_pcrel
= false;
10955 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10956 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10957 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10958 if (relnum
< reloc_count
- 1)
10960 Reltype
next_rela(preloc
+ reloc_size
);
10961 unsigned int r_type2
10962 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10963 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10964 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10965 && next_rela
.get_r_offset() == rela
.get_r_offset())
10968 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10971 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10972 r_type
= elfcpp::R_POWERPC_NONE
;
10976 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10977 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10979 value
= dtp_offset
;
10981 this->skip_next_tls_get_addr_call();
10984 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10986 // Second instruction of an initial exec sequence
10987 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10988 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10989 if (tls_type
== tls::TLSOPT_TO_LE
)
10991 Address roff
= rela
.get_r_offset() & 3;
10992 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
10993 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10994 unsigned int reg
= size
== 32 ? 2 : 13;
10995 insn
= at_tls_transform(insn
, reg
);
10996 gold_assert(insn
!= 0);
10999 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11000 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11002 value
= psymval
->value(object
, rela
.get_r_addend());
11004 else if (roff
== 1)
11006 // For pcrel IE to LE we already have the full offset
11007 // and thus don't need an addi here. A nop or mr will do.
11008 if ((insn
& (0x3f << 26)) == 14 << 26)
11010 // Extract regs from addi rt,ra,si.
11011 unsigned int rt
= (insn
>> 21) & 0x1f;
11012 unsigned int ra
= (insn
>> 16) & 0x1f;
11017 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11018 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11019 insn
|= (31u << 26) | (444u << 1);
11022 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11023 r_type
= elfcpp::R_POWERPC_NONE
;
11027 else if (!has_stub_value
)
11029 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11030 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11032 // PLTCALL without plt entry => convert to direct call
11033 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11034 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11035 insn
= (insn
& 1) | b
;
11036 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11038 r_type
= elfcpp::R_PPC_PLTREL24
;
11039 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11040 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11042 r_type
= elfcpp::R_POWERPC_REL24
;
11044 Address addend
= 0;
11046 && (r_type
== elfcpp::R_PPC_PLTREL24
11047 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11048 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11049 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11050 addend
= rela
.get_r_addend();
11051 value
= psymval
->value(object
, addend
);
11052 unsigned int local_ent
= 0;
11053 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11055 if (target
->abiversion() >= 2)
11058 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11060 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11064 unsigned int dest_shndx
;
11065 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11066 &value
, &dest_shndx
);
11069 Address max_branch
= max_branch_delta
<size
>(r_type
);
11070 if (max_branch
!= 0
11071 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11073 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
11075 ? object
->ppc64_needs_toc(gsym
)
11076 : object
->ppc64_needs_toc(r_sym
)))))
11078 Stub_table
<size
, big_endian
>* stub_table
11079 = object
->stub_table(relinfo
->data_shndx
);
11080 if (stub_table
!= NULL
)
11082 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11083 = stub_table
->find_long_branch_entry(object
, value
);
11086 if (ent
->save_res_
)
11087 value
= (value
- target
->savres_section()->address()
11088 + stub_table
->branch_size());
11091 value
= (stub_table
->stub_address()
11092 + stub_table
->plt_size()
11095 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
11096 value
+= ent
->tocoff_
;
11098 has_stub_value
= true;
11102 if (!has_stub_value
)
11103 value
+= local_ent
;
11108 case elfcpp::R_PPC64_REL24_NOTOC
:
11112 case elfcpp::R_PPC64_REL64
:
11113 case elfcpp::R_POWERPC_REL32
:
11114 case elfcpp::R_POWERPC_REL24
:
11115 case elfcpp::R_PPC_PLTREL24
:
11116 case elfcpp::R_PPC_LOCAL24PC
:
11117 case elfcpp::R_POWERPC_REL16
:
11118 case elfcpp::R_POWERPC_REL16_LO
:
11119 case elfcpp::R_POWERPC_REL16_HI
:
11120 case elfcpp::R_POWERPC_REL16_HA
:
11121 case elfcpp::R_POWERPC_REL16DX_HA
:
11122 case elfcpp::R_PPC64_REL16_HIGH
:
11123 case elfcpp::R_PPC64_REL16_HIGHA
:
11124 case elfcpp::R_PPC64_REL16_HIGHER
:
11125 case elfcpp::R_PPC64_REL16_HIGHERA
:
11126 case elfcpp::R_PPC64_REL16_HIGHEST
:
11127 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11128 case elfcpp::R_POWERPC_REL14
:
11129 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11130 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11131 case elfcpp::R_PPC64_PCREL34
:
11132 case elfcpp::R_PPC64_GOT_PCREL34
:
11133 case elfcpp::R_PPC64_PLT_PCREL34
:
11134 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11135 case elfcpp::R_PPC64_PCREL28
:
11136 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11137 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11138 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11139 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11140 case elfcpp::R_PPC64_REL16_HIGHER34
:
11141 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11142 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11143 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11147 case elfcpp::R_PPC64_TOC16
:
11148 case elfcpp::R_PPC64_TOC16_LO
:
11149 case elfcpp::R_PPC64_TOC16_HI
:
11150 case elfcpp::R_PPC64_TOC16_HA
:
11151 case elfcpp::R_PPC64_TOC16_DS
:
11152 case elfcpp::R_PPC64_TOC16_LO_DS
:
11153 // Subtract the TOC base address.
11154 value
-= (target
->got_section()->output_section()->address()
11155 + object
->toc_base_offset());
11158 case elfcpp::R_POWERPC_SECTOFF
:
11159 case elfcpp::R_POWERPC_SECTOFF_LO
:
11160 case elfcpp::R_POWERPC_SECTOFF_HI
:
11161 case elfcpp::R_POWERPC_SECTOFF_HA
:
11162 case elfcpp::R_PPC64_SECTOFF_DS
:
11163 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11165 value
-= os
->address();
11168 case elfcpp::R_PPC64_TPREL16_DS
:
11169 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11170 case elfcpp::R_PPC64_TPREL16_HIGH
:
11171 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11173 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11176 case elfcpp::R_POWERPC_TPREL16
:
11177 case elfcpp::R_POWERPC_TPREL16_LO
:
11178 case elfcpp::R_POWERPC_TPREL16_HI
:
11179 case elfcpp::R_POWERPC_TPREL16_HA
:
11180 case elfcpp::R_POWERPC_TPREL
:
11181 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11182 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11183 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11184 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11185 case elfcpp::R_PPC64_TPREL34
:
11186 // tls symbol values are relative to tls_segment()->vaddr()
11187 value
-= tp_offset
;
11190 case elfcpp::R_PPC64_DTPREL16_DS
:
11191 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11192 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11193 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11194 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11195 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11197 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11198 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11201 case elfcpp::R_POWERPC_DTPREL16
:
11202 case elfcpp::R_POWERPC_DTPREL16_LO
:
11203 case elfcpp::R_POWERPC_DTPREL16_HI
:
11204 case elfcpp::R_POWERPC_DTPREL16_HA
:
11205 case elfcpp::R_POWERPC_DTPREL
:
11206 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11207 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11208 case elfcpp::R_PPC64_DTPREL34
:
11209 // tls symbol values are relative to tls_segment()->vaddr()
11210 value
-= dtp_offset
;
11213 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11215 value
+= object
->ppc64_local_entry_offset(gsym
);
11217 value
+= object
->ppc64_local_entry_offset(r_sym
);
11224 Insn branch_bit
= 0;
11227 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11228 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11229 branch_bit
= 1 << 21;
11231 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11232 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11234 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11235 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11236 insn
&= ~(1 << 21);
11237 insn
|= branch_bit
;
11238 if (this->is_isa_v2
)
11240 // Set 'a' bit. This is 0b00010 in BO field for branch
11241 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11242 // for branch on CTR insns (BO == 1a00t or 1a01t).
11243 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11244 insn
|= 0x02 << 21;
11245 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11246 insn
|= 0x08 << 21;
11252 // Invert 'y' bit if not the default.
11253 if (static_cast<Signed_address
>(value
) < 0)
11256 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11260 case elfcpp::R_POWERPC_PLT16_HA
:
11262 && !parameters
->options().output_is_position_independent())
11264 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11265 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11267 // Convert addis to lis.
11268 if ((insn
& (0x3f << 26)) == 15u << 26
11269 && (insn
& (0x1f << 16)) != 0)
11271 insn
&= ~(0x1f << 16);
11272 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11282 ? relative_value_is_known(gsym
)
11283 : relative_value_is_known(psymval
))
11288 uint64_t pinsn
, pinsn2
;
11295 // Multi-instruction sequences that access the GOT/TOC can
11296 // be optimized, eg.
11297 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11298 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11300 // addis ra,r2,0; addi rb,ra,x@toc@l;
11301 // to nop; addi rb,r2,x@toc;
11302 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11303 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11304 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11305 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11306 case elfcpp::R_POWERPC_GOT16_HA
:
11307 case elfcpp::R_PPC64_TOC16_HA
:
11308 if (size
== 64 && parameters
->options().toc_optimize())
11310 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11311 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11312 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11313 && object
->make_toc_relative(target
, &value
))
11314 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11315 && object
->make_got_relative(target
, psymval
,
11316 rela
.get_r_addend(),
11319 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11320 == ((15u << 26) | (2 << 16)));
11322 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11323 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11324 && value
+ 0x8000 < 0x10000)
11326 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11332 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11333 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11334 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11335 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11336 case elfcpp::R_POWERPC_GOT16_LO
:
11337 case elfcpp::R_PPC64_GOT16_LO_DS
:
11338 case elfcpp::R_PPC64_TOC16_LO
:
11339 case elfcpp::R_PPC64_TOC16_LO_DS
:
11340 if (size
== 64 && parameters
->options().toc_optimize())
11342 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11343 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11344 bool changed
= false;
11345 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11346 && object
->make_toc_relative(target
, &value
))
11347 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11348 && object
->make_got_relative(target
, psymval
,
11349 rela
.get_r_addend(),
11352 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11353 insn
^= (14u << 26) ^ (58u << 26);
11354 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11357 if (ok_lo_toc_insn(insn
, r_type
)
11358 && value
+ 0x8000 < 0x10000)
11360 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11362 // Transform addic to addi when we change reg.
11363 insn
&= ~((0x3f << 26) | (0x1f << 16));
11364 insn
|= (14u << 26) | (2 << 16);
11368 insn
&= ~(0x1f << 16);
11374 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11378 case elfcpp::R_PPC64_GOT_PCREL34
:
11379 if (size
== 64 && parameters
->options().toc_optimize())
11381 iview
= reinterpret_cast<Insn
*>(view
);
11382 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11384 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11385 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11386 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11389 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11391 if (relval
+ (1ULL << 33) < 1ULL << 34)
11394 // Replace with paddi
11395 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11396 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11397 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11398 pinsn
& 0xffffffff);
11404 case elfcpp::R_PPC64_PCREL34
:
11407 iview
= reinterpret_cast<Insn
*>(view
);
11408 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11410 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11411 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11412 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11413 | (14ULL << 26) /* paddi */))
11417 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11418 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11419 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11420 if (relnum
>= reloc_count
- 1)
11423 Reltype
next_rela(preloc
+ reloc_size
);
11424 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11425 != elfcpp::R_PPC64_PCREL_OPT
)
11426 || next_rela
.get_r_offset() != rela
.get_r_offset())
11429 Address off
= next_rela
.get_r_addend();
11431 off
= 8; // zero means next insn.
11432 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11435 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11436 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11438 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11440 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11442 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11443 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11444 pinsn
& 0xffffffff);
11445 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11450 case elfcpp::R_POWERPC_TPREL16_HA
:
11451 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11453 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11454 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11459 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11461 // R_PPC_TLSGD, R_PPC_TLSLD
11464 case elfcpp::R_POWERPC_TPREL16_LO
:
11465 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11467 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11468 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11469 insn
&= ~(0x1f << 16);
11470 insn
|= (size
== 32 ? 2 : 13) << 16;
11471 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11475 case elfcpp::R_PPC64_ENTRY
:
11478 value
= (target
->got_section()->output_section()->address()
11479 + object
->toc_base_offset());
11480 if (value
+ 0x80008000 <= 0xffffffff
11481 && !parameters
->options().output_is_position_independent())
11483 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11484 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11485 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11487 if ((insn1
& ~0xfffc) == ld_2_12
11488 && insn2
== add_2_2_12
)
11490 insn1
= lis_2
+ ha(value
);
11491 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11492 insn2
= addi_2_2
+ l(value
);
11493 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11500 if (value
+ 0x80008000 <= 0xffffffff)
11502 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11503 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11504 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11506 if ((insn1
& ~0xfffc) == ld_2_12
11507 && insn2
== add_2_2_12
)
11509 insn1
= addis_2_12
+ ha(value
);
11510 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11511 insn2
= addi_2_2
+ l(value
);
11512 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11520 case elfcpp::R_POWERPC_REL16_LO
:
11521 // If we are generating a non-PIC executable, edit
11522 // 0: addis 2,12,.TOC.-0b@ha
11523 // addi 2,2,.TOC.-0b@l
11524 // used by ELFv2 global entry points to set up r2, to
11526 // addi 2,2,.TOC.@l
11527 // if .TOC. is in range. */
11529 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11532 && target
->abiversion() >= 2
11533 && !parameters
->options().output_is_position_independent()
11534 && rela
.get_r_addend() == d_offset
+ 4
11536 && strcmp(gsym
->name(), ".TOC.") == 0)
11538 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11539 Reltype
prev_rela(preloc
- reloc_size
);
11540 if ((prev_rela
.get_r_info()
11541 == elfcpp::elf_r_info
<size
>(r_sym
,
11542 elfcpp::R_POWERPC_REL16_HA
))
11543 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11544 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11546 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11547 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11548 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11550 if ((insn1
& 0xffff0000) == addis_2_12
11551 && (insn2
& 0xffff0000) == addi_2_2
)
11553 insn1
= lis_2
+ ha(value
+ address
- 4);
11554 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11555 insn2
= addi_2_2
+ l(value
+ address
- 4);
11556 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11559 relinfo
->rr
->set_strategy(relnum
- 1,
11560 Relocatable_relocs::RELOC_SPECIAL
);
11561 relinfo
->rr
->set_strategy(relnum
,
11562 Relocatable_relocs::RELOC_SPECIAL
);
11572 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11573 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11576 case elfcpp::R_POWERPC_ADDR32
:
11577 case elfcpp::R_POWERPC_UADDR32
:
11579 overflow
= Reloc::CHECK_BITFIELD
;
11582 case elfcpp::R_POWERPC_REL32
:
11583 case elfcpp::R_POWERPC_REL16DX_HA
:
11585 overflow
= Reloc::CHECK_SIGNED
;
11588 case elfcpp::R_POWERPC_UADDR16
:
11589 overflow
= Reloc::CHECK_BITFIELD
;
11592 case elfcpp::R_POWERPC_ADDR16
:
11593 // We really should have three separate relocations,
11594 // one for 16-bit data, one for insns with 16-bit signed fields,
11595 // and one for insns with 16-bit unsigned fields.
11596 overflow
= Reloc::CHECK_BITFIELD
;
11597 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11598 overflow
= Reloc::CHECK_LOW_INSN
;
11601 case elfcpp::R_POWERPC_ADDR16_HI
:
11602 case elfcpp::R_POWERPC_ADDR16_HA
:
11603 case elfcpp::R_POWERPC_GOT16_HI
:
11604 case elfcpp::R_POWERPC_GOT16_HA
:
11605 case elfcpp::R_POWERPC_PLT16_HI
:
11606 case elfcpp::R_POWERPC_PLT16_HA
:
11607 case elfcpp::R_POWERPC_SECTOFF_HI
:
11608 case elfcpp::R_POWERPC_SECTOFF_HA
:
11609 case elfcpp::R_PPC64_TOC16_HI
:
11610 case elfcpp::R_PPC64_TOC16_HA
:
11611 case elfcpp::R_PPC64_PLTGOT16_HI
:
11612 case elfcpp::R_PPC64_PLTGOT16_HA
:
11613 case elfcpp::R_POWERPC_TPREL16_HI
:
11614 case elfcpp::R_POWERPC_TPREL16_HA
:
11615 case elfcpp::R_POWERPC_DTPREL16_HI
:
11616 case elfcpp::R_POWERPC_DTPREL16_HA
:
11617 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11618 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11619 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11620 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11621 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11622 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11623 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11624 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11625 case elfcpp::R_POWERPC_REL16_HI
:
11626 case elfcpp::R_POWERPC_REL16_HA
:
11628 overflow
= Reloc::CHECK_HIGH_INSN
;
11631 case elfcpp::R_POWERPC_REL16
:
11632 case elfcpp::R_PPC64_TOC16
:
11633 case elfcpp::R_POWERPC_GOT16
:
11634 case elfcpp::R_POWERPC_SECTOFF
:
11635 case elfcpp::R_POWERPC_TPREL16
:
11636 case elfcpp::R_POWERPC_DTPREL16
:
11637 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11638 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11639 case elfcpp::R_POWERPC_GOT_TPREL16
:
11640 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11641 overflow
= Reloc::CHECK_LOW_INSN
;
11644 case elfcpp::R_PPC64_REL24_NOTOC
:
11648 case elfcpp::R_POWERPC_ADDR24
:
11649 case elfcpp::R_POWERPC_ADDR14
:
11650 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11651 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11652 case elfcpp::R_PPC64_ADDR16_DS
:
11653 case elfcpp::R_POWERPC_REL24
:
11654 case elfcpp::R_PPC_PLTREL24
:
11655 case elfcpp::R_PPC_LOCAL24PC
:
11656 case elfcpp::R_PPC64_TPREL16_DS
:
11657 case elfcpp::R_PPC64_DTPREL16_DS
:
11658 case elfcpp::R_PPC64_TOC16_DS
:
11659 case elfcpp::R_PPC64_GOT16_DS
:
11660 case elfcpp::R_PPC64_SECTOFF_DS
:
11661 case elfcpp::R_POWERPC_REL14
:
11662 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11663 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11664 case elfcpp::R_PPC64_D34
:
11665 case elfcpp::R_PPC64_PCREL34
:
11666 case elfcpp::R_PPC64_GOT_PCREL34
:
11667 case elfcpp::R_PPC64_PLT_PCREL34
:
11668 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11669 case elfcpp::R_PPC64_D28
:
11670 case elfcpp::R_PPC64_PCREL28
:
11671 case elfcpp::R_PPC64_TPREL34
:
11672 case elfcpp::R_PPC64_DTPREL34
:
11673 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11674 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11675 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11676 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11677 overflow
= Reloc::CHECK_SIGNED
;
11681 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11684 if (overflow
== Reloc::CHECK_LOW_INSN
11685 || overflow
== Reloc::CHECK_HIGH_INSN
)
11687 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11689 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11690 overflow
= Reloc::CHECK_BITFIELD
;
11691 else if (overflow
== Reloc::CHECK_LOW_INSN
11692 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11693 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11694 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11695 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11696 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11697 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11698 overflow
= Reloc::CHECK_UNSIGNED
;
11700 overflow
= Reloc::CHECK_SIGNED
;
11703 bool maybe_dq_reloc
= false;
11704 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11705 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11708 case elfcpp::R_POWERPC_NONE
:
11709 case elfcpp::R_POWERPC_TLS
:
11710 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11711 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11712 case elfcpp::R_POWERPC_PLTSEQ
:
11713 case elfcpp::R_POWERPC_PLTCALL
:
11714 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11715 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11716 case elfcpp::R_PPC64_PCREL_OPT
:
11719 case elfcpp::R_PPC64_ADDR64
:
11720 case elfcpp::R_PPC64_REL64
:
11721 case elfcpp::R_PPC64_TOC
:
11722 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11723 Reloc::addr64(view
, value
);
11726 case elfcpp::R_POWERPC_TPREL
:
11727 case elfcpp::R_POWERPC_DTPREL
:
11729 Reloc::addr64(view
, value
);
11731 status
= Reloc::addr32(view
, value
, overflow
);
11734 case elfcpp::R_PPC64_UADDR64
:
11735 Reloc::addr64_u(view
, value
);
11738 case elfcpp::R_POWERPC_ADDR32
:
11739 status
= Reloc::addr32(view
, value
, overflow
);
11742 case elfcpp::R_POWERPC_REL32
:
11743 case elfcpp::R_POWERPC_UADDR32
:
11744 status
= Reloc::addr32_u(view
, value
, overflow
);
11747 case elfcpp::R_PPC64_REL24_NOTOC
:
11749 goto unsupp
; // R_PPC_EMB_RELSDA
11751 case elfcpp::R_POWERPC_ADDR24
:
11752 case elfcpp::R_POWERPC_REL24
:
11753 case elfcpp::R_PPC_PLTREL24
:
11754 case elfcpp::R_PPC_LOCAL24PC
:
11755 status
= Reloc::addr24(view
, value
, overflow
);
11758 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11759 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11760 case elfcpp::R_POWERPC_GOT_TPREL16
:
11761 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11764 // On ppc64 these are all ds form
11765 maybe_dq_reloc
= true;
11769 case elfcpp::R_POWERPC_ADDR16
:
11770 case elfcpp::R_POWERPC_REL16
:
11771 case elfcpp::R_PPC64_TOC16
:
11772 case elfcpp::R_POWERPC_GOT16
:
11773 case elfcpp::R_POWERPC_SECTOFF
:
11774 case elfcpp::R_POWERPC_TPREL16
:
11775 case elfcpp::R_POWERPC_DTPREL16
:
11776 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11777 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11778 case elfcpp::R_POWERPC_ADDR16_LO
:
11779 case elfcpp::R_POWERPC_REL16_LO
:
11780 case elfcpp::R_PPC64_TOC16_LO
:
11781 case elfcpp::R_POWERPC_GOT16_LO
:
11782 case elfcpp::R_POWERPC_PLT16_LO
:
11783 case elfcpp::R_POWERPC_SECTOFF_LO
:
11784 case elfcpp::R_POWERPC_TPREL16_LO
:
11785 case elfcpp::R_POWERPC_DTPREL16_LO
:
11786 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11787 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11789 status
= Reloc::addr16(view
, value
, overflow
);
11791 maybe_dq_reloc
= true;
11794 case elfcpp::R_POWERPC_UADDR16
:
11795 status
= Reloc::addr16_u(view
, value
, overflow
);
11798 case elfcpp::R_PPC64_ADDR16_HIGH
:
11799 case elfcpp::R_PPC64_TPREL16_HIGH
:
11800 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11802 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11805 case elfcpp::R_POWERPC_ADDR16_HI
:
11806 case elfcpp::R_POWERPC_REL16_HI
:
11807 case elfcpp::R_PPC64_REL16_HIGH
:
11808 case elfcpp::R_PPC64_TOC16_HI
:
11809 case elfcpp::R_POWERPC_GOT16_HI
:
11810 case elfcpp::R_POWERPC_PLT16_HI
:
11811 case elfcpp::R_POWERPC_SECTOFF_HI
:
11812 case elfcpp::R_POWERPC_TPREL16_HI
:
11813 case elfcpp::R_POWERPC_DTPREL16_HI
:
11814 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11815 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11816 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11817 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11818 Reloc::addr16_hi(view
, value
);
11821 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11822 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11823 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11825 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11828 case elfcpp::R_POWERPC_ADDR16_HA
:
11829 case elfcpp::R_POWERPC_REL16_HA
:
11830 case elfcpp::R_PPC64_REL16_HIGHA
:
11831 case elfcpp::R_PPC64_TOC16_HA
:
11832 case elfcpp::R_POWERPC_GOT16_HA
:
11833 case elfcpp::R_POWERPC_PLT16_HA
:
11834 case elfcpp::R_POWERPC_SECTOFF_HA
:
11835 case elfcpp::R_POWERPC_TPREL16_HA
:
11836 case elfcpp::R_POWERPC_DTPREL16_HA
:
11837 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11838 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11839 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11840 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11841 Reloc::addr16_ha(view
, value
);
11844 case elfcpp::R_POWERPC_REL16DX_HA
:
11845 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11848 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11850 // R_PPC_EMB_NADDR16_LO
11853 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11854 case elfcpp::R_PPC64_REL16_HIGHER
:
11855 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11856 Reloc::addr16_hi2(view
, value
);
11859 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11861 // R_PPC_EMB_NADDR16_HI
11864 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11865 case elfcpp::R_PPC64_REL16_HIGHERA
:
11866 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11867 Reloc::addr16_ha2(view
, value
);
11870 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11872 // R_PPC_EMB_NADDR16_HA
11875 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11876 case elfcpp::R_PPC64_REL16_HIGHEST
:
11877 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11878 Reloc::addr16_hi3(view
, value
);
11881 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11883 // R_PPC_EMB_SDAI16
11886 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11887 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11888 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11889 Reloc::addr16_ha3(view
, value
);
11892 case elfcpp::R_PPC64_DTPREL16_DS
:
11893 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11895 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11898 case elfcpp::R_PPC64_TPREL16_DS
:
11899 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11901 // R_PPC_TLSGD, R_PPC_TLSLD
11904 case elfcpp::R_PPC64_ADDR16_DS
:
11905 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11906 case elfcpp::R_PPC64_TOC16_DS
:
11907 case elfcpp::R_PPC64_TOC16_LO_DS
:
11908 case elfcpp::R_PPC64_GOT16_DS
:
11909 case elfcpp::R_PPC64_GOT16_LO_DS
:
11910 case elfcpp::R_PPC64_PLT16_LO_DS
:
11911 case elfcpp::R_PPC64_SECTOFF_DS
:
11912 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11913 maybe_dq_reloc
= true;
11916 case elfcpp::R_POWERPC_ADDR14
:
11917 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11918 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11919 case elfcpp::R_POWERPC_REL14
:
11920 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11921 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11922 status
= Reloc::addr14(view
, value
, overflow
);
11925 case elfcpp::R_POWERPC_COPY
:
11926 case elfcpp::R_POWERPC_GLOB_DAT
:
11927 case elfcpp::R_POWERPC_JMP_SLOT
:
11928 case elfcpp::R_POWERPC_RELATIVE
:
11929 case elfcpp::R_POWERPC_DTPMOD
:
11930 case elfcpp::R_PPC64_JMP_IREL
:
11931 case elfcpp::R_POWERPC_IRELATIVE
:
11932 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11933 _("unexpected reloc %u in object file"),
11937 case elfcpp::R_PPC64_TOCSAVE
:
11943 Symbol_location loc
;
11944 loc
.object
= relinfo
->object
;
11945 loc
.shndx
= relinfo
->data_shndx
;
11946 loc
.offset
= rela
.get_r_offset();
11947 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
11948 if (tocsave
->find(loc
) != tocsave
->end())
11950 // If we've generated plt calls using this tocsave, then
11951 // the nop needs to be changed to save r2.
11952 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11953 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11954 elfcpp::Swap
<32, big_endian
>::
11955 writeval(iview
, std_2_1
+ target
->stk_toc());
11960 case elfcpp::R_PPC_EMB_SDA2I16
:
11961 case elfcpp::R_PPC_EMB_SDA2REL
:
11964 // R_PPC64_TLSGD, R_PPC64_TLSLD
11967 case elfcpp::R_PPC64_D34
:
11968 case elfcpp::R_PPC64_D34_LO
:
11969 case elfcpp::R_PPC64_PCREL34
:
11970 case elfcpp::R_PPC64_GOT_PCREL34
:
11971 case elfcpp::R_PPC64_PLT_PCREL34
:
11972 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11973 case elfcpp::R_PPC64_TPREL34
:
11974 case elfcpp::R_PPC64_DTPREL34
:
11975 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11976 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11977 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11978 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11981 status
= Reloc::addr34(view
, value
, overflow
);
11984 case elfcpp::R_PPC64_D34_HI30
:
11987 Reloc::addr34_hi(view
, value
);
11990 case elfcpp::R_PPC64_D34_HA30
:
11993 Reloc::addr34_ha(view
, value
);
11996 case elfcpp::R_PPC64_D28
:
11997 case elfcpp::R_PPC64_PCREL28
:
12000 status
= Reloc::addr28(view
, value
, overflow
);
12003 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12004 case elfcpp::R_PPC64_REL16_HIGHER34
:
12007 Reloc::addr16_higher34(view
, value
);
12010 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12011 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12014 Reloc::addr16_highera34(view
, value
);
12017 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12018 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12021 Reloc::addr16_highest34(view
, value
);
12024 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12025 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12028 Reloc::addr16_highesta34(view
, value
);
12031 case elfcpp::R_POWERPC_PLT32
:
12032 case elfcpp::R_POWERPC_PLTREL32
:
12033 case elfcpp::R_PPC_SDAREL16
:
12034 case elfcpp::R_POWERPC_ADDR30
:
12035 case elfcpp::R_PPC64_PLT64
:
12036 case elfcpp::R_PPC64_PLTREL64
:
12037 case elfcpp::R_PPC64_PLTGOT16
:
12038 case elfcpp::R_PPC64_PLTGOT16_LO
:
12039 case elfcpp::R_PPC64_PLTGOT16_HI
:
12040 case elfcpp::R_PPC64_PLTGOT16_HA
:
12041 case elfcpp::R_PPC64_PLTGOT16_DS
:
12042 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12043 case elfcpp::R_PPC_TOC16
:
12046 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12047 _("unsupported reloc %u"),
12052 if (maybe_dq_reloc
)
12055 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12057 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12058 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12059 && (insn
& 3) == 1))
12060 status
= Reloc::addr16_dq(view
, value
, overflow
);
12061 else if (size
== 64
12062 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12063 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12064 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12065 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12066 status
= Reloc::addr16_ds(view
, value
, overflow
);
12068 status
= Reloc::addr16(view
, value
, overflow
);
12071 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12074 && gsym
->is_undefined()
12075 && is_branch_reloc
<size
>(r_type
))))
12077 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12078 _("relocation overflow"));
12079 if (has_stub_value
)
12080 gold_info(_("try relinking with a smaller --stub-group-size"));
12086 // Relocate section data.
12088 template<int size
, bool big_endian
>
12090 Target_powerpc
<size
, big_endian
>::relocate_section(
12091 const Relocate_info
<size
, big_endian
>* relinfo
,
12092 unsigned int sh_type
,
12093 const unsigned char* prelocs
,
12094 size_t reloc_count
,
12095 Output_section
* output_section
,
12096 bool needs_special_offset_handling
,
12097 unsigned char* view
,
12099 section_size_type view_size
,
12100 const Reloc_symbol_changes
* reloc_symbol_changes
)
12102 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12103 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12104 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12105 Powerpc_comdat_behavior
;
12106 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12109 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12111 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12112 Powerpc_comdat_behavior
, Classify_reloc
>(
12118 needs_special_offset_handling
,
12122 reloc_symbol_changes
);
12125 template<int size
, bool big_endian
>
12126 class Powerpc_scan_relocatable_reloc
12129 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12130 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12131 static const int sh_type
= elfcpp::SHT_RELA
;
12133 // Return the symbol referred to by the relocation.
12134 static inline unsigned int
12135 get_r_sym(const Reltype
* reloc
)
12136 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12138 // Return the type of the relocation.
12139 static inline unsigned int
12140 get_r_type(const Reltype
* reloc
)
12141 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12143 // Return the strategy to use for a local symbol which is not a
12144 // section symbol, given the relocation type.
12145 inline Relocatable_relocs::Reloc_strategy
12146 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12148 if (r_type
== 0 && r_sym
== 0)
12149 return Relocatable_relocs::RELOC_DISCARD
;
12150 return Relocatable_relocs::RELOC_COPY
;
12153 // Return the strategy to use for a local symbol which is a section
12154 // symbol, given the relocation type.
12155 inline Relocatable_relocs::Reloc_strategy
12156 local_section_strategy(unsigned int, Relobj
*)
12158 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12161 // Return the strategy to use for a global symbol, given the
12162 // relocation type, the object, and the symbol index.
12163 inline Relocatable_relocs::Reloc_strategy
12164 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12167 && (r_type
== elfcpp::R_PPC_PLTREL24
12168 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12169 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12170 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12171 return Relocatable_relocs::RELOC_SPECIAL
;
12172 return Relocatable_relocs::RELOC_COPY
;
12176 // Scan the relocs during a relocatable link.
12178 template<int size
, bool big_endian
>
12180 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12181 Symbol_table
* symtab
,
12183 Sized_relobj_file
<size
, big_endian
>* object
,
12184 unsigned int data_shndx
,
12185 unsigned int sh_type
,
12186 const unsigned char* prelocs
,
12187 size_t reloc_count
,
12188 Output_section
* output_section
,
12189 bool needs_special_offset_handling
,
12190 size_t local_symbol_count
,
12191 const unsigned char* plocal_symbols
,
12192 Relocatable_relocs
* rr
)
12194 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12196 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12198 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12206 needs_special_offset_handling
,
12207 local_symbol_count
,
12212 // Scan the relocs for --emit-relocs.
12214 template<int size
, bool big_endian
>
12216 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12217 Symbol_table
* symtab
,
12219 Sized_relobj_file
<size
, big_endian
>* object
,
12220 unsigned int data_shndx
,
12221 unsigned int sh_type
,
12222 const unsigned char* prelocs
,
12223 size_t reloc_count
,
12224 Output_section
* output_section
,
12225 bool needs_special_offset_handling
,
12226 size_t local_symbol_count
,
12227 const unsigned char* plocal_syms
,
12228 Relocatable_relocs
* rr
)
12230 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12232 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12233 Emit_relocs_strategy
;
12235 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12237 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12245 needs_special_offset_handling
,
12246 local_symbol_count
,
12251 // Emit relocations for a section.
12252 // This is a modified version of the function by the same name in
12253 // target-reloc.h. Using relocate_special_relocatable for
12254 // R_PPC_PLTREL24 would require duplication of the entire body of the
12255 // loop, so we may as well duplicate the whole thing.
12257 template<int size
, bool big_endian
>
12259 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12260 const Relocate_info
<size
, big_endian
>* relinfo
,
12261 unsigned int sh_type
,
12262 const unsigned char* prelocs
,
12263 size_t reloc_count
,
12264 Output_section
* output_section
,
12265 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12267 Address view_address
,
12269 unsigned char* reloc_view
,
12270 section_size_type reloc_view_size
)
12272 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12274 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12275 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12276 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12277 // Offset from start of insn to d-field reloc.
12278 const int d_offset
= big_endian
? 2 : 0;
12280 Powerpc_relobj
<size
, big_endian
>* const object
12281 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12282 const unsigned int local_count
= object
->local_symbol_count();
12283 unsigned int got2_shndx
= object
->got2_shndx();
12284 Address got2_addend
= 0;
12285 if (got2_shndx
!= 0)
12287 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12288 gold_assert(got2_addend
!= invalid_address
);
12291 const bool relocatable
= parameters
->options().relocatable();
12293 unsigned char* pwrite
= reloc_view
;
12294 bool zap_next
= false;
12295 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12297 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12298 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12301 Reltype
reloc(prelocs
);
12302 Reltype_write
reloc_write(pwrite
);
12304 Address offset
= reloc
.get_r_offset();
12305 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12306 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12307 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12308 const unsigned int orig_r_sym
= r_sym
;
12309 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12310 = reloc
.get_r_addend();
12311 const Symbol
* gsym
= NULL
;
12315 // We could arrange to discard these and other relocs for
12316 // tls optimised sequences in the strategy methods, but for
12317 // now do as BFD ld does.
12318 r_type
= elfcpp::R_POWERPC_NONE
;
12322 // Get the new symbol index.
12323 Output_section
* os
= NULL
;
12324 if (r_sym
< local_count
)
12328 case Relocatable_relocs::RELOC_COPY
:
12329 case Relocatable_relocs::RELOC_SPECIAL
:
12332 r_sym
= object
->symtab_index(r_sym
);
12333 gold_assert(r_sym
!= -1U);
12337 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12339 // We are adjusting a section symbol. We need to find
12340 // the symbol table index of the section symbol for
12341 // the output section corresponding to input section
12342 // in which this symbol is defined.
12343 gold_assert(r_sym
< local_count
);
12345 unsigned int shndx
=
12346 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12347 gold_assert(is_ordinary
);
12348 os
= object
->output_section(shndx
);
12349 gold_assert(os
!= NULL
);
12350 gold_assert(os
->needs_symtab_index());
12351 r_sym
= os
->symtab_index();
12356 gold_unreachable();
12361 gsym
= object
->global_symbol(r_sym
);
12362 gold_assert(gsym
!= NULL
);
12363 if (gsym
->is_forwarder())
12364 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12366 gold_assert(gsym
->has_symtab_index());
12367 r_sym
= gsym
->symtab_index();
12370 // Get the new offset--the location in the output section where
12371 // this relocation should be applied.
12372 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12373 offset
+= offset_in_output_section
;
12376 section_offset_type sot_offset
=
12377 convert_types
<section_offset_type
, Address
>(offset
);
12378 section_offset_type new_sot_offset
=
12379 output_section
->output_offset(object
, relinfo
->data_shndx
,
12381 gold_assert(new_sot_offset
!= -1);
12382 offset
= new_sot_offset
;
12385 // In an object file, r_offset is an offset within the section.
12386 // In an executable or dynamic object, generated by
12387 // --emit-relocs, r_offset is an absolute address.
12390 offset
+= view_address
;
12391 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12392 offset
-= offset_in_output_section
;
12395 // Handle the reloc addend based on the strategy.
12396 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12398 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12400 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12401 addend
= psymval
->value(object
, addend
);
12402 // In a relocatable link, the symbol value is relative to
12403 // the start of the output section. For a non-relocatable
12404 // link, we need to adjust the addend.
12407 gold_assert(os
!= NULL
);
12408 addend
-= os
->address();
12411 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12415 if (addend
>= 32768)
12416 addend
+= got2_addend
;
12418 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12420 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12421 addend
-= d_offset
;
12423 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12425 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12426 addend
-= d_offset
+ 4;
12430 gold_unreachable();
12434 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12435 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12436 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12437 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12439 // First instruction of a global dynamic sequence,
12441 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12442 switch (this->optimize_tls_gd(final
))
12444 case tls::TLSOPT_TO_IE
:
12445 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12446 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12448 case tls::TLSOPT_TO_LE
:
12449 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12450 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12451 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12454 r_type
= elfcpp::R_POWERPC_NONE
;
12455 offset
-= d_offset
;
12462 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12463 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12464 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12465 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12467 // First instruction of a local dynamic sequence,
12469 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12471 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12472 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12474 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12475 const Output_section
* os
= relinfo
->layout
->tls_segment()
12477 gold_assert(os
!= NULL
);
12478 gold_assert(os
->needs_symtab_index());
12479 r_sym
= os
->symtab_index();
12480 addend
= dtp_offset
;
12484 r_type
= elfcpp::R_POWERPC_NONE
;
12485 offset
-= d_offset
;
12489 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12490 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12491 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12492 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12494 // First instruction of initial exec sequence.
12495 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12496 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12498 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12499 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12500 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12503 r_type
= elfcpp::R_POWERPC_NONE
;
12504 offset
-= d_offset
;
12508 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12509 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12511 // Second instruction of a global dynamic sequence,
12512 // the __tls_get_addr call
12513 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12514 switch (this->optimize_tls_gd(final
))
12516 case tls::TLSOPT_TO_IE
:
12517 r_type
= elfcpp::R_POWERPC_NONE
;
12520 case tls::TLSOPT_TO_LE
:
12521 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12522 offset
+= d_offset
;
12529 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12530 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12532 // Second instruction of a local dynamic sequence,
12533 // the __tls_get_addr call
12534 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12536 const Output_section
* os
= relinfo
->layout
->tls_segment()
12538 gold_assert(os
!= NULL
);
12539 gold_assert(os
->needs_symtab_index());
12540 r_sym
= os
->symtab_index();
12541 addend
= dtp_offset
;
12542 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12543 offset
+= d_offset
;
12547 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12549 // Second instruction of an initial exec sequence
12550 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12551 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12553 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12554 offset
+= d_offset
;
12559 reloc_write
.put_r_offset(offset
);
12560 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12561 reloc_write
.put_r_addend(addend
);
12563 pwrite
+= reloc_size
;
12566 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12567 == reloc_view_size
);
12570 // Return the value to use for a dynamic symbol which requires special
12571 // treatment. This is how we support equality comparisons of function
12572 // pointers across shared library boundaries, as described in the
12573 // processor specific ABI supplement.
12575 template<int size
, bool big_endian
>
12577 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12581 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12582 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12583 p
!= this->stub_tables_
.end();
12586 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12587 = (*p
)->find_plt_call_entry(gsym
);
12589 return (*p
)->stub_address() + ent
->off_
;
12592 else if (this->abiversion() >= 2)
12594 Address off
= this->glink_section()->find_global_entry(gsym
);
12595 if (off
!= invalid_address
)
12596 return this->glink_section()->global_entry_address() + off
;
12598 gold_unreachable();
12601 // Return the PLT address to use for a local symbol.
12602 template<int size
, bool big_endian
>
12604 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12605 const Relobj
* object
,
12606 unsigned int symndx
) const
12610 const Sized_relobj
<size
, big_endian
>* relobj
12611 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12612 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12613 p
!= this->stub_tables_
.end();
12616 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12617 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12619 return (*p
)->stub_address() + ent
->off_
;
12622 gold_unreachable();
12625 // Return the PLT address to use for a global symbol.
12626 template<int size
, bool big_endian
>
12628 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12629 const Symbol
* gsym
) const
12633 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12634 p
!= this->stub_tables_
.end();
12637 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12638 = (*p
)->find_plt_call_entry(gsym
);
12640 return (*p
)->stub_address() + ent
->off_
;
12643 else if (this->abiversion() >= 2)
12645 Address off
= this->glink_section()->find_global_entry(gsym
);
12646 if (off
!= invalid_address
)
12647 return this->glink_section()->global_entry_address() + off
;
12649 gold_unreachable();
12652 // Return the offset to use for the GOT_INDX'th got entry which is
12653 // for a local tls symbol specified by OBJECT, SYMNDX.
12654 template<int size
, bool big_endian
>
12656 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12657 const Relobj
* object
,
12658 unsigned int symndx
,
12659 unsigned int got_indx
) const
12661 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12662 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12663 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12665 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12666 got_type
<= GOT_TYPE_TPREL
;
12667 got_type
= Got_type(got_type
+ 1))
12668 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12670 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12671 if (got_type
== GOT_TYPE_TLSGD
)
12673 if (off
== got_indx
* (size
/ 8))
12675 if (got_type
== GOT_TYPE_TPREL
)
12678 return -dtp_offset
;
12682 gold_unreachable();
12685 // Return the offset to use for the GOT_INDX'th got entry which is
12686 // for global tls symbol GSYM.
12687 template<int size
, bool big_endian
>
12689 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12691 unsigned int got_indx
) const
12693 if (gsym
->type() == elfcpp::STT_TLS
)
12695 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12696 got_type
<= GOT_TYPE_TPREL
;
12697 got_type
= Got_type(got_type
+ 1))
12698 if (gsym
->has_got_offset(got_type
))
12700 unsigned int off
= gsym
->got_offset(got_type
);
12701 if (got_type
== GOT_TYPE_TLSGD
)
12703 if (off
== got_indx
* (size
/ 8))
12705 if (got_type
== GOT_TYPE_TPREL
)
12708 return -dtp_offset
;
12712 gold_unreachable();
12715 // The selector for powerpc object files.
12717 template<int size
, bool big_endian
>
12718 class Target_selector_powerpc
: public Target_selector
12721 Target_selector_powerpc()
12722 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12725 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12726 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12728 ? (big_endian
? "elf64ppc" : "elf64lppc")
12729 : (big_endian
? "elf32ppc" : "elf32lppc")))
12733 do_instantiate_target()
12734 { return new Target_powerpc
<size
, big_endian
>(); }
12737 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12738 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12739 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12740 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12742 // Instantiate these constants for -O0
12743 template<int size
, bool big_endian
>
12744 const typename Output_data_glink
<size
, big_endian
>::Address
12745 Output_data_glink
<size
, big_endian
>::invalid_address
;
12746 template<int size
, bool big_endian
>
12747 const typename Stub_table
<size
, big_endian
>::Address
12748 Stub_table
<size
, big_endian
>::invalid_address
;
12749 template<int size
, bool big_endian
>
12750 const typename Target_powerpc
<size
, big_endian
>::Address
12751 Target_powerpc
<size
, big_endian
>::invalid_address
;
12753 } // End anonymous namespace.