1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2020 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_stubs_(false), plt_thread_safe_(false), plt_localentry0_(false),
651 plt_localentry0_init_(false), has_localentry0_(false),
652 has_tls_get_addr_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 power10_stubs() const
1083 { return this->power10_stubs_
; }
1088 if (parameters
->options().power10_stubs_enum()
1089 != General_options::POWER10_STUBS_NO
)
1090 this->power10_stubs_
= true;
1094 power10_stubs_auto() const
1096 return (parameters
->options().power10_stubs_enum()
1097 == General_options::POWER10_STUBS_AUTO
);
1101 plt_thread_safe() const
1102 { return this->plt_thread_safe_
; }
1105 plt_localentry0() const
1106 { return this->plt_localentry0_
; }
1109 set_has_localentry0()
1111 this->has_localentry0_
= true;
1115 is_elfv2_localentry0(const Symbol
* gsym
) const
1118 && this->abiversion() >= 2
1119 && this->plt_localentry0()
1120 && gsym
->type() == elfcpp::STT_FUNC
1121 && gsym
->is_defined()
1122 && gsym
->nonvis() >> 3 == 0
1123 && !gsym
->non_zero_localentry());
1127 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1128 unsigned int r_sym
) const
1130 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1131 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1134 && this->abiversion() >= 2
1135 && this->plt_localentry0()
1136 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1138 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1140 if (!psymval
->is_ifunc_symbol()
1141 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1148 // Remember any symbols seen with non-zero localentry, even those
1149 // not providing a definition
1151 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1156 unsigned char st_other
= sym
.get_st_other();
1157 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1158 to
->set_non_zero_localentry();
1160 // We haven't resolved anything, continue normal processing.
1166 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1169 set_abiversion(int ver
)
1171 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1172 flags
&= ~elfcpp::EF_PPC64_ABI
;
1173 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1174 this->set_processor_specific_flags(flags
);
1178 tls_get_addr_opt() const
1179 { return this->tls_get_addr_opt_
; }
1182 tls_get_addr() const
1183 { return this->tls_get_addr_
; }
1185 // If optimizing __tls_get_addr calls, whether this is the
1186 // "__tls_get_addr" symbol.
1188 is_tls_get_addr_opt(const Symbol
* gsym
) const
1190 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1191 || gsym
== this->tls_get_addr_opt_
);
1195 replace_tls_get_addr(const Symbol
* gsym
) const
1196 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1199 set_has_tls_get_addr_opt()
1200 { this->has_tls_get_addr_opt_
= true; }
1202 // Offset to toc save stack slot
1205 { return this->abiversion() < 2 ? 40 : 24; }
1207 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1208 // so use the CR save slot. Used only by __tls_get_addr call stub,
1209 // relying on __tls_get_addr not saving CR itself.
1212 { return this->abiversion() < 2 ? 32 : 8; }
1214 // Merge object attributes from input object with those in the output.
1216 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1232 : tls_get_addr_state_(NOT_EXPECTED
),
1233 relinfo_(NULL
), relnum_(0), r_offset_(0)
1238 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1245 if (this->relinfo_
!= NULL
)
1246 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1247 _("missing expected __tls_get_addr call"));
1251 expect_tls_get_addr_call(
1252 const Relocate_info
<size
, big_endian
>* relinfo
,
1256 this->tls_get_addr_state_
= EXPECTED
;
1257 this->relinfo_
= relinfo
;
1258 this->relnum_
= relnum
;
1259 this->r_offset_
= r_offset
;
1263 expect_tls_get_addr_call()
1264 { this->tls_get_addr_state_
= EXPECTED
; }
1267 skip_next_tls_get_addr_call()
1268 {this->tls_get_addr_state_
= SKIP
; }
1271 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1272 unsigned int r_type
, const Symbol
* gsym
)
1275 = ((r_type
== elfcpp::R_POWERPC_REL24
1276 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1277 || r_type
== elfcpp::R_PPC_PLTREL24
1278 || is_plt16_reloc
<size
>(r_type
)
1279 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1280 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1281 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1282 || r_type
== elfcpp::R_POWERPC_PLTCALL
1283 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1284 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1286 && (gsym
== target
->tls_get_addr()
1287 || gsym
== target
->tls_get_addr_opt()));
1288 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1289 this->tls_get_addr_state_
= NOT_EXPECTED
;
1290 if (is_tls_call
&& last_tls
!= EXPECTED
)
1292 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1301 // What we're up to regarding calls to __tls_get_addr.
1302 // On powerpc, the branch and link insn making a call to
1303 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1304 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1305 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1306 // The marker relocation always comes first, and has the same
1307 // symbol as the reloc on the insn setting up the __tls_get_addr
1308 // argument. This ties the arg setup insn with the call insn,
1309 // allowing ld to safely optimize away the call. We check that
1310 // every call to __tls_get_addr has a marker relocation, and that
1311 // every marker relocation is on a call to __tls_get_addr.
1312 Tls_get_addr tls_get_addr_state_
;
1313 // Info about the last reloc for error message.
1314 const Relocate_info
<size
, big_endian
>* relinfo_
;
1319 // The class which scans relocations.
1320 class Scan
: protected Track_tls
1323 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1326 : Track_tls(), issued_non_pic_error_(false)
1330 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1333 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1334 Sized_relobj_file
<size
, big_endian
>* object
,
1335 unsigned int data_shndx
,
1336 Output_section
* output_section
,
1337 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1338 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1342 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1343 Sized_relobj_file
<size
, big_endian
>* object
,
1344 unsigned int data_shndx
,
1345 Output_section
* output_section
,
1346 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1350 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1352 Sized_relobj_file
<size
, big_endian
>* relobj
,
1355 const elfcpp::Rela
<size
, big_endian
>& ,
1356 unsigned int r_type
,
1357 const elfcpp::Sym
<size
, big_endian
>&)
1359 // PowerPC64 .opd is not folded, so any identical function text
1360 // may be folded and we'll still keep function addresses distinct.
1361 // That means no reloc is of concern here.
1364 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1365 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1366 if (ppcobj
->abiversion() == 1)
1369 // For 32-bit and ELFv2, conservatively assume anything but calls to
1370 // function code might be taking the address of the function.
1371 return !is_branch_reloc
<size
>(r_type
);
1375 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1377 Sized_relobj_file
<size
, big_endian
>* relobj
,
1380 const elfcpp::Rela
<size
, big_endian
>& ,
1381 unsigned int r_type
,
1387 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1388 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1389 if (ppcobj
->abiversion() == 1)
1392 return !is_branch_reloc
<size
>(r_type
);
1396 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1397 Sized_relobj_file
<size
, big_endian
>* object
,
1398 unsigned int r_type
, bool report_err
);
1402 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1403 unsigned int r_type
);
1406 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1407 unsigned int r_type
, Symbol
*);
1410 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1411 Target_powerpc
* target
);
1414 check_non_pic(Relobj
*, unsigned int r_type
);
1416 // Whether we have issued an error about a non-PIC compilation.
1417 bool issued_non_pic_error_
;
1421 symval_for_branch(const Symbol_table
* symtab
,
1422 const Sized_symbol
<size
>* gsym
,
1423 Powerpc_relobj
<size
, big_endian
>* object
,
1424 Address
*value
, unsigned int *dest_shndx
);
1426 // The class which implements relocation.
1427 class Relocate
: protected Track_tls
1430 // Use 'at' branch hints when true, 'y' when false.
1431 // FIXME maybe: set this with an option.
1432 static const bool is_isa_v2
= true;
1438 // Do a relocation. Return false if the caller should not issue
1439 // any warnings about this relocation.
1441 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1442 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1443 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1444 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1448 class Relocate_comdat_behavior
1451 // Decide what the linker should do for relocations that refer to
1452 // discarded comdat sections.
1453 inline Comdat_behavior
1454 get(const char* name
)
1456 gold::Default_comdat_behavior default_behavior
;
1457 Comdat_behavior ret
= default_behavior
.get(name
);
1458 if (ret
== CB_ERROR
)
1461 && (strcmp(name
, ".fixup") == 0
1462 || strcmp(name
, ".got2") == 0))
1465 && (strcmp(name
, ".opd") == 0
1466 || strcmp(name
, ".toc") == 0
1467 || strcmp(name
, ".toc1") == 0))
1474 // Optimize the TLS relocation type based on what we know about the
1475 // symbol. IS_FINAL is true if the final address of this symbol is
1476 // known at link time.
1478 tls::Tls_optimization
1479 optimize_tls_gd(bool is_final
)
1481 // If we are generating a shared library, then we can't do anything
1483 if (parameters
->options().shared()
1484 || !parameters
->options().tls_optimize())
1485 return tls::TLSOPT_NONE
;
1488 return tls::TLSOPT_TO_IE
;
1489 return tls::TLSOPT_TO_LE
;
1492 tls::Tls_optimization
1495 if (parameters
->options().shared()
1496 || !parameters
->options().tls_optimize())
1497 return tls::TLSOPT_NONE
;
1499 return tls::TLSOPT_TO_LE
;
1502 tls::Tls_optimization
1503 optimize_tls_ie(bool is_final
)
1506 || parameters
->options().shared()
1507 || !parameters
->options().tls_optimize())
1508 return tls::TLSOPT_NONE
;
1510 return tls::TLSOPT_TO_LE
;
1515 make_glink_section(Layout
*);
1517 // Create the PLT section.
1519 make_plt_section(Symbol_table
*, Layout
*);
1522 make_iplt_section(Symbol_table
*, Layout
*);
1525 make_lplt_section(Layout
*);
1528 make_brlt_section(Layout
*);
1530 // Create a PLT entry for a global symbol.
1532 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1534 // Create a PLT entry for a local IFUNC symbol.
1536 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1537 Sized_relobj_file
<size
, big_endian
>*,
1540 // Create a PLT entry for a local non-IFUNC symbol.
1542 make_local_plt_entry(Layout
*,
1543 Sized_relobj_file
<size
, big_endian
>*,
1547 // Create a GOT entry for local dynamic __tls_get_addr.
1549 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1550 Sized_relobj_file
<size
, big_endian
>* object
);
1553 tlsld_got_offset() const
1555 return this->tlsld_got_offset_
;
1558 // Get the dynamic reloc section, creating it if necessary.
1560 rela_dyn_section(Layout
*);
1562 // Similarly, but for ifunc symbols get the one for ifunc.
1564 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1566 // Copy a relocation against a global symbol.
1568 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1569 Sized_relobj_file
<size
, big_endian
>* object
,
1570 unsigned int shndx
, Output_section
* output_section
,
1571 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1573 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1574 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1575 symtab
->get_sized_symbol
<size
>(sym
),
1576 object
, shndx
, output_section
,
1577 r_type
, reloc
.get_r_offset(),
1578 reloc
.get_r_addend(),
1579 this->rela_dyn_section(layout
));
1582 // Look over all the input sections, deciding where to place stubs.
1584 group_sections(Layout
*, const Task
*, bool);
1586 // Sort output sections by address.
1587 struct Sort_sections
1590 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1591 { return sec1
->address() < sec2
->address(); }
1597 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1598 unsigned int data_shndx
,
1600 unsigned int r_type
,
1603 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1604 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1610 // Return whether this branch is going via a plt call stub, and if
1611 // so, mark it as having an R_PPC64_TOCSAVE.
1613 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1614 unsigned int shndx
, Address offset
,
1615 Target_powerpc
* target
, Symbol_table
* symtab
);
1617 // If this branch needs a plt call stub, or a long branch stub, make one.
1619 make_stub(Stub_table
<size
, big_endian
>*,
1620 Stub_table
<size
, big_endian
>*,
1621 Symbol_table
*) const;
1624 // The branch location..
1625 Powerpc_relobj
<size
, big_endian
>* object_
;
1626 unsigned int shndx_
;
1628 // ..and the branch type and destination.
1629 unsigned int r_type_
: 31;
1630 unsigned int tocsave_
: 1;
1631 unsigned int r_sym_
;
1635 // Information about this specific target which we pass to the
1636 // general Target structure.
1637 static Target::Target_info powerpc_info
;
1639 // The types of GOT entries needed for this platform.
1640 // These values are exposed to the ABI in an incremental link.
1641 // Do not renumber existing values without changing the version
1642 // number of the .gnu_incremental_inputs section.
1646 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1647 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1648 GOT_TYPE_TPREL
// entry for @got@tprel
1652 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1653 // The PLT section. This is a container for a table of addresses,
1654 // and their relocations. Each address in the PLT has a dynamic
1655 // relocation (R_*_JMP_SLOT) and each address will have a
1656 // corresponding entry in .glink for lazy resolution of the PLT.
1657 // ppc32 initialises the PLT to point at the .glink entry, while
1658 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1659 // linker adds a stub that loads the PLT entry into ctr then
1660 // branches to ctr. There may be more than one stub for each PLT
1661 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1662 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1663 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1664 // The IPLT section. Like plt_, this is a container for a table of
1665 // addresses and their relocations, specifically for STT_GNU_IFUNC
1666 // functions that resolve locally (STT_GNU_IFUNC functions that
1667 // don't resolve locally go in PLT). Unlike plt_, these have no
1668 // entry in .glink for lazy resolution, and the relocation section
1669 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1670 // the relocation section may contain relocations against
1671 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1672 // relocation section will appear at the end of other dynamic
1673 // relocations, so that ld.so applies these relocations after other
1674 // dynamic relocations. In a static executable, the relocation
1675 // section is emitted and marked with __rela_iplt_start and
1676 // __rela_iplt_end symbols.
1677 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1678 // A PLT style section for local, non-ifunc symbols
1679 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1680 // Section holding long branch destinations.
1681 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1682 // The .glink section.
1683 Output_data_glink
<size
, big_endian
>* glink_
;
1684 // The dynamic reloc section.
1685 Reloc_section
* rela_dyn_
;
1686 // Relocs saved to avoid a COPY reloc.
1687 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1688 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1689 unsigned int tlsld_got_offset_
;
1691 Stub_tables stub_tables_
;
1692 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1693 Branch_lookup_table branch_lookup_table_
;
1695 typedef std::vector
<Branch_info
> Branches
;
1696 Branches branch_info_
;
1697 Tocsave_loc tocsave_loc_
;
1699 bool power10_stubs_
;
1700 bool plt_thread_safe_
;
1701 bool plt_localentry0_
;
1702 bool plt_localentry0_init_
;
1703 bool has_localentry0_
;
1704 bool has_tls_get_addr_opt_
;
1707 int relax_fail_count_
;
1708 int32_t stub_group_size_
;
1710 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1712 // The "__tls_get_addr" symbol, if present
1713 Symbol
* tls_get_addr_
;
1714 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1715 Symbol
* tls_get_addr_opt_
;
1717 // Attributes in output.
1718 Attributes_section_data
* attributes_section_data_
;
1720 // Last input file to change various attribute tags
1721 const char* last_fp_
;
1722 const char* last_ld_
;
1723 const char* last_vec_
;
1724 const char* last_struct_
;
1728 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1731 true, // is_big_endian
1732 elfcpp::EM_PPC
, // machine_code
1733 false, // has_make_symbol
1734 false, // has_resolve
1735 false, // has_code_fill
1736 true, // is_default_stack_executable
1737 false, // can_icf_inline_merge_sections
1739 "/usr/lib/ld.so.1", // dynamic_linker
1740 0x10000000, // default_text_segment_address
1741 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1742 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1743 false, // isolate_execinstr
1745 elfcpp::SHN_UNDEF
, // small_common_shndx
1746 elfcpp::SHN_UNDEF
, // large_common_shndx
1747 0, // small_common_section_flags
1748 0, // large_common_section_flags
1749 NULL
, // attributes_section
1750 NULL
, // attributes_vendor
1751 "_start", // entry_symbol_name
1752 32, // hash_entry_size
1753 elfcpp::SHT_PROGBITS
, // unwind_section_type
1757 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1760 false, // is_big_endian
1761 elfcpp::EM_PPC
, // machine_code
1762 false, // has_make_symbol
1763 false, // has_resolve
1764 false, // has_code_fill
1765 true, // is_default_stack_executable
1766 false, // can_icf_inline_merge_sections
1768 "/usr/lib/ld.so.1", // dynamic_linker
1769 0x10000000, // default_text_segment_address
1770 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1771 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1772 false, // isolate_execinstr
1774 elfcpp::SHN_UNDEF
, // small_common_shndx
1775 elfcpp::SHN_UNDEF
, // large_common_shndx
1776 0, // small_common_section_flags
1777 0, // large_common_section_flags
1778 NULL
, // attributes_section
1779 NULL
, // attributes_vendor
1780 "_start", // entry_symbol_name
1781 32, // hash_entry_size
1782 elfcpp::SHT_PROGBITS
, // unwind_section_type
1786 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1789 true, // is_big_endian
1790 elfcpp::EM_PPC64
, // machine_code
1791 false, // has_make_symbol
1792 true, // has_resolve
1793 false, // has_code_fill
1794 false, // is_default_stack_executable
1795 false, // can_icf_inline_merge_sections
1797 "/usr/lib/ld.so.1", // dynamic_linker
1798 0x10000000, // default_text_segment_address
1799 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1800 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1801 false, // isolate_execinstr
1803 elfcpp::SHN_UNDEF
, // small_common_shndx
1804 elfcpp::SHN_UNDEF
, // large_common_shndx
1805 0, // small_common_section_flags
1806 0, // large_common_section_flags
1807 NULL
, // attributes_section
1808 NULL
, // attributes_vendor
1809 "_start", // entry_symbol_name
1810 32, // hash_entry_size
1811 elfcpp::SHT_PROGBITS
, // unwind_section_type
1815 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1818 false, // is_big_endian
1819 elfcpp::EM_PPC64
, // machine_code
1820 false, // has_make_symbol
1821 true, // has_resolve
1822 false, // has_code_fill
1823 false, // is_default_stack_executable
1824 false, // can_icf_inline_merge_sections
1826 "/usr/lib/ld.so.1", // dynamic_linker
1827 0x10000000, // default_text_segment_address
1828 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1829 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1830 false, // isolate_execinstr
1832 elfcpp::SHN_UNDEF
, // small_common_shndx
1833 elfcpp::SHN_UNDEF
, // large_common_shndx
1834 0, // small_common_section_flags
1835 0, // large_common_section_flags
1836 NULL
, // attributes_section
1837 NULL
, // attributes_vendor
1838 "_start", // entry_symbol_name
1839 32, // hash_entry_size
1840 elfcpp::SHT_PROGBITS
, // unwind_section_type
1845 is_branch_reloc(unsigned int r_type
)
1847 return (r_type
== elfcpp::R_POWERPC_REL24
1848 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1849 || r_type
== elfcpp::R_PPC_PLTREL24
1850 || r_type
== elfcpp::R_PPC_LOCAL24PC
1851 || r_type
== elfcpp::R_POWERPC_REL14
1852 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1853 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1854 || r_type
== elfcpp::R_POWERPC_ADDR24
1855 || r_type
== elfcpp::R_POWERPC_ADDR14
1856 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1857 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1860 // Reloc resolves to plt entry.
1863 is_plt16_reloc(unsigned int r_type
)
1865 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1866 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1867 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1868 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1871 // If INSN is an opcode that may be used with an @tls operand, return
1872 // the transformed insn for TLS optimisation, otherwise return 0. If
1873 // REG is non-zero only match an insn with RB or RA equal to REG.
1875 at_tls_transform(uint32_t insn
, unsigned int reg
)
1877 if ((insn
& (0x3f << 26)) != 31 << 26)
1881 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1882 rtra
= insn
& ((1 << 26) - (1 << 16));
1883 else if (((insn
>> 16) & 0x1f) == reg
)
1884 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1888 if ((insn
& (0x3ff << 1)) == 266 << 1)
1891 else if ((insn
& (0x1f << 1)) == 23 << 1
1892 && ((insn
& (0x1f << 6)) < 14 << 6
1893 || ((insn
& (0x1f << 6)) >= 16 << 6
1894 && (insn
& (0x1f << 6)) < 24 << 6)))
1895 // load and store indexed -> dform
1896 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1897 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1898 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1899 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1900 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1902 insn
= (58 << 26) | 2;
1910 template<int size
, bool big_endian
>
1911 class Powerpc_relocate_functions
1931 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1932 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1933 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1935 template<int valsize
>
1937 has_overflow_signed(Address value
)
1939 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1940 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1941 limit
<<= ((valsize
- 1) >> 1);
1942 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1943 return value
+ limit
> (limit
<< 1) - 1;
1946 template<int valsize
>
1948 has_overflow_unsigned(Address value
)
1950 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1951 limit
<<= ((valsize
- 1) >> 1);
1952 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1953 return value
> (limit
<< 1) - 1;
1956 template<int valsize
>
1958 has_overflow_bitfield(Address value
)
1960 return (has_overflow_unsigned
<valsize
>(value
)
1961 && has_overflow_signed
<valsize
>(value
));
1964 template<int valsize
>
1965 static inline Status
1966 overflowed(Address value
, Overflow_check overflow
)
1968 if (overflow
== CHECK_SIGNED
)
1970 if (has_overflow_signed
<valsize
>(value
))
1971 return STATUS_OVERFLOW
;
1973 else if (overflow
== CHECK_UNSIGNED
)
1975 if (has_overflow_unsigned
<valsize
>(value
))
1976 return STATUS_OVERFLOW
;
1978 else if (overflow
== CHECK_BITFIELD
)
1980 if (has_overflow_bitfield
<valsize
>(value
))
1981 return STATUS_OVERFLOW
;
1986 // Do a simple RELA relocation
1987 template<int fieldsize
, int valsize
>
1988 static inline Status
1989 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1991 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1992 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1993 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1994 return overflowed
<valsize
>(value
, overflow
);
1997 template<int fieldsize
, int valsize
>
1998 static inline Status
1999 rela(unsigned char* view
,
2000 unsigned int right_shift
,
2001 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2003 Overflow_check overflow
)
2005 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2006 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2007 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2008 if (overflow
== CHECK_SIGNED
)
2009 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2011 value
= value
>> right_shift
;
2012 Valtype reloc
= value
;
2015 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2016 return overflowed
<valsize
>(value
, overflow
);
2019 // Do a simple RELA relocation, unaligned.
2020 template<int fieldsize
, int valsize
>
2021 static inline Status
2022 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2024 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2025 return overflowed
<valsize
>(value
, overflow
);
2028 template<int fieldsize
, int valsize
>
2029 static inline Status
2030 rela_ua(unsigned char* view
,
2031 unsigned int right_shift
,
2032 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2034 Overflow_check overflow
)
2036 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2038 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2039 if (overflow
== CHECK_SIGNED
)
2040 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2042 value
= value
>> right_shift
;
2043 Valtype reloc
= value
;
2046 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2047 return overflowed
<valsize
>(value
, overflow
);
2051 // R_PPC64_ADDR64: (Symbol + Addend)
2053 addr64(unsigned char* view
, Address value
)
2054 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2056 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2058 addr64_u(unsigned char* view
, Address value
)
2059 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2061 // R_POWERPC_ADDR32: (Symbol + Addend)
2062 static inline Status
2063 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2064 { return This::template rela
<32,32>(view
, value
, overflow
); }
2066 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2067 static inline Status
2068 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2069 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2071 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2072 static inline Status
2073 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2075 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2077 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2078 stat
= STATUS_OVERFLOW
;
2082 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2083 static inline Status
2084 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2085 { return This::template rela
<16,16>(view
, value
, overflow
); }
2087 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2088 static inline Status
2089 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2090 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2092 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2093 static inline Status
2094 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2096 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2097 if ((value
& 3) != 0)
2098 stat
= STATUS_OVERFLOW
;
2102 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2103 static inline Status
2104 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2106 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2107 if ((value
& 15) != 0)
2108 stat
= STATUS_OVERFLOW
;
2112 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2114 addr16_hi(unsigned char* view
, Address value
)
2115 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2117 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2119 addr16_ha(unsigned char* view
, Address value
)
2120 { This::addr16_hi(view
, value
+ 0x8000); }
2122 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2124 addr16_hi2(unsigned char* view
, Address value
)
2125 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2127 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2129 addr16_ha2(unsigned char* view
, Address value
)
2130 { This::addr16_hi2(view
, value
+ 0x8000); }
2132 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2134 addr16_hi3(unsigned char* view
, Address value
)
2135 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2137 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2139 addr16_ha3(unsigned char* view
, Address value
)
2140 { This::addr16_hi3(view
, value
+ 0x8000); }
2142 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2143 static inline Status
2144 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2146 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2147 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2148 stat
= STATUS_OVERFLOW
;
2152 // R_POWERPC_REL16DX_HA
2153 static inline Status
2154 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2156 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2157 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2158 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2160 value
= static_cast<SignedAddress
>(value
) >> 16;
2161 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2162 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2163 return overflowed
<16>(value
, overflow
);
2167 static inline Status
2168 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2170 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2172 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2178 addr34_hi(unsigned char *view
, uint64_t value
)
2179 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2183 addr34_ha(unsigned char *view
, uint64_t value
)
2184 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2187 static inline Status
2188 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2190 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2192 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2196 // R_PPC64_ADDR16_HIGHER34
2198 addr16_higher34(unsigned char* view
, uint64_t value
)
2199 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2201 // R_PPC64_ADDR16_HIGHERA34
2203 addr16_highera34(unsigned char* view
, uint64_t value
)
2204 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2206 // R_PPC64_ADDR16_HIGHEST34
2208 addr16_highest34(unsigned char* view
, uint64_t value
)
2209 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2211 // R_PPC64_ADDR16_HIGHESTA34
2213 addr16_highesta34(unsigned char* view
, uint64_t value
)
2214 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2217 // Set ABI version for input and output.
2219 template<int size
, bool big_endian
>
2221 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2223 this->e_flags_
|= ver
;
2224 if (this->abiversion() != 0)
2226 Target_powerpc
<size
, big_endian
>* target
=
2227 static_cast<Target_powerpc
<size
, big_endian
>*>(
2228 parameters
->sized_target
<size
, big_endian
>());
2229 if (target
->abiversion() == 0)
2230 target
->set_abiversion(this->abiversion());
2231 else if (target
->abiversion() != this->abiversion())
2232 gold_error(_("%s: ABI version %d is not compatible "
2233 "with ABI version %d output"),
2234 this->name().c_str(),
2235 this->abiversion(), target
->abiversion());
2240 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2241 // relocatable object, if such sections exists.
2243 template<int size
, bool big_endian
>
2245 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2246 Read_symbols_data
* sd
)
2248 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2249 const unsigned char* namesu
= sd
->section_names
->data();
2250 const char* names
= reinterpret_cast<const char*>(namesu
);
2251 section_size_type names_size
= sd
->section_names_size
;
2252 const unsigned char* s
;
2254 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2255 size
== 32 ? ".got2" : ".opd",
2256 names
, names_size
, NULL
);
2259 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2260 this->special_
= ndx
;
2263 if (this->abiversion() == 0)
2264 this->set_abiversion(1);
2265 else if (this->abiversion() > 1)
2266 gold_error(_("%s: .opd invalid in abiv%d"),
2267 this->name().c_str(), this->abiversion());
2272 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2273 names
, names_size
, NULL
);
2276 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2277 this->relatoc_
= ndx
;
2278 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2279 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2282 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2285 // Examine .rela.opd to build info about function entry points.
2287 template<int size
, bool big_endian
>
2289 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2291 const unsigned char* prelocs
,
2292 const unsigned char* plocal_syms
)
2296 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2297 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2298 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2299 Address expected_off
= 0;
2300 bool regular
= true;
2301 unsigned int opd_ent_size
= 0;
2303 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2305 Reltype
reloc(prelocs
);
2306 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2307 = reloc
.get_r_info();
2308 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2309 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2311 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2312 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2315 if (r_sym
< this->local_symbol_count())
2317 typename
elfcpp::Sym
<size
, big_endian
>
2318 lsym(plocal_syms
+ r_sym
* sym_size
);
2319 shndx
= lsym
.get_st_shndx();
2320 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2321 value
= lsym
.get_st_value();
2324 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2326 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2327 value
+ reloc
.get_r_addend());
2330 expected_off
= reloc
.get_r_offset();
2331 opd_ent_size
= expected_off
;
2333 else if (expected_off
!= reloc
.get_r_offset())
2335 expected_off
+= opd_ent_size
;
2337 else if (r_type
== elfcpp::R_PPC64_TOC
)
2339 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2344 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2345 this->name().c_str(), r_type
);
2349 if (reloc_count
<= 2)
2350 opd_ent_size
= this->section_size(this->opd_shndx());
2351 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2355 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2356 this->name().c_str());
2362 // Returns true if a code sequence loading the TOC entry at VALUE
2363 // relative to the TOC pointer can be converted into code calculating
2364 // a TOC pointer relative offset.
2365 // If so, the TOC pointer relative offset is stored to VALUE.
2367 template<int size
, bool big_endian
>
2369 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2370 Target_powerpc
<size
, big_endian
>* target
,
2376 // With -mcmodel=medium code it is quite possible to have
2377 // toc-relative relocs referring to objects outside the TOC.
2378 // Don't try to look at a non-existent TOC.
2379 if (this->toc_shndx() == 0)
2382 // Convert VALUE back to an address by adding got_base (see below),
2383 // then to an offset in the TOC by subtracting the TOC output
2384 // section address and the TOC output offset. Since this TOC output
2385 // section and the got output section are one and the same, we can
2386 // omit adding and subtracting the output section address.
2387 Address off
= (*value
+ this->toc_base_offset()
2388 - this->output_section_offset(this->toc_shndx()));
2389 // Is this offset in the TOC? -mcmodel=medium code may be using
2390 // TOC relative access to variables outside the TOC. Those of
2391 // course can't be optimized. We also don't try to optimize code
2392 // that is using a different object's TOC.
2393 if (off
>= this->section_size(this->toc_shndx()))
2396 if (this->no_toc_opt(off
))
2399 section_size_type vlen
;
2400 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2401 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2403 Address got_base
= (target
->got_section()->output_section()->address()
2404 + this->toc_base_offset());
2406 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2413 template<int size
, bool big_endian
>
2415 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2416 Target_powerpc
<size
, big_endian
>* target
,
2417 const Symbol_value
<size
>* psymval
,
2421 Address addr
= psymval
->value(this, addend
);
2422 Address got_base
= (target
->got_section()->output_section()->address()
2423 + this->toc_base_offset());
2425 if (addr
+ 0x80008000 > 0xffffffff)
2432 // Perform the Sized_relobj_file method, then set up opd info from
2435 template<int size
, bool big_endian
>
2437 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2439 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2442 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2443 p
!= rd
->relocs
.end();
2446 if (p
->data_shndx
== this->opd_shndx())
2448 uint64_t opd_size
= this->section_size(this->opd_shndx());
2449 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2452 this->init_opd(opd_size
);
2453 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2454 rd
->local_symbols
->data());
2462 // Read the symbols then set up st_other vector.
2464 template<int size
, bool big_endian
>
2466 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2468 this->base_read_symbols(sd
);
2469 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2473 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2474 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2475 const unsigned int loccount
= this->do_local_symbol_count();
2478 this->st_other_
.resize(loccount
);
2479 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2480 off_t locsize
= loccount
* sym_size
;
2481 const unsigned int symtab_shndx
= this->symtab_shndx();
2482 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2483 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2484 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2485 locsize
, true, false);
2487 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2489 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2490 unsigned char st_other
= sym
.get_st_other();
2491 this->st_other_
[i
] = st_other
;
2492 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2494 if (this->abiversion() == 0)
2495 this->set_abiversion(2);
2496 else if (this->abiversion() < 2)
2497 gold_error(_("%s: local symbol %d has invalid st_other"
2498 " for ABI version 1"),
2499 this->name().c_str(), i
);
2505 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2506 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2507 bool merge_attributes
= false;
2508 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2510 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2511 switch (shdr
.get_sh_type())
2513 case elfcpp::SHT_GNU_ATTRIBUTES
:
2515 gold_assert(this->attributes_section_data_
== NULL
);
2516 section_offset_type section_offset
= shdr
.get_sh_offset();
2517 section_size_type section_size
=
2518 convert_to_section_size_type(shdr
.get_sh_size());
2519 const unsigned char* view
=
2520 this->get_view(section_offset
, section_size
, true, false);
2521 this->attributes_section_data_
=
2522 new Attributes_section_data(view
, section_size
);
2526 case elfcpp::SHT_SYMTAB
:
2528 // Sometimes an object has no contents except the section
2529 // name string table and an empty symbol table with the
2530 // undefined symbol. We don't want to merge
2531 // processor-specific flags from such an object.
2532 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2533 elfcpp::Elf_sizes
<size
>::sym_size
;
2534 if (shdr
.get_sh_size() > sym_size
)
2535 merge_attributes
= true;
2539 case elfcpp::SHT_STRTAB
:
2543 merge_attributes
= true;
2548 if (!merge_attributes
)
2550 // Should rarely happen.
2551 delete this->attributes_section_data_
;
2552 this->attributes_section_data_
= NULL
;
2556 template<int size
, bool big_endian
>
2558 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2560 this->e_flags_
|= ver
;
2561 if (this->abiversion() != 0)
2563 Target_powerpc
<size
, big_endian
>* target
=
2564 static_cast<Target_powerpc
<size
, big_endian
>*>(
2565 parameters
->sized_target
<size
, big_endian
>());
2566 if (target
->abiversion() == 0)
2567 target
->set_abiversion(this->abiversion());
2568 else if (target
->abiversion() != this->abiversion())
2569 gold_error(_("%s: ABI version %d is not compatible "
2570 "with ABI version %d output"),
2571 this->name().c_str(),
2572 this->abiversion(), target
->abiversion());
2577 // Call Sized_dynobj::base_read_symbols to read the symbols then
2578 // read .opd from a dynamic object, filling in opd_ent_ vector,
2580 template<int size
, bool big_endian
>
2582 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2584 this->base_read_symbols(sd
);
2585 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2586 const unsigned char* ps
=
2587 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2588 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2590 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2591 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2593 section_offset_type section_offset
= shdr
.get_sh_offset();
2594 section_size_type section_size
=
2595 convert_to_section_size_type(shdr
.get_sh_size());
2596 const unsigned char* view
=
2597 this->get_view(section_offset
, section_size
, true, false);
2598 this->attributes_section_data_
=
2599 new Attributes_section_data(view
, section_size
);
2605 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2606 const unsigned char* namesu
= sd
->section_names
->data();
2607 const char* names
= reinterpret_cast<const char*>(namesu
);
2608 const unsigned char* s
= NULL
;
2609 const unsigned char* opd
;
2610 section_size_type opd_size
;
2612 // Find and read .opd section.
2615 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2616 sd
->section_names_size
,
2621 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2622 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2623 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2625 if (this->abiversion() == 0)
2626 this->set_abiversion(1);
2627 else if (this->abiversion() > 1)
2628 gold_error(_("%s: .opd invalid in abiv%d"),
2629 this->name().c_str(), this->abiversion());
2631 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2632 this->opd_address_
= shdr
.get_sh_addr();
2633 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2634 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2640 // Build set of executable sections.
2641 // Using a set is probably overkill. There is likely to be only
2642 // a few executable sections, typically .init, .text and .fini,
2643 // and they are generally grouped together.
2644 typedef std::set
<Sec_info
> Exec_sections
;
2645 Exec_sections exec_sections
;
2647 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2649 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2650 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2651 && ((shdr
.get_sh_flags()
2652 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2653 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2654 && shdr
.get_sh_size() != 0)
2656 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2657 shdr
.get_sh_size(), i
));
2660 if (exec_sections
.empty())
2663 // Look over the OPD entries. This is complicated by the fact
2664 // that some binaries will use two-word entries while others
2665 // will use the standard three-word entries. In most cases
2666 // the third word (the environment pointer for languages like
2667 // Pascal) is unused and will be zero. If the third word is
2668 // used it should not be pointing into executable sections,
2670 this->init_opd(opd_size
);
2671 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2673 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2674 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2675 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2677 // Chances are that this is the third word of an OPD entry.
2679 typename
Exec_sections::const_iterator e
2680 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2681 if (e
!= exec_sections
.begin())
2684 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2686 // We have an address in an executable section.
2687 // VAL ought to be the function entry, set it up.
2688 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2689 // Skip second word of OPD entry, the TOC pointer.
2693 // If we didn't match any executable sections, we likely
2694 // have a non-zero third word in the OPD entry.
2699 // Relocate sections.
2701 template<int size
, bool big_endian
>
2703 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2704 const Symbol_table
* symtab
, const Layout
* layout
,
2705 const unsigned char* pshdrs
, Output_file
* of
,
2706 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2708 unsigned int start
= 1;
2710 && this->relatoc_
!= 0
2711 && !parameters
->options().relocatable())
2713 // Relocate .toc first.
2714 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2715 this->relatoc_
, this->relatoc_
);
2716 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2717 1, this->relatoc_
- 1);
2718 start
= this->relatoc_
+ 1;
2720 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2721 start
, this->shnum() - 1);
2723 if (!parameters
->options().output_is_position_independent())
2725 Target_powerpc
<size
, big_endian
>* target
2726 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2727 parameters
->sized_target
<size
, big_endian
>());
2728 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2730 const section_size_type offset
= target
->lplt_section()->offset();
2731 const section_size_type oview_size
2732 = convert_to_section_size_type(target
->lplt_section()->data_size());
2733 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2735 bool modified
= false;
2736 unsigned int nsyms
= this->local_symbol_count();
2737 for (unsigned int i
= 0; i
< nsyms
; i
++)
2738 if (this->local_has_plt_offset(i
))
2740 Address value
= this->local_symbol_value(i
, 0);
2742 value
+= ppc64_local_entry_offset(i
);
2743 size_t off
= this->local_plt_offset(i
);
2744 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2748 of
->write_output_view(offset
, oview_size
, oview
);
2753 // Set up some symbols.
2755 template<int size
, bool big_endian
>
2757 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2758 Symbol_table
* symtab
,
2763 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2764 // undefined when scanning relocs (and thus requires
2765 // non-relative dynamic relocs). The proper value will be
2767 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2768 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2770 Target_powerpc
<size
, big_endian
>* target
=
2771 static_cast<Target_powerpc
<size
, big_endian
>*>(
2772 parameters
->sized_target
<size
, big_endian
>());
2773 Output_data_got_powerpc
<size
, big_endian
>* got
2774 = target
->got_section(symtab
, layout
);
2775 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2776 Symbol_table::PREDEFINED
,
2780 elfcpp::STV_HIDDEN
, 0,
2784 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2785 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2786 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2788 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2790 = layout
->add_output_section_data(".sdata", 0,
2792 | elfcpp::SHF_WRITE
,
2793 sdata
, ORDER_SMALL_DATA
, false);
2794 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2795 Symbol_table::PREDEFINED
,
2796 os
, 32768, 0, elfcpp::STT_OBJECT
,
2797 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2803 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2804 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2805 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2807 Target_powerpc
<size
, big_endian
>* target
=
2808 static_cast<Target_powerpc
<size
, big_endian
>*>(
2809 parameters
->sized_target
<size
, big_endian
>());
2810 Output_data_got_powerpc
<size
, big_endian
>* got
2811 = target
->got_section(symtab
, layout
);
2812 symtab
->define_in_output_data(".TOC.", NULL
,
2813 Symbol_table::PREDEFINED
,
2817 elfcpp::STV_HIDDEN
, 0,
2822 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2823 if (parameters
->options().tls_get_addr_optimize()
2824 && this->tls_get_addr_
!= NULL
2825 && this->tls_get_addr_
->in_reg())
2826 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2827 if (this->tls_get_addr_opt_
!= NULL
)
2829 if (this->tls_get_addr_
->is_undefined()
2830 || this->tls_get_addr_
->is_from_dynobj())
2832 // Make it seem as if references to __tls_get_addr are
2833 // really to __tls_get_addr_opt, so the latter symbol is
2834 // made dynamic, not the former.
2835 this->tls_get_addr_
->clear_in_reg();
2836 this->tls_get_addr_opt_
->set_in_reg();
2838 // We have a non-dynamic definition for __tls_get_addr.
2839 // Make __tls_get_addr_opt the same, if it does not already have
2840 // a non-dynamic definition.
2841 else if (this->tls_get_addr_opt_
->is_undefined()
2842 || this->tls_get_addr_opt_
->is_from_dynobj())
2844 Sized_symbol
<size
>* from
2845 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2846 Sized_symbol
<size
>* to
2847 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2848 symtab
->clone
<size
>(to
, from
);
2853 // Set up PowerPC target specific relobj.
2855 template<int size
, bool big_endian
>
2857 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2858 const std::string
& name
,
2859 Input_file
* input_file
,
2860 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2862 int et
= ehdr
.get_e_type();
2863 // ET_EXEC files are valid input for --just-symbols/-R,
2864 // and we treat them as relocatable objects.
2865 if (et
== elfcpp::ET_REL
2866 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2868 Powerpc_relobj
<size
, big_endian
>* obj
=
2869 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2873 else if (et
== elfcpp::ET_DYN
)
2875 Powerpc_dynobj
<size
, big_endian
>* obj
=
2876 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2882 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2887 template<int size
, bool big_endian
>
2888 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2891 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2892 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2894 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2895 : Output_data_got
<size
, big_endian
>(),
2896 symtab_(symtab
), layout_(layout
),
2897 header_ent_cnt_(size
== 32 ? 3 : 1),
2898 header_index_(size
== 32 ? 0x2000 : 0)
2901 this->set_addralign(256);
2904 // Override all the Output_data_got methods we use so as to first call
2907 add_global(Symbol
* gsym
, unsigned int got_type
)
2909 this->reserve_ent();
2910 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2914 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2916 this->reserve_ent();
2917 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2921 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2922 { return this->add_global_plt(gsym
, got_type
); }
2925 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2926 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2928 this->reserve_ent();
2929 Output_data_got
<size
, big_endian
>::
2930 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2934 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2935 Output_data_reloc_generic
* rel_dyn
,
2936 unsigned int r_type_1
, unsigned int r_type_2
)
2938 if (gsym
->has_got_offset(got_type
))
2941 this->reserve_ent(2);
2942 Output_data_got
<size
, big_endian
>::
2943 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2947 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2949 this->reserve_ent();
2950 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2955 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2957 this->reserve_ent();
2958 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2963 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2964 { return this->add_local_plt(object
, sym_index
, got_type
); }
2967 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2968 unsigned int got_type
,
2969 Output_data_reloc_generic
* rel_dyn
,
2970 unsigned int r_type
)
2972 if (object
->local_has_got_offset(sym_index
, got_type
))
2975 this->reserve_ent(2);
2976 Output_data_got
<size
, big_endian
>::
2977 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2981 add_constant(Valtype constant
)
2983 this->reserve_ent();
2984 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2988 add_constant_pair(Valtype c1
, Valtype c2
)
2990 this->reserve_ent(2);
2991 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2994 // Offset of _GLOBAL_OFFSET_TABLE_.
2998 return this->got_offset(this->header_index_
);
3001 // Offset of base used to access the GOT/TOC.
3002 // The got/toc pointer reg will be set to this value.
3004 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
3007 return this->g_o_t();
3009 return (this->output_section()->address()
3010 + object
->toc_base_offset()
3014 // Ensure our GOT has a header.
3016 set_final_data_size()
3018 if (this->header_ent_cnt_
!= 0)
3019 this->make_header();
3020 Output_data_got
<size
, big_endian
>::set_final_data_size();
3023 // First word of GOT header needs some values that are not
3024 // handled by Output_data_got so poke them in here.
3025 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3027 do_write(Output_file
* of
)
3030 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3031 val
= this->layout_
->dynamic_section()->address();
3033 val
= this->output_section()->address() + 0x8000;
3034 this->replace_constant(this->header_index_
, val
);
3035 Output_data_got
<size
, big_endian
>::do_write(of
);
3040 reserve_ent(unsigned int cnt
= 1)
3042 if (this->header_ent_cnt_
== 0)
3044 if (this->num_entries() + cnt
> this->header_index_
)
3045 this->make_header();
3051 this->header_ent_cnt_
= 0;
3052 this->header_index_
= this->num_entries();
3055 Output_data_got
<size
, big_endian
>::add_constant(0);
3056 Output_data_got
<size
, big_endian
>::add_constant(0);
3057 Output_data_got
<size
, big_endian
>::add_constant(0);
3059 // Define _GLOBAL_OFFSET_TABLE_ at the header
3060 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3063 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3064 sym
->set_value(this->g_o_t());
3067 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3068 Symbol_table::PREDEFINED
,
3069 this, this->g_o_t(), 0,
3072 elfcpp::STV_HIDDEN
, 0,
3076 Output_data_got
<size
, big_endian
>::add_constant(0);
3079 // Stashed pointers.
3080 Symbol_table
* symtab_
;
3084 unsigned int header_ent_cnt_
;
3085 // GOT header index.
3086 unsigned int header_index_
;
3089 // Get the GOT section, creating it if necessary.
3091 template<int size
, bool big_endian
>
3092 Output_data_got_powerpc
<size
, big_endian
>*
3093 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3096 if (this->got_
== NULL
)
3098 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3101 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3103 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3104 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3105 this->got_
, ORDER_DATA
, false);
3111 // Get the dynamic reloc section, creating it if necessary.
3113 template<int size
, bool big_endian
>
3114 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3115 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3117 if (this->rela_dyn_
== NULL
)
3119 gold_assert(layout
!= NULL
);
3120 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3121 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3122 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3123 ORDER_DYNAMIC_RELOCS
, false);
3125 return this->rela_dyn_
;
3128 // Similarly, but for ifunc symbols get the one for ifunc.
3130 template<int size
, bool big_endian
>
3131 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3132 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3137 return this->rela_dyn_section(layout
);
3139 if (this->iplt_
== NULL
)
3140 this->make_iplt_section(symtab
, layout
);
3141 return this->iplt_
->rel_plt();
3147 // Determine the stub group size. The group size is the absolute
3148 // value of the parameter --stub-group-size. If --stub-group-size
3149 // is passed a negative value, we restrict stubs to be always after
3150 // the stubbed branches.
3151 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3152 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3153 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3154 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3155 owner_(NULL
), output_section_(NULL
)
3159 // Return true iff input section can be handled by current stub
3162 can_add_to_stub_group(Output_section
* o
,
3163 const Output_section::Input_section
* i
,
3166 const Output_section::Input_section
*
3172 { return output_section_
; }
3175 set_output_and_owner(Output_section
* o
,
3176 const Output_section::Input_section
* i
)
3178 this->output_section_
= o
;
3187 // Adding group sections before the stubs.
3188 FINDING_STUB_SECTION
,
3189 // Adding group sections after the stubs.
3193 uint32_t stub_group_size_
;
3194 bool stubs_always_after_branch_
;
3195 bool suppress_size_errors_
;
3196 // True if a stub group can serve multiple output sections.
3199 // Current max size of group. Starts at stub_group_size_ but is
3200 // reduced to stub_group_size_/1024 on seeing a section with
3201 // external conditional branches.
3202 uint32_t group_size_
;
3203 uint64_t group_start_addr_
;
3204 // owner_ and output_section_ specify the section to which stubs are
3205 // attached. The stubs are placed at the end of this section.
3206 const Output_section::Input_section
* owner_
;
3207 Output_section
* output_section_
;
3210 // Return true iff input section can be handled by current stub
3211 // group. Sections are presented to this function in order,
3212 // so the first section is the head of the group.
3215 Stub_control::can_add_to_stub_group(Output_section
* o
,
3216 const Output_section::Input_section
* i
,
3219 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3221 uint64_t start_addr
= o
->address();
3224 // .init and .fini sections are pasted together to form a single
3225 // function. We can't be adding stubs in the middle of the function.
3226 this_size
= o
->data_size();
3229 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3230 this_size
= i
->data_size();
3233 uint64_t end_addr
= start_addr
+ this_size
;
3234 uint32_t group_size
= this->stub_group_size_
;
3236 this->group_size_
= group_size
= group_size
>> 10;
3238 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3239 gold_warning(_("%s:%s exceeds group size"),
3240 i
->relobj()->name().c_str(),
3241 i
->relobj()->section_name(i
->shndx()).c_str());
3243 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3244 has14
? " 14bit" : "",
3245 i
->relobj()->name().c_str(),
3246 i
->relobj()->section_name(i
->shndx()).c_str(),
3247 (long long) this_size
,
3248 (this->state_
== NO_GROUP
3250 : (long long) end_addr
- this->group_start_addr_
));
3252 if (this->state_
== NO_GROUP
)
3254 // Only here on very first use of Stub_control
3256 this->output_section_
= o
;
3257 this->state_
= FINDING_STUB_SECTION
;
3258 this->group_size_
= group_size
;
3259 this->group_start_addr_
= start_addr
;
3262 else if (!this->multi_os_
&& this->output_section_
!= o
)
3264 else if (this->state_
== HAS_STUB_SECTION
)
3266 // Can we add this section, which is after the stubs, to the
3268 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3271 else if (this->state_
== FINDING_STUB_SECTION
)
3273 if ((whole_sec
&& this->output_section_
== o
)
3274 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3276 // Stubs are added at the end of "owner_".
3278 this->output_section_
= o
;
3281 // The group before the stubs has reached maximum size.
3282 // Now see about adding sections after the stubs to the
3283 // group. If the current section has a 14-bit branch and
3284 // the group before the stubs exceeds group_size_ (because
3285 // they didn't have 14-bit branches), don't add sections
3286 // after the stubs: The size of stubs for such a large
3287 // group may exceed the reach of a 14-bit branch.
3288 if (!this->stubs_always_after_branch_
3289 && this_size
<= this->group_size_
3290 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3292 gold_debug(DEBUG_TARGET
, "adding after stubs");
3293 this->state_
= HAS_STUB_SECTION
;
3294 this->group_start_addr_
= start_addr
;
3301 gold_debug(DEBUG_TARGET
,
3302 !this->multi_os_
&& this->output_section_
!= o
3303 ? "nope, new output section\n"
3304 : "nope, didn't fit\n");
3306 // The section fails to fit in the current group. Set up a few
3307 // things for the next group. owner_ and output_section_ will be
3308 // set later after we've retrieved those values for the current
3310 this->state_
= FINDING_STUB_SECTION
;
3311 this->group_size_
= group_size
;
3312 this->group_start_addr_
= start_addr
;
3316 // Look over all the input sections, deciding where to place stubs.
3318 template<int size
, bool big_endian
>
3320 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3322 bool no_size_errors
)
3324 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3325 parameters
->options().stub_group_multi());
3327 // Group input sections and insert stub table
3328 Stub_table_owner
* table_owner
= NULL
;
3329 std::vector
<Stub_table_owner
*> tables
;
3330 Layout::Section_list section_list
;
3331 layout
->get_executable_sections(§ion_list
);
3332 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3333 for (Layout::Section_list::iterator o
= section_list
.begin();
3334 o
!= section_list
.end();
3337 typedef Output_section::Input_section_list Input_section_list
;
3338 for (Input_section_list::const_iterator i
3339 = (*o
)->input_sections().begin();
3340 i
!= (*o
)->input_sections().end();
3343 if (i
->is_input_section()
3344 || i
->is_relaxed_input_section())
3346 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3347 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3348 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3349 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3351 table_owner
->output_section
= stub_control
.output_section();
3352 table_owner
->owner
= stub_control
.owner();
3353 stub_control
.set_output_and_owner(*o
, &*i
);
3356 if (table_owner
== NULL
)
3358 table_owner
= new Stub_table_owner
;
3359 tables
.push_back(table_owner
);
3361 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3365 if (table_owner
!= NULL
)
3367 table_owner
->output_section
= stub_control
.output_section();
3368 table_owner
->owner
= stub_control
.owner();;
3370 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3374 Stub_table
<size
, big_endian
>* stub_table
;
3376 if ((*t
)->owner
->is_input_section())
3377 stub_table
= new Stub_table
<size
, big_endian
>(this,
3378 (*t
)->output_section
,
3380 this->stub_tables_
.size());
3381 else if ((*t
)->owner
->is_relaxed_input_section())
3382 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3383 (*t
)->owner
->relaxed_input_section());
3386 this->stub_tables_
.push_back(stub_table
);
3392 static unsigned long
3393 max_branch_delta (unsigned int r_type
)
3395 if (r_type
== elfcpp::R_POWERPC_REL14
3396 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3397 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3399 if (r_type
== elfcpp::R_POWERPC_REL24
3400 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3401 || r_type
== elfcpp::R_PPC_PLTREL24
3402 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3407 // Return whether this branch is going via a plt call stub.
3409 template<int size
, bool big_endian
>
3411 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3412 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3415 Target_powerpc
* target
,
3416 Symbol_table
* symtab
)
3418 if (this->object_
!= ppc_object
3419 || this->shndx_
!= shndx
3420 || this->offset_
!= offset
)
3423 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3424 if (sym
!= NULL
&& sym
->is_forwarder())
3425 sym
= symtab
->resolve_forwards(sym
);
3426 if (target
->replace_tls_get_addr(sym
))
3427 sym
= target
->tls_get_addr_opt();
3428 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3430 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3431 && !target
->is_elfv2_localentry0(gsym
))
3432 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3433 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3441 // If this branch needs a plt call stub, or a long branch stub, make one.
3443 template<int size
, bool big_endian
>
3445 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3446 Stub_table
<size
, big_endian
>* stub_table
,
3447 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3448 Symbol_table
* symtab
) const
3450 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3451 Target_powerpc
<size
, big_endian
>* target
=
3452 static_cast<Target_powerpc
<size
, big_endian
>*>(
3453 parameters
->sized_target
<size
, big_endian
>());
3454 if (sym
!= NULL
&& sym
->is_forwarder())
3455 sym
= symtab
->resolve_forwards(sym
);
3456 if (target
->replace_tls_get_addr(sym
))
3457 sym
= target
->tls_get_addr_opt();
3458 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3462 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3463 : this->object_
->local_has_plt_offset(this->r_sym_
))
3467 && target
->abiversion() >= 2
3468 && !parameters
->options().output_is_position_independent()
3469 && !is_branch_reloc
<size
>(this->r_type_
))
3470 target
->glink_section()->add_global_entry(gsym
);
3473 if (stub_table
== NULL
3476 && !parameters
->options().output_is_position_independent()
3477 && !is_branch_reloc
<size
>(this->r_type_
)))
3478 stub_table
= this->object_
->stub_table(this->shndx_
);
3479 if (stub_table
== NULL
)
3481 // This is a ref from a data section to an ifunc symbol,
3482 // or a non-branch reloc for which we always want to use
3483 // one set of stubs for resolving function addresses.
3484 stub_table
= ifunc_stub_table
;
3486 gold_assert(stub_table
!= NULL
);
3487 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3488 if (from
!= invalid_address
)
3489 from
+= (this->object_
->output_section(this->shndx_
)->address()
3492 ok
= stub_table
->add_plt_call_entry(from
,
3493 this->object_
, gsym
,
3494 this->r_type_
, this->addend_
,
3497 ok
= stub_table
->add_plt_call_entry(from
,
3498 this->object_
, this->r_sym_
,
3499 this->r_type_
, this->addend_
,
3505 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3506 if (max_branch_offset
== 0)
3508 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3509 gold_assert(from
!= invalid_address
);
3510 from
+= (this->object_
->output_section(this->shndx_
)->address()
3515 switch (gsym
->source())
3517 case Symbol::FROM_OBJECT
:
3519 Object
* symobj
= gsym
->object();
3520 if (symobj
->is_dynamic()
3521 || symobj
->pluginobj() != NULL
)
3524 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3525 if (shndx
== elfcpp::SHN_UNDEF
)
3530 case Symbol::IS_UNDEFINED
:
3536 Symbol_table::Compute_final_value_status status
;
3537 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3538 if (status
!= Symbol_table::CFVS_OK
)
3541 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3545 const Symbol_value
<size
>* psymval
3546 = this->object_
->local_symbol(this->r_sym_
);
3547 Symbol_value
<size
> symval
;
3548 if (psymval
->is_section_symbol())
3549 symval
.set_is_section_symbol();
3550 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3551 typename
ObjType::Compute_final_local_value_status status
3552 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3554 if (status
!= ObjType::CFLV_OK
3555 || !symval
.has_output_value())
3557 to
= symval
.value(this->object_
, 0);
3559 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3561 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3562 to
+= this->addend_
;
3563 if (stub_table
== NULL
)
3564 stub_table
= this->object_
->stub_table(this->shndx_
);
3565 if (size
== 64 && target
->abiversion() < 2)
3567 unsigned int dest_shndx
;
3568 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3572 Address delta
= to
- from
;
3573 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3575 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3577 ? this->object_
->ppc64_needs_toc(gsym
)
3578 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3580 if (stub_table
== NULL
)
3582 gold_warning(_("%s:%s: branch in non-executable section,"
3583 " no long branch stub for you"),
3584 this->object_
->name().c_str(),
3585 this->object_
->section_name(this->shndx_
).c_str());
3588 bool save_res
= (size
== 64
3590 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3591 && gsym
->output_data() == target
->savres_section());
3592 ok
= stub_table
->add_long_branch_entry(this->object_
,
3594 from
, to
, save_res
);
3598 gold_debug(DEBUG_TARGET
,
3599 "branch at %s:%s+%#lx\n"
3600 "can't reach stub attached to %s:%s",
3601 this->object_
->name().c_str(),
3602 this->object_
->section_name(this->shndx_
).c_str(),
3603 (unsigned long) this->offset_
,
3604 stub_table
->relobj()->name().c_str(),
3605 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3610 // Relaxation hook. This is where we do stub generation.
3612 template<int size
, bool big_endian
>
3614 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3615 const Input_objects
*,
3616 Symbol_table
* symtab
,
3620 unsigned int prev_brlt_size
= 0;
3624 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3626 && this->abiversion() < 2
3628 && !parameters
->options().user_set_plt_thread_safe())
3630 static const char* const thread_starter
[] =
3634 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3636 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3637 "mq_notify", "create_timer",
3642 "GOMP_parallel_start",
3643 "GOMP_parallel_loop_static",
3644 "GOMP_parallel_loop_static_start",
3645 "GOMP_parallel_loop_dynamic",
3646 "GOMP_parallel_loop_dynamic_start",
3647 "GOMP_parallel_loop_guided",
3648 "GOMP_parallel_loop_guided_start",
3649 "GOMP_parallel_loop_runtime",
3650 "GOMP_parallel_loop_runtime_start",
3651 "GOMP_parallel_sections",
3652 "GOMP_parallel_sections_start",
3657 if (parameters
->options().shared())
3661 for (unsigned int i
= 0;
3662 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3665 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3666 thread_safe
= (sym
!= NULL
3668 && sym
->in_real_elf());
3674 this->plt_thread_safe_
= thread_safe
;
3679 this->stub_group_size_
= parameters
->options().stub_group_size();
3680 bool no_size_errors
= true;
3681 if (this->stub_group_size_
== 1)
3682 this->stub_group_size_
= 0x1c00000;
3683 else if (this->stub_group_size_
== -1)
3684 this->stub_group_size_
= -0x1e00000;
3686 no_size_errors
= false;
3687 this->group_sections(layout
, task
, no_size_errors
);
3689 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3691 this->branch_lookup_table_
.clear();
3692 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3693 p
!= this->stub_tables_
.end();
3696 (*p
)->clear_stubs(true);
3698 this->stub_tables_
.clear();
3699 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3700 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3701 program_name
, this->stub_group_size_
);
3702 this->group_sections(layout
, task
, true);
3705 // We need address of stub tables valid for make_stub.
3706 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3707 p
!= this->stub_tables_
.end();
3710 const Powerpc_relobj
<size
, big_endian
>* object
3711 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3712 Address off
= object
->get_output_section_offset((*p
)->shndx());
3713 gold_assert(off
!= invalid_address
);
3714 Output_section
* os
= (*p
)->output_section();
3715 (*p
)->set_address_and_size(os
, off
);
3720 // Clear plt call stubs, long branch stubs and branch lookup table.
3721 prev_brlt_size
= this->branch_lookup_table_
.size();
3722 this->branch_lookup_table_
.clear();
3723 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3724 p
!= this->stub_tables_
.end();
3727 (*p
)->clear_stubs(false);
3731 // Build all the stubs.
3732 this->relax_failed_
= false;
3733 Stub_table
<size
, big_endian
>* ifunc_stub_table
3734 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3735 Stub_table
<size
, big_endian
>* one_stub_table
3736 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3737 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3738 b
!= this->branch_info_
.end();
3741 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3742 && !this->relax_failed_
)
3744 this->relax_failed_
= true;
3745 this->relax_fail_count_
++;
3746 if (this->relax_fail_count_
< 3)
3750 bool do_resize
= false;
3751 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3752 p
!= this->stub_tables_
.end();
3754 if ((*p
)->need_resize())
3761 this->branch_lookup_table_
.clear();
3762 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3763 p
!= this->stub_tables_
.end();
3765 (*p
)->set_resizing(true);
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 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3780 p
!= this->stub_tables_
.end();
3782 (*p
)->set_resizing(false);
3785 // Did anything change size?
3786 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3787 bool again
= num_huge_branches
!= prev_brlt_size
;
3788 if (size
== 64 && num_huge_branches
!= 0)
3789 this->make_brlt_section(layout
);
3790 if (size
== 64 && again
)
3791 this->brlt_section_
->set_current_size(num_huge_branches
);
3793 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3794 p
!= this->stub_tables_
.rend();
3796 (*p
)->remove_eh_frame(layout
);
3798 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3799 p
!= this->stub_tables_
.end();
3801 (*p
)->add_eh_frame(layout
);
3803 typedef Unordered_set
<Output_section
*> Output_sections
;
3804 Output_sections os_need_update
;
3805 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3806 p
!= this->stub_tables_
.end();
3809 if ((*p
)->size_update())
3812 os_need_update
.insert((*p
)->output_section());
3816 // Set output section offsets for all input sections in an output
3817 // section that just changed size. Anything past the stubs will
3819 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3820 p
!= os_need_update
.end();
3823 Output_section
* os
= *p
;
3825 typedef Output_section::Input_section_list Input_section_list
;
3826 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3827 i
!= os
->input_sections().end();
3830 off
= align_address(off
, i
->addralign());
3831 if (i
->is_input_section() || i
->is_relaxed_input_section())
3832 i
->relobj()->set_section_offset(i
->shndx(), off
);
3833 if (i
->is_relaxed_input_section())
3835 Stub_table
<size
, big_endian
>* stub_table
3836 = static_cast<Stub_table
<size
, big_endian
>*>(
3837 i
->relaxed_input_section());
3838 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3839 off
+= stub_table_size
;
3840 // After a few iterations, set current stub table size
3841 // as min size threshold, so later stub tables can only
3844 stub_table
->set_min_size_threshold(stub_table_size
);
3847 off
+= i
->data_size();
3849 // If .branch_lt is part of this output section, then we have
3850 // just done the offset adjustment.
3851 os
->clear_section_offsets_need_adjustment();
3856 && num_huge_branches
!= 0
3857 && parameters
->options().output_is_position_independent())
3859 // Fill in the BRLT relocs.
3860 this->brlt_section_
->reset_brlt_sizes();
3861 for (typename
Branch_lookup_table::const_iterator p
3862 = this->branch_lookup_table_
.begin();
3863 p
!= this->branch_lookup_table_
.end();
3866 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3868 this->brlt_section_
->finalize_brlt_sizes();
3872 && (parameters
->options().user_set_emit_stub_syms()
3873 ? parameters
->options().emit_stub_syms()
3875 || parameters
->options().output_is_position_independent()
3876 || parameters
->options().emit_relocs())))
3878 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3879 p
!= this->stub_tables_
.end();
3881 (*p
)->define_stub_syms(symtab
);
3883 if (this->glink_
!= NULL
)
3885 int stub_size
= this->glink_
->pltresolve_size();
3886 Address value
= -stub_size
;
3892 this->define_local(symtab
, "__glink_PLTresolve",
3893 this->glink_
, value
, stub_size
);
3896 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3903 template<int size
, bool big_endian
>
3905 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3906 unsigned char* oview
,
3910 uint64_t address
= plt
->address();
3911 off_t len
= plt
->data_size();
3913 if (plt
== this->glink_
)
3915 // See Output_data_glink::do_write() for glink contents.
3918 gold_assert(parameters
->doing_static_link());
3919 // Static linking may need stubs, to support ifunc and long
3920 // branches. We need to create an output section for
3921 // .eh_frame early in the link process, to have a place to
3922 // attach stub .eh_frame info. We also need to have
3923 // registered a CIE that matches the stub CIE. Both of
3924 // these requirements are satisfied by creating an FDE and
3925 // CIE for .glink, even though static linking will leave
3926 // .glink zero length.
3927 // ??? Hopefully generating an FDE with a zero address range
3928 // won't confuse anything that consumes .eh_frame info.
3930 else if (size
== 64)
3932 // There is one word before __glink_PLTresolve
3936 else if (parameters
->options().output_is_position_independent())
3938 // There are two FDEs for a position independent glink.
3939 // The first covers the branch table, the second
3940 // __glink_PLTresolve at the end of glink.
3941 off_t resolve_size
= this->glink_
->pltresolve_size();
3942 if (oview
[9] == elfcpp::DW_CFA_nop
)
3943 len
-= resolve_size
;
3946 address
+= len
- resolve_size
;
3953 // Must be a stub table.
3954 const Stub_table
<size
, big_endian
>* stub_table
3955 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3956 uint64_t stub_address
= stub_table
->stub_address();
3957 len
-= stub_address
- address
;
3958 address
= stub_address
;
3961 *paddress
= address
;
3965 // A class to handle the PLT data.
3967 template<int size
, bool big_endian
>
3968 class Output_data_plt_powerpc
: public Output_section_data_build
3971 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3972 size
, big_endian
> Reloc_section
;
3974 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3975 Reloc_section
* plt_rel
,
3977 : Output_section_data_build(size
== 32 ? 4 : 8),
3983 // Add an entry to the PLT.
3988 add_ifunc_entry(Symbol
*);
3991 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3994 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3996 // Return the .rela.plt section data.
4003 // Return the number of PLT entries.
4007 if (this->current_data_size() == 0)
4009 return ((this->current_data_size() - this->first_plt_entry_offset())
4010 / this->plt_entry_size());
4015 do_adjust_output_section(Output_section
* os
)
4020 // Write to a map file.
4022 do_print_to_mapfile(Mapfile
* mapfile
) const
4023 { mapfile
->print_output_data(this, this->name_
); }
4026 // Return the offset of the first non-reserved PLT entry.
4028 first_plt_entry_offset() const
4030 // IPLT and LPLT have no reserved entry.
4031 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4033 return this->targ_
->first_plt_entry_offset();
4036 // Return the size of each PLT entry.
4038 plt_entry_size() const
4040 return this->targ_
->plt_entry_size();
4043 // Write out the PLT data.
4045 do_write(Output_file
*);
4047 // The reloc section.
4048 Reloc_section
* rel_
;
4049 // Allows access to .glink for do_write.
4050 Target_powerpc
<size
, big_endian
>* targ_
;
4051 // What to report in map file.
4055 // Add an entry to the PLT.
4057 template<int size
, bool big_endian
>
4059 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4061 if (!gsym
->has_plt_offset())
4063 section_size_type off
= this->current_data_size();
4065 off
+= this->first_plt_entry_offset();
4066 gsym
->set_plt_offset(off
);
4067 gsym
->set_needs_dynsym_entry();
4068 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4069 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4070 off
+= this->plt_entry_size();
4071 this->set_current_data_size(off
);
4075 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4077 template<int size
, bool big_endian
>
4079 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4081 if (!gsym
->has_plt_offset())
4083 section_size_type off
= this->current_data_size();
4084 gsym
->set_plt_offset(off
);
4085 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4086 if (size
== 64 && this->targ_
->abiversion() < 2)
4087 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4088 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4089 off
+= this->plt_entry_size();
4090 this->set_current_data_size(off
);
4094 // Add an entry for a local symbol to the PLT.
4096 template<int size
, bool big_endian
>
4098 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4099 Sized_relobj_file
<size
, big_endian
>* relobj
,
4100 unsigned int local_sym_index
)
4102 if (!relobj
->local_has_plt_offset(local_sym_index
))
4104 section_size_type off
= this->current_data_size();
4105 relobj
->set_local_plt_offset(local_sym_index
, off
);
4108 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4109 if (size
== 64 && this->targ_
->abiversion() < 2)
4110 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4111 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4112 dynrel
, this, off
, 0);
4114 off
+= this->plt_entry_size();
4115 this->set_current_data_size(off
);
4119 // Add an entry for a local ifunc symbol to the IPLT.
4121 template<int size
, bool big_endian
>
4123 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4124 Sized_relobj_file
<size
, big_endian
>* relobj
,
4125 unsigned int local_sym_index
)
4127 if (!relobj
->local_has_plt_offset(local_sym_index
))
4129 section_size_type off
= this->current_data_size();
4130 relobj
->set_local_plt_offset(local_sym_index
, off
);
4131 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4132 if (size
== 64 && this->targ_
->abiversion() < 2)
4133 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4134 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4136 off
+= this->plt_entry_size();
4137 this->set_current_data_size(off
);
4141 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4142 static const uint32_t add_2_2_11
= 0x7c425a14;
4143 static const uint32_t add_2_2_12
= 0x7c426214;
4144 static const uint32_t add_3_3_2
= 0x7c631214;
4145 static const uint32_t add_3_3_13
= 0x7c636a14;
4146 static const uint32_t add_3_12_2
= 0x7c6c1214;
4147 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4148 static const uint32_t add_11_0_11
= 0x7d605a14;
4149 static const uint32_t add_11_2_11
= 0x7d625a14;
4150 static const uint32_t add_11_11_2
= 0x7d6b1214;
4151 static const uint32_t add_12_11_12
= 0x7d8b6214;
4152 static const uint32_t addi_0_12
= 0x380c0000;
4153 static const uint32_t addi_2_2
= 0x38420000;
4154 static const uint32_t addi_3_3
= 0x38630000;
4155 static const uint32_t addi_11_11
= 0x396b0000;
4156 static const uint32_t addi_12_1
= 0x39810000;
4157 static const uint32_t addi_12_11
= 0x398b0000;
4158 static const uint32_t addi_12_12
= 0x398c0000;
4159 static const uint32_t addis_0_2
= 0x3c020000;
4160 static const uint32_t addis_0_13
= 0x3c0d0000;
4161 static const uint32_t addis_2_12
= 0x3c4c0000;
4162 static const uint32_t addis_11_2
= 0x3d620000;
4163 static const uint32_t addis_11_11
= 0x3d6b0000;
4164 static const uint32_t addis_11_30
= 0x3d7e0000;
4165 static const uint32_t addis_12_1
= 0x3d810000;
4166 static const uint32_t addis_12_2
= 0x3d820000;
4167 static const uint32_t addis_12_11
= 0x3d8b0000;
4168 static const uint32_t addis_12_12
= 0x3d8c0000;
4169 static const uint32_t b
= 0x48000000;
4170 static const uint32_t bcl_20_31
= 0x429f0005;
4171 static const uint32_t bctr
= 0x4e800420;
4172 static const uint32_t bctrl
= 0x4e800421;
4173 static const uint32_t beqlr
= 0x4d820020;
4174 static const uint32_t blr
= 0x4e800020;
4175 static const uint32_t bnectr_p4
= 0x4ce20420;
4176 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4177 static const uint32_t cmpldi_2_0
= 0x28220000;
4178 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4179 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4180 static const uint32_t cror_15_15_15
= 0x4def7b82;
4181 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4182 static const uint32_t ld_0_1
= 0xe8010000;
4183 static const uint32_t ld_0_12
= 0xe80c0000;
4184 static const uint32_t ld_2_1
= 0xe8410000;
4185 static const uint32_t ld_2_2
= 0xe8420000;
4186 static const uint32_t ld_2_11
= 0xe84b0000;
4187 static const uint32_t ld_2_12
= 0xe84c0000;
4188 static const uint32_t ld_11_1
= 0xe9610000;
4189 static const uint32_t ld_11_2
= 0xe9620000;
4190 static const uint32_t ld_11_3
= 0xe9630000;
4191 static const uint32_t ld_11_11
= 0xe96b0000;
4192 static const uint32_t ld_12_2
= 0xe9820000;
4193 static const uint32_t ld_12_3
= 0xe9830000;
4194 static const uint32_t ld_12_11
= 0xe98b0000;
4195 static const uint32_t ld_12_12
= 0xe98c0000;
4196 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4197 static const uint32_t lfd_0_1
= 0xc8010000;
4198 static const uint32_t li_0_0
= 0x38000000;
4199 static const uint32_t li_11_0
= 0x39600000;
4200 static const uint32_t li_12_0
= 0x39800000;
4201 static const uint32_t lis_0
= 0x3c000000;
4202 static const uint32_t lis_2
= 0x3c400000;
4203 static const uint32_t lis_11
= 0x3d600000;
4204 static const uint32_t lis_12
= 0x3d800000;
4205 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4206 static const uint32_t lwz_0_12
= 0x800c0000;
4207 static const uint32_t lwz_11_3
= 0x81630000;
4208 static const uint32_t lwz_11_11
= 0x816b0000;
4209 static const uint32_t lwz_11_30
= 0x817e0000;
4210 static const uint32_t lwz_12_3
= 0x81830000;
4211 static const uint32_t lwz_12_12
= 0x818c0000;
4212 static const uint32_t lwzu_0_12
= 0x840c0000;
4213 static const uint32_t mflr_0
= 0x7c0802a6;
4214 static const uint32_t mflr_11
= 0x7d6802a6;
4215 static const uint32_t mflr_12
= 0x7d8802a6;
4216 static const uint32_t mr_0_3
= 0x7c601b78;
4217 static const uint32_t mr_3_0
= 0x7c030378;
4218 static const uint32_t mtctr_0
= 0x7c0903a6;
4219 static const uint32_t mtctr_11
= 0x7d6903a6;
4220 static const uint32_t mtctr_12
= 0x7d8903a6;
4221 static const uint32_t mtlr_0
= 0x7c0803a6;
4222 static const uint32_t mtlr_11
= 0x7d6803a6;
4223 static const uint32_t mtlr_12
= 0x7d8803a6;
4224 static const uint32_t nop
= 0x60000000;
4225 static const uint32_t ori_0_0_0
= 0x60000000;
4226 static const uint32_t ori_11_11_0
= 0x616b0000;
4227 static const uint32_t ori_12_12_0
= 0x618c0000;
4228 static const uint32_t oris_12_12_0
= 0x658c0000;
4229 static const uint32_t sldi_11_11_34
= 0x796b1746;
4230 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4231 static const uint32_t srdi_0_0_2
= 0x7800f082;
4232 static const uint32_t std_0_1
= 0xf8010000;
4233 static const uint32_t std_0_12
= 0xf80c0000;
4234 static const uint32_t std_2_1
= 0xf8410000;
4235 static const uint32_t std_11_1
= 0xf9610000;
4236 static const uint32_t stfd_0_1
= 0xd8010000;
4237 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4238 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4239 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4240 static const uint32_t xor_2_12_12
= 0x7d826278;
4241 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4243 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4244 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4245 static const uint64_t pnop
= 0x0700000000000000ULL
;
4247 // Write out the PLT.
4249 template<int size
, bool big_endian
>
4251 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4253 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4255 const section_size_type offset
= this->offset();
4256 const section_size_type oview_size
4257 = convert_to_section_size_type(this->data_size());
4258 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4259 unsigned char* pov
= oview
;
4260 unsigned char* endpov
= oview
+ oview_size
;
4262 // The address of the .glink branch table
4263 const Output_data_glink
<size
, big_endian
>* glink
4264 = this->targ_
->glink_section();
4265 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4267 while (pov
< endpov
)
4269 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4274 of
->write_output_view(offset
, oview_size
, oview
);
4278 // Create the PLT section.
4280 template<int size
, bool big_endian
>
4282 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4285 if (this->plt_
== NULL
)
4287 if (this->got_
== NULL
)
4288 this->got_section(symtab
, layout
);
4290 if (this->glink_
== NULL
)
4291 make_glink_section(layout
);
4293 // Ensure that .rela.dyn always appears before .rela.plt This is
4294 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4295 // needs to include .rela.plt in its range.
4296 this->rela_dyn_section(layout
);
4298 Reloc_section
* plt_rel
= new Reloc_section(false);
4299 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4300 elfcpp::SHF_ALLOC
, plt_rel
,
4301 ORDER_DYNAMIC_PLT_RELOCS
, false);
4303 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4305 layout
->add_output_section_data(".plt",
4307 ? elfcpp::SHT_PROGBITS
4308 : elfcpp::SHT_NOBITS
),
4309 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4316 Output_section
* rela_plt_os
= plt_rel
->output_section();
4317 rela_plt_os
->set_info_section(this->plt_
->output_section());
4321 // Create the IPLT section.
4323 template<int size
, bool big_endian
>
4325 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4328 if (this->iplt_
== NULL
)
4330 this->make_plt_section(symtab
, layout
);
4331 this->make_lplt_section(layout
);
4333 Reloc_section
* iplt_rel
= new Reloc_section(false);
4334 if (this->rela_dyn_
->output_section())
4335 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4337 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4339 if (this->plt_
->output_section())
4340 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4344 // Create the LPLT section.
4346 template<int size
, bool big_endian
>
4348 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4350 if (this->lplt_
== NULL
)
4352 Reloc_section
* lplt_rel
= NULL
;
4353 if (parameters
->options().output_is_position_independent())
4355 lplt_rel
= new Reloc_section(false);
4356 this->rela_dyn_section(layout
);
4357 if (this->rela_dyn_
->output_section())
4358 this->rela_dyn_
->output_section()
4359 ->add_output_section_data(lplt_rel
);
4362 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4364 this->make_brlt_section(layout
);
4365 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4366 this->brlt_section_
->output_section()
4367 ->add_output_section_data(this->lplt_
);
4369 layout
->add_output_section_data(".branch_lt",
4370 elfcpp::SHT_PROGBITS
,
4371 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4378 // A section for huge long branch addresses, similar to plt section.
4380 template<int size
, bool big_endian
>
4381 class Output_data_brlt_powerpc
: public Output_section_data_build
4384 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4385 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4386 size
, big_endian
> Reloc_section
;
4388 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4389 Reloc_section
* brlt_rel
)
4390 : Output_section_data_build(size
== 32 ? 4 : 8),
4398 this->reset_data_size();
4399 this->rel_
->reset_data_size();
4403 finalize_brlt_sizes()
4405 this->finalize_data_size();
4406 this->rel_
->finalize_data_size();
4409 // Add a reloc for an entry in the BRLT.
4411 add_reloc(Address to
, unsigned int off
)
4412 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4414 // Update section and reloc section size.
4416 set_current_size(unsigned int num_branches
)
4418 this->reset_address_and_file_offset();
4419 this->set_current_data_size(num_branches
* 16);
4420 this->finalize_data_size();
4421 Output_section
* os
= this->output_section();
4422 os
->set_section_offsets_need_adjustment();
4423 if (this->rel_
!= NULL
)
4425 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4426 this->rel_
->reset_address_and_file_offset();
4427 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4428 this->rel_
->finalize_data_size();
4429 Output_section
* os
= this->rel_
->output_section();
4430 os
->set_section_offsets_need_adjustment();
4436 do_adjust_output_section(Output_section
* os
)
4441 // Write to a map file.
4443 do_print_to_mapfile(Mapfile
* mapfile
) const
4444 { mapfile
->print_output_data(this, "** BRLT"); }
4447 // Write out the BRLT data.
4449 do_write(Output_file
*);
4451 // The reloc section.
4452 Reloc_section
* rel_
;
4453 Target_powerpc
<size
, big_endian
>* targ_
;
4456 // Make the branch lookup table section.
4458 template<int size
, bool big_endian
>
4460 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4462 if (size
== 64 && this->brlt_section_
== NULL
)
4464 Reloc_section
* brlt_rel
= NULL
;
4465 bool is_pic
= parameters
->options().output_is_position_independent();
4468 // When PIC we can't fill in .branch_lt but must initialise at
4469 // runtime via dynamic relocations.
4470 this->rela_dyn_section(layout
);
4471 brlt_rel
= new Reloc_section(false);
4472 if (this->rela_dyn_
->output_section())
4473 this->rela_dyn_
->output_section()
4474 ->add_output_section_data(brlt_rel
);
4477 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4478 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4479 this->plt_
->output_section()
4480 ->add_output_section_data(this->brlt_section_
);
4482 layout
->add_output_section_data(".branch_lt",
4483 elfcpp::SHT_PROGBITS
,
4484 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4485 this->brlt_section_
,
4491 // Write out .branch_lt when non-PIC.
4493 template<int size
, bool big_endian
>
4495 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4497 if (size
== 64 && !parameters
->options().output_is_position_independent())
4499 const section_size_type offset
= this->offset();
4500 const section_size_type oview_size
4501 = convert_to_section_size_type(this->data_size());
4502 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4504 this->targ_
->write_branch_lookup_table(oview
);
4505 of
->write_output_view(offset
, oview_size
, oview
);
4509 static inline uint32_t
4515 static inline uint32_t
4521 static inline uint32_t
4524 return hi(a
+ 0x8000);
4527 static inline uint64_t
4530 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4533 static inline uint64_t
4536 return (v
+ (1ULL << 33)) >> 34;
4542 static const unsigned char eh_frame_cie
[12];
4546 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4549 'z', 'R', 0, // Augmentation string.
4550 4, // Code alignment.
4551 0x80 - size
/ 8 , // Data alignment.
4553 1, // Augmentation size.
4554 (elfcpp::DW_EH_PE_pcrel
4555 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4556 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4559 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4560 static const unsigned char glink_eh_frame_fde_64v1
[] =
4562 0, 0, 0, 0, // Replaced with offset to .glink.
4563 0, 0, 0, 0, // Replaced with size of .glink.
4564 0, // Augmentation size.
4565 elfcpp::DW_CFA_advance_loc
+ 1,
4566 elfcpp::DW_CFA_register
, 65, 12,
4567 elfcpp::DW_CFA_advance_loc
+ 5,
4568 elfcpp::DW_CFA_restore_extended
, 65
4571 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4572 static const unsigned char glink_eh_frame_fde_64v2
[] =
4574 0, 0, 0, 0, // Replaced with offset to .glink.
4575 0, 0, 0, 0, // Replaced with size of .glink.
4576 0, // Augmentation size.
4577 elfcpp::DW_CFA_advance_loc
+ 1,
4578 elfcpp::DW_CFA_register
, 65, 0,
4579 elfcpp::DW_CFA_advance_loc
+ 7,
4580 elfcpp::DW_CFA_restore_extended
, 65
4583 // Describe __glink_PLTresolve use of LR, 32-bit version.
4584 static const unsigned char glink_eh_frame_fde_32
[] =
4586 0, 0, 0, 0, // Replaced with offset to .glink.
4587 0, 0, 0, 0, // Replaced with size of .glink.
4588 0, // Augmentation size.
4589 elfcpp::DW_CFA_advance_loc
+ 2,
4590 elfcpp::DW_CFA_register
, 65, 0,
4591 elfcpp::DW_CFA_advance_loc
+ 4,
4592 elfcpp::DW_CFA_restore_extended
, 65
4595 static const unsigned char default_fde
[] =
4597 0, 0, 0, 0, // Replaced with offset to stubs.
4598 0, 0, 0, 0, // Replaced with size of stubs.
4599 0, // Augmentation size.
4600 elfcpp::DW_CFA_nop
, // Pad.
4605 template<bool big_endian
>
4607 write_insn(unsigned char* p
, uint32_t v
)
4609 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4613 static inline unsigned int
4616 if (!parameters
->options().user_set_plt_align())
4617 return size
== 64 ? 32 : 8;
4618 return 1 << parameters
->options().plt_align();
4621 // Stub_table holds information about plt and long branch stubs.
4622 // Stubs are built in an area following some input section determined
4623 // by group_sections(). This input section is converted to a relaxed
4624 // input section allowing it to be resized to accommodate the stubs
4626 template<int size
, bool big_endian
>
4627 class Stub_table
: public Output_relaxed_input_section
4632 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4633 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4634 r2save_(0), localentry0_(0), tocoff_(0)
4639 unsigned int iter_
: 1;
4640 unsigned int notoc_
: 1;
4641 unsigned int toc_
: 1;
4642 unsigned int r2save_
: 1;
4643 unsigned int localentry0_
: 1;
4644 unsigned int tocoff_
: 8;
4646 struct Branch_stub_ent
4648 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4649 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4654 unsigned int iter_
: 1;
4655 unsigned int notoc_
: 1;
4656 unsigned int toc_
: 1;
4657 unsigned int save_res_
: 1;
4658 unsigned int tocoff_
: 8;
4660 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4661 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4663 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4664 Output_section
* output_section
,
4665 const Output_section::Input_section
* owner
,
4667 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4669 ->section_addralign(owner
->shndx())),
4670 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4671 orig_data_size_(owner
->current_data_size()),
4672 plt_size_(0), last_plt_size_(0),
4673 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4674 need_save_res_(false), need_resize_(false), resizing_(false),
4677 this->set_output_section(output_section
);
4679 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4680 new_relaxed
.push_back(this);
4681 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4684 // Add a plt call stub.
4686 add_plt_call_entry(Address
,
4687 const Sized_relobj_file
<size
, big_endian
>*,
4694 add_plt_call_entry(Address
,
4695 const Sized_relobj_file
<size
, big_endian
>*,
4701 // Find a given plt call stub.
4703 find_plt_call_entry(const Symbol
*) const;
4706 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4707 unsigned int) const;
4710 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4716 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4721 // Add a long branch stub.
4723 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4724 unsigned int, Address
, Address
, bool);
4726 const Branch_stub_ent
*
4727 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4731 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4733 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4734 if (max_branch_offset
== 0)
4736 gold_assert(from
!= invalid_address
);
4737 Address loc
= off
+ this->stub_address();
4738 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4742 clear_stubs(bool all
)
4744 this->plt_call_stubs_
.clear();
4745 this->plt_size_
= 0;
4746 this->long_branch_stubs_
.clear();
4747 this->branch_size_
= 0;
4748 this->need_save_res_
= false;
4751 this->last_plt_size_
= 0;
4752 this->last_branch_size_
= 0;
4758 { return need_resize_
; }
4761 set_resizing(bool val
)
4763 this->resizing_
= val
;
4766 this->need_resize_
= false;
4767 this->plt_size_
= 0;
4768 this->branch_size_
= 0;
4769 this->need_save_res_
= false;
4774 set_address_and_size(const Output_section
* os
, Address off
)
4776 Address start_off
= off
;
4777 off
+= this->orig_data_size_
;
4778 Address my_size
= this->plt_size_
+ this->branch_size_
;
4779 if (this->need_save_res_
)
4780 my_size
+= this->targ_
->savres_section()->data_size();
4782 off
= align_address(off
, this->stub_align());
4783 // Include original section size and alignment padding in size
4784 my_size
+= off
- start_off
;
4785 // Ensure new size is always larger than min size
4786 // threshold. Alignment requirement is included in "my_size", so
4787 // increase "my_size" does not invalidate alignment.
4788 if (my_size
< this->min_size_threshold_
)
4789 my_size
= this->min_size_threshold_
;
4790 this->reset_address_and_file_offset();
4791 this->set_current_data_size(my_size
);
4792 this->set_address_and_file_offset(os
->address() + start_off
,
4793 os
->offset() + start_off
);
4798 stub_address() const
4800 return align_address(this->address() + this->orig_data_size_
,
4801 this->stub_align());
4807 return align_address(this->offset() + this->orig_data_size_
,
4808 this->stub_align());
4813 { return this->plt_size_
; }
4817 { return this->branch_size_
; }
4820 set_min_size_threshold(Address min_size
)
4821 { this->min_size_threshold_
= min_size
; }
4824 define_stub_syms(Symbol_table
*);
4829 Output_section
* os
= this->output_section();
4830 if (os
->addralign() < this->stub_align())
4832 os
->set_addralign(this->stub_align());
4833 // FIXME: get rid of the insane checkpointing.
4834 // We can't increase alignment of the input section to which
4835 // stubs are attached; The input section may be .init which
4836 // is pasted together with other .init sections to form a
4837 // function. Aligning might insert zero padding resulting in
4838 // sigill. However we do need to increase alignment of the
4839 // output section so that the align_address() on offset in
4840 // set_address_and_size() adds the same padding as the
4841 // align_address() on address in stub_address().
4842 // What's more, we need this alignment for the layout done in
4843 // relaxation_loop_body() so that the output section starts at
4844 // a suitably aligned address.
4845 os
->checkpoint_set_addralign(this->stub_align());
4847 if (this->last_plt_size_
!= this->plt_size_
4848 || this->last_branch_size_
!= this->branch_size_
)
4850 this->last_plt_size_
= this->plt_size_
;
4851 this->last_branch_size_
= this->branch_size_
;
4857 // Add .eh_frame info for this stub section.
4859 add_eh_frame(Layout
* layout
);
4861 // Remove .eh_frame info for this stub section.
4863 remove_eh_frame(Layout
* layout
);
4865 Target_powerpc
<size
, big_endian
>*
4871 class Plt_stub_key_hash
;
4872 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4873 Plt_stub_key_hash
> Plt_stub_entries
;
4874 class Branch_stub_key
;
4875 class Branch_stub_key_hash
;
4876 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4877 Branch_stub_key_hash
> Branch_stub_entries
;
4879 // Alignment of stub section.
4883 unsigned int min_align
= size
== 64 ? 32 : 16;
4884 unsigned int user_align
= 1 << parameters
->options().plt_align();
4885 return std::max(user_align
, min_align
);
4888 // Return the plt offset for the given call stub.
4890 plt_off(typename
Plt_stub_entries::const_iterator p
,
4891 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4893 const Symbol
* gsym
= p
->first
.sym_
;
4895 return this->targ_
->plt_off(gsym
, sec
);
4898 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4899 unsigned int local_sym_index
= p
->first
.locsym_
;
4900 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4904 // Size of a given plt call stub.
4906 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4909 plt_call_align(unsigned int bytes
) const
4911 unsigned int align
= param_plt_align
<size
>();
4912 return (bytes
+ align
- 1) & -align
;
4915 // Return long branch stub size.
4917 branch_stub_size(typename
Branch_stub_entries::iterator p
,
4921 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
4924 build_tls_opt_tail(unsigned char* p
);
4927 plt_error(const Plt_stub_key
& p
);
4931 do_write(Output_file
*);
4933 // Plt call stub keys.
4937 Plt_stub_key(const Symbol
* sym
)
4938 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4941 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4942 unsigned int locsym_index
)
4943 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4946 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4948 unsigned int r_type
,
4950 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4953 this->addend_
= addend
;
4954 else if (parameters
->options().output_is_position_independent()
4955 && (r_type
== elfcpp::R_PPC_PLTREL24
4956 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4958 this->addend_
= addend
;
4959 if (this->addend_
>= 32768)
4960 this->object_
= object
;
4964 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4965 unsigned int locsym_index
,
4966 unsigned int r_type
,
4968 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4971 this->addend_
= addend
;
4972 else if (parameters
->options().output_is_position_independent()
4973 && (r_type
== elfcpp::R_PPC_PLTREL24
4974 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4975 this->addend_
= addend
;
4978 bool operator==(const Plt_stub_key
& that
) const
4980 return (this->sym_
== that
.sym_
4981 && this->object_
== that
.object_
4982 && this->addend_
== that
.addend_
4983 && this->locsym_
== that
.locsym_
);
4987 const Sized_relobj_file
<size
, big_endian
>* object_
;
4988 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4989 unsigned int locsym_
;
4992 class Plt_stub_key_hash
4995 size_t operator()(const Plt_stub_key
& ent
) const
4997 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
4998 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5004 // Long branch stub keys.
5005 class Branch_stub_key
5008 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
5009 : dest_(to
), toc_base_off_(0)
5012 toc_base_off_
= obj
->toc_base_offset();
5015 bool operator==(const Branch_stub_key
& that
) const
5017 return (this->dest_
== that
.dest_
5019 || this->toc_base_off_
== that
.toc_base_off_
));
5023 unsigned int toc_base_off_
;
5026 class Branch_stub_key_hash
5029 size_t operator()(const Branch_stub_key
& key
) const
5030 { return key
.dest_
^ key
.toc_base_off_
; }
5033 // In a sane world this would be a global.
5034 Target_powerpc
<size
, big_endian
>* targ_
;
5035 // Map sym/object/addend to stub offset.
5036 Plt_stub_entries plt_call_stubs_
;
5037 // Map destination address to stub offset.
5038 Branch_stub_entries long_branch_stubs_
;
5039 // size of input section
5040 section_size_type orig_data_size_
;
5042 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5043 // Some rare cases cause (PR/20529) fluctuation in stub table
5044 // size, which leads to an endless relax loop. This is to be fixed
5045 // by, after the first few iterations, allowing only increase of
5046 // stub table size. This variable sets the minimal possible size of
5047 // a stub table, it is zero for the first few iterations, then
5048 // increases monotonically.
5049 Address min_size_threshold_
;
5050 // Set if this stub group needs a copy of out-of-line register
5051 // save/restore functions.
5052 bool need_save_res_
;
5053 // Set when notoc_/r2save_ changes after sizing a stub
5055 // Set when resizing stubs
5057 // Per stub table unique identifier.
5061 // Add a plt call stub, if we do not already have one for this
5062 // sym/object/addend combo.
5064 template<int size
, bool big_endian
>
5066 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5068 const Sized_relobj_file
<size
, big_endian
>* object
,
5070 unsigned int r_type
,
5074 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5075 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5076 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5077 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5081 && this->targ_
->is_elfv2_localentry0(gsym
))
5083 p
.first
->second
.localentry0_
= 1;
5084 this->targ_
->set_has_localentry0();
5086 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5088 if (!p
.second
&& !p
.first
->second
.notoc_
5089 && (!this->targ_
->power10_stubs()
5090 || this->targ_
->power10_stubs_auto()))
5091 this->need_resize_
= true;
5092 p
.first
->second
.notoc_
= 1;
5096 if (!p
.second
&& !p
.first
->second
.toc_
)
5097 this->need_resize_
= true;
5098 p
.first
->second
.toc_
= 1;
5099 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5101 if (!p
.second
&& !p
.first
->second
.r2save_
)
5102 this->need_resize_
= true;
5103 p
.first
->second
.r2save_
= 1;
5107 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5109 if (this->resizing_
)
5111 p
.first
->second
.iter_
= 1;
5112 p
.first
->second
.off_
= this->plt_size_
;
5114 this->plt_size_
+= this->plt_call_size(p
.first
);
5115 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5116 this->targ_
->set_has_tls_get_addr_opt();
5117 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5119 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5122 template<int size
, bool big_endian
>
5124 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5126 const Sized_relobj_file
<size
, big_endian
>* object
,
5127 unsigned int locsym_index
,
5128 unsigned int r_type
,
5132 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5133 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5134 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5135 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5139 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5141 p
.first
->second
.localentry0_
= 1;
5142 this->targ_
->set_has_localentry0();
5144 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5146 if (!p
.second
&& !p
.first
->second
.notoc_
5147 && (!this->targ_
->power10_stubs()
5148 || this->targ_
->power10_stubs_auto()))
5149 this->need_resize_
= true;
5150 p
.first
->second
.notoc_
= 1;
5154 if (!p
.second
&& !p
.first
->second
.toc_
)
5155 this->need_resize_
= true;
5156 p
.first
->second
.toc_
= 1;
5157 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5159 if (!p
.second
&& !p
.first
->second
.r2save_
)
5160 this->need_resize_
= true;
5161 p
.first
->second
.r2save_
= 1;
5165 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5167 if (this->resizing_
)
5169 p
.first
->second
.iter_
= 1;
5170 p
.first
->second
.off_
= this->plt_size_
;
5172 this->plt_size_
+= this->plt_call_size(p
.first
);
5173 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5175 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5178 // Find a plt call stub.
5180 template<int size
, bool big_endian
>
5181 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5182 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5183 const Sized_relobj_file
<size
, big_endian
>* object
,
5185 unsigned int r_type
,
5186 Address addend
) const
5188 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5189 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5190 if (p
== this->plt_call_stubs_
.end())
5195 template<int size
, bool big_endian
>
5196 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5197 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5199 Plt_stub_key
key(gsym
);
5200 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5201 if (p
== this->plt_call_stubs_
.end())
5206 template<int size
, bool big_endian
>
5207 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5208 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5209 const Sized_relobj_file
<size
, big_endian
>* object
,
5210 unsigned int locsym_index
,
5211 unsigned int r_type
,
5212 Address addend
) const
5214 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5215 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5216 if (p
== this->plt_call_stubs_
.end())
5221 template<int size
, bool big_endian
>
5222 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5223 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5224 const Sized_relobj_file
<size
, big_endian
>* object
,
5225 unsigned int locsym_index
) const
5227 Plt_stub_key
key(object
, locsym_index
);
5228 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5229 if (p
== this->plt_call_stubs_
.end())
5234 // Add a long branch stub if we don't already have one to given
5237 template<int size
, bool big_endian
>
5239 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5240 const Powerpc_relobj
<size
, big_endian
>* object
,
5241 unsigned int r_type
,
5246 Branch_stub_key
key(object
, to
);
5247 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5248 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5249 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5250 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5253 if (!p
.second
&& !p
.first
->second
.notoc_
)
5254 this->need_resize_
= true;
5255 p
.first
->second
.notoc_
= true;
5259 if (!p
.second
&& !p
.first
->second
.toc_
)
5260 this->need_resize_
= true;
5261 p
.first
->second
.toc_
= true;
5263 gold_assert(save_res
== p
.first
->second
.save_res_
);
5264 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5266 if (this->resizing_
)
5268 p
.first
->second
.iter_
= 1;
5269 p
.first
->second
.off_
= this->branch_size_
;
5272 this->need_save_res_
= true;
5275 bool need_lt
= false;
5276 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5277 this->branch_size_
+= stub_size
;
5278 if (size
== 64 && need_lt
)
5279 this->targ_
->add_branch_lookup_table(to
);
5282 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5285 // Find long branch stub offset.
5287 template<int size
, bool big_endian
>
5288 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5289 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5290 const Powerpc_relobj
<size
, big_endian
>* object
,
5293 Branch_stub_key
key(object
, to
);
5294 typename
Branch_stub_entries::const_iterator p
5295 = this->long_branch_stubs_
.find(key
);
5296 if (p
== this->long_branch_stubs_
.end())
5301 template<bool big_endian
>
5303 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5307 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5308 else if (delta
< 256)
5310 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5311 fde
.push_back(delta
);
5313 else if (delta
< 65536)
5315 fde
.resize(fde
.size() + 3);
5316 unsigned char *p
= &*fde
.end() - 3;
5317 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5318 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5322 fde
.resize(fde
.size() + 5);
5323 unsigned char *p
= &*fde
.end() - 5;
5324 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5325 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5329 template<typename T
>
5331 stub_sort(T s1
, T s2
)
5333 return s1
->second
.off_
< s2
->second
.off_
;
5336 // Add .eh_frame info for this stub section. Unlike other linker
5337 // generated .eh_frame this is added late in the link, because we
5338 // only want the .eh_frame info if this particular stub section is
5341 template<int size
, bool big_endian
>
5343 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5346 || !parameters
->options().ld_generated_unwind_info())
5349 // Since we add stub .eh_frame info late, it must be placed
5350 // after all other linker generated .eh_frame info so that
5351 // merge mapping need not be updated for input sections.
5352 // There is no provision to use a different CIE to that used
5354 if (!this->targ_
->has_glink())
5357 typedef typename
Plt_stub_entries::iterator plt_iter
;
5358 std::vector
<plt_iter
> calls
;
5359 if (!this->plt_call_stubs_
.empty())
5360 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5361 cs
!= this->plt_call_stubs_
.end();
5363 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5364 && cs
->second
.r2save_
5365 && !cs
->second
.localentry0_
)
5366 || (cs
->second
.notoc_
5367 && !this->targ_
->power10_stubs()))
5368 calls
.push_back(cs
);
5369 if (calls
.size() > 1)
5370 std::stable_sort(calls
.begin(), calls
.end(),
5371 stub_sort
<plt_iter
>);
5373 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5374 std::vector
<branch_iter
> branches
;
5375 if (!this->long_branch_stubs_
.empty()
5376 && !this->targ_
->power10_stubs())
5377 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5378 bs
!= this->long_branch_stubs_
.end();
5380 if (bs
->second
.notoc_
)
5381 branches
.push_back(bs
);
5382 if (branches
.size() > 1)
5383 std::stable_sort(branches
.begin(), branches
.end(),
5384 stub_sort
<branch_iter
>);
5386 if (calls
.empty() && branches
.empty())
5389 unsigned int last_eh_loc
= 0;
5390 // offset pcrel sdata4, size udata4, and augmentation size byte.
5391 std::vector
<unsigned char> fde(9, 0);
5393 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5395 plt_iter cs
= calls
[i
];
5396 unsigned int off
= cs
->second
.off_
;
5397 // The __tls_get_addr_opt call stub needs to describe where
5398 // it saves LR, to support exceptions that might be thrown
5399 // from __tls_get_addr, and to support asynchronous exceptions.
5400 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5403 if (cs
->second
.r2save_
5404 && !cs
->second
.localentry0_
)
5407 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5408 fde
.resize(fde
.size() + 6);
5409 unsigned char* p
= &*fde
.end() - 6;
5410 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5412 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5413 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5414 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5415 *p
++ = elfcpp::DW_CFA_restore_extended
;
5417 last_eh_loc
= off
+ delta
;
5421 // notoc stubs also should describe LR changes, to support
5422 // asynchronous exceptions.
5423 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5424 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5425 fde
.resize(fde
.size() + 6);
5426 unsigned char* p
= &*fde
.end() - 6;
5427 *p
++ = elfcpp::DW_CFA_register
;
5430 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5431 *p
++ = elfcpp::DW_CFA_restore_extended
;
5433 last_eh_loc
= off
+ 8;
5436 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5438 branch_iter bs
= branches
[i
];
5439 unsigned int off
= bs
->second
.off_
+ 8;
5440 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5441 fde
.resize(fde
.size() + 6);
5442 unsigned char* p
= &*fde
.end() - 6;
5443 *p
++ = elfcpp::DW_CFA_register
;
5446 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5447 *p
++ = elfcpp::DW_CFA_restore_extended
;
5449 last_eh_loc
= off
+ 8;
5452 layout
->add_eh_frame_for_plt(this,
5453 Eh_cie
<size
>::eh_frame_cie
,
5454 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5455 &*fde
.begin(), fde
.size());
5458 template<int size
, bool big_endian
>
5460 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5463 && parameters
->options().ld_generated_unwind_info()
5464 && this->targ_
->has_glink())
5465 layout
->remove_eh_frame_for_plt(this,
5466 Eh_cie
<size
>::eh_frame_cie
,
5467 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5470 // A class to handle .glink.
5472 template<int size
, bool big_endian
>
5473 class Output_data_glink
: public Output_section_data
5476 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5477 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5479 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5480 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5481 end_branch_table_(), ge_size_(0)
5485 add_eh_frame(Layout
* layout
);
5488 add_global_entry(const Symbol
*);
5491 find_global_entry(const Symbol
*) const;
5494 global_entry_align(unsigned int off
) const
5496 unsigned int align
= param_plt_align
<size
>();
5497 return (off
+ align
- 1) & -align
;
5501 global_entry_off() const
5503 return this->global_entry_align(this->end_branch_table_
);
5507 global_entry_address() const
5509 gold_assert(this->is_data_size_valid());
5510 return this->address() + this->global_entry_off();
5514 pltresolve_size() const
5518 + (this->targ_
->abiversion() < 2 ? 11 * 4 : 14 * 4));
5523 // Write to a map file.
5525 do_print_to_mapfile(Mapfile
* mapfile
) const
5526 { mapfile
->print_output_data(this, _("** glink")); }
5530 set_final_data_size();
5534 do_write(Output_file
*);
5536 // Allows access to .got and .plt for do_write.
5537 Target_powerpc
<size
, big_endian
>* targ_
;
5539 // Map sym to stub offset.
5540 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5541 Global_entry_stub_entries global_entry_stubs_
;
5543 unsigned int end_branch_table_
, ge_size_
;
5546 template<int size
, bool big_endian
>
5548 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5550 if (!parameters
->options().ld_generated_unwind_info())
5555 if (this->targ_
->abiversion() < 2)
5556 layout
->add_eh_frame_for_plt(this,
5557 Eh_cie
<64>::eh_frame_cie
,
5558 sizeof (Eh_cie
<64>::eh_frame_cie
),
5559 glink_eh_frame_fde_64v1
,
5560 sizeof (glink_eh_frame_fde_64v1
));
5562 layout
->add_eh_frame_for_plt(this,
5563 Eh_cie
<64>::eh_frame_cie
,
5564 sizeof (Eh_cie
<64>::eh_frame_cie
),
5565 glink_eh_frame_fde_64v2
,
5566 sizeof (glink_eh_frame_fde_64v2
));
5570 // 32-bit .glink can use the default since the CIE return
5571 // address reg, LR, is valid.
5572 layout
->add_eh_frame_for_plt(this,
5573 Eh_cie
<32>::eh_frame_cie
,
5574 sizeof (Eh_cie
<32>::eh_frame_cie
),
5576 sizeof (default_fde
));
5577 // Except where LR is used in a PIC __glink_PLTresolve.
5578 if (parameters
->options().output_is_position_independent())
5579 layout
->add_eh_frame_for_plt(this,
5580 Eh_cie
<32>::eh_frame_cie
,
5581 sizeof (Eh_cie
<32>::eh_frame_cie
),
5582 glink_eh_frame_fde_32
,
5583 sizeof (glink_eh_frame_fde_32
));
5587 template<int size
, bool big_endian
>
5589 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5591 unsigned int off
= this->global_entry_align(this->ge_size_
);
5592 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5593 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5595 this->ge_size_
= off
+ 16;
5598 template<int size
, bool big_endian
>
5599 typename Output_data_glink
<size
, big_endian
>::Address
5600 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5602 typename
Global_entry_stub_entries::const_iterator p
5603 = this->global_entry_stubs_
.find(gsym
);
5604 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5607 template<int size
, bool big_endian
>
5609 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5611 unsigned int count
= this->targ_
->plt_entry_count();
5612 section_size_type total
= 0;
5618 // space for branch table
5619 total
+= 4 * (count
- 1);
5621 total
+= -total
& 15;
5622 total
+= this->pltresolve_size();
5626 total
+= this->pltresolve_size();
5628 // space for branch table
5630 if (this->targ_
->abiversion() < 2)
5634 total
+= 4 * (count
- 0x8000);
5638 this->end_branch_table_
= total
;
5639 total
= this->global_entry_align(total
);
5640 total
+= this->ge_size_
;
5642 this->set_data_size(total
);
5645 // Define symbols on stubs, identifying the stub.
5647 template<int size
, bool big_endian
>
5649 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5651 if (!this->plt_call_stubs_
.empty())
5653 // The key for the plt call stub hash table includes addresses,
5654 // therefore traversal order depends on those addresses, which
5655 // can change between runs if gold is a PIE. Unfortunately the
5656 // output .symtab ordering depends on the order in which symbols
5657 // are added to the linker symtab. We want reproducible output
5658 // so must sort the call stub symbols.
5659 typedef typename
Plt_stub_entries::iterator plt_iter
;
5660 std::vector
<plt_iter
> sorted
;
5661 sorted
.resize(this->plt_call_stubs_
.size());
5663 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5664 cs
!= this->plt_call_stubs_
.end();
5666 sorted
[cs
->second
.indx_
] = cs
;
5668 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5670 plt_iter cs
= sorted
[i
];
5673 if (cs
->first
.addend_
!= 0)
5674 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5677 if (cs
->first
.object_
)
5679 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5680 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5681 sprintf(obj
, "%x:", ppcobj
->uniq());
5684 const char *symname
;
5685 if (cs
->first
.sym_
== NULL
)
5687 sprintf(localname
, "%x", cs
->first
.locsym_
);
5688 symname
= localname
;
5690 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5691 symname
= this->targ_
->tls_get_addr_opt()->name();
5693 symname
= cs
->first
.sym_
->name();
5694 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5695 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5697 = this->stub_address() - this->address() + cs
->second
.off_
;
5698 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5699 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5703 typedef typename
Branch_stub_entries::iterator branch_iter
;
5704 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5705 bs
!= this->long_branch_stubs_
.end();
5708 if (bs
->second
.save_res_
)
5711 char* name
= new char[8 + 13 + 16 + 1];
5712 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5713 static_cast<unsigned long long>(bs
->first
.dest_
));
5714 Address value
= (this->stub_address() - this->address()
5715 + this->plt_size_
+ bs
->second
.off_
);
5716 bool need_lt
= false;
5717 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5718 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5722 // Emit the start of a __tls_get_addr_opt plt call stub.
5724 template<int size
, bool big_endian
>
5726 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5729 unsigned char* p
= *pp
;
5732 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5734 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5736 write_insn
<big_endian
>(p
, mr_0_3
);
5738 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5740 write_insn
<big_endian
>(p
, add_3_12_13
);
5742 write_insn
<big_endian
>(p
, beqlr
);
5744 write_insn
<big_endian
>(p
, mr_3_0
);
5748 write_insn
<big_endian
>(p
, mflr_11
);
5750 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5756 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5758 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5760 write_insn
<big_endian
>(p
, mr_0_3
);
5762 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5764 write_insn
<big_endian
>(p
, add_3_12_2
);
5766 write_insn
<big_endian
>(p
, beqlr
);
5768 write_insn
<big_endian
>(p
, mr_3_0
);
5770 write_insn
<big_endian
>(p
, nop
);
5776 // Emit the tail of a __tls_get_addr_opt plt call stub.
5778 template<int size
, bool big_endian
>
5780 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5782 write_insn
<big_endian
>(p
, bctrl
);
5784 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5786 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5788 write_insn
<big_endian
>(p
, mtlr_11
);
5790 write_insn
<big_endian
>(p
, blr
);
5793 // Emit pc-relative plt call stub code.
5795 template<bool big_endian
>
5796 static unsigned char*
5797 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5800 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5805 write_insn
<big_endian
>(p
, nop
);
5813 write_insn
<big_endian
>(p
, insn
>> 32);
5815 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5817 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5820 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5824 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5827 insn
= paddi_12_pc
| d34(off
);
5828 write_insn
<big_endian
>(p
, insn
>> 32);
5830 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5834 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5838 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5840 write_insn
<big_endian
>(p
, add_12_11_12
);
5845 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5847 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5851 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5854 insn
= paddi_12_pc
| d34(off
);
5855 write_insn
<big_endian
>(p
, insn
>> 32);
5857 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5861 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5865 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5867 write_insn
<big_endian
>(p
, add_12_11_12
);
5873 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5874 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5879 // lis %r12,xxx-1b@highest
5880 // ori %r12,%r12,xxx-1b@higher
5881 // sldi %r12,%r12,32
5882 // oris %r12,%r12,xxx-1b@high
5883 // ori %r12,%r12,xxx-1b@l
5884 // add/ldx %r12,%r11,%r12
5886 template<bool big_endian
>
5887 static unsigned char*
5888 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5890 write_insn
<big_endian
>(p
, mflr_12
);
5892 write_insn
<big_endian
>(p
, bcl_20_31
);
5894 write_insn
<big_endian
>(p
, mflr_11
);
5896 write_insn
<big_endian
>(p
, mtlr_12
);
5898 if (off
+ 0x8000 < 0x10000)
5901 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5903 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5905 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5907 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5910 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5912 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5916 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5918 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5923 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5925 if (((off
>> 32) & 0xffff) != 0)
5927 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5931 if (((off
>> 32) & 0xffffffffULL
) != 0)
5933 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5938 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5943 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5947 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5949 write_insn
<big_endian
>(p
, add_12_11_12
);
5955 // Size of a given plt call stub.
5957 template<int size
, bool big_endian
>
5959 Stub_table
<size
, big_endian
>::plt_call_size(
5960 typename
Plt_stub_entries::iterator p
) const
5964 const Symbol
* gsym
= p
->first
.sym_
;
5966 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
5969 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5970 uint64_t plt_addr
= this->plt_off(p
, &plt
);
5971 plt_addr
+= plt
->address();
5972 if (this->targ_
->power10_stubs()
5973 && this->targ_
->power10_stubs_auto())
5975 unsigned int bytes
= 0;
5976 if (p
->second
.notoc_
)
5978 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
5980 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
5981 uint64_t odd
= from
& 4;
5982 uint64_t off
= plt_addr
- from
;
5983 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5984 bytes
+= odd
+ 4 * 4;
5985 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5989 bytes
= this->plt_call_align(bytes
);
5991 unsigned int tail
= 0;
5994 p
->second
.tocoff_
= bytes
;
5995 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
5998 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6004 if (p
->second
.r2save_
)
6007 = this->targ_
->got_section()->output_section()->address();
6008 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6009 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6010 got_addr
+= ppcobj
->toc_base_offset();
6011 uint64_t off
= plt_addr
- got_addr
;
6012 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6014 return bytes
+ tail
;
6018 unsigned int bytes
= 0;
6019 unsigned int tail
= 0;
6020 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6023 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6030 if (p
->second
.r2save_
)
6033 if (this->targ_
->power10_stubs())
6035 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6036 uint64_t odd
= from
& 4;
6037 uint64_t off
= plt_addr
- from
;
6038 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6039 bytes
+= odd
+ 4 * 4;
6040 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6044 return bytes
+ tail
;
6047 if (p
->second
.notoc_
)
6049 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6050 uint64_t off
= plt_addr
- from
;
6051 if (off
+ 0x8000 < 0x10000)
6053 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6058 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6059 && ((off
>> 32) & 0xffff) != 0)
6061 if (((off
>> 32) & 0xffffffffULL
) != 0)
6068 return bytes
+ tail
;
6071 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6072 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6073 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6074 got_addr
+= ppcobj
->toc_base_offset();
6075 uint64_t off
= plt_addr
- got_addr
;
6076 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6077 if (this->targ_
->abiversion() < 2)
6079 bool static_chain
= parameters
->options().plt_static_chain();
6080 bool thread_safe
= this->targ_
->plt_thread_safe();
6084 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6086 return bytes
+ tail
;
6090 // Return long branch stub size.
6092 template<int size
, bool big_endian
>
6094 Stub_table
<size
, big_endian
>::branch_stub_size(
6095 typename
Branch_stub_entries::iterator p
,
6098 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6101 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6103 if (parameters
->options().output_is_position_independent())
6108 uint64_t off
= p
->first
.dest_
- loc
;
6109 unsigned int bytes
= 0;
6110 if (p
->second
.notoc_
)
6112 if (this->targ_
->power10_stubs())
6114 Address odd
= loc
& 4;
6115 if (off
+ (1 << 25) < 2 << 25)
6117 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6119 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6123 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6125 p
->second
.tocoff_
= bytes
;
6130 if (off
+ 0x8000 < 0x10000)
6132 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6134 if (off
+ 24 + (1 << 25) < 2 << 25)
6140 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6141 && ((off
>> 32) & 0xffff) != 0)
6143 if (((off
>> 32) & 0xffffffffULL
) != 0)
6153 if (off
+ (1 << 25) < 2 << 25)
6155 if (!this->targ_
->power10_stubs()
6156 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6161 template<int size
, bool big_endian
>
6163 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6166 gold_error(_("linkage table error against `%s'"),
6167 p
.sym_
->demangled_name().c_str());
6169 gold_error(_("linkage table error against `%s:[local %u]'"),
6170 p
.object_
->name().c_str(),
6174 // Write out plt and long branch stub code.
6176 template<int size
, bool big_endian
>
6178 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6180 if (this->plt_call_stubs_
.empty()
6181 && this->long_branch_stubs_
.empty())
6184 const section_size_type start_off
= this->offset();
6185 const section_size_type off
= this->stub_offset();
6186 const section_size_type oview_size
=
6187 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6188 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6192 && this->targ_
->power10_stubs())
6194 const Output_data_got_powerpc
<size
, big_endian
>* got
6195 = this->targ_
->got_section();
6196 Address got_os_addr
= got
->output_section()->address();
6198 if (!this->plt_call_stubs_
.empty())
6200 // Write out plt call stubs.
6201 typename
Plt_stub_entries::const_iterator cs
;
6202 for (cs
= this->plt_call_stubs_
.begin();
6203 cs
!= this->plt_call_stubs_
.end();
6206 p
= oview
+ cs
->second
.off_
;
6207 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6208 Address pltoff
= this->plt_off(cs
, &plt
);
6209 Address plt_addr
= pltoff
+ plt
->address();
6210 if (this->targ_
->power10_stubs_auto())
6212 if (cs
->second
.notoc_
)
6214 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6215 this->build_tls_opt_head(&p
, false);
6216 Address from
= this->stub_address() + (p
- oview
);
6217 Address delta
= plt_addr
- from
;
6218 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6220 write_insn
<big_endian
>(p
, mtctr_12
);
6222 write_insn
<big_endian
>(p
, bctr
);
6224 p
= oview
+ this->plt_call_align(p
- oview
);
6226 if (cs
->second
.toc_
)
6228 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6231 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6232 this->build_tls_opt_head(&p
, save_lr
);
6234 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6235 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(
6237 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6238 Address off
= plt_addr
- got_addr
;
6240 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6241 this->plt_error(cs
->first
);
6243 if (cs
->second
.r2save_
)
6245 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6250 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6252 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6257 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6260 write_insn
<big_endian
>(p
, mtctr_12
);
6262 if (cs
->second
.r2save_
6263 && !cs
->second
.localentry0_
6264 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6265 this->build_tls_opt_tail(p
);
6267 write_insn
<big_endian
>(p
, bctr
);
6272 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6275 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6276 this->build_tls_opt_head(&p
, save_lr
);
6278 if (cs
->second
.r2save_
)
6280 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6283 Address from
= this->stub_address() + (p
- oview
);
6284 Address delta
= plt_addr
- from
;
6285 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6286 write_insn
<big_endian
>(p
, mtctr_12
);
6288 if (cs
->second
.r2save_
6289 && !cs
->second
.localentry0_
6290 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6291 this->build_tls_opt_tail(p
);
6293 write_insn
<big_endian
>(p
, bctr
);
6298 // Write out long branch stubs.
6299 typename
Branch_stub_entries::const_iterator bs
;
6300 for (bs
= this->long_branch_stubs_
.begin();
6301 bs
!= this->long_branch_stubs_
.end();
6304 if (bs
->second
.save_res_
)
6306 Address off
= this->plt_size_
+ bs
->second
.off_
;
6308 Address loc
= this->stub_address() + off
;
6309 Address delta
= bs
->first
.dest_
- loc
;
6310 if (this->targ_
->power10_stubs_auto())
6312 if (bs
->second
.notoc_
)
6314 unsigned char* startp
= p
;
6315 p
= build_power10_offset
<big_endian
>(p
, delta
,
6317 delta
-= p
- startp
;
6319 if (delta
+ (1 << 25) < 2 << 25)
6320 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6323 write_insn
<big_endian
>(p
, mtctr_12
);
6325 write_insn
<big_endian
>(p
, bctr
);
6328 delta
-= p
- startp
;
6330 if (bs
->second
.toc_
)
6332 if (delta
+ (1 << 25) >= 2 << 25)
6335 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6336 gold_assert(brlt_addr
!= invalid_address
);
6337 brlt_addr
+= this->targ_
->brlt_section()->address();
6338 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6339 Address brltoff
= brlt_addr
- got_addr
;
6340 if (ha(brltoff
) == 0)
6342 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6347 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6349 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6353 if (delta
+ (1 << 25) < 2 << 25)
6354 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6357 write_insn
<big_endian
>(p
, mtctr_12
);
6359 write_insn
<big_endian
>(p
, bctr
);
6365 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
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
);
6383 else if (size
== 64)
6385 const Output_data_got_powerpc
<size
, big_endian
>* got
6386 = this->targ_
->got_section();
6387 Address got_os_addr
= got
->output_section()->address();
6389 if (!this->plt_call_stubs_
.empty()
6390 && this->targ_
->abiversion() >= 2)
6392 // Write out plt call stubs for ELFv2.
6393 typename
Plt_stub_entries::const_iterator cs
;
6394 for (cs
= this->plt_call_stubs_
.begin();
6395 cs
!= this->plt_call_stubs_
.end();
6398 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6399 Address pltoff
= this->plt_off(cs
, &plt
);
6400 Address plt_addr
= pltoff
+ plt
->address();
6402 p
= oview
+ cs
->second
.off_
;
6403 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6405 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6406 this->build_tls_opt_head(&p
, save_lr
);
6408 if (cs
->second
.r2save_
)
6410 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6413 if (cs
->second
.notoc_
)
6415 Address from
= this->stub_address() + (p
- oview
) + 8;
6416 Address off
= plt_addr
- from
;
6417 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6421 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6422 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6423 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6424 Address off
= plt_addr
- got_addr
;
6426 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6427 this->plt_error(cs
->first
);
6431 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6433 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6438 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6442 write_insn
<big_endian
>(p
, mtctr_12
);
6444 if (cs
->second
.r2save_
6445 && !cs
->second
.localentry0_
6446 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6447 this->build_tls_opt_tail(p
);
6449 write_insn
<big_endian
>(p
, bctr
);
6452 else if (!this->plt_call_stubs_
.empty())
6454 // Write out plt call stubs for ELFv1.
6455 typename
Plt_stub_entries::const_iterator cs
;
6456 for (cs
= this->plt_call_stubs_
.begin();
6457 cs
!= this->plt_call_stubs_
.end();
6460 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6461 Address pltoff
= this->plt_off(cs
, &plt
);
6462 Address plt_addr
= pltoff
+ plt
->address();
6463 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6464 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6465 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6466 Address off
= plt_addr
- got_addr
;
6468 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6469 || cs
->second
.notoc_
)
6470 this->plt_error(cs
->first
);
6472 bool static_chain
= parameters
->options().plt_static_chain();
6473 bool thread_safe
= this->targ_
->plt_thread_safe();
6474 bool use_fake_dep
= false;
6475 Address cmp_branch_off
= 0;
6478 unsigned int pltindex
6479 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6480 / this->targ_
->plt_entry_size());
6482 = (this->targ_
->glink_section()->pltresolve_size()
6484 if (pltindex
> 32768)
6485 glinkoff
+= (pltindex
- 32768) * 4;
6487 = this->targ_
->glink_section()->address() + glinkoff
;
6489 = (this->stub_address() + cs
->second
.off_
+ 20
6490 + 4 * cs
->second
.r2save_
6491 + 4 * (ha(off
) != 0)
6492 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6493 + 4 * static_chain
);
6494 cmp_branch_off
= to
- from
;
6495 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6498 p
= oview
+ cs
->second
.off_
;
6499 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6501 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6502 this->build_tls_opt_head(&p
, save_lr
);
6503 use_fake_dep
= thread_safe
;
6505 if (cs
->second
.r2save_
)
6507 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6512 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6514 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6516 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6518 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6522 write_insn
<big_endian
>(p
, mtctr_12
);
6526 write_insn
<big_endian
>(p
, xor_2_12_12
);
6528 write_insn
<big_endian
>(p
, add_11_11_2
);
6531 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6535 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6541 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6543 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6545 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6549 write_insn
<big_endian
>(p
, mtctr_12
);
6553 write_insn
<big_endian
>(p
, xor_11_12_12
);
6555 write_insn
<big_endian
>(p
, add_2_2_11
);
6560 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6563 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6566 if (cs
->second
.r2save_
6567 && !cs
->second
.localentry0_
6568 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6569 this->build_tls_opt_tail(p
);
6570 else if (thread_safe
&& !use_fake_dep
)
6572 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6574 write_insn
<big_endian
>(p
, bnectr_p4
);
6576 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6579 write_insn
<big_endian
>(p
, bctr
);
6583 // Write out long branch stubs.
6584 typename
Branch_stub_entries::const_iterator bs
;
6585 for (bs
= this->long_branch_stubs_
.begin();
6586 bs
!= this->long_branch_stubs_
.end();
6589 if (bs
->second
.save_res_
)
6591 Address off
= this->plt_size_
+ bs
->second
.off_
;
6593 Address loc
= this->stub_address() + off
;
6594 Address delta
= bs
->first
.dest_
- loc
;
6595 if (bs
->second
.notoc_
)
6597 unsigned char* startp
= p
;
6598 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6599 delta
-= p
- startp
;
6601 else if (delta
+ (1 << 25) >= 2 << 25)
6604 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6605 gold_assert(brlt_addr
!= invalid_address
);
6606 brlt_addr
+= this->targ_
->brlt_section()->address();
6607 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6608 Address brltoff
= brlt_addr
- got_addr
;
6609 if (ha(brltoff
) == 0)
6611 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6616 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6618 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6622 if (delta
+ (1 << 25) < 2 << 25)
6623 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6626 write_insn
<big_endian
>(p
, mtctr_12
);
6628 write_insn
<big_endian
>(p
, bctr
);
6634 if (!this->plt_call_stubs_
.empty())
6636 // The address of _GLOBAL_OFFSET_TABLE_.
6637 Address g_o_t
= invalid_address
;
6639 // Write out plt call stubs.
6640 typename
Plt_stub_entries::const_iterator cs
;
6641 for (cs
= this->plt_call_stubs_
.begin();
6642 cs
!= this->plt_call_stubs_
.end();
6645 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6646 Address plt_addr
= this->plt_off(cs
, &plt
);
6647 plt_addr
+= plt
->address();
6649 p
= oview
+ cs
->second
.off_
;
6650 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6651 this->build_tls_opt_head(&p
, false);
6652 if (parameters
->options().output_is_position_independent())
6655 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6656 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6657 (cs
->first
.object_
));
6658 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6660 unsigned int got2
= ppcobj
->got2_shndx();
6661 got_addr
= ppcobj
->get_output_section_offset(got2
);
6662 gold_assert(got_addr
!= invalid_address
);
6663 got_addr
+= (ppcobj
->output_section(got2
)->address()
6664 + cs
->first
.addend_
);
6668 if (g_o_t
== invalid_address
)
6670 const Output_data_got_powerpc
<size
, big_endian
>* got
6671 = this->targ_
->got_section();
6672 g_o_t
= got
->address() + got
->g_o_t();
6677 Address off
= plt_addr
- got_addr
;
6679 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6682 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6684 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6689 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6691 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6694 write_insn
<big_endian
>(p
, mtctr_11
);
6696 write_insn
<big_endian
>(p
, bctr
);
6700 // Write out long branch stubs.
6701 typename
Branch_stub_entries::const_iterator bs
;
6702 for (bs
= this->long_branch_stubs_
.begin();
6703 bs
!= this->long_branch_stubs_
.end();
6706 if (bs
->second
.save_res_
)
6708 Address off
= this->plt_size_
+ bs
->second
.off_
;
6710 Address loc
= this->stub_address() + off
;
6711 Address delta
= bs
->first
.dest_
- loc
;
6712 if (delta
+ (1 << 25) < 2 << 25)
6713 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6714 else if (!parameters
->options().output_is_position_independent())
6716 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6718 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6723 write_insn
<big_endian
>(p
, mflr_0
);
6725 write_insn
<big_endian
>(p
, bcl_20_31
);
6727 write_insn
<big_endian
>(p
, mflr_12
);
6729 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6731 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6733 write_insn
<big_endian
>(p
, mtlr_0
);
6736 write_insn
<big_endian
>(p
, mtctr_12
);
6738 write_insn
<big_endian
>(p
, bctr
);
6741 if (this->need_save_res_
)
6743 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6744 memcpy (p
, this->targ_
->savres_section()->contents(),
6745 this->targ_
->savres_section()->data_size());
6749 // Write out .glink.
6751 template<int size
, bool big_endian
>
6753 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6755 const section_size_type off
= this->offset();
6756 const section_size_type oview_size
=
6757 convert_to_section_size_type(this->data_size());
6758 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6761 // The base address of the .plt section.
6762 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6763 Address plt_base
= this->targ_
->plt_section()->address();
6767 if (this->end_branch_table_
!= 0)
6769 // Write pltresolve stub.
6771 Address after_bcl
= this->address() + 16;
6772 Address pltoff
= plt_base
- after_bcl
;
6774 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6776 if (this->targ_
->abiversion() < 2)
6778 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6779 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6780 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6781 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6782 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6783 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6784 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6785 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6786 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6787 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6791 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6792 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6793 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6794 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6795 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6796 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6797 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6798 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6799 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
6800 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6801 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6802 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6803 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6805 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6806 gold_assert(p
== oview
+ this->pltresolve_size());
6808 // Write lazy link call stubs.
6810 while (p
< oview
+ this->end_branch_table_
)
6812 if (this->targ_
->abiversion() < 2)
6816 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6820 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6821 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6824 uint32_t branch_off
= 8 - (p
- oview
);
6825 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6830 Address plt_base
= this->targ_
->plt_section()->address();
6831 Address iplt_base
= invalid_address
;
6832 unsigned int global_entry_off
= this->global_entry_off();
6833 Address global_entry_base
= this->address() + global_entry_off
;
6834 typename
Global_entry_stub_entries::const_iterator ge
;
6835 for (ge
= this->global_entry_stubs_
.begin();
6836 ge
!= this->global_entry_stubs_
.end();
6839 p
= oview
+ global_entry_off
+ ge
->second
;
6840 Address plt_addr
= ge
->first
->plt_offset();
6841 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6842 && ge
->first
->can_use_relative_reloc(false))
6844 if (iplt_base
== invalid_address
)
6845 iplt_base
= this->targ_
->iplt_section()->address();
6846 plt_addr
+= iplt_base
;
6849 plt_addr
+= plt_base
;
6850 Address my_addr
= global_entry_base
+ ge
->second
;
6851 Address off
= plt_addr
- my_addr
;
6853 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6854 gold_error(_("linkage table error against `%s'"),
6855 ge
->first
->demangled_name().c_str());
6857 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6858 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6859 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6860 write_insn
<big_endian
>(p
, bctr
);
6865 const Output_data_got_powerpc
<size
, big_endian
>* got
6866 = this->targ_
->got_section();
6867 // The address of _GLOBAL_OFFSET_TABLE_.
6868 Address g_o_t
= got
->address() + got
->g_o_t();
6870 // Write out pltresolve branch table.
6872 unsigned int the_end
= oview_size
- this->pltresolve_size();
6873 unsigned char* end_p
= oview
+ the_end
;
6874 while (p
< end_p
- 8 * 4)
6875 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6877 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6879 // Write out pltresolve call stub.
6880 end_p
= oview
+ oview_size
;
6881 if (parameters
->options().output_is_position_independent())
6883 Address res0_off
= 0;
6884 Address after_bcl_off
= the_end
+ 12;
6885 Address bcl_res0
= after_bcl_off
- res0_off
;
6887 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6889 write_insn
<big_endian
>(p
, mflr_0
);
6891 write_insn
<big_endian
>(p
, bcl_20_31
);
6893 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6895 write_insn
<big_endian
>(p
, mflr_12
);
6897 write_insn
<big_endian
>(p
, mtlr_0
);
6899 write_insn
<big_endian
>(p
, sub_11_11_12
);
6902 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6904 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6906 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6908 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6910 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6914 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6916 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6919 write_insn
<big_endian
>(p
, mtctr_0
);
6921 write_insn
<big_endian
>(p
, add_0_11_11
);
6923 write_insn
<big_endian
>(p
, add_11_0_11
);
6927 Address res0
= this->address();
6929 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6931 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
6933 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6934 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
6936 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
6938 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
6940 write_insn
<big_endian
>(p
, mtctr_0
);
6942 write_insn
<big_endian
>(p
, add_0_11_11
);
6944 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6945 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
6947 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6949 write_insn
<big_endian
>(p
, add_11_0_11
);
6952 write_insn
<big_endian
>(p
, bctr
);
6956 write_insn
<big_endian
>(p
, nop
);
6961 of
->write_output_view(off
, oview_size
, oview
);
6965 // A class to handle linker generated save/restore functions.
6967 template<int size
, bool big_endian
>
6968 class Output_data_save_res
: public Output_section_data_build
6971 Output_data_save_res(Symbol_table
* symtab
);
6973 const unsigned char*
6980 // Write to a map file.
6982 do_print_to_mapfile(Mapfile
* mapfile
) const
6983 { mapfile
->print_output_data(this, _("** save/restore")); }
6986 do_write(Output_file
*);
6989 // The maximum size of save/restore contents.
6990 static const unsigned int savres_max
= 218*4;
6993 savres_define(Symbol_table
* symtab
,
6995 unsigned int lo
, unsigned int hi
,
6996 unsigned char* write_ent(unsigned char*, int),
6997 unsigned char* write_tail(unsigned char*, int));
6999 unsigned char *contents_
;
7002 template<bool big_endian
>
7003 static unsigned char*
7004 savegpr0(unsigned char* p
, int r
)
7006 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7007 write_insn
<big_endian
>(p
, insn
);
7011 template<bool big_endian
>
7012 static unsigned char*
7013 savegpr0_tail(unsigned char* p
, int r
)
7015 p
= savegpr0
<big_endian
>(p
, r
);
7016 uint32_t insn
= std_0_1
+ 16;
7017 write_insn
<big_endian
>(p
, insn
);
7019 write_insn
<big_endian
>(p
, blr
);
7023 template<bool big_endian
>
7024 static unsigned char*
7025 restgpr0(unsigned char* p
, int r
)
7027 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7028 write_insn
<big_endian
>(p
, insn
);
7032 template<bool big_endian
>
7033 static unsigned char*
7034 restgpr0_tail(unsigned char* p
, int r
)
7036 uint32_t insn
= ld_0_1
+ 16;
7037 write_insn
<big_endian
>(p
, insn
);
7039 p
= restgpr0
<big_endian
>(p
, r
);
7040 write_insn
<big_endian
>(p
, mtlr_0
);
7044 p
= restgpr0
<big_endian
>(p
, 30);
7045 p
= restgpr0
<big_endian
>(p
, 31);
7047 write_insn
<big_endian
>(p
, blr
);
7051 template<bool big_endian
>
7052 static unsigned char*
7053 savegpr1(unsigned char* p
, int r
)
7055 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7056 write_insn
<big_endian
>(p
, insn
);
7060 template<bool big_endian
>
7061 static unsigned char*
7062 savegpr1_tail(unsigned char* p
, int r
)
7064 p
= savegpr1
<big_endian
>(p
, r
);
7065 write_insn
<big_endian
>(p
, blr
);
7069 template<bool big_endian
>
7070 static unsigned char*
7071 restgpr1(unsigned char* p
, int r
)
7073 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7074 write_insn
<big_endian
>(p
, insn
);
7078 template<bool big_endian
>
7079 static unsigned char*
7080 restgpr1_tail(unsigned char* p
, int r
)
7082 p
= restgpr1
<big_endian
>(p
, r
);
7083 write_insn
<big_endian
>(p
, blr
);
7087 template<bool big_endian
>
7088 static unsigned char*
7089 savefpr(unsigned char* p
, int r
)
7091 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7092 write_insn
<big_endian
>(p
, insn
);
7096 template<bool big_endian
>
7097 static unsigned char*
7098 savefpr0_tail(unsigned char* p
, int r
)
7100 p
= savefpr
<big_endian
>(p
, r
);
7101 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7103 write_insn
<big_endian
>(p
, blr
);
7107 template<bool big_endian
>
7108 static unsigned char*
7109 restfpr(unsigned char* p
, int r
)
7111 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7112 write_insn
<big_endian
>(p
, insn
);
7116 template<bool big_endian
>
7117 static unsigned char*
7118 restfpr0_tail(unsigned char* p
, int r
)
7120 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7122 p
= restfpr
<big_endian
>(p
, r
);
7123 write_insn
<big_endian
>(p
, mtlr_0
);
7127 p
= restfpr
<big_endian
>(p
, 30);
7128 p
= restfpr
<big_endian
>(p
, 31);
7130 write_insn
<big_endian
>(p
, blr
);
7134 template<bool big_endian
>
7135 static unsigned char*
7136 savefpr1_tail(unsigned char* p
, int r
)
7138 p
= savefpr
<big_endian
>(p
, r
);
7139 write_insn
<big_endian
>(p
, blr
);
7143 template<bool big_endian
>
7144 static unsigned char*
7145 restfpr1_tail(unsigned char* p
, int r
)
7147 p
= restfpr
<big_endian
>(p
, r
);
7148 write_insn
<big_endian
>(p
, blr
);
7152 template<bool big_endian
>
7153 static unsigned char*
7154 savevr(unsigned char* p
, int r
)
7156 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7157 write_insn
<big_endian
>(p
, insn
);
7159 insn
= stvx_0_12_0
+ (r
<< 21);
7160 write_insn
<big_endian
>(p
, insn
);
7164 template<bool big_endian
>
7165 static unsigned char*
7166 savevr_tail(unsigned char* p
, int r
)
7168 p
= savevr
<big_endian
>(p
, r
);
7169 write_insn
<big_endian
>(p
, blr
);
7173 template<bool big_endian
>
7174 static unsigned char*
7175 restvr(unsigned char* p
, int r
)
7177 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7178 write_insn
<big_endian
>(p
, insn
);
7180 insn
= lvx_0_12_0
+ (r
<< 21);
7181 write_insn
<big_endian
>(p
, insn
);
7185 template<bool big_endian
>
7186 static unsigned char*
7187 restvr_tail(unsigned char* p
, int r
)
7189 p
= restvr
<big_endian
>(p
, r
);
7190 write_insn
<big_endian
>(p
, blr
);
7195 template<int size
, bool big_endian
>
7196 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7197 Symbol_table
* symtab
)
7198 : Output_section_data_build(4),
7201 this->savres_define(symtab
,
7202 "_savegpr0_", 14, 31,
7203 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7204 this->savres_define(symtab
,
7205 "_restgpr0_", 14, 29,
7206 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7207 this->savres_define(symtab
,
7208 "_restgpr0_", 30, 31,
7209 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7210 this->savres_define(symtab
,
7211 "_savegpr1_", 14, 31,
7212 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7213 this->savres_define(symtab
,
7214 "_restgpr1_", 14, 31,
7215 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7216 this->savres_define(symtab
,
7217 "_savefpr_", 14, 31,
7218 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7219 this->savres_define(symtab
,
7220 "_restfpr_", 14, 29,
7221 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7222 this->savres_define(symtab
,
7223 "_restfpr_", 30, 31,
7224 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7225 this->savres_define(symtab
,
7227 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7228 this->savres_define(symtab
,
7230 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7231 this->savres_define(symtab
,
7233 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7234 this->savres_define(symtab
,
7236 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7239 template<int size
, bool big_endian
>
7241 Output_data_save_res
<size
, big_endian
>::savres_define(
7242 Symbol_table
* symtab
,
7244 unsigned int lo
, unsigned int hi
,
7245 unsigned char* write_ent(unsigned char*, int),
7246 unsigned char* write_tail(unsigned char*, int))
7248 size_t len
= strlen(name
);
7249 bool writing
= false;
7252 memcpy(sym
, name
, len
);
7255 for (unsigned int i
= lo
; i
<= hi
; i
++)
7257 sym
[len
+ 0] = i
/ 10 + '0';
7258 sym
[len
+ 1] = i
% 10 + '0';
7259 Symbol
* gsym
= symtab
->lookup(sym
);
7260 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7261 writing
= writing
|| refd
;
7264 if (this->contents_
== NULL
)
7265 this->contents_
= new unsigned char[this->savres_max
];
7267 section_size_type value
= this->current_data_size();
7268 unsigned char* p
= this->contents_
+ value
;
7270 p
= write_ent(p
, i
);
7272 p
= write_tail(p
, i
);
7273 section_size_type cur_size
= p
- this->contents_
;
7274 this->set_current_data_size(cur_size
);
7276 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7277 this, value
, cur_size
- value
,
7278 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7279 elfcpp::STV_HIDDEN
, 0, false, false);
7284 // Write out save/restore.
7286 template<int size
, bool big_endian
>
7288 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7290 const section_size_type off
= this->offset();
7291 const section_size_type oview_size
=
7292 convert_to_section_size_type(this->data_size());
7293 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7294 memcpy(oview
, this->contents_
, oview_size
);
7295 of
->write_output_view(off
, oview_size
, oview
);
7299 // Create the glink section.
7301 template<int size
, bool big_endian
>
7303 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7305 if (this->glink_
== NULL
)
7307 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7308 this->glink_
->add_eh_frame(layout
);
7309 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7310 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7311 this->glink_
, ORDER_TEXT
, false);
7315 // Create a PLT entry for a global symbol.
7317 template<int size
, bool big_endian
>
7319 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7323 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7324 && gsym
->can_use_relative_reloc(false))
7326 if (this->iplt_
== NULL
)
7327 this->make_iplt_section(symtab
, layout
);
7328 this->iplt_
->add_ifunc_entry(gsym
);
7332 if (this->plt_
== NULL
)
7333 this->make_plt_section(symtab
, layout
);
7334 this->plt_
->add_entry(gsym
);
7338 // Make a PLT entry for a local symbol.
7340 template<int size
, bool big_endian
>
7342 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7344 Sized_relobj_file
<size
, big_endian
>* relobj
,
7347 if (this->lplt_
== NULL
)
7348 this->make_lplt_section(layout
);
7349 this->lplt_
->add_local_entry(relobj
, r_sym
);
7352 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7354 template<int size
, bool big_endian
>
7356 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7357 Symbol_table
* symtab
,
7359 Sized_relobj_file
<size
, big_endian
>* relobj
,
7362 if (this->iplt_
== NULL
)
7363 this->make_iplt_section(symtab
, layout
);
7364 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7367 // Return the number of entries in the PLT.
7369 template<int size
, bool big_endian
>
7371 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7373 if (this->plt_
== NULL
)
7375 return this->plt_
->entry_count();
7378 // Create a GOT entry for local dynamic __tls_get_addr calls.
7380 template<int size
, bool big_endian
>
7382 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7383 Symbol_table
* symtab
,
7385 Sized_relobj_file
<size
, big_endian
>* object
)
7387 if (this->tlsld_got_offset_
== -1U)
7389 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7390 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7391 Output_data_got_powerpc
<size
, big_endian
>* got
7392 = this->got_section(symtab
, layout
);
7393 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7394 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7396 this->tlsld_got_offset_
= got_offset
;
7398 return this->tlsld_got_offset_
;
7401 // Get the Reference_flags for a particular relocation.
7403 template<int size
, bool big_endian
>
7405 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7406 unsigned int r_type
,
7407 const Target_powerpc
* target
)
7413 case elfcpp::R_POWERPC_NONE
:
7414 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7415 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7416 case elfcpp::R_PPC64_TOC
:
7417 // No symbol reference.
7420 case elfcpp::R_PPC64_ADDR64
:
7421 case elfcpp::R_PPC64_UADDR64
:
7422 case elfcpp::R_POWERPC_ADDR32
:
7423 case elfcpp::R_POWERPC_UADDR32
:
7424 case elfcpp::R_POWERPC_ADDR16
:
7425 case elfcpp::R_POWERPC_UADDR16
:
7426 case elfcpp::R_POWERPC_ADDR16_LO
:
7427 case elfcpp::R_POWERPC_ADDR16_HI
:
7428 case elfcpp::R_POWERPC_ADDR16_HA
:
7429 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7430 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7431 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7432 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7433 case elfcpp::R_PPC64_D34
:
7434 case elfcpp::R_PPC64_D34_LO
:
7435 case elfcpp::R_PPC64_D34_HI30
:
7436 case elfcpp::R_PPC64_D34_HA30
:
7437 case elfcpp::R_PPC64_D28
:
7438 ref
= Symbol::ABSOLUTE_REF
;
7441 case elfcpp::R_POWERPC_ADDR24
:
7442 case elfcpp::R_POWERPC_ADDR14
:
7443 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7444 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7445 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7448 case elfcpp::R_PPC64_REL64
:
7449 case elfcpp::R_POWERPC_REL32
:
7450 case elfcpp::R_PPC_LOCAL24PC
:
7451 case elfcpp::R_POWERPC_REL16
:
7452 case elfcpp::R_POWERPC_REL16_LO
:
7453 case elfcpp::R_POWERPC_REL16_HI
:
7454 case elfcpp::R_POWERPC_REL16_HA
:
7455 case elfcpp::R_PPC64_REL16_HIGH
:
7456 case elfcpp::R_PPC64_REL16_HIGHA
:
7457 case elfcpp::R_PPC64_REL16_HIGHER
:
7458 case elfcpp::R_PPC64_REL16_HIGHERA
:
7459 case elfcpp::R_PPC64_REL16_HIGHEST
:
7460 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7461 case elfcpp::R_PPC64_PCREL34
:
7462 case elfcpp::R_PPC64_REL16_HIGHER34
:
7463 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7464 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7465 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7466 case elfcpp::R_PPC64_PCREL28
:
7467 ref
= Symbol::RELATIVE_REF
;
7470 case elfcpp::R_PPC64_REL24_NOTOC
:
7474 case elfcpp::R_POWERPC_REL24
:
7475 case elfcpp::R_PPC_PLTREL24
:
7476 case elfcpp::R_POWERPC_REL14
:
7477 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7478 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7479 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7482 case elfcpp::R_POWERPC_GOT16
:
7483 case elfcpp::R_POWERPC_GOT16_LO
:
7484 case elfcpp::R_POWERPC_GOT16_HI
:
7485 case elfcpp::R_POWERPC_GOT16_HA
:
7486 case elfcpp::R_PPC64_GOT16_DS
:
7487 case elfcpp::R_PPC64_GOT16_LO_DS
:
7488 case elfcpp::R_PPC64_GOT_PCREL34
:
7489 case elfcpp::R_PPC64_TOC16
:
7490 case elfcpp::R_PPC64_TOC16_LO
:
7491 case elfcpp::R_PPC64_TOC16_HI
:
7492 case elfcpp::R_PPC64_TOC16_HA
:
7493 case elfcpp::R_PPC64_TOC16_DS
:
7494 case elfcpp::R_PPC64_TOC16_LO_DS
:
7495 case elfcpp::R_POWERPC_PLT16_LO
:
7496 case elfcpp::R_POWERPC_PLT16_HI
:
7497 case elfcpp::R_POWERPC_PLT16_HA
:
7498 case elfcpp::R_PPC64_PLT16_LO_DS
:
7499 case elfcpp::R_PPC64_PLT_PCREL34
:
7500 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7501 ref
= Symbol::RELATIVE_REF
;
7504 case elfcpp::R_POWERPC_GOT_TPREL16
:
7505 case elfcpp::R_POWERPC_TLS
:
7506 case elfcpp::R_PPC64_TLSGD
:
7507 case elfcpp::R_PPC64_TLSLD
:
7508 case elfcpp::R_PPC64_TPREL34
:
7509 case elfcpp::R_PPC64_DTPREL34
:
7510 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7511 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7512 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7513 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7514 ref
= Symbol::TLS_REF
;
7517 case elfcpp::R_POWERPC_COPY
:
7518 case elfcpp::R_POWERPC_GLOB_DAT
:
7519 case elfcpp::R_POWERPC_JMP_SLOT
:
7520 case elfcpp::R_POWERPC_RELATIVE
:
7521 case elfcpp::R_POWERPC_DTPMOD
:
7523 // Not expected. We will give an error later.
7527 if (size
== 64 && target
->abiversion() < 2)
7528 ref
|= Symbol::FUNC_DESC_ABI
;
7532 // Report an unsupported relocation against a local symbol.
7534 template<int size
, bool big_endian
>
7536 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7537 Sized_relobj_file
<size
, big_endian
>* object
,
7538 unsigned int r_type
)
7540 gold_error(_("%s: unsupported reloc %u against local symbol"),
7541 object
->name().c_str(), r_type
);
7544 // We are about to emit a dynamic relocation of type R_TYPE. If the
7545 // dynamic linker does not support it, issue an error.
7547 template<int size
, bool big_endian
>
7549 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7550 unsigned int r_type
)
7552 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7554 // These are the relocation types supported by glibc for both 32-bit
7555 // and 64-bit powerpc.
7558 case elfcpp::R_POWERPC_NONE
:
7559 case elfcpp::R_POWERPC_RELATIVE
:
7560 case elfcpp::R_POWERPC_GLOB_DAT
:
7561 case elfcpp::R_POWERPC_DTPMOD
:
7562 case elfcpp::R_POWERPC_DTPREL
:
7563 case elfcpp::R_POWERPC_TPREL
:
7564 case elfcpp::R_POWERPC_JMP_SLOT
:
7565 case elfcpp::R_POWERPC_COPY
:
7566 case elfcpp::R_POWERPC_IRELATIVE
:
7567 case elfcpp::R_POWERPC_ADDR32
:
7568 case elfcpp::R_POWERPC_UADDR32
:
7569 case elfcpp::R_POWERPC_ADDR24
:
7570 case elfcpp::R_POWERPC_ADDR16
:
7571 case elfcpp::R_POWERPC_UADDR16
:
7572 case elfcpp::R_POWERPC_ADDR16_LO
:
7573 case elfcpp::R_POWERPC_ADDR16_HI
:
7574 case elfcpp::R_POWERPC_ADDR16_HA
:
7575 case elfcpp::R_POWERPC_ADDR14
:
7576 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7577 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7578 case elfcpp::R_POWERPC_REL32
:
7579 case elfcpp::R_POWERPC_TPREL16
:
7580 case elfcpp::R_POWERPC_TPREL16_LO
:
7581 case elfcpp::R_POWERPC_TPREL16_HI
:
7582 case elfcpp::R_POWERPC_TPREL16_HA
:
7593 // These are the relocation types supported only on 64-bit.
7594 case elfcpp::R_PPC64_ADDR64
:
7595 case elfcpp::R_PPC64_UADDR64
:
7596 case elfcpp::R_PPC64_JMP_IREL
:
7597 case elfcpp::R_PPC64_ADDR16_DS
:
7598 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7599 case elfcpp::R_PPC64_ADDR16_HIGH
:
7600 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7601 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7602 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7603 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7604 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7605 case elfcpp::R_PPC64_REL64
:
7606 case elfcpp::R_POWERPC_ADDR30
:
7607 case elfcpp::R_PPC64_TPREL16_DS
:
7608 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7609 case elfcpp::R_PPC64_TPREL16_HIGH
:
7610 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7611 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7612 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7613 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7614 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7625 // These are the relocation types supported only on 32-bit.
7626 // ??? glibc ld.so doesn't need to support these.
7627 case elfcpp::R_POWERPC_REL24
:
7628 case elfcpp::R_POWERPC_DTPREL16
:
7629 case elfcpp::R_POWERPC_DTPREL16_LO
:
7630 case elfcpp::R_POWERPC_DTPREL16_HI
:
7631 case elfcpp::R_POWERPC_DTPREL16_HA
:
7639 // This prevents us from issuing more than one error per reloc
7640 // section. But we can still wind up issuing more than one
7641 // error per object file.
7642 if (this->issued_non_pic_error_
)
7644 gold_assert(parameters
->options().output_is_position_independent());
7645 object
->error(_("requires unsupported dynamic reloc; "
7646 "recompile with -fPIC"));
7647 this->issued_non_pic_error_
= true;
7651 // Return whether we need to make a PLT entry for a relocation of the
7652 // given type against a STT_GNU_IFUNC symbol.
7654 template<int size
, bool big_endian
>
7656 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7657 Target_powerpc
<size
, big_endian
>* target
,
7658 Sized_relobj_file
<size
, big_endian
>* object
,
7659 unsigned int r_type
,
7662 // In non-pic code any reference will resolve to the plt call stub
7663 // for the ifunc symbol.
7664 if ((size
== 32 || target
->abiversion() >= 2)
7665 && !parameters
->options().output_is_position_independent())
7670 // Word size refs from data sections are OK, but don't need a PLT entry.
7671 case elfcpp::R_POWERPC_ADDR32
:
7672 case elfcpp::R_POWERPC_UADDR32
:
7677 case elfcpp::R_PPC64_ADDR64
:
7678 case elfcpp::R_PPC64_UADDR64
:
7683 // GOT refs are good, but also don't need a PLT entry.
7684 case elfcpp::R_POWERPC_GOT16
:
7685 case elfcpp::R_POWERPC_GOT16_LO
:
7686 case elfcpp::R_POWERPC_GOT16_HI
:
7687 case elfcpp::R_POWERPC_GOT16_HA
:
7688 case elfcpp::R_PPC64_GOT16_DS
:
7689 case elfcpp::R_PPC64_GOT16_LO_DS
:
7690 case elfcpp::R_PPC64_GOT_PCREL34
:
7693 // PLT relocs are OK and need a PLT entry.
7694 case elfcpp::R_POWERPC_PLT16_LO
:
7695 case elfcpp::R_POWERPC_PLT16_HI
:
7696 case elfcpp::R_POWERPC_PLT16_HA
:
7697 case elfcpp::R_PPC64_PLT16_LO_DS
:
7698 case elfcpp::R_POWERPC_PLTSEQ
:
7699 case elfcpp::R_POWERPC_PLTCALL
:
7700 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7701 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7702 case elfcpp::R_PPC64_PLT_PCREL34
:
7703 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7707 // Function calls are good, and these do need a PLT entry.
7708 case elfcpp::R_PPC64_REL24_NOTOC
:
7712 case elfcpp::R_POWERPC_ADDR24
:
7713 case elfcpp::R_POWERPC_ADDR14
:
7714 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7715 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7716 case elfcpp::R_POWERPC_REL24
:
7717 case elfcpp::R_PPC_PLTREL24
:
7718 case elfcpp::R_POWERPC_REL14
:
7719 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7720 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7727 // Anything else is a problem.
7728 // If we are building a static executable, the libc startup function
7729 // responsible for applying indirect function relocations is going
7730 // to complain about the reloc type.
7731 // If we are building a dynamic executable, we will have a text
7732 // relocation. The dynamic loader will set the text segment
7733 // writable and non-executable to apply text relocations. So we'll
7734 // segfault when trying to run the indirection function to resolve
7737 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7738 object
->name().c_str(), r_type
);
7742 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7746 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7748 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7749 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7750 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7751 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7752 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7753 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7754 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7755 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7756 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7757 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7758 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7759 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7760 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7761 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7762 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7763 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7764 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7765 /* Exclude lfqu by testing reloc. If relocs are ever
7766 defined for the reduced D field in psq_lu then those
7767 will need testing too. */
7768 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7769 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7770 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7772 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7773 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7774 /* Exclude stfqu. psq_stu as above for psq_lu. */
7775 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7776 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7777 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7778 && (insn
& 1) == 0));
7781 // Scan a relocation for a local symbol.
7783 template<int size
, bool big_endian
>
7785 Target_powerpc
<size
, big_endian
>::Scan::local(
7786 Symbol_table
* symtab
,
7788 Target_powerpc
<size
, big_endian
>* target
,
7789 Sized_relobj_file
<size
, big_endian
>* object
,
7790 unsigned int data_shndx
,
7791 Output_section
* output_section
,
7792 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7793 unsigned int r_type
,
7794 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7797 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7799 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7800 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7802 this->expect_tls_get_addr_call();
7803 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7804 if (tls_type
!= tls::TLSOPT_NONE
)
7805 this->skip_next_tls_get_addr_call();
7807 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7808 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7810 this->expect_tls_get_addr_call();
7811 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7812 if (tls_type
!= tls::TLSOPT_NONE
)
7813 this->skip_next_tls_get_addr_call();
7816 Powerpc_relobj
<size
, big_endian
>* ppc_object
7817 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7822 && data_shndx
== ppc_object
->opd_shndx()
7823 && r_type
== elfcpp::R_PPC64_ADDR64
)
7824 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7828 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7829 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7830 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7832 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7833 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7834 r_type
, r_sym
, reloc
.get_r_addend());
7835 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7840 case elfcpp::R_POWERPC_NONE
:
7841 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7842 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7843 case elfcpp::R_POWERPC_TLS
:
7844 case elfcpp::R_PPC64_ENTRY
:
7845 case elfcpp::R_POWERPC_PLTSEQ
:
7846 case elfcpp::R_POWERPC_PLTCALL
:
7847 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7848 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7849 case elfcpp::R_PPC64_PCREL_OPT
:
7850 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7851 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7852 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7853 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7854 case elfcpp::R_PPC64_REL16_HIGHER34
:
7855 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7856 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7857 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7858 case elfcpp::R_PPC64_D34
:
7859 case elfcpp::R_PPC64_D34_LO
:
7860 case elfcpp::R_PPC64_D34_HI30
:
7861 case elfcpp::R_PPC64_D34_HA30
:
7862 case elfcpp::R_PPC64_D28
:
7863 case elfcpp::R_PPC64_PCREL34
:
7864 case elfcpp::R_PPC64_PCREL28
:
7865 case elfcpp::R_PPC64_TPREL34
:
7866 case elfcpp::R_PPC64_DTPREL34
:
7869 case elfcpp::R_PPC64_TOC
:
7871 Output_data_got_powerpc
<size
, big_endian
>* got
7872 = target
->got_section(symtab
, layout
);
7873 if (parameters
->options().output_is_position_independent())
7875 Address off
= reloc
.get_r_offset();
7877 && target
->abiversion() < 2
7878 && data_shndx
== ppc_object
->opd_shndx()
7879 && ppc_object
->get_opd_discard(off
- 8))
7882 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7883 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7884 rela_dyn
->add_output_section_relative(got
->output_section(),
7885 elfcpp::R_POWERPC_RELATIVE
,
7887 object
, data_shndx
, off
,
7888 symobj
->toc_base_offset());
7893 case elfcpp::R_PPC64_ADDR64
:
7894 case elfcpp::R_PPC64_UADDR64
:
7895 case elfcpp::R_POWERPC_ADDR32
:
7896 case elfcpp::R_POWERPC_UADDR32
:
7897 case elfcpp::R_POWERPC_ADDR24
:
7898 case elfcpp::R_POWERPC_ADDR16
:
7899 case elfcpp::R_POWERPC_ADDR16_LO
:
7900 case elfcpp::R_POWERPC_ADDR16_HI
:
7901 case elfcpp::R_POWERPC_ADDR16_HA
:
7902 case elfcpp::R_POWERPC_UADDR16
:
7903 case elfcpp::R_PPC64_ADDR16_HIGH
:
7904 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7905 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7906 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7907 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7908 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7909 case elfcpp::R_PPC64_ADDR16_DS
:
7910 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7911 case elfcpp::R_POWERPC_ADDR14
:
7912 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7913 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7914 // If building a shared library (or a position-independent
7915 // executable), we need to create a dynamic relocation for
7917 if (parameters
->options().output_is_position_independent()
7918 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7920 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7922 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7923 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7924 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7926 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7927 : elfcpp::R_POWERPC_RELATIVE
);
7928 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7929 output_section
, data_shndx
,
7930 reloc
.get_r_offset(),
7931 reloc
.get_r_addend(), false);
7933 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7935 check_non_pic(object
, r_type
);
7936 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7937 data_shndx
, reloc
.get_r_offset(),
7938 reloc
.get_r_addend());
7942 gold_assert(lsym
.get_st_value() == 0);
7943 unsigned int shndx
= lsym
.get_st_shndx();
7945 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7948 object
->error(_("section symbol %u has bad shndx %u"),
7951 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7952 output_section
, data_shndx
,
7953 reloc
.get_r_offset());
7958 case elfcpp::R_PPC64_PLT_PCREL34
:
7959 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7960 case elfcpp::R_POWERPC_PLT16_LO
:
7961 case elfcpp::R_POWERPC_PLT16_HI
:
7962 case elfcpp::R_POWERPC_PLT16_HA
:
7963 case elfcpp::R_PPC64_PLT16_LO_DS
:
7966 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7967 target
->make_local_plt_entry(layout
, object
, r_sym
);
7971 case elfcpp::R_PPC64_REL24_NOTOC
:
7975 case elfcpp::R_POWERPC_REL24
:
7976 case elfcpp::R_PPC_PLTREL24
:
7977 case elfcpp::R_PPC_LOCAL24PC
:
7978 case elfcpp::R_POWERPC_REL14
:
7979 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7980 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7983 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7984 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7985 r_type
, r_sym
, reloc
.get_r_addend());
7989 case elfcpp::R_PPC64_TOCSAVE
:
7990 // R_PPC64_TOCSAVE follows a call instruction to indicate the
7991 // caller has already saved r2 and thus a plt call stub need not
7994 && target
->mark_pltcall(ppc_object
, data_shndx
,
7995 reloc
.get_r_offset() - 4, symtab
))
7997 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7998 unsigned int shndx
= lsym
.get_st_shndx();
8000 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8002 object
->error(_("tocsave symbol %u has bad shndx %u"),
8005 target
->add_tocsave(ppc_object
, shndx
,
8006 lsym
.get_st_value() + reloc
.get_r_addend());
8010 case elfcpp::R_PPC64_REL64
:
8011 case elfcpp::R_POWERPC_REL32
:
8012 case elfcpp::R_POWERPC_REL16
:
8013 case elfcpp::R_POWERPC_REL16_LO
:
8014 case elfcpp::R_POWERPC_REL16_HI
:
8015 case elfcpp::R_POWERPC_REL16_HA
:
8016 case elfcpp::R_POWERPC_REL16DX_HA
:
8017 case elfcpp::R_PPC64_REL16_HIGH
:
8018 case elfcpp::R_PPC64_REL16_HIGHA
:
8019 case elfcpp::R_PPC64_REL16_HIGHER
:
8020 case elfcpp::R_PPC64_REL16_HIGHERA
:
8021 case elfcpp::R_PPC64_REL16_HIGHEST
:
8022 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8023 case elfcpp::R_POWERPC_SECTOFF
:
8024 case elfcpp::R_POWERPC_SECTOFF_LO
:
8025 case elfcpp::R_POWERPC_SECTOFF_HI
:
8026 case elfcpp::R_POWERPC_SECTOFF_HA
:
8027 case elfcpp::R_PPC64_SECTOFF_DS
:
8028 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8029 case elfcpp::R_POWERPC_TPREL16
:
8030 case elfcpp::R_POWERPC_TPREL16_LO
:
8031 case elfcpp::R_POWERPC_TPREL16_HI
:
8032 case elfcpp::R_POWERPC_TPREL16_HA
:
8033 case elfcpp::R_PPC64_TPREL16_DS
:
8034 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8035 case elfcpp::R_PPC64_TPREL16_HIGH
:
8036 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8037 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8038 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8039 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8040 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8041 case elfcpp::R_POWERPC_DTPREL16
:
8042 case elfcpp::R_POWERPC_DTPREL16_LO
:
8043 case elfcpp::R_POWERPC_DTPREL16_HI
:
8044 case elfcpp::R_POWERPC_DTPREL16_HA
:
8045 case elfcpp::R_PPC64_DTPREL16_DS
:
8046 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8047 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8048 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8049 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8050 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8051 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8052 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8053 case elfcpp::R_PPC64_TLSGD
:
8054 case elfcpp::R_PPC64_TLSLD
:
8055 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8058 case elfcpp::R_PPC64_GOT_PCREL34
:
8059 case elfcpp::R_POWERPC_GOT16
:
8060 case elfcpp::R_POWERPC_GOT16_LO
:
8061 case elfcpp::R_POWERPC_GOT16_HI
:
8062 case elfcpp::R_POWERPC_GOT16_HA
:
8063 case elfcpp::R_PPC64_GOT16_DS
:
8064 case elfcpp::R_PPC64_GOT16_LO_DS
:
8066 // The symbol requires a GOT entry.
8067 Output_data_got_powerpc
<size
, big_endian
>* got
8068 = target
->got_section(symtab
, layout
);
8069 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8071 if (!parameters
->options().output_is_position_independent())
8074 && (size
== 32 || target
->abiversion() >= 2))
8075 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
8077 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
8079 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
8081 // If we are generating a shared object or a pie, this
8082 // symbol's GOT entry will be set by a dynamic relocation.
8084 off
= got
->add_constant(0);
8085 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
8087 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8089 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8090 : elfcpp::R_POWERPC_RELATIVE
);
8091 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8092 got
, off
, 0, false);
8097 case elfcpp::R_PPC64_TOC16
:
8098 case elfcpp::R_PPC64_TOC16_LO
:
8099 case elfcpp::R_PPC64_TOC16_HI
:
8100 case elfcpp::R_PPC64_TOC16_HA
:
8101 case elfcpp::R_PPC64_TOC16_DS
:
8102 case elfcpp::R_PPC64_TOC16_LO_DS
:
8103 // We need a GOT section.
8104 target
->got_section(symtab
, layout
);
8107 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8108 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8109 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8110 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8111 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8113 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8114 if (tls_type
== tls::TLSOPT_NONE
)
8116 Output_data_got_powerpc
<size
, big_endian
>* got
8117 = target
->got_section(symtab
, layout
);
8118 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8119 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8120 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
8121 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
8123 else if (tls_type
== tls::TLSOPT_TO_LE
)
8125 // no GOT relocs needed for Local Exec.
8132 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8133 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8134 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8135 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8136 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8138 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8139 if (tls_type
== tls::TLSOPT_NONE
)
8140 target
->tlsld_got_offset(symtab
, layout
, object
);
8141 else if (tls_type
== tls::TLSOPT_TO_LE
)
8143 // no GOT relocs needed for Local Exec.
8144 if (parameters
->options().emit_relocs())
8146 Output_section
* os
= layout
->tls_segment()->first_section();
8147 gold_assert(os
!= NULL
);
8148 os
->set_needs_symtab_index();
8156 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8157 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8158 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8159 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8160 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8162 Output_data_got_powerpc
<size
, big_endian
>* got
8163 = target
->got_section(symtab
, layout
);
8164 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8165 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
8169 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8170 case elfcpp::R_POWERPC_GOT_TPREL16
:
8171 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8172 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8173 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8175 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8176 if (tls_type
== tls::TLSOPT_NONE
)
8178 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8179 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
8181 Output_data_got_powerpc
<size
, big_endian
>* got
8182 = target
->got_section(symtab
, layout
);
8183 unsigned int off
= got
->add_constant(0);
8184 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
8186 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8187 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8188 elfcpp::R_POWERPC_TPREL
,
8192 else if (tls_type
== tls::TLSOPT_TO_LE
)
8194 // no GOT relocs needed for Local Exec.
8202 unsupported_reloc_local(object
, r_type
);
8207 && parameters
->options().toc_optimize())
8209 if (data_shndx
== ppc_object
->toc_shndx())
8212 if (r_type
!= elfcpp::R_PPC64_ADDR64
8213 || (is_ifunc
&& target
->abiversion() < 2))
8215 else if (parameters
->options().output_is_position_independent())
8221 unsigned int shndx
= lsym
.get_st_shndx();
8222 if (shndx
>= elfcpp::SHN_LORESERVE
8223 && shndx
!= elfcpp::SHN_XINDEX
)
8228 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8231 enum {no_check
, check_lo
, check_ha
} insn_check
;
8235 insn_check
= no_check
;
8238 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8239 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8240 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8241 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8242 case elfcpp::R_POWERPC_GOT16_HA
:
8243 case elfcpp::R_PPC64_TOC16_HA
:
8244 insn_check
= check_ha
;
8247 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8248 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8249 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8250 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8251 case elfcpp::R_POWERPC_GOT16_LO
:
8252 case elfcpp::R_PPC64_GOT16_LO_DS
:
8253 case elfcpp::R_PPC64_TOC16_LO
:
8254 case elfcpp::R_PPC64_TOC16_LO_DS
:
8255 insn_check
= check_lo
;
8259 section_size_type slen
;
8260 const unsigned char* view
= NULL
;
8261 if (insn_check
!= no_check
)
8263 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8264 section_size_type off
=
8265 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8268 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8269 if (insn_check
== check_lo
8270 ? !ok_lo_toc_insn(insn
, r_type
)
8271 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8272 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8274 ppc_object
->set_no_toc_opt();
8275 gold_warning(_("%s: toc optimization is not supported "
8276 "for %#08x instruction"),
8277 ppc_object
->name().c_str(), insn
);
8286 case elfcpp::R_PPC64_TOC16
:
8287 case elfcpp::R_PPC64_TOC16_LO
:
8288 case elfcpp::R_PPC64_TOC16_HI
:
8289 case elfcpp::R_PPC64_TOC16_HA
:
8290 case elfcpp::R_PPC64_TOC16_DS
:
8291 case elfcpp::R_PPC64_TOC16_LO_DS
:
8292 unsigned int shndx
= lsym
.get_st_shndx();
8293 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8295 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8296 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8298 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8299 if (dst_off
< ppc_object
->section_size(shndx
))
8302 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8304 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8306 // Need to check that the insn is a ld
8308 view
= ppc_object
->section_contents(data_shndx
,
8311 section_size_type off
=
8312 (convert_to_section_size_type(reloc
.get_r_offset())
8313 + (big_endian
? -2 : 3));
8315 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8319 ppc_object
->set_no_toc_opt(dst_off
);
8330 case elfcpp::R_POWERPC_REL32
:
8331 if (ppc_object
->got2_shndx() != 0
8332 && parameters
->options().output_is_position_independent())
8334 unsigned int shndx
= lsym
.get_st_shndx();
8335 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8337 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8338 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8339 && (ppc_object
->section_flags(data_shndx
)
8340 & elfcpp::SHF_EXECINSTR
) != 0)
8341 gold_error(_("%s: unsupported -mbss-plt code"),
8342 ppc_object
->name().c_str());
8352 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8353 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8354 case elfcpp::R_POWERPC_GOT_TPREL16
:
8355 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8356 case elfcpp::R_POWERPC_GOT16
:
8357 case elfcpp::R_PPC64_GOT16_DS
:
8358 case elfcpp::R_PPC64_TOC16
:
8359 case elfcpp::R_PPC64_TOC16_DS
:
8360 ppc_object
->set_has_small_toc_reloc();
8368 case elfcpp::R_POWERPC_TPREL16
:
8369 case elfcpp::R_POWERPC_TPREL16_LO
:
8370 case elfcpp::R_POWERPC_TPREL16_HI
:
8371 case elfcpp::R_POWERPC_TPREL16_HA
:
8372 case elfcpp::R_PPC64_TPREL16_DS
:
8373 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8374 case elfcpp::R_PPC64_TPREL16_HIGH
:
8375 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8376 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8377 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8378 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8379 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8380 case elfcpp::R_PPC64_TPREL34
:
8381 layout
->set_has_static_tls();
8389 case elfcpp::R_PPC64_D34
:
8390 case elfcpp::R_PPC64_D34_LO
:
8391 case elfcpp::R_PPC64_D34_HI30
:
8392 case elfcpp::R_PPC64_D34_HA30
:
8393 case elfcpp::R_PPC64_D28
:
8394 case elfcpp::R_PPC64_PCREL34
:
8395 case elfcpp::R_PPC64_PCREL28
:
8396 case elfcpp::R_PPC64_TPREL34
:
8397 case elfcpp::R_PPC64_DTPREL34
:
8398 case elfcpp::R_PPC64_PLT_PCREL34
:
8399 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8400 case elfcpp::R_PPC64_GOT_PCREL34
:
8401 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8402 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8403 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8404 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8405 target
->set_power10_stubs();
8412 // Report an unsupported relocation against a global symbol.
8414 template<int size
, bool big_endian
>
8416 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8417 Sized_relobj_file
<size
, big_endian
>* object
,
8418 unsigned int r_type
,
8421 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8422 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8425 // Scan a relocation for a global symbol.
8427 template<int size
, bool big_endian
>
8429 Target_powerpc
<size
, big_endian
>::Scan::global(
8430 Symbol_table
* symtab
,
8432 Target_powerpc
<size
, big_endian
>* target
,
8433 Sized_relobj_file
<size
, big_endian
>* object
,
8434 unsigned int data_shndx
,
8435 Output_section
* output_section
,
8436 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8437 unsigned int r_type
,
8440 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8444 if (target
->replace_tls_get_addr(gsym
))
8445 // Change a __tls_get_addr reference to __tls_get_addr_opt
8446 // so dynamic relocs are emitted against the latter symbol.
8447 gsym
= target
->tls_get_addr_opt();
8449 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8450 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8452 this->expect_tls_get_addr_call();
8453 const bool final
= gsym
->final_value_is_known();
8454 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8455 if (tls_type
!= tls::TLSOPT_NONE
)
8456 this->skip_next_tls_get_addr_call();
8458 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8459 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8461 this->expect_tls_get_addr_call();
8462 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8463 if (tls_type
!= tls::TLSOPT_NONE
)
8464 this->skip_next_tls_get_addr_call();
8467 Powerpc_relobj
<size
, big_endian
>* ppc_object
8468 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8470 // A STT_GNU_IFUNC symbol may require a PLT entry.
8471 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8472 bool pushed_ifunc
= false;
8473 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8475 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8476 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8477 r_type
, r_sym
, reloc
.get_r_addend());
8478 target
->make_plt_entry(symtab
, layout
, gsym
);
8479 pushed_ifunc
= true;
8484 case elfcpp::R_POWERPC_NONE
:
8485 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8486 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8487 case elfcpp::R_PPC_LOCAL24PC
:
8488 case elfcpp::R_POWERPC_TLS
:
8489 case elfcpp::R_PPC64_ENTRY
:
8490 case elfcpp::R_POWERPC_PLTSEQ
:
8491 case elfcpp::R_POWERPC_PLTCALL
:
8492 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8493 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8494 case elfcpp::R_PPC64_PCREL_OPT
:
8495 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8496 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8497 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8498 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8499 case elfcpp::R_PPC64_REL16_HIGHER34
:
8500 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8501 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8502 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8503 case elfcpp::R_PPC64_D34
:
8504 case elfcpp::R_PPC64_D34_LO
:
8505 case elfcpp::R_PPC64_D34_HI30
:
8506 case elfcpp::R_PPC64_D34_HA30
:
8507 case elfcpp::R_PPC64_D28
:
8508 case elfcpp::R_PPC64_PCREL34
:
8509 case elfcpp::R_PPC64_PCREL28
:
8510 case elfcpp::R_PPC64_TPREL34
:
8511 case elfcpp::R_PPC64_DTPREL34
:
8514 case elfcpp::R_PPC64_TOC
:
8516 Output_data_got_powerpc
<size
, big_endian
>* got
8517 = target
->got_section(symtab
, layout
);
8518 if (parameters
->options().output_is_position_independent())
8520 Address off
= reloc
.get_r_offset();
8522 && data_shndx
== ppc_object
->opd_shndx()
8523 && ppc_object
->get_opd_discard(off
- 8))
8526 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8527 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8528 if (data_shndx
!= ppc_object
->opd_shndx())
8529 symobj
= static_cast
8530 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8531 rela_dyn
->add_output_section_relative(got
->output_section(),
8532 elfcpp::R_POWERPC_RELATIVE
,
8534 object
, data_shndx
, off
,
8535 symobj
->toc_base_offset());
8540 case elfcpp::R_PPC64_ADDR64
:
8542 && target
->abiversion() < 2
8543 && data_shndx
== ppc_object
->opd_shndx()
8544 && (gsym
->is_defined_in_discarded_section()
8545 || gsym
->object() != object
))
8547 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8551 case elfcpp::R_PPC64_UADDR64
:
8552 case elfcpp::R_POWERPC_ADDR32
:
8553 case elfcpp::R_POWERPC_UADDR32
:
8554 case elfcpp::R_POWERPC_ADDR24
:
8555 case elfcpp::R_POWERPC_ADDR16
:
8556 case elfcpp::R_POWERPC_ADDR16_LO
:
8557 case elfcpp::R_POWERPC_ADDR16_HI
:
8558 case elfcpp::R_POWERPC_ADDR16_HA
:
8559 case elfcpp::R_POWERPC_UADDR16
:
8560 case elfcpp::R_PPC64_ADDR16_HIGH
:
8561 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8562 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8563 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8564 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8565 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8566 case elfcpp::R_PPC64_ADDR16_DS
:
8567 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8568 case elfcpp::R_POWERPC_ADDR14
:
8569 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8570 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8572 // Make a PLT entry if necessary.
8573 if (gsym
->needs_plt_entry())
8575 // Since this is not a PC-relative relocation, we may be
8576 // taking the address of a function. In that case we need to
8577 // set the entry in the dynamic symbol table to the address of
8578 // the PLT call stub.
8579 bool need_ifunc_plt
= false;
8580 if ((size
== 32 || target
->abiversion() >= 2)
8581 && gsym
->is_from_dynobj()
8582 && !parameters
->options().output_is_position_independent())
8584 gsym
->set_needs_dynsym_value();
8585 need_ifunc_plt
= true;
8587 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8589 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8590 target
->push_branch(ppc_object
, data_shndx
,
8591 reloc
.get_r_offset(), r_type
, r_sym
,
8592 reloc
.get_r_addend());
8593 target
->make_plt_entry(symtab
, layout
, gsym
);
8596 // Make a dynamic relocation if necessary.
8597 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8598 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8600 if (!parameters
->options().output_is_position_independent()
8601 && gsym
->may_need_copy_reloc())
8603 target
->copy_reloc(symtab
, layout
, object
,
8604 data_shndx
, output_section
, gsym
, reloc
);
8606 else if ((((size
== 32
8607 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8609 && r_type
== elfcpp::R_PPC64_ADDR64
8610 && target
->abiversion() >= 2))
8611 && gsym
->can_use_relative_reloc(false)
8612 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8613 && parameters
->options().shared()))
8615 && r_type
== elfcpp::R_PPC64_ADDR64
8616 && target
->abiversion() < 2
8617 && (gsym
->can_use_relative_reloc(false)
8618 || data_shndx
== ppc_object
->opd_shndx())))
8620 Reloc_section
* rela_dyn
8621 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8622 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8623 : elfcpp::R_POWERPC_RELATIVE
);
8624 rela_dyn
->add_symbolless_global_addend(
8625 gsym
, dynrel
, output_section
, object
, data_shndx
,
8626 reloc
.get_r_offset(), reloc
.get_r_addend());
8630 Reloc_section
* rela_dyn
8631 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8632 check_non_pic(object
, r_type
);
8633 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8635 reloc
.get_r_offset(),
8636 reloc
.get_r_addend());
8639 && parameters
->options().toc_optimize()
8640 && data_shndx
== ppc_object
->toc_shndx())
8641 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8647 case elfcpp::R_PPC64_PLT_PCREL34
:
8648 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8649 case elfcpp::R_POWERPC_PLT16_LO
:
8650 case elfcpp::R_POWERPC_PLT16_HI
:
8651 case elfcpp::R_POWERPC_PLT16_HA
:
8652 case elfcpp::R_PPC64_PLT16_LO_DS
:
8654 target
->make_plt_entry(symtab
, layout
, gsym
);
8657 case elfcpp::R_PPC64_REL24_NOTOC
:
8661 case elfcpp::R_PPC_PLTREL24
:
8662 case elfcpp::R_POWERPC_REL24
:
8665 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8666 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8667 r_type
, r_sym
, reloc
.get_r_addend());
8668 if (gsym
->needs_plt_entry()
8669 || (!gsym
->final_value_is_known()
8670 && (gsym
->is_undefined()
8671 || gsym
->is_from_dynobj()
8672 || gsym
->is_preemptible())))
8673 target
->make_plt_entry(symtab
, layout
, gsym
);
8677 case elfcpp::R_PPC64_REL64
:
8678 case elfcpp::R_POWERPC_REL32
:
8679 // Make a dynamic relocation if necessary.
8680 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8682 if (!parameters
->options().output_is_position_independent()
8683 && gsym
->may_need_copy_reloc())
8685 target
->copy_reloc(symtab
, layout
, object
,
8686 data_shndx
, output_section
, gsym
,
8691 Reloc_section
* rela_dyn
8692 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8693 check_non_pic(object
, r_type
);
8694 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8695 data_shndx
, reloc
.get_r_offset(),
8696 reloc
.get_r_addend());
8701 case elfcpp::R_POWERPC_REL14
:
8702 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8703 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8706 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8707 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8708 r_type
, r_sym
, reloc
.get_r_addend());
8712 case elfcpp::R_PPC64_TOCSAVE
:
8713 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8714 // caller has already saved r2 and thus a plt call stub need not
8717 && target
->mark_pltcall(ppc_object
, data_shndx
,
8718 reloc
.get_r_offset() - 4, symtab
))
8720 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8722 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8724 object
->error(_("tocsave symbol %u has bad shndx %u"),
8728 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8729 target
->add_tocsave(ppc_object
, shndx
,
8730 sym
->value() + reloc
.get_r_addend());
8735 case elfcpp::R_POWERPC_REL16
:
8736 case elfcpp::R_POWERPC_REL16_LO
:
8737 case elfcpp::R_POWERPC_REL16_HI
:
8738 case elfcpp::R_POWERPC_REL16_HA
:
8739 case elfcpp::R_POWERPC_REL16DX_HA
:
8740 case elfcpp::R_PPC64_REL16_HIGH
:
8741 case elfcpp::R_PPC64_REL16_HIGHA
:
8742 case elfcpp::R_PPC64_REL16_HIGHER
:
8743 case elfcpp::R_PPC64_REL16_HIGHERA
:
8744 case elfcpp::R_PPC64_REL16_HIGHEST
:
8745 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8746 case elfcpp::R_POWERPC_SECTOFF
:
8747 case elfcpp::R_POWERPC_SECTOFF_LO
:
8748 case elfcpp::R_POWERPC_SECTOFF_HI
:
8749 case elfcpp::R_POWERPC_SECTOFF_HA
:
8750 case elfcpp::R_PPC64_SECTOFF_DS
:
8751 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8752 case elfcpp::R_POWERPC_TPREL16
:
8753 case elfcpp::R_POWERPC_TPREL16_LO
:
8754 case elfcpp::R_POWERPC_TPREL16_HI
:
8755 case elfcpp::R_POWERPC_TPREL16_HA
:
8756 case elfcpp::R_PPC64_TPREL16_DS
:
8757 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8758 case elfcpp::R_PPC64_TPREL16_HIGH
:
8759 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8760 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8761 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8762 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8763 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8764 case elfcpp::R_POWERPC_DTPREL16
:
8765 case elfcpp::R_POWERPC_DTPREL16_LO
:
8766 case elfcpp::R_POWERPC_DTPREL16_HI
:
8767 case elfcpp::R_POWERPC_DTPREL16_HA
:
8768 case elfcpp::R_PPC64_DTPREL16_DS
:
8769 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8770 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8771 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8772 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8773 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8774 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8775 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8776 case elfcpp::R_PPC64_TLSGD
:
8777 case elfcpp::R_PPC64_TLSLD
:
8778 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8781 case elfcpp::R_PPC64_GOT_PCREL34
:
8782 case elfcpp::R_POWERPC_GOT16
:
8783 case elfcpp::R_POWERPC_GOT16_LO
:
8784 case elfcpp::R_POWERPC_GOT16_HI
:
8785 case elfcpp::R_POWERPC_GOT16_HA
:
8786 case elfcpp::R_PPC64_GOT16_DS
:
8787 case elfcpp::R_PPC64_GOT16_LO_DS
:
8789 // The symbol requires a GOT entry.
8790 Output_data_got_powerpc
<size
, big_endian
>* got
;
8792 got
= target
->got_section(symtab
, layout
);
8793 if (gsym
->final_value_is_known())
8796 && (size
== 32 || target
->abiversion() >= 2))
8797 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8799 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8801 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8803 // If we are generating a shared object or a pie, this
8804 // symbol's GOT entry will be set by a dynamic relocation.
8805 unsigned int off
= got
->add_constant(0);
8806 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8808 Reloc_section
* rela_dyn
8809 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8811 if (gsym
->can_use_relative_reloc(false)
8813 || target
->abiversion() >= 2)
8814 && gsym
->visibility() == elfcpp::STV_PROTECTED
8815 && parameters
->options().shared()))
8817 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8818 : elfcpp::R_POWERPC_RELATIVE
);
8819 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8823 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8824 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8830 case elfcpp::R_PPC64_TOC16
:
8831 case elfcpp::R_PPC64_TOC16_LO
:
8832 case elfcpp::R_PPC64_TOC16_HI
:
8833 case elfcpp::R_PPC64_TOC16_HA
:
8834 case elfcpp::R_PPC64_TOC16_DS
:
8835 case elfcpp::R_PPC64_TOC16_LO_DS
:
8836 // We need a GOT section.
8837 target
->got_section(symtab
, layout
);
8840 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8841 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8842 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8843 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8844 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8846 const bool final
= gsym
->final_value_is_known();
8847 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8848 if (tls_type
== tls::TLSOPT_NONE
)
8850 Output_data_got_powerpc
<size
, big_endian
>* got
8851 = target
->got_section(symtab
, layout
);
8852 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8853 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8854 elfcpp::R_POWERPC_DTPMOD
,
8855 elfcpp::R_POWERPC_DTPREL
);
8857 else if (tls_type
== tls::TLSOPT_TO_IE
)
8859 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8861 Output_data_got_powerpc
<size
, big_endian
>* got
8862 = target
->got_section(symtab
, layout
);
8863 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8864 if (gsym
->is_undefined()
8865 || gsym
->is_from_dynobj())
8867 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8868 elfcpp::R_POWERPC_TPREL
);
8872 unsigned int off
= got
->add_constant(0);
8873 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8874 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8875 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8880 else if (tls_type
== tls::TLSOPT_TO_LE
)
8882 // no GOT relocs needed for Local Exec.
8889 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8890 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8891 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8892 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8893 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8895 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8896 if (tls_type
== tls::TLSOPT_NONE
)
8897 target
->tlsld_got_offset(symtab
, layout
, object
);
8898 else if (tls_type
== tls::TLSOPT_TO_LE
)
8900 // no GOT relocs needed for Local Exec.
8901 if (parameters
->options().emit_relocs())
8903 Output_section
* os
= layout
->tls_segment()->first_section();
8904 gold_assert(os
!= NULL
);
8905 os
->set_needs_symtab_index();
8913 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8914 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8915 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8916 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8917 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8919 Output_data_got_powerpc
<size
, big_endian
>* got
8920 = target
->got_section(symtab
, layout
);
8921 if (!gsym
->final_value_is_known()
8922 && (gsym
->is_from_dynobj()
8923 || gsym
->is_undefined()
8924 || gsym
->is_preemptible()))
8925 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
8926 target
->rela_dyn_section(layout
),
8927 elfcpp::R_POWERPC_DTPREL
);
8929 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
8933 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8934 case elfcpp::R_POWERPC_GOT_TPREL16
:
8935 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8936 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8937 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8939 const bool final
= gsym
->final_value_is_known();
8940 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8941 if (tls_type
== tls::TLSOPT_NONE
)
8943 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8945 Output_data_got_powerpc
<size
, big_endian
>* got
8946 = target
->got_section(symtab
, layout
);
8947 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8948 if (gsym
->is_undefined()
8949 || gsym
->is_from_dynobj())
8951 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8952 elfcpp::R_POWERPC_TPREL
);
8956 unsigned int off
= got
->add_constant(0);
8957 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8958 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8959 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8964 else if (tls_type
== tls::TLSOPT_TO_LE
)
8966 // no GOT relocs needed for Local Exec.
8974 unsupported_reloc_global(object
, r_type
, gsym
);
8979 && parameters
->options().toc_optimize())
8981 if (data_shndx
== ppc_object
->toc_shndx())
8984 if (r_type
!= elfcpp::R_PPC64_ADDR64
8985 || (is_ifunc
&& target
->abiversion() < 2))
8987 else if (parameters
->options().output_is_position_independent()
8988 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
8991 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8994 enum {no_check
, check_lo
, check_ha
} insn_check
;
8998 insn_check
= no_check
;
9001 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9002 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9003 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9004 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9005 case elfcpp::R_POWERPC_GOT16_HA
:
9006 case elfcpp::R_PPC64_TOC16_HA
:
9007 insn_check
= check_ha
;
9010 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9011 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9012 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9013 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9014 case elfcpp::R_POWERPC_GOT16_LO
:
9015 case elfcpp::R_PPC64_GOT16_LO_DS
:
9016 case elfcpp::R_PPC64_TOC16_LO
:
9017 case elfcpp::R_PPC64_TOC16_LO_DS
:
9018 insn_check
= check_lo
;
9022 section_size_type slen
;
9023 const unsigned char* view
= NULL
;
9024 if (insn_check
!= no_check
)
9026 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9027 section_size_type off
=
9028 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9031 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9032 if (insn_check
== check_lo
9033 ? !ok_lo_toc_insn(insn
, r_type
)
9034 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9035 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9037 ppc_object
->set_no_toc_opt();
9038 gold_warning(_("%s: toc optimization is not supported "
9039 "for %#08x instruction"),
9040 ppc_object
->name().c_str(), insn
);
9049 case elfcpp::R_PPC64_TOC16
:
9050 case elfcpp::R_PPC64_TOC16_LO
:
9051 case elfcpp::R_PPC64_TOC16_HI
:
9052 case elfcpp::R_PPC64_TOC16_HA
:
9053 case elfcpp::R_PPC64_TOC16_DS
:
9054 case elfcpp::R_PPC64_TOC16_LO_DS
:
9055 if (gsym
->source() == Symbol::FROM_OBJECT
9056 && !gsym
->object()->is_dynamic())
9058 Powerpc_relobj
<size
, big_endian
>* sym_object
9059 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9061 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9062 if (shndx
== sym_object
->toc_shndx())
9064 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9065 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9066 if (dst_off
< sym_object
->section_size(shndx
))
9069 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9071 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9073 // Need to check that the insn is a ld
9075 view
= ppc_object
->section_contents(data_shndx
,
9078 section_size_type off
=
9079 (convert_to_section_size_type(reloc
.get_r_offset())
9080 + (big_endian
? -2 : 3));
9082 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9086 sym_object
->set_no_toc_opt(dst_off
);
9098 case elfcpp::R_PPC_LOCAL24PC
:
9099 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9100 gold_error(_("%s: unsupported -mbss-plt code"),
9101 ppc_object
->name().c_str());
9110 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9111 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9112 case elfcpp::R_POWERPC_GOT_TPREL16
:
9113 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9114 case elfcpp::R_POWERPC_GOT16
:
9115 case elfcpp::R_PPC64_GOT16_DS
:
9116 case elfcpp::R_PPC64_TOC16
:
9117 case elfcpp::R_PPC64_TOC16_DS
:
9118 ppc_object
->set_has_small_toc_reloc();
9126 case elfcpp::R_POWERPC_TPREL16
:
9127 case elfcpp::R_POWERPC_TPREL16_LO
:
9128 case elfcpp::R_POWERPC_TPREL16_HI
:
9129 case elfcpp::R_POWERPC_TPREL16_HA
:
9130 case elfcpp::R_PPC64_TPREL16_DS
:
9131 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9132 case elfcpp::R_PPC64_TPREL16_HIGH
:
9133 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9134 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9135 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9136 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9137 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9138 case elfcpp::R_PPC64_TPREL34
:
9139 layout
->set_has_static_tls();
9147 case elfcpp::R_PPC64_D34
:
9148 case elfcpp::R_PPC64_D34_LO
:
9149 case elfcpp::R_PPC64_D34_HI30
:
9150 case elfcpp::R_PPC64_D34_HA30
:
9151 case elfcpp::R_PPC64_D28
:
9152 case elfcpp::R_PPC64_PCREL34
:
9153 case elfcpp::R_PPC64_PCREL28
:
9154 case elfcpp::R_PPC64_TPREL34
:
9155 case elfcpp::R_PPC64_DTPREL34
:
9156 case elfcpp::R_PPC64_PLT_PCREL34
:
9157 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9158 case elfcpp::R_PPC64_GOT_PCREL34
:
9159 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9160 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9161 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9162 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9163 target
->set_power10_stubs();
9170 // Process relocations for gc.
9172 template<int size
, bool big_endian
>
9174 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9175 Symbol_table
* symtab
,
9177 Sized_relobj_file
<size
, big_endian
>* object
,
9178 unsigned int data_shndx
,
9180 const unsigned char* prelocs
,
9182 Output_section
* output_section
,
9183 bool needs_special_offset_handling
,
9184 size_t local_symbol_count
,
9185 const unsigned char* plocal_symbols
)
9187 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9188 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9191 Powerpc_relobj
<size
, big_endian
>* ppc_object
9192 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9194 ppc_object
->set_opd_valid();
9195 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9197 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9198 for (p
= ppc_object
->access_from_map()->begin();
9199 p
!= ppc_object
->access_from_map()->end();
9202 Address dst_off
= p
->first
;
9203 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9204 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9205 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9207 Relobj
* src_obj
= s
->first
;
9208 unsigned int src_indx
= s
->second
;
9209 symtab
->gc()->add_reference(src_obj
, src_indx
,
9210 ppc_object
, dst_indx
);
9214 ppc_object
->access_from_map()->clear();
9215 ppc_object
->process_gc_mark(symtab
);
9216 // Don't look at .opd relocs as .opd will reference everything.
9220 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9229 needs_special_offset_handling
,
9234 // Handle target specific gc actions when adding a gc reference from
9235 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9236 // and DST_OFF. For powerpc64, this adds a referenc to the code
9237 // section of a function descriptor.
9239 template<int size
, bool big_endian
>
9241 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9242 Symbol_table
* symtab
,
9244 unsigned int src_shndx
,
9246 unsigned int dst_shndx
,
9247 Address dst_off
) const
9249 if (size
!= 64 || dst_obj
->is_dynamic())
9252 Powerpc_relobj
<size
, big_endian
>* ppc_object
9253 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9254 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9256 if (ppc_object
->opd_valid())
9258 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9259 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9263 // If we haven't run scan_opd_relocs, we must delay
9264 // processing this function descriptor reference.
9265 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9270 // Add any special sections for this symbol to the gc work list.
9271 // For powerpc64, this adds the code section of a function
9274 template<int size
, bool big_endian
>
9276 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9277 Symbol_table
* symtab
,
9280 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9282 Powerpc_relobj
<size
, big_endian
>* ppc_object
9283 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9285 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9286 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9288 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9289 Address dst_off
= gsym
->value();
9290 if (ppc_object
->opd_valid())
9292 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9293 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9297 ppc_object
->add_gc_mark(dst_off
);
9302 // For a symbol location in .opd, set LOC to the location of the
9305 template<int size
, bool big_endian
>
9307 Target_powerpc
<size
, big_endian
>::do_function_location(
9308 Symbol_location
* loc
) const
9310 if (size
== 64 && loc
->shndx
!= 0)
9312 if (loc
->object
->is_dynamic())
9314 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9315 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9316 if (loc
->shndx
== ppc_object
->opd_shndx())
9319 Address off
= loc
->offset
- ppc_object
->opd_address();
9320 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9321 loc
->offset
= dest_off
;
9326 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9327 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9328 if (loc
->shndx
== ppc_object
->opd_shndx())
9331 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9332 loc
->offset
= dest_off
;
9338 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9339 // compiled with -fsplit-stack. The function calls non-split-stack
9340 // code. Change the function to ensure it has enough stack space to
9341 // call some random function.
9343 template<int size
, bool big_endian
>
9345 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9348 section_offset_type fnoffset
,
9349 section_size_type fnsize
,
9350 const unsigned char* prelocs
,
9352 unsigned char* view
,
9353 section_size_type view_size
,
9355 std::string
* to
) const
9357 // 32-bit not supported.
9361 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9362 prelocs
, reloc_count
, view
, view_size
,
9367 // The function always starts with
9368 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9369 // addis %r12,%r1,-allocate@ha
9370 // addi %r12,%r12,-allocate@l
9372 // but note that the addis or addi may be replaced with a nop
9374 unsigned char *entry
= view
+ fnoffset
;
9375 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9377 if ((insn
& 0xffff0000) == addis_2_12
)
9379 /* Skip ELFv2 global entry code. */
9381 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9384 unsigned char *pinsn
= entry
;
9386 const uint32_t ld_private_ss
= 0xe80d8fc0;
9387 if (insn
== ld_private_ss
)
9389 int32_t allocate
= 0;
9393 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9394 if ((insn
& 0xffff0000) == addis_12_1
)
9395 allocate
+= (insn
& 0xffff) << 16;
9396 else if ((insn
& 0xffff0000) == addi_12_1
9397 || (insn
& 0xffff0000) == addi_12_12
)
9398 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9399 else if (insn
!= nop
)
9402 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9404 int extra
= parameters
->options().split_stack_adjust_size();
9406 if (allocate
>= 0 || extra
< 0)
9408 object
->error(_("split-stack stack size overflow at "
9409 "section %u offset %0zx"),
9410 shndx
, static_cast<size_t>(fnoffset
));
9414 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9415 if (insn
!= addis_12_1
)
9417 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9419 insn
= addi_12_12
| (allocate
& 0xffff);
9420 if (insn
!= addi_12_12
)
9422 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9428 insn
= addi_12_1
| (allocate
& 0xffff);
9429 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9432 if (pinsn
!= entry
+ 12)
9433 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9441 if (!object
->has_no_split_stack())
9442 object
->error(_("failed to match split-stack sequence at "
9443 "section %u offset %0zx"),
9444 shndx
, static_cast<size_t>(fnoffset
));
9448 // Scan relocations for a section.
9450 template<int size
, bool big_endian
>
9452 Target_powerpc
<size
, big_endian
>::scan_relocs(
9453 Symbol_table
* symtab
,
9455 Sized_relobj_file
<size
, big_endian
>* object
,
9456 unsigned int data_shndx
,
9457 unsigned int sh_type
,
9458 const unsigned char* prelocs
,
9460 Output_section
* output_section
,
9461 bool needs_special_offset_handling
,
9462 size_t local_symbol_count
,
9463 const unsigned char* plocal_symbols
)
9465 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9466 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9469 if (!this->plt_localentry0_init_
)
9471 bool plt_localentry0
= false;
9473 && this->abiversion() >= 2)
9475 if (parameters
->options().user_set_plt_localentry())
9476 plt_localentry0
= parameters
->options().plt_localentry();
9478 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9479 gold_warning(_("--plt-localentry is especially dangerous without "
9480 "ld.so support to detect ABI violations"));
9482 this->plt_localentry0_
= plt_localentry0
;
9483 this->plt_localentry0_init_
= true;
9486 if (sh_type
== elfcpp::SHT_REL
)
9488 gold_error(_("%s: unsupported REL reloc section"),
9489 object
->name().c_str());
9493 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9502 needs_special_offset_handling
,
9507 // Functor class for processing the global symbol table.
9508 // Removes symbols defined on discarded opd entries.
9510 template<bool big_endian
>
9511 class Global_symbol_visitor_opd
9514 Global_symbol_visitor_opd()
9518 operator()(Sized_symbol
<64>* sym
)
9520 if (sym
->has_symtab_index()
9521 || sym
->source() != Symbol::FROM_OBJECT
9522 || !sym
->in_real_elf())
9525 if (sym
->object()->is_dynamic())
9528 Powerpc_relobj
<64, big_endian
>* symobj
9529 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9530 if (symobj
->opd_shndx() == 0)
9534 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9535 if (shndx
== symobj
->opd_shndx()
9536 && symobj
->get_opd_discard(sym
->value()))
9538 sym
->set_undefined();
9539 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9540 sym
->set_is_defined_in_discarded_section();
9541 sym
->set_symtab_index(-1U);
9546 template<int size
, bool big_endian
>
9548 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9550 Symbol_table
* symtab
)
9554 Output_data_save_res
<size
, big_endian
>* savres
9555 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9556 this->savres_section_
= savres
;
9557 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9558 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9559 savres
, ORDER_TEXT
, false);
9563 // Sort linker created .got section first (for the header), then input
9564 // sections belonging to files using small model code.
9566 template<bool big_endian
>
9567 class Sort_toc_sections
9571 operator()(const Output_section::Input_section
& is1
,
9572 const Output_section::Input_section
& is2
) const
9574 if (!is1
.is_input_section() && is2
.is_input_section())
9577 = (is1
.is_input_section()
9578 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9579 ->has_small_toc_reloc()));
9581 = (is2
.is_input_section()
9582 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9583 ->has_small_toc_reloc()));
9584 return small1
&& !small2
;
9588 // Finalize the sections.
9590 template<int size
, bool big_endian
>
9592 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9594 const Input_objects
* input_objects
,
9595 Symbol_table
* symtab
)
9597 if (parameters
->doing_static_link())
9599 // At least some versions of glibc elf-init.o have a strong
9600 // reference to __rela_iplt marker syms. A weak ref would be
9602 if (this->iplt_
!= NULL
)
9604 Reloc_section
* rel
= this->iplt_
->rel_plt();
9605 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9606 Symbol_table::PREDEFINED
, rel
, 0, 0,
9607 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9608 elfcpp::STV_HIDDEN
, 0, false, true);
9609 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9610 Symbol_table::PREDEFINED
, rel
, 0, 0,
9611 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9612 elfcpp::STV_HIDDEN
, 0, true, true);
9616 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9617 Symbol_table::PREDEFINED
, 0, 0,
9618 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9619 elfcpp::STV_HIDDEN
, 0, true, false);
9620 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9621 Symbol_table::PREDEFINED
, 0, 0,
9622 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9623 elfcpp::STV_HIDDEN
, 0, true, false);
9629 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9630 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9632 if (!parameters
->options().relocatable())
9634 this->define_save_restore_funcs(layout
, symtab
);
9636 // Annoyingly, we need to make these sections now whether or
9637 // not we need them. If we delay until do_relax then we
9638 // need to mess with the relaxation machinery checkpointing.
9639 this->got_section(symtab
, layout
);
9640 this->make_brlt_section(layout
);
9642 if (parameters
->options().toc_sort())
9644 Output_section
* os
= this->got_
->output_section();
9645 if (os
!= NULL
&& os
->input_sections().size() > 1)
9646 std::stable_sort(os
->input_sections().begin(),
9647 os
->input_sections().end(),
9648 Sort_toc_sections
<big_endian
>());
9653 // Fill in some more dynamic tags.
9654 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9657 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9659 : this->plt_
->rel_plt());
9660 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9661 this->rela_dyn_
, true, size
== 32);
9665 if (this->got_
!= NULL
)
9667 this->got_
->finalize_data_size();
9668 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9669 this->got_
, this->got_
->g_o_t());
9671 if (this->has_tls_get_addr_opt_
)
9672 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9676 if (this->glink_
!= NULL
)
9678 this->glink_
->finalize_data_size();
9679 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9681 (this->glink_
->pltresolve_size()
9684 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9685 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9686 ((this->has_localentry0_
9687 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9688 | (this->has_tls_get_addr_opt_
9689 ? elfcpp::PPC64_OPT_TLS
: 0)));
9693 // Emit any relocs we saved in an attempt to avoid generating COPY
9695 if (this->copy_relocs_
.any_saved_relocs())
9696 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9698 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9699 p
!= input_objects
->relobj_end();
9702 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9703 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9704 if (ppc_relobj
->attributes_section_data())
9705 this->merge_object_attributes(ppc_relobj
,
9706 ppc_relobj
->attributes_section_data());
9708 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9709 p
!= input_objects
->dynobj_end();
9712 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9713 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9714 if (ppc_dynobj
->attributes_section_data())
9715 this->merge_object_attributes(ppc_dynobj
,
9716 ppc_dynobj
->attributes_section_data());
9719 // Create a .gnu.attributes section if we have merged any attributes
9721 if (this->attributes_section_data_
!= NULL
9722 && this->attributes_section_data_
->size() != 0)
9724 Output_attributes_section_data
* attributes_section
9725 = new Output_attributes_section_data(*this->attributes_section_data_
);
9726 layout
->add_output_section_data(".gnu.attributes",
9727 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9728 attributes_section
, ORDER_INVALID
, false);
9732 // Merge object attributes from input file called NAME with those of the
9733 // output. The input object attributes are in the object pointed by PASD.
9735 template<int size
, bool big_endian
>
9737 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9739 const Attributes_section_data
* pasd
)
9741 // Return if there is no attributes section data.
9745 // Create output object attributes.
9746 if (this->attributes_section_data_
== NULL
)
9747 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9749 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9750 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9751 Object_attribute
* out_attr
9752 = this->attributes_section_data_
->known_attributes(vendor
);
9754 const char* name
= obj
->name().c_str();
9758 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9759 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9760 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9761 bool warn_only
= obj
->is_dynamic();
9762 if (in_fp
!= out_fp
)
9765 if ((in_fp
& 3) == 0)
9767 else if ((out_fp
& 3) == 0)
9771 out_fp
|= in_fp
& 3;
9772 out_attr
[tag
].set_int_value(out_fp
);
9773 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9774 this->last_fp_
= name
;
9777 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9779 err
= N_("%s uses hard float, %s uses soft float");
9780 first
= this->last_fp_
;
9783 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9785 err
= N_("%s uses hard float, %s uses soft float");
9787 second
= this->last_fp_
;
9789 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9791 err
= N_("%s uses double-precision hard float, "
9792 "%s uses single-precision hard float");
9793 first
= this->last_fp_
;
9796 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9798 err
= N_("%s uses double-precision hard float, "
9799 "%s uses single-precision hard float");
9801 second
= this->last_fp_
;
9804 if (err
|| (in_fp
& 0xc) == 0)
9806 else if ((out_fp
& 0xc) == 0)
9810 out_fp
|= in_fp
& 0xc;
9811 out_attr
[tag
].set_int_value(out_fp
);
9812 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9813 this->last_ld_
= name
;
9816 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9818 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9820 second
= this->last_ld_
;
9822 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9824 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9825 first
= this->last_ld_
;
9828 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9830 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9831 first
= this->last_ld_
;
9834 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9836 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9838 second
= this->last_ld_
;
9843 if (parameters
->options().warn_mismatch())
9846 gold_warning(_(err
), first
, second
);
9848 gold_error(_(err
), first
, second
);
9850 // Arrange for this attribute to be deleted. It's better to
9851 // say "don't know" about a file than to wrongly claim compliance.
9853 out_attr
[tag
].set_type(0);
9859 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9860 int in_vec
= in_attr
[tag
].int_value() & 3;
9861 int out_vec
= out_attr
[tag
].int_value() & 3;
9862 if (in_vec
!= out_vec
)
9867 else if (out_vec
== 0)
9870 out_attr
[tag
].set_int_value(out_vec
);
9871 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9872 this->last_vec_
= name
;
9874 // For now, allow generic to transition to AltiVec or SPE
9875 // without a warning. If GCC marked files with their stack
9876 // alignment and used don't-care markings for files which are
9877 // not affected by the vector ABI, we could warn about this
9879 else if (in_vec
== 1)
9881 else if (out_vec
== 1)
9884 out_attr
[tag
].set_int_value(out_vec
);
9885 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9886 this->last_vec_
= name
;
9888 else if (out_vec
< in_vec
)
9890 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9891 first
= this->last_vec_
;
9894 else if (out_vec
> in_vec
)
9896 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9898 second
= this->last_vec_
;
9902 if (parameters
->options().warn_mismatch())
9903 gold_error(_(err
), first
, second
);
9904 out_attr
[tag
].set_type(0);
9908 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
9909 int in_struct
= in_attr
[tag
].int_value() & 3;
9910 int out_struct
= out_attr
[tag
].int_value() & 3;
9911 if (in_struct
!= out_struct
)
9914 if (in_struct
== 0 || in_struct
== 3)
9916 else if (out_struct
== 0)
9918 out_struct
= in_struct
;
9919 out_attr
[tag
].set_int_value(out_struct
);
9920 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9921 this->last_struct_
= name
;
9923 else if (out_struct
< in_struct
)
9925 err
= N_("%s uses r3/r4 for small structure returns, "
9927 first
= this->last_struct_
;
9930 else if (out_struct
> in_struct
)
9932 err
= N_("%s uses r3/r4 for small structure returns, "
9935 second
= this->last_struct_
;
9939 if (parameters
->options().warn_mismatch())
9940 gold_error(_(err
), first
, second
);
9941 out_attr
[tag
].set_type(0);
9946 // Merge Tag_compatibility attributes and any common GNU ones.
9947 this->attributes_section_data_
->merge(name
, pasd
);
9950 // Emit any saved relocs, and mark toc entries using any of these
9951 // relocs as not optimizable.
9953 template<int sh_type
, int size
, bool big_endian
>
9955 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
9956 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
9959 && parameters
->options().toc_optimize())
9961 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
9962 Copy_reloc_entries::iterator p
= this->entries_
.begin();
9963 p
!= this->entries_
.end();
9966 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
9969 // If the symbol is no longer defined in a dynamic object,
9970 // then we emitted a COPY relocation. If it is still
9971 // dynamic then we'll need dynamic relocations and thus
9972 // can't optimize toc entries.
9973 if (entry
.sym_
->is_from_dynobj())
9975 Powerpc_relobj
<size
, big_endian
>* ppc_object
9976 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
9977 if (entry
.shndx_
== ppc_object
->toc_shndx())
9978 ppc_object
->set_no_toc_opt(entry
.address_
);
9983 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
9986 // Return the value to use for a branch relocation.
9988 template<int size
, bool big_endian
>
9990 Target_powerpc
<size
, big_endian
>::symval_for_branch(
9991 const Symbol_table
* symtab
,
9992 const Sized_symbol
<size
>* gsym
,
9993 Powerpc_relobj
<size
, big_endian
>* object
,
9995 unsigned int *dest_shndx
)
9997 if (size
== 32 || this->abiversion() >= 2)
10001 // If the symbol is defined in an opd section, ie. is a function
10002 // descriptor, use the function descriptor code entry address
10003 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10005 && (gsym
->source() != Symbol::FROM_OBJECT
10006 || gsym
->object()->is_dynamic()))
10009 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10010 unsigned int shndx
= symobj
->opd_shndx();
10013 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10014 if (opd_addr
== invalid_address
)
10016 opd_addr
+= symobj
->output_section_address(shndx
);
10017 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10020 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10021 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10024 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10025 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10026 *dest_shndx
= folded
.second
;
10028 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10029 if (sec_addr
== invalid_address
)
10032 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10033 *value
= sec_addr
+ sec_off
;
10040 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10042 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10045 if (gsym
->is_from_dynobj()
10046 || gsym
->is_undefined()
10047 || gsym
->is_preemptible())
10050 if (gsym
->is_absolute())
10051 return !parameters
->options().output_is_position_independent();
10058 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10060 if (psymval
->is_ifunc_symbol())
10064 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10066 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10069 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10070 // pld ra,symbol@got@pcrel
10071 // load/store rt,0(ra)
10073 // pla ra,symbol@pcrel
10074 // load/store rt,0(ra)
10075 // may be translated to
10076 // pload/pstore rt,symbol@pcrel
10078 // This function returns true if the optimization is possible, placing
10079 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10081 // On entry to this function, the linker has already determined that
10082 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10083 // while *PINSN2 is the second instruction.
10086 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10088 uint32_t insn2
= *pinsn2
>> 32;
10091 // Check that regs match.
10092 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10095 switch ((insn2
>> 26) & 63)
10111 // These are the PMLS cases, where we just need to tack a prefix
10112 // on the insn. Check that the D field is zero.
10113 if ((insn2
& 0xffff) != 0)
10115 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10116 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10119 case 58: // lwa, ld
10120 if ((insn2
& 0xfffd) != 0)
10122 i1new
= ((1ULL << 58) | (1ULL << 52)
10123 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10124 | (insn2
& (31ULL << 21)));
10127 case 57: // lxsd, lxssp
10128 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10130 i1new
= ((1ULL << 58) | (1ULL << 52)
10131 | ((40ULL | (insn2
& 3)) << 26)
10132 | (insn2
& (31ULL << 21)));
10135 case 61: // stxsd, stxssp, lxv, stxv
10136 if ((insn2
& 3) == 0)
10138 else if ((insn2
& 3) >= 2)
10140 if ((insn2
& 0xfffc) != 0)
10142 i1new
= ((1ULL << 58) | (1ULL << 52)
10143 | ((44ULL | (insn2
& 3)) << 26)
10144 | (insn2
& (31ULL << 21)));
10148 if ((insn2
& 0xfff0) != 0)
10150 i1new
= ((1ULL << 58) | (1ULL << 52)
10151 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10152 | (insn2
& (31ULL << 21)));
10157 if ((insn2
& 0xffff) != 0)
10159 i1new
= ((1ULL << 58) | (1ULL << 52)
10160 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10163 case 62: // std, stq
10164 if ((insn2
& 0xfffd) != 0)
10166 i1new
= ((1ULL << 58) | (1ULL << 52)
10167 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10168 | (insn2
& (31ULL << 21)));
10173 *pinsn2
= (uint64_t) nop
<< 32;
10177 // Perform a relocation.
10179 template<int size
, bool big_endian
>
10181 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10182 const Relocate_info
<size
, big_endian
>* relinfo
,
10184 Target_powerpc
* target
,
10185 Output_section
* os
,
10187 const unsigned char* preloc
,
10188 const Sized_symbol
<size
>* gsym
,
10189 const Symbol_value
<size
>* psymval
,
10190 unsigned char* view
,
10192 section_size_type view_size
)
10194 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10195 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10196 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10201 if (target
->replace_tls_get_addr(gsym
))
10202 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10204 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10205 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10206 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10208 case Track_tls::NOT_EXPECTED
:
10209 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10210 _("__tls_get_addr call lacks marker reloc"));
10212 case Track_tls::EXPECTED
:
10213 // We have already complained.
10215 case Track_tls::SKIP
:
10216 if (is_plt16_reloc
<size
>(r_type
)
10217 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10218 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10220 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10221 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10223 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10225 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10226 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10228 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10229 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10231 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10232 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10233 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10236 case Track_tls::NORMAL
:
10240 // Offset from start of insn to d-field reloc.
10241 const int d_offset
= big_endian
? 2 : 0;
10243 Powerpc_relobj
<size
, big_endian
>* const object
10244 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10246 bool has_stub_value
= false;
10247 bool localentry0
= false;
10248 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10249 bool has_plt_offset
10251 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10252 : object
->local_has_plt_offset(r_sym
));
10254 && !is_plt16_reloc
<size
>(r_type
)
10255 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10256 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10257 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10258 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10259 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10260 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10261 && (!psymval
->is_ifunc_symbol()
10262 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10266 && target
->abiversion() >= 2
10267 && !parameters
->options().output_is_position_independent()
10268 && !is_branch_reloc
<size
>(r_type
))
10270 Address off
= target
->glink_section()->find_global_entry(gsym
);
10271 if (off
!= invalid_address
)
10273 value
= target
->glink_section()->global_entry_address() + off
;
10274 has_stub_value
= true;
10279 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10280 if (target
->stub_tables().size() == 1)
10281 stub_table
= target
->stub_tables()[0];
10282 if (stub_table
== NULL
10285 && !parameters
->options().output_is_position_independent()
10286 && !is_branch_reloc
<size
>(r_type
)))
10287 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10288 if (stub_table
== NULL
)
10290 // This is a ref from a data section to an ifunc symbol,
10291 // or a non-branch reloc for which we always want to use
10292 // one set of stubs for resolving function addresses.
10293 if (target
->stub_tables().size() != 0)
10294 stub_table
= target
->stub_tables()[0];
10296 if (stub_table
!= NULL
)
10298 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10300 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10301 rela
.get_r_addend());
10303 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10304 rela
.get_r_addend());
10307 value
= stub_table
->stub_address() + ent
->off_
;
10308 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10309 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10310 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10312 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10313 value
+= ent
->tocoff_
;
10316 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10318 if (!(target
->power10_stubs()
10319 && target
->power10_stubs_auto()))
10322 else if (size
== 64
10324 && relnum
< reloc_count
- 1)
10326 Reltype
next_rela(preloc
+ reloc_size
);
10327 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10328 == elfcpp::R_PPC64_TOCSAVE
10329 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
10332 localentry0
= ent
->localentry0_
;
10333 has_stub_value
= true;
10337 // We don't care too much about bogus debug references to
10338 // non-local functions, but otherwise there had better be a plt
10339 // call stub or global entry stub as appropriate.
10340 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10343 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10344 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10345 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10347 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10349 value
= target
->plt_off(gsym
, &plt
);
10351 value
= target
->plt_off(object
, r_sym
, &plt
);
10352 value
+= plt
->address();
10356 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10357 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10358 value
-= (target
->got_section()->output_section()->address()
10359 + object
->toc_base_offset());
10361 else if (parameters
->options().output_is_position_independent())
10363 if (rela
.get_r_addend() >= 32768)
10365 unsigned int got2
= object
->got2_shndx();
10366 value
-= (object
->get_output_section_offset(got2
)
10367 + object
->output_section(got2
)->address()
10368 + rela
.get_r_addend());
10371 value
-= (target
->got_section()->address()
10372 + target
->got_section()->g_o_t());
10375 else if (!has_plt_offset
10376 && (is_plt16_reloc
<size
>(r_type
)
10377 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10378 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10380 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10381 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10382 r_type
= elfcpp::R_POWERPC_NONE
;
10384 else if (!has_plt_offset
10385 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10386 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10388 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10389 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10390 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10391 r_type
= elfcpp::R_POWERPC_NONE
;
10393 else if (r_type
== elfcpp::R_POWERPC_GOT16
10394 || r_type
== elfcpp::R_POWERPC_GOT16_LO
10395 || r_type
== elfcpp::R_POWERPC_GOT16_HI
10396 || r_type
== elfcpp::R_POWERPC_GOT16_HA
10397 || r_type
== elfcpp::R_PPC64_GOT16_DS
10398 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10399 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10403 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10404 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10408 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10409 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10411 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10412 value
+= target
->got_section()->address();
10414 value
-= target
->got_section()->got_base_offset(object
);
10416 else if (r_type
== elfcpp::R_PPC64_TOC
)
10418 value
= (target
->got_section()->output_section()->address()
10419 + object
->toc_base_offset());
10421 else if (gsym
!= NULL
10422 && (r_type
== elfcpp::R_POWERPC_REL24
10423 || r_type
== elfcpp::R_PPC_PLTREL24
)
10428 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10429 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10430 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10431 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10433 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10434 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10435 if ((insn
& 1) != 0
10437 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10439 elfcpp::Swap
<32, big_endian
>::
10440 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10441 can_plt_call
= true;
10446 // If we don't have a branch and link followed by a nop,
10447 // we can't go via the plt because there is no place to
10448 // put a toc restoring instruction.
10449 // Unless we know we won't be returning.
10450 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10451 can_plt_call
= true;
10455 // g++ as of 20130507 emits self-calls without a
10456 // following nop. This is arguably wrong since we have
10457 // conflicting information. On the one hand a global
10458 // symbol and on the other a local call sequence, but
10459 // don't error for this special case.
10460 // It isn't possible to cheaply verify we have exactly
10461 // such a call. Allow all calls to the same section.
10463 Address code
= value
;
10464 if (gsym
->source() == Symbol::FROM_OBJECT
10465 && gsym
->object() == object
)
10467 unsigned int dest_shndx
= 0;
10468 if (target
->abiversion() < 2)
10470 Address addend
= rela
.get_r_addend();
10471 code
= psymval
->value(object
, addend
);
10472 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10473 &code
, &dest_shndx
);
10476 if (dest_shndx
== 0)
10477 dest_shndx
= gsym
->shndx(&is_ordinary
);
10478 ok
= dest_shndx
== relinfo
->data_shndx
;
10482 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10483 _("call lacks nop, can't restore toc; "
10484 "recompile with -fPIC"));
10490 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10491 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10492 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10493 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10494 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10496 // First instruction of a global dynamic sequence, arg setup insn.
10497 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10498 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10499 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10500 if (tls_type
== tls::TLSOPT_NONE
)
10501 got_type
= GOT_TYPE_TLSGD
;
10502 else if (tls_type
== tls::TLSOPT_TO_IE
)
10503 got_type
= GOT_TYPE_TPREL
;
10504 if (got_type
!= GOT_TYPE_STANDARD
)
10508 gold_assert(gsym
->has_got_offset(got_type
));
10509 value
= gsym
->got_offset(got_type
);
10513 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10514 value
= object
->local_got_offset(r_sym
, got_type
);
10516 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10517 value
+= target
->got_section()->address();
10519 value
-= target
->got_section()->got_base_offset(object
);
10521 if (tls_type
== tls::TLSOPT_TO_IE
)
10523 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10525 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10526 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10528 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10530 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10531 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10532 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10533 pinsn
& 0xffffffff);
10534 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10538 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10539 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10541 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10542 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10543 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10545 insn
|= 32 << 26; // lwz
10547 insn
|= 58 << 26; // ld
10548 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10550 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10551 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10554 else if (tls_type
== tls::TLSOPT_TO_LE
)
10556 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10558 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10559 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10561 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10562 // pla pcrel -> paddi r13
10563 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10564 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10565 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10566 pinsn
& 0xffffffff);
10567 r_type
= elfcpp::R_PPC64_TPREL34
;
10568 value
= psymval
->value(object
, rela
.get_r_addend());
10572 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10573 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10575 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10576 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10577 insn
&= (1 << 26) - (1 << 21); // extract rt
10581 insn
|= addis_0_13
;
10582 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10583 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10584 value
= psymval
->value(object
, rela
.get_r_addend());
10588 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10590 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10591 r_type
= elfcpp::R_POWERPC_NONE
;
10596 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10597 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10598 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10599 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10600 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10602 // First instruction of a local dynamic sequence, arg setup insn.
10603 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10604 if (tls_type
== tls::TLSOPT_NONE
)
10606 value
= target
->tlsld_got_offset();
10607 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10608 value
+= target
->got_section()->address();
10610 value
-= target
->got_section()->got_base_offset(object
);
10614 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10615 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10617 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10618 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10620 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10621 // pla pcrel -> paddi r13
10622 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10623 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10624 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10625 pinsn
& 0xffffffff);
10626 r_type
= elfcpp::R_PPC64_TPREL34
;
10627 value
= dtp_offset
;
10629 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10630 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10632 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10633 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10634 insn
&= (1 << 26) - (1 << 21); // extract rt
10638 insn
|= addis_0_13
;
10639 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10640 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10641 value
= dtp_offset
;
10645 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10647 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10648 r_type
= elfcpp::R_POWERPC_NONE
;
10652 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10653 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10654 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10655 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10656 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10658 // Accesses relative to a local dynamic sequence address,
10659 // no optimisation here.
10662 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10663 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10667 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10668 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10670 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10671 value
+= target
->got_section()->address();
10673 value
-= target
->got_section()->got_base_offset(object
);
10675 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10676 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10677 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10678 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10679 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10681 // First instruction of initial exec sequence.
10682 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10683 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10684 if (tls_type
== tls::TLSOPT_NONE
)
10688 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10689 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10693 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10694 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10696 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10697 value
+= target
->got_section()->address();
10699 value
-= target
->got_section()->got_base_offset(object
);
10703 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10704 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10706 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10707 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10709 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10710 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10711 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10712 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10713 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10714 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10715 pinsn
& 0xffffffff);
10716 r_type
= elfcpp::R_PPC64_TPREL34
;
10717 value
= psymval
->value(object
, rela
.get_r_addend());
10719 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10720 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10722 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10723 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10724 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10728 insn
|= addis_0_13
;
10729 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10730 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10731 value
= psymval
->value(object
, rela
.get_r_addend());
10735 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10737 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10738 r_type
= elfcpp::R_POWERPC_NONE
;
10742 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10743 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10745 // Second instruction of a global dynamic sequence,
10746 // the __tls_get_addr call
10747 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10748 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10749 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10750 if (tls_type
!= tls::TLSOPT_NONE
)
10752 if (tls_type
== tls::TLSOPT_TO_IE
)
10754 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10755 Insn insn
= add_3_3_13
;
10758 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10759 r_type
= elfcpp::R_POWERPC_NONE
;
10763 bool is_pcrel
= false;
10764 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10765 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10766 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10767 if (relnum
< reloc_count
- 1)
10769 Reltype
next_rela(preloc
+ reloc_size
);
10770 unsigned int r_type2
10771 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10772 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10773 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10774 && next_rela
.get_r_offset() == rela
.get_r_offset())
10777 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10780 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10781 r_type
= elfcpp::R_POWERPC_NONE
;
10785 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10786 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10788 value
= psymval
->value(object
, rela
.get_r_addend());
10791 this->skip_next_tls_get_addr_call();
10794 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10795 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10797 // Second instruction of a local dynamic sequence,
10798 // the __tls_get_addr call
10799 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10800 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10801 if (tls_type
== tls::TLSOPT_TO_LE
)
10803 bool is_pcrel
= false;
10804 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10805 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10806 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10807 if (relnum
< reloc_count
- 1)
10809 Reltype
next_rela(preloc
+ reloc_size
);
10810 unsigned int r_type2
10811 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10812 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10813 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10814 && next_rela
.get_r_offset() == rela
.get_r_offset())
10817 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10820 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10821 r_type
= elfcpp::R_POWERPC_NONE
;
10825 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10826 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10828 value
= dtp_offset
;
10830 this->skip_next_tls_get_addr_call();
10833 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10835 // Second instruction of an initial exec sequence
10836 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10837 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10838 if (tls_type
== tls::TLSOPT_TO_LE
)
10840 Address roff
= rela
.get_r_offset() & 3;
10841 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
10842 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10843 unsigned int reg
= size
== 32 ? 2 : 13;
10844 insn
= at_tls_transform(insn
, reg
);
10845 gold_assert(insn
!= 0);
10848 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10849 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10851 value
= psymval
->value(object
, rela
.get_r_addend());
10853 else if (roff
== 1)
10855 // For pcrel IE to LE we already have the full offset
10856 // and thus don't need an addi here. A nop or mr will do.
10857 if ((insn
& (0x3f << 26)) == 14 << 26)
10859 // Extract regs from addi rt,ra,si.
10860 unsigned int rt
= (insn
>> 21) & 0x1f;
10861 unsigned int ra
= (insn
>> 16) & 0x1f;
10866 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
10867 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
10868 insn
|= (31u << 26) | (444u << 1);
10871 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10872 r_type
= elfcpp::R_POWERPC_NONE
;
10876 else if (!has_stub_value
)
10878 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
10879 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
10881 // PLTCALL without plt entry => convert to direct call
10882 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10883 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10884 insn
= (insn
& 1) | b
;
10885 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10887 r_type
= elfcpp::R_PPC_PLTREL24
;
10888 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10889 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
10891 r_type
= elfcpp::R_POWERPC_REL24
;
10893 Address addend
= 0;
10895 && (r_type
== elfcpp::R_PPC_PLTREL24
10896 || r_type
== elfcpp::R_POWERPC_PLT16_LO
10897 || r_type
== elfcpp::R_POWERPC_PLT16_HI
10898 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
10899 addend
= rela
.get_r_addend();
10900 value
= psymval
->value(object
, addend
);
10901 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
10903 if (target
->abiversion() >= 2)
10906 value
+= object
->ppc64_local_entry_offset(gsym
);
10908 value
+= object
->ppc64_local_entry_offset(r_sym
);
10912 unsigned int dest_shndx
;
10913 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10914 &value
, &dest_shndx
);
10917 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
10918 if (max_branch_offset
!= 0
10919 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
10921 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
10923 ? object
->ppc64_needs_toc(gsym
)
10924 : object
->ppc64_needs_toc(r_sym
)))))
10926 Stub_table
<size
, big_endian
>* stub_table
10927 = object
->stub_table(relinfo
->data_shndx
);
10928 if (stub_table
!= NULL
)
10930 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
10931 = stub_table
->find_long_branch_entry(object
, value
);
10934 if (ent
->save_res_
)
10935 value
= (value
- target
->savres_section()->address()
10936 + stub_table
->branch_size());
10939 value
= (stub_table
->stub_address()
10940 + stub_table
->plt_size()
10943 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10944 value
+= ent
->tocoff_
;
10946 has_stub_value
= true;
10954 case elfcpp::R_PPC64_REL24_NOTOC
:
10958 case elfcpp::R_PPC64_REL64
:
10959 case elfcpp::R_POWERPC_REL32
:
10960 case elfcpp::R_POWERPC_REL24
:
10961 case elfcpp::R_PPC_PLTREL24
:
10962 case elfcpp::R_PPC_LOCAL24PC
:
10963 case elfcpp::R_POWERPC_REL16
:
10964 case elfcpp::R_POWERPC_REL16_LO
:
10965 case elfcpp::R_POWERPC_REL16_HI
:
10966 case elfcpp::R_POWERPC_REL16_HA
:
10967 case elfcpp::R_POWERPC_REL16DX_HA
:
10968 case elfcpp::R_PPC64_REL16_HIGH
:
10969 case elfcpp::R_PPC64_REL16_HIGHA
:
10970 case elfcpp::R_PPC64_REL16_HIGHER
:
10971 case elfcpp::R_PPC64_REL16_HIGHERA
:
10972 case elfcpp::R_PPC64_REL16_HIGHEST
:
10973 case elfcpp::R_PPC64_REL16_HIGHESTA
:
10974 case elfcpp::R_POWERPC_REL14
:
10975 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10976 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10977 case elfcpp::R_PPC64_PCREL34
:
10978 case elfcpp::R_PPC64_GOT_PCREL34
:
10979 case elfcpp::R_PPC64_PLT_PCREL34
:
10980 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
10981 case elfcpp::R_PPC64_PCREL28
:
10982 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
10983 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
10984 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
10985 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
10986 case elfcpp::R_PPC64_REL16_HIGHER34
:
10987 case elfcpp::R_PPC64_REL16_HIGHERA34
:
10988 case elfcpp::R_PPC64_REL16_HIGHEST34
:
10989 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
10993 case elfcpp::R_PPC64_TOC16
:
10994 case elfcpp::R_PPC64_TOC16_LO
:
10995 case elfcpp::R_PPC64_TOC16_HI
:
10996 case elfcpp::R_PPC64_TOC16_HA
:
10997 case elfcpp::R_PPC64_TOC16_DS
:
10998 case elfcpp::R_PPC64_TOC16_LO_DS
:
10999 // Subtract the TOC base address.
11000 value
-= (target
->got_section()->output_section()->address()
11001 + object
->toc_base_offset());
11004 case elfcpp::R_POWERPC_SECTOFF
:
11005 case elfcpp::R_POWERPC_SECTOFF_LO
:
11006 case elfcpp::R_POWERPC_SECTOFF_HI
:
11007 case elfcpp::R_POWERPC_SECTOFF_HA
:
11008 case elfcpp::R_PPC64_SECTOFF_DS
:
11009 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11011 value
-= os
->address();
11014 case elfcpp::R_PPC64_TPREL16_DS
:
11015 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11016 case elfcpp::R_PPC64_TPREL16_HIGH
:
11017 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11019 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11022 case elfcpp::R_POWERPC_TPREL16
:
11023 case elfcpp::R_POWERPC_TPREL16_LO
:
11024 case elfcpp::R_POWERPC_TPREL16_HI
:
11025 case elfcpp::R_POWERPC_TPREL16_HA
:
11026 case elfcpp::R_POWERPC_TPREL
:
11027 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11028 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11029 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11030 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11031 case elfcpp::R_PPC64_TPREL34
:
11032 // tls symbol values are relative to tls_segment()->vaddr()
11033 value
-= tp_offset
;
11036 case elfcpp::R_PPC64_DTPREL16_DS
:
11037 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11038 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11039 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11040 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11041 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11043 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11044 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11047 case elfcpp::R_POWERPC_DTPREL16
:
11048 case elfcpp::R_POWERPC_DTPREL16_LO
:
11049 case elfcpp::R_POWERPC_DTPREL16_HI
:
11050 case elfcpp::R_POWERPC_DTPREL16_HA
:
11051 case elfcpp::R_POWERPC_DTPREL
:
11052 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11053 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11054 case elfcpp::R_PPC64_DTPREL34
:
11055 // tls symbol values are relative to tls_segment()->vaddr()
11056 value
-= dtp_offset
;
11059 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11061 value
+= object
->ppc64_local_entry_offset(gsym
);
11063 value
+= object
->ppc64_local_entry_offset(r_sym
);
11070 Insn branch_bit
= 0;
11073 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11074 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11075 branch_bit
= 1 << 21;
11077 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11078 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11080 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11081 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11082 insn
&= ~(1 << 21);
11083 insn
|= branch_bit
;
11084 if (this->is_isa_v2
)
11086 // Set 'a' bit. This is 0b00010 in BO field for branch
11087 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11088 // for branch on CTR insns (BO == 1a00t or 1a01t).
11089 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11090 insn
|= 0x02 << 21;
11091 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11092 insn
|= 0x08 << 21;
11098 // Invert 'y' bit if not the default.
11099 if (static_cast<Signed_address
>(value
) < 0)
11102 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11106 case elfcpp::R_POWERPC_PLT16_HA
:
11108 && !parameters
->options().output_is_position_independent())
11110 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11111 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11113 // Convert addis to lis.
11114 if ((insn
& (0x3f << 26)) == 15u << 26
11115 && (insn
& (0x1f << 16)) != 0)
11117 insn
&= ~(0x1f << 16);
11118 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11129 ? relative_value_is_known(gsym
)
11130 : relative_value_is_known(psymval
)))
11135 uint64_t pinsn
, pinsn2
;
11142 // Multi-instruction sequences that access the GOT/TOC can
11143 // be optimized, eg.
11144 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11145 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11147 // addis ra,r2,0; addi rb,ra,x@toc@l;
11148 // to nop; addi rb,r2,x@toc;
11149 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11150 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11151 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11152 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11153 case elfcpp::R_POWERPC_GOT16_HA
:
11154 case elfcpp::R_PPC64_TOC16_HA
:
11155 if (parameters
->options().toc_optimize())
11157 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11158 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11159 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11160 && object
->make_toc_relative(target
, &value
))
11161 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11162 && object
->make_got_relative(target
, psymval
,
11163 rela
.get_r_addend(),
11166 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11167 == ((15u << 26) | (2 << 16)));
11169 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11170 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11171 && value
+ 0x8000 < 0x10000)
11173 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11179 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11180 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11181 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11182 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11183 case elfcpp::R_POWERPC_GOT16_LO
:
11184 case elfcpp::R_PPC64_GOT16_LO_DS
:
11185 case elfcpp::R_PPC64_TOC16_LO
:
11186 case elfcpp::R_PPC64_TOC16_LO_DS
:
11187 if (parameters
->options().toc_optimize())
11189 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11190 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11191 bool changed
= false;
11192 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11193 && object
->make_toc_relative(target
, &value
))
11194 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11195 && object
->make_got_relative(target
, psymval
,
11196 rela
.get_r_addend(),
11199 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11200 insn
^= (14u << 26) ^ (58u << 26);
11201 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11204 if (ok_lo_toc_insn(insn
, r_type
)
11205 && value
+ 0x8000 < 0x10000)
11207 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11209 // Transform addic to addi when we change reg.
11210 insn
&= ~((0x3f << 26) | (0x1f << 16));
11211 insn
|= (14u << 26) | (2 << 16);
11215 insn
&= ~(0x1f << 16);
11221 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11225 case elfcpp::R_PPC64_GOT_PCREL34
:
11226 if (parameters
->options().toc_optimize())
11228 iview
= reinterpret_cast<Insn
*>(view
);
11229 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11231 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11232 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11233 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11236 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11238 if (relval
+ (1ULL << 33) < 1ULL << 34)
11241 // Replace with paddi
11242 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11243 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11244 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11245 pinsn
& 0xffffffff);
11251 case elfcpp::R_PPC64_PCREL34
:
11253 iview
= reinterpret_cast<Insn
*>(view
);
11254 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11256 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11257 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11258 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11259 | (14ULL << 26) /* paddi */))
11263 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11264 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11265 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11266 if (relnum
>= reloc_count
- 1)
11269 Reltype
next_rela(preloc
+ reloc_size
);
11270 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11271 != elfcpp::R_PPC64_PCREL_OPT
)
11272 || next_rela
.get_r_offset() != rela
.get_r_offset())
11275 Address off
= next_rela
.get_r_addend();
11277 off
= 8; // zero means next insn.
11278 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11281 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11282 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11284 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11286 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11288 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11289 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11290 pinsn
& 0xffffffff);
11291 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11296 case elfcpp::R_POWERPC_TPREL16_HA
:
11297 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
11299 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11300 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11301 if ((insn
& ((0x3f << 26) | 0x1f << 16))
11302 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
11306 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11312 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11314 // R_PPC_TLSGD, R_PPC_TLSLD
11317 case elfcpp::R_POWERPC_TPREL16_LO
:
11318 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
11320 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11321 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11322 insn
&= ~(0x1f << 16);
11323 insn
|= (size
== 32 ? 2 : 13) << 16;
11324 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11328 case elfcpp::R_PPC64_ENTRY
:
11329 value
= (target
->got_section()->output_section()->address()
11330 + object
->toc_base_offset());
11331 if (value
+ 0x80008000 <= 0xffffffff
11332 && !parameters
->options().output_is_position_independent())
11334 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11335 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11336 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11338 if ((insn1
& ~0xfffc) == ld_2_12
11339 && insn2
== add_2_2_12
)
11341 insn1
= lis_2
+ ha(value
);
11342 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11343 insn2
= addi_2_2
+ l(value
);
11344 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11351 if (value
+ 0x80008000 <= 0xffffffff)
11353 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11354 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11355 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11357 if ((insn1
& ~0xfffc) == ld_2_12
11358 && insn2
== add_2_2_12
)
11360 insn1
= addis_2_12
+ ha(value
);
11361 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11362 insn2
= addi_2_2
+ l(value
);
11363 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11370 case elfcpp::R_POWERPC_REL16_LO
:
11371 // If we are generating a non-PIC executable, edit
11372 // 0: addis 2,12,.TOC.-0b@ha
11373 // addi 2,2,.TOC.-0b@l
11374 // used by ELFv2 global entry points to set up r2, to
11376 // addi 2,2,.TOC.@l
11377 // if .TOC. is in range. */
11378 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
11381 && target
->abiversion() >= 2
11382 && !parameters
->options().output_is_position_independent()
11383 && rela
.get_r_addend() == d_offset
+ 4
11385 && strcmp(gsym
->name(), ".TOC.") == 0)
11387 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11388 Reltype
prev_rela(preloc
- reloc_size
);
11389 if ((prev_rela
.get_r_info()
11390 == elfcpp::elf_r_info
<size
>(r_sym
,
11391 elfcpp::R_POWERPC_REL16_HA
))
11392 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11393 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11395 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11396 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11397 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11399 if ((insn1
& 0xffff0000) == addis_2_12
11400 && (insn2
& 0xffff0000) == addi_2_2
)
11402 insn1
= lis_2
+ ha(value
+ address
- 4);
11403 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11404 insn2
= addi_2_2
+ l(value
+ address
- 4);
11405 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11408 relinfo
->rr
->set_strategy(relnum
- 1,
11409 Relocatable_relocs::RELOC_SPECIAL
);
11410 relinfo
->rr
->set_strategy(relnum
,
11411 Relocatable_relocs::RELOC_SPECIAL
);
11421 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11422 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11425 case elfcpp::R_POWERPC_ADDR32
:
11426 case elfcpp::R_POWERPC_UADDR32
:
11428 overflow
= Reloc::CHECK_BITFIELD
;
11431 case elfcpp::R_POWERPC_REL32
:
11432 case elfcpp::R_POWERPC_REL16DX_HA
:
11434 overflow
= Reloc::CHECK_SIGNED
;
11437 case elfcpp::R_POWERPC_UADDR16
:
11438 overflow
= Reloc::CHECK_BITFIELD
;
11441 case elfcpp::R_POWERPC_ADDR16
:
11442 // We really should have three separate relocations,
11443 // one for 16-bit data, one for insns with 16-bit signed fields,
11444 // and one for insns with 16-bit unsigned fields.
11445 overflow
= Reloc::CHECK_BITFIELD
;
11446 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11447 overflow
= Reloc::CHECK_LOW_INSN
;
11450 case elfcpp::R_POWERPC_ADDR16_HI
:
11451 case elfcpp::R_POWERPC_ADDR16_HA
:
11452 case elfcpp::R_POWERPC_GOT16_HI
:
11453 case elfcpp::R_POWERPC_GOT16_HA
:
11454 case elfcpp::R_POWERPC_PLT16_HI
:
11455 case elfcpp::R_POWERPC_PLT16_HA
:
11456 case elfcpp::R_POWERPC_SECTOFF_HI
:
11457 case elfcpp::R_POWERPC_SECTOFF_HA
:
11458 case elfcpp::R_PPC64_TOC16_HI
:
11459 case elfcpp::R_PPC64_TOC16_HA
:
11460 case elfcpp::R_PPC64_PLTGOT16_HI
:
11461 case elfcpp::R_PPC64_PLTGOT16_HA
:
11462 case elfcpp::R_POWERPC_TPREL16_HI
:
11463 case elfcpp::R_POWERPC_TPREL16_HA
:
11464 case elfcpp::R_POWERPC_DTPREL16_HI
:
11465 case elfcpp::R_POWERPC_DTPREL16_HA
:
11466 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11467 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11468 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11469 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11470 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11471 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11472 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11473 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11474 case elfcpp::R_POWERPC_REL16_HI
:
11475 case elfcpp::R_POWERPC_REL16_HA
:
11477 overflow
= Reloc::CHECK_HIGH_INSN
;
11480 case elfcpp::R_POWERPC_REL16
:
11481 case elfcpp::R_PPC64_TOC16
:
11482 case elfcpp::R_POWERPC_GOT16
:
11483 case elfcpp::R_POWERPC_SECTOFF
:
11484 case elfcpp::R_POWERPC_TPREL16
:
11485 case elfcpp::R_POWERPC_DTPREL16
:
11486 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11487 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11488 case elfcpp::R_POWERPC_GOT_TPREL16
:
11489 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11490 overflow
= Reloc::CHECK_LOW_INSN
;
11493 case elfcpp::R_PPC64_REL24_NOTOC
:
11497 case elfcpp::R_POWERPC_ADDR24
:
11498 case elfcpp::R_POWERPC_ADDR14
:
11499 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11500 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11501 case elfcpp::R_PPC64_ADDR16_DS
:
11502 case elfcpp::R_POWERPC_REL24
:
11503 case elfcpp::R_PPC_PLTREL24
:
11504 case elfcpp::R_PPC_LOCAL24PC
:
11505 case elfcpp::R_PPC64_TPREL16_DS
:
11506 case elfcpp::R_PPC64_DTPREL16_DS
:
11507 case elfcpp::R_PPC64_TOC16_DS
:
11508 case elfcpp::R_PPC64_GOT16_DS
:
11509 case elfcpp::R_PPC64_SECTOFF_DS
:
11510 case elfcpp::R_POWERPC_REL14
:
11511 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11512 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11513 case elfcpp::R_PPC64_D34
:
11514 case elfcpp::R_PPC64_PCREL34
:
11515 case elfcpp::R_PPC64_GOT_PCREL34
:
11516 case elfcpp::R_PPC64_PLT_PCREL34
:
11517 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11518 case elfcpp::R_PPC64_D28
:
11519 case elfcpp::R_PPC64_PCREL28
:
11520 case elfcpp::R_PPC64_TPREL34
:
11521 case elfcpp::R_PPC64_DTPREL34
:
11522 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11523 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11524 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11525 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11526 overflow
= Reloc::CHECK_SIGNED
;
11530 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11533 if (overflow
== Reloc::CHECK_LOW_INSN
11534 || overflow
== Reloc::CHECK_HIGH_INSN
)
11536 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11538 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11539 overflow
= Reloc::CHECK_BITFIELD
;
11540 else if (overflow
== Reloc::CHECK_LOW_INSN
11541 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11542 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11543 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11544 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11545 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11546 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11547 overflow
= Reloc::CHECK_UNSIGNED
;
11549 overflow
= Reloc::CHECK_SIGNED
;
11552 bool maybe_dq_reloc
= false;
11553 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11554 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11557 case elfcpp::R_POWERPC_NONE
:
11558 case elfcpp::R_POWERPC_TLS
:
11559 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11560 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11561 case elfcpp::R_POWERPC_PLTSEQ
:
11562 case elfcpp::R_POWERPC_PLTCALL
:
11563 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11564 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11565 case elfcpp::R_PPC64_PCREL_OPT
:
11568 case elfcpp::R_PPC64_ADDR64
:
11569 case elfcpp::R_PPC64_REL64
:
11570 case elfcpp::R_PPC64_TOC
:
11571 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11572 Reloc::addr64(view
, value
);
11575 case elfcpp::R_POWERPC_TPREL
:
11576 case elfcpp::R_POWERPC_DTPREL
:
11578 Reloc::addr64(view
, value
);
11580 status
= Reloc::addr32(view
, value
, overflow
);
11583 case elfcpp::R_PPC64_UADDR64
:
11584 Reloc::addr64_u(view
, value
);
11587 case elfcpp::R_POWERPC_ADDR32
:
11588 status
= Reloc::addr32(view
, value
, overflow
);
11591 case elfcpp::R_POWERPC_REL32
:
11592 case elfcpp::R_POWERPC_UADDR32
:
11593 status
= Reloc::addr32_u(view
, value
, overflow
);
11596 case elfcpp::R_PPC64_REL24_NOTOC
:
11598 goto unsupp
; // R_PPC_EMB_RELSDA
11600 case elfcpp::R_POWERPC_ADDR24
:
11601 case elfcpp::R_POWERPC_REL24
:
11602 case elfcpp::R_PPC_PLTREL24
:
11603 case elfcpp::R_PPC_LOCAL24PC
:
11604 status
= Reloc::addr24(view
, value
, overflow
);
11607 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11608 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11609 case elfcpp::R_POWERPC_GOT_TPREL16
:
11610 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11613 // On ppc64 these are all ds form
11614 maybe_dq_reloc
= true;
11618 case elfcpp::R_POWERPC_ADDR16
:
11619 case elfcpp::R_POWERPC_REL16
:
11620 case elfcpp::R_PPC64_TOC16
:
11621 case elfcpp::R_POWERPC_GOT16
:
11622 case elfcpp::R_POWERPC_SECTOFF
:
11623 case elfcpp::R_POWERPC_TPREL16
:
11624 case elfcpp::R_POWERPC_DTPREL16
:
11625 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11626 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11627 case elfcpp::R_POWERPC_ADDR16_LO
:
11628 case elfcpp::R_POWERPC_REL16_LO
:
11629 case elfcpp::R_PPC64_TOC16_LO
:
11630 case elfcpp::R_POWERPC_GOT16_LO
:
11631 case elfcpp::R_POWERPC_PLT16_LO
:
11632 case elfcpp::R_POWERPC_SECTOFF_LO
:
11633 case elfcpp::R_POWERPC_TPREL16_LO
:
11634 case elfcpp::R_POWERPC_DTPREL16_LO
:
11635 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11636 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11638 status
= Reloc::addr16(view
, value
, overflow
);
11640 maybe_dq_reloc
= true;
11643 case elfcpp::R_POWERPC_UADDR16
:
11644 status
= Reloc::addr16_u(view
, value
, overflow
);
11647 case elfcpp::R_PPC64_ADDR16_HIGH
:
11648 case elfcpp::R_PPC64_TPREL16_HIGH
:
11649 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11651 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11654 case elfcpp::R_POWERPC_ADDR16_HI
:
11655 case elfcpp::R_POWERPC_REL16_HI
:
11656 case elfcpp::R_PPC64_REL16_HIGH
:
11657 case elfcpp::R_PPC64_TOC16_HI
:
11658 case elfcpp::R_POWERPC_GOT16_HI
:
11659 case elfcpp::R_POWERPC_PLT16_HI
:
11660 case elfcpp::R_POWERPC_SECTOFF_HI
:
11661 case elfcpp::R_POWERPC_TPREL16_HI
:
11662 case elfcpp::R_POWERPC_DTPREL16_HI
:
11663 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11664 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11665 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11666 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11667 Reloc::addr16_hi(view
, value
);
11670 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11671 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11672 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11674 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11677 case elfcpp::R_POWERPC_ADDR16_HA
:
11678 case elfcpp::R_POWERPC_REL16_HA
:
11679 case elfcpp::R_PPC64_REL16_HIGHA
:
11680 case elfcpp::R_PPC64_TOC16_HA
:
11681 case elfcpp::R_POWERPC_GOT16_HA
:
11682 case elfcpp::R_POWERPC_PLT16_HA
:
11683 case elfcpp::R_POWERPC_SECTOFF_HA
:
11684 case elfcpp::R_POWERPC_TPREL16_HA
:
11685 case elfcpp::R_POWERPC_DTPREL16_HA
:
11686 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11687 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11688 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11689 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11690 Reloc::addr16_ha(view
, value
);
11693 case elfcpp::R_POWERPC_REL16DX_HA
:
11694 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11697 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11699 // R_PPC_EMB_NADDR16_LO
11702 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11703 case elfcpp::R_PPC64_REL16_HIGHER
:
11704 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11705 Reloc::addr16_hi2(view
, value
);
11708 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11710 // R_PPC_EMB_NADDR16_HI
11713 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11714 case elfcpp::R_PPC64_REL16_HIGHERA
:
11715 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11716 Reloc::addr16_ha2(view
, value
);
11719 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11721 // R_PPC_EMB_NADDR16_HA
11724 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11725 case elfcpp::R_PPC64_REL16_HIGHEST
:
11726 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11727 Reloc::addr16_hi3(view
, value
);
11730 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11732 // R_PPC_EMB_SDAI16
11735 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11736 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11737 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11738 Reloc::addr16_ha3(view
, value
);
11741 case elfcpp::R_PPC64_DTPREL16_DS
:
11742 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11744 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11747 case elfcpp::R_PPC64_TPREL16_DS
:
11748 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11750 // R_PPC_TLSGD, R_PPC_TLSLD
11753 case elfcpp::R_PPC64_ADDR16_DS
:
11754 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11755 case elfcpp::R_PPC64_TOC16_DS
:
11756 case elfcpp::R_PPC64_TOC16_LO_DS
:
11757 case elfcpp::R_PPC64_GOT16_DS
:
11758 case elfcpp::R_PPC64_GOT16_LO_DS
:
11759 case elfcpp::R_PPC64_PLT16_LO_DS
:
11760 case elfcpp::R_PPC64_SECTOFF_DS
:
11761 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11762 maybe_dq_reloc
= true;
11765 case elfcpp::R_POWERPC_ADDR14
:
11766 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11767 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11768 case elfcpp::R_POWERPC_REL14
:
11769 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11770 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11771 status
= Reloc::addr14(view
, value
, overflow
);
11774 case elfcpp::R_POWERPC_COPY
:
11775 case elfcpp::R_POWERPC_GLOB_DAT
:
11776 case elfcpp::R_POWERPC_JMP_SLOT
:
11777 case elfcpp::R_POWERPC_RELATIVE
:
11778 case elfcpp::R_POWERPC_DTPMOD
:
11779 case elfcpp::R_PPC64_JMP_IREL
:
11780 case elfcpp::R_POWERPC_IRELATIVE
:
11781 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11782 _("unexpected reloc %u in object file"),
11786 case elfcpp::R_PPC64_TOCSAVE
:
11792 Symbol_location loc
;
11793 loc
.object
= relinfo
->object
;
11794 loc
.shndx
= relinfo
->data_shndx
;
11795 loc
.offset
= rela
.get_r_offset();
11796 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
11797 if (p
!= target
->tocsave_loc().end())
11799 // If we've generated plt calls using this tocsave, then
11800 // the nop needs to be changed to save r2.
11801 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11802 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11803 elfcpp::Swap
<32, big_endian
>::
11804 writeval(iview
, std_2_1
+ target
->stk_toc());
11809 case elfcpp::R_PPC_EMB_SDA2I16
:
11810 case elfcpp::R_PPC_EMB_SDA2REL
:
11813 // R_PPC64_TLSGD, R_PPC64_TLSLD
11816 case elfcpp::R_PPC64_D34
:
11817 case elfcpp::R_PPC64_D34_LO
:
11818 case elfcpp::R_PPC64_PCREL34
:
11819 case elfcpp::R_PPC64_GOT_PCREL34
:
11820 case elfcpp::R_PPC64_PLT_PCREL34
:
11821 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11822 case elfcpp::R_PPC64_TPREL34
:
11823 case elfcpp::R_PPC64_DTPREL34
:
11824 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11825 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11826 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11827 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11830 status
= Reloc::addr34(view
, value
, overflow
);
11833 case elfcpp::R_PPC64_D34_HI30
:
11836 Reloc::addr34_hi(view
, value
);
11839 case elfcpp::R_PPC64_D34_HA30
:
11842 Reloc::addr34_ha(view
, value
);
11845 case elfcpp::R_PPC64_D28
:
11846 case elfcpp::R_PPC64_PCREL28
:
11849 status
= Reloc::addr28(view
, value
, overflow
);
11852 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
11853 case elfcpp::R_PPC64_REL16_HIGHER34
:
11856 Reloc::addr16_higher34(view
, value
);
11859 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
11860 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11863 Reloc::addr16_highera34(view
, value
);
11866 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
11867 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11870 Reloc::addr16_highest34(view
, value
);
11873 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
11874 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11877 Reloc::addr16_highesta34(view
, value
);
11880 case elfcpp::R_POWERPC_PLT32
:
11881 case elfcpp::R_POWERPC_PLTREL32
:
11882 case elfcpp::R_PPC_SDAREL16
:
11883 case elfcpp::R_POWERPC_ADDR30
:
11884 case elfcpp::R_PPC64_PLT64
:
11885 case elfcpp::R_PPC64_PLTREL64
:
11886 case elfcpp::R_PPC64_PLTGOT16
:
11887 case elfcpp::R_PPC64_PLTGOT16_LO
:
11888 case elfcpp::R_PPC64_PLTGOT16_HI
:
11889 case elfcpp::R_PPC64_PLTGOT16_HA
:
11890 case elfcpp::R_PPC64_PLTGOT16_DS
:
11891 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
11892 case elfcpp::R_PPC_TOC16
:
11895 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11896 _("unsupported reloc %u"),
11901 if (maybe_dq_reloc
)
11904 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11906 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
11907 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
11908 && (insn
& 3) == 1))
11909 status
= Reloc::addr16_dq(view
, value
, overflow
);
11910 else if (size
== 64
11911 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
11912 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
11913 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
11914 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
11915 status
= Reloc::addr16_ds(view
, value
, overflow
);
11917 status
= Reloc::addr16(view
, value
, overflow
);
11920 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
11923 && gsym
->is_undefined()
11924 && is_branch_reloc
<size
>(r_type
))))
11926 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11927 _("relocation overflow"));
11928 if (has_stub_value
)
11929 gold_info(_("try relinking with a smaller --stub-group-size"));
11935 // Relocate section data.
11937 template<int size
, bool big_endian
>
11939 Target_powerpc
<size
, big_endian
>::relocate_section(
11940 const Relocate_info
<size
, big_endian
>* relinfo
,
11941 unsigned int sh_type
,
11942 const unsigned char* prelocs
,
11943 size_t reloc_count
,
11944 Output_section
* output_section
,
11945 bool needs_special_offset_handling
,
11946 unsigned char* view
,
11948 section_size_type view_size
,
11949 const Reloc_symbol_changes
* reloc_symbol_changes
)
11951 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
11952 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
11953 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
11954 Powerpc_comdat_behavior
;
11955 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11958 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11960 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
11961 Powerpc_comdat_behavior
, Classify_reloc
>(
11967 needs_special_offset_handling
,
11971 reloc_symbol_changes
);
11974 template<int size
, bool big_endian
>
11975 class Powerpc_scan_relocatable_reloc
11978 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11979 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11980 static const int sh_type
= elfcpp::SHT_RELA
;
11982 // Return the symbol referred to by the relocation.
11983 static inline unsigned int
11984 get_r_sym(const Reltype
* reloc
)
11985 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
11987 // Return the type of the relocation.
11988 static inline unsigned int
11989 get_r_type(const Reltype
* reloc
)
11990 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
11992 // Return the strategy to use for a local symbol which is not a
11993 // section symbol, given the relocation type.
11994 inline Relocatable_relocs::Reloc_strategy
11995 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
11997 if (r_type
== 0 && r_sym
== 0)
11998 return Relocatable_relocs::RELOC_DISCARD
;
11999 return Relocatable_relocs::RELOC_COPY
;
12002 // Return the strategy to use for a local symbol which is a section
12003 // symbol, given the relocation type.
12004 inline Relocatable_relocs::Reloc_strategy
12005 local_section_strategy(unsigned int, Relobj
*)
12007 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12010 // Return the strategy to use for a global symbol, given the
12011 // relocation type, the object, and the symbol index.
12012 inline Relocatable_relocs::Reloc_strategy
12013 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12016 && (r_type
== elfcpp::R_PPC_PLTREL24
12017 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12018 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12019 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12020 return Relocatable_relocs::RELOC_SPECIAL
;
12021 return Relocatable_relocs::RELOC_COPY
;
12025 // Scan the relocs during a relocatable link.
12027 template<int size
, bool big_endian
>
12029 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12030 Symbol_table
* symtab
,
12032 Sized_relobj_file
<size
, big_endian
>* object
,
12033 unsigned int data_shndx
,
12034 unsigned int sh_type
,
12035 const unsigned char* prelocs
,
12036 size_t reloc_count
,
12037 Output_section
* output_section
,
12038 bool needs_special_offset_handling
,
12039 size_t local_symbol_count
,
12040 const unsigned char* plocal_symbols
,
12041 Relocatable_relocs
* rr
)
12043 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12045 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12047 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12055 needs_special_offset_handling
,
12056 local_symbol_count
,
12061 // Scan the relocs for --emit-relocs.
12063 template<int size
, bool big_endian
>
12065 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12066 Symbol_table
* symtab
,
12068 Sized_relobj_file
<size
, big_endian
>* object
,
12069 unsigned int data_shndx
,
12070 unsigned int sh_type
,
12071 const unsigned char* prelocs
,
12072 size_t reloc_count
,
12073 Output_section
* output_section
,
12074 bool needs_special_offset_handling
,
12075 size_t local_symbol_count
,
12076 const unsigned char* plocal_syms
,
12077 Relocatable_relocs
* rr
)
12079 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12081 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12082 Emit_relocs_strategy
;
12084 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12086 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12094 needs_special_offset_handling
,
12095 local_symbol_count
,
12100 // Emit relocations for a section.
12101 // This is a modified version of the function by the same name in
12102 // target-reloc.h. Using relocate_special_relocatable for
12103 // R_PPC_PLTREL24 would require duplication of the entire body of the
12104 // loop, so we may as well duplicate the whole thing.
12106 template<int size
, bool big_endian
>
12108 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12109 const Relocate_info
<size
, big_endian
>* relinfo
,
12110 unsigned int sh_type
,
12111 const unsigned char* prelocs
,
12112 size_t reloc_count
,
12113 Output_section
* output_section
,
12114 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12116 Address view_address
,
12118 unsigned char* reloc_view
,
12119 section_size_type reloc_view_size
)
12121 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12123 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12124 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12125 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12126 // Offset from start of insn to d-field reloc.
12127 const int d_offset
= big_endian
? 2 : 0;
12129 Powerpc_relobj
<size
, big_endian
>* const object
12130 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12131 const unsigned int local_count
= object
->local_symbol_count();
12132 unsigned int got2_shndx
= object
->got2_shndx();
12133 Address got2_addend
= 0;
12134 if (got2_shndx
!= 0)
12136 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12137 gold_assert(got2_addend
!= invalid_address
);
12140 const bool relocatable
= parameters
->options().relocatable();
12142 unsigned char* pwrite
= reloc_view
;
12143 bool zap_next
= false;
12144 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12146 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12147 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12150 Reltype
reloc(prelocs
);
12151 Reltype_write
reloc_write(pwrite
);
12153 Address offset
= reloc
.get_r_offset();
12154 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12155 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12156 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12157 const unsigned int orig_r_sym
= r_sym
;
12158 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12159 = reloc
.get_r_addend();
12160 const Symbol
* gsym
= NULL
;
12164 // We could arrange to discard these and other relocs for
12165 // tls optimised sequences in the strategy methods, but for
12166 // now do as BFD ld does.
12167 r_type
= elfcpp::R_POWERPC_NONE
;
12171 // Get the new symbol index.
12172 Output_section
* os
= NULL
;
12173 if (r_sym
< local_count
)
12177 case Relocatable_relocs::RELOC_COPY
:
12178 case Relocatable_relocs::RELOC_SPECIAL
:
12181 r_sym
= object
->symtab_index(r_sym
);
12182 gold_assert(r_sym
!= -1U);
12186 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12188 // We are adjusting a section symbol. We need to find
12189 // the symbol table index of the section symbol for
12190 // the output section corresponding to input section
12191 // in which this symbol is defined.
12192 gold_assert(r_sym
< local_count
);
12194 unsigned int shndx
=
12195 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12196 gold_assert(is_ordinary
);
12197 os
= object
->output_section(shndx
);
12198 gold_assert(os
!= NULL
);
12199 gold_assert(os
->needs_symtab_index());
12200 r_sym
= os
->symtab_index();
12205 gold_unreachable();
12210 gsym
= object
->global_symbol(r_sym
);
12211 gold_assert(gsym
!= NULL
);
12212 if (gsym
->is_forwarder())
12213 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12215 gold_assert(gsym
->has_symtab_index());
12216 r_sym
= gsym
->symtab_index();
12219 // Get the new offset--the location in the output section where
12220 // this relocation should be applied.
12221 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12222 offset
+= offset_in_output_section
;
12225 section_offset_type sot_offset
=
12226 convert_types
<section_offset_type
, Address
>(offset
);
12227 section_offset_type new_sot_offset
=
12228 output_section
->output_offset(object
, relinfo
->data_shndx
,
12230 gold_assert(new_sot_offset
!= -1);
12231 offset
= new_sot_offset
;
12234 // In an object file, r_offset is an offset within the section.
12235 // In an executable or dynamic object, generated by
12236 // --emit-relocs, r_offset is an absolute address.
12239 offset
+= view_address
;
12240 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12241 offset
-= offset_in_output_section
;
12244 // Handle the reloc addend based on the strategy.
12245 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12247 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12249 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12250 addend
= psymval
->value(object
, addend
);
12251 // In a relocatable link, the symbol value is relative to
12252 // the start of the output section. For a non-relocatable
12253 // link, we need to adjust the addend.
12256 gold_assert(os
!= NULL
);
12257 addend
-= os
->address();
12260 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12264 if (addend
>= 32768)
12265 addend
+= got2_addend
;
12267 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12269 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12270 addend
-= d_offset
;
12272 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12274 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12275 addend
-= d_offset
+ 4;
12279 gold_unreachable();
12283 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12284 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12285 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12286 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12288 // First instruction of a global dynamic sequence,
12290 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12291 switch (this->optimize_tls_gd(final
))
12293 case tls::TLSOPT_TO_IE
:
12294 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12295 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12297 case tls::TLSOPT_TO_LE
:
12298 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12299 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12300 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12303 r_type
= elfcpp::R_POWERPC_NONE
;
12304 offset
-= d_offset
;
12311 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12312 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12313 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12314 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12316 // First instruction of a local dynamic sequence,
12318 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12320 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12321 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12323 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12324 const Output_section
* os
= relinfo
->layout
->tls_segment()
12326 gold_assert(os
!= NULL
);
12327 gold_assert(os
->needs_symtab_index());
12328 r_sym
= os
->symtab_index();
12329 addend
= dtp_offset
;
12333 r_type
= elfcpp::R_POWERPC_NONE
;
12334 offset
-= d_offset
;
12338 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12339 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12340 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12341 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12343 // First instruction of initial exec sequence.
12344 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12345 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12347 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12348 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12349 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12352 r_type
= elfcpp::R_POWERPC_NONE
;
12353 offset
-= d_offset
;
12357 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12358 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12360 // Second instruction of a global dynamic sequence,
12361 // the __tls_get_addr call
12362 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12363 switch (this->optimize_tls_gd(final
))
12365 case tls::TLSOPT_TO_IE
:
12366 r_type
= elfcpp::R_POWERPC_NONE
;
12369 case tls::TLSOPT_TO_LE
:
12370 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12371 offset
+= d_offset
;
12378 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12379 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12381 // Second instruction of a local dynamic sequence,
12382 // the __tls_get_addr call
12383 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12385 const Output_section
* os
= relinfo
->layout
->tls_segment()
12387 gold_assert(os
!= NULL
);
12388 gold_assert(os
->needs_symtab_index());
12389 r_sym
= os
->symtab_index();
12390 addend
= dtp_offset
;
12391 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12392 offset
+= d_offset
;
12396 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12398 // Second instruction of an initial exec sequence
12399 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12400 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12402 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12403 offset
+= d_offset
;
12408 reloc_write
.put_r_offset(offset
);
12409 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12410 reloc_write
.put_r_addend(addend
);
12412 pwrite
+= reloc_size
;
12415 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12416 == reloc_view_size
);
12419 // Return the value to use for a dynamic symbol which requires special
12420 // treatment. This is how we support equality comparisons of function
12421 // pointers across shared library boundaries, as described in the
12422 // processor specific ABI supplement.
12424 template<int size
, bool big_endian
>
12426 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12430 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12431 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12432 p
!= this->stub_tables_
.end();
12435 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12436 = (*p
)->find_plt_call_entry(gsym
);
12438 return (*p
)->stub_address() + ent
->off_
;
12441 else if (this->abiversion() >= 2)
12443 Address off
= this->glink_section()->find_global_entry(gsym
);
12444 if (off
!= invalid_address
)
12445 return this->glink_section()->global_entry_address() + off
;
12447 gold_unreachable();
12450 // Return the PLT address to use for a local symbol.
12451 template<int size
, bool big_endian
>
12453 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12454 const Relobj
* object
,
12455 unsigned int symndx
) const
12459 const Sized_relobj
<size
, big_endian
>* relobj
12460 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12461 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12462 p
!= this->stub_tables_
.end();
12465 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12466 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12468 return (*p
)->stub_address() + ent
->off_
;
12471 gold_unreachable();
12474 // Return the PLT address to use for a global symbol.
12475 template<int size
, bool big_endian
>
12477 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12478 const Symbol
* gsym
) const
12482 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12483 p
!= this->stub_tables_
.end();
12486 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12487 = (*p
)->find_plt_call_entry(gsym
);
12489 return (*p
)->stub_address() + ent
->off_
;
12492 else if (this->abiversion() >= 2)
12494 Address off
= this->glink_section()->find_global_entry(gsym
);
12495 if (off
!= invalid_address
)
12496 return this->glink_section()->global_entry_address() + off
;
12498 gold_unreachable();
12501 // Return the offset to use for the GOT_INDX'th got entry which is
12502 // for a local tls symbol specified by OBJECT, SYMNDX.
12503 template<int size
, bool big_endian
>
12505 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12506 const Relobj
* object
,
12507 unsigned int symndx
,
12508 unsigned int got_indx
) const
12510 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12511 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12512 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12514 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12515 got_type
<= GOT_TYPE_TPREL
;
12516 got_type
= Got_type(got_type
+ 1))
12517 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12519 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12520 if (got_type
== GOT_TYPE_TLSGD
)
12522 if (off
== got_indx
* (size
/ 8))
12524 if (got_type
== GOT_TYPE_TPREL
)
12527 return -dtp_offset
;
12531 gold_unreachable();
12534 // Return the offset to use for the GOT_INDX'th got entry which is
12535 // for global tls symbol GSYM.
12536 template<int size
, bool big_endian
>
12538 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12540 unsigned int got_indx
) const
12542 if (gsym
->type() == elfcpp::STT_TLS
)
12544 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12545 got_type
<= GOT_TYPE_TPREL
;
12546 got_type
= Got_type(got_type
+ 1))
12547 if (gsym
->has_got_offset(got_type
))
12549 unsigned int off
= gsym
->got_offset(got_type
);
12550 if (got_type
== GOT_TYPE_TLSGD
)
12552 if (off
== got_indx
* (size
/ 8))
12554 if (got_type
== GOT_TYPE_TPREL
)
12557 return -dtp_offset
;
12561 gold_unreachable();
12564 // The selector for powerpc object files.
12566 template<int size
, bool big_endian
>
12567 class Target_selector_powerpc
: public Target_selector
12570 Target_selector_powerpc()
12571 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12574 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12575 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12577 ? (big_endian
? "elf64ppc" : "elf64lppc")
12578 : (big_endian
? "elf32ppc" : "elf32lppc")))
12582 do_instantiate_target()
12583 { return new Target_powerpc
<size
, big_endian
>(); }
12586 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12587 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12588 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12589 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12591 // Instantiate these constants for -O0
12592 template<int size
, bool big_endian
>
12593 const typename Output_data_glink
<size
, big_endian
>::Address
12594 Output_data_glink
<size
, big_endian
>::invalid_address
;
12595 template<int size
, bool big_endian
>
12596 const typename Stub_table
<size
, big_endian
>::Address
12597 Stub_table
<size
, big_endian
>::invalid_address
;
12598 template<int size
, bool big_endian
>
12599 const typename Target_powerpc
<size
, big_endian
>::Address
12600 Target_powerpc
<size
, big_endian
>::invalid_address
;
12602 } // End anonymous namespace.