1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2023 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
44 #include "attributes.h"
51 template<int size
, bool big_endian
>
52 class Output_data_plt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_brlt_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_got_powerpc
;
60 template<int size
, bool big_endian
>
61 class Output_data_glink
;
63 template<int size
, bool big_endian
>
66 template<int size
, bool big_endian
>
67 class Output_data_save_res
;
69 template<int size
, bool big_endian
>
72 struct Stub_table_owner
75 : output_section(NULL
), owner(NULL
)
78 Output_section
* output_section
;
79 const Output_section::Input_section
* owner
;
83 inline bool is_branch_reloc(unsigned int);
86 inline bool is_plt16_reloc(unsigned int);
88 // Counter incremented on every Powerpc_relobj constructed.
89 static uint32_t object_id
= 0;
91 template<int size
, bool big_endian
>
92 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
95 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
96 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
97 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
99 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
100 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
101 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
102 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
103 has_small_toc_reloc_(false), opd_valid_(false),
104 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
105 access_from_map_(), has14_(), stub_table_index_(), st_other_(),
106 attributes_section_data_(NULL
)
108 this->set_abiversion(0);
112 { delete this->attributes_section_data_
; }
114 // Read the symbols then set up st_other vector.
116 do_read_symbols(Read_symbols_data
*);
118 // Arrange to always relocate .toc first.
120 do_relocate_sections(
121 const Symbol_table
* symtab
, const Layout
* layout
,
122 const unsigned char* pshdrs
, Output_file
* of
,
123 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
125 // The .toc section index.
132 // Mark .toc entry at OFF as not optimizable.
134 set_no_toc_opt(Address off
)
136 if (this->no_toc_opt_
.empty())
137 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
140 if (off
< this->no_toc_opt_
.size())
141 this->no_toc_opt_
[off
] = true;
144 // Mark the entire .toc as not optimizable.
148 this->no_toc_opt_
.resize(1);
149 this->no_toc_opt_
[0] = true;
152 // Return true if code using the .toc entry at OFF should not be edited.
154 no_toc_opt(Address off
) const
156 if (this->no_toc_opt_
.empty())
159 if (off
>= this->no_toc_opt_
.size())
161 return this->no_toc_opt_
[off
];
164 // The .got2 section shndx.
169 return this->special_
;
174 // The .opd section shndx.
181 return this->special_
;
184 // Init OPD entry arrays.
186 init_opd(size_t opd_size
)
188 size_t count
= this->opd_ent_ndx(opd_size
);
189 this->opd_ent_
.resize(count
);
192 // Return section and offset of function entry for .opd + R_OFF.
194 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
196 size_t ndx
= this->opd_ent_ndx(r_off
);
197 gold_assert(ndx
< this->opd_ent_
.size());
198 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
200 *value
= this->opd_ent_
[ndx
].off
;
201 return this->opd_ent_
[ndx
].shndx
;
204 // Set section and offset of function entry for .opd + R_OFF.
206 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
208 size_t ndx
= this->opd_ent_ndx(r_off
);
209 gold_assert(ndx
< this->opd_ent_
.size());
210 this->opd_ent_
[ndx
].shndx
= shndx
;
211 this->opd_ent_
[ndx
].off
= value
;
214 // Return discard flag for .opd + R_OFF.
216 get_opd_discard(Address r_off
) const
218 size_t ndx
= this->opd_ent_ndx(r_off
);
219 gold_assert(ndx
< this->opd_ent_
.size());
220 return this->opd_ent_
[ndx
].discard
;
223 // Set discard flag for .opd + R_OFF.
225 set_opd_discard(Address r_off
)
227 size_t ndx
= this->opd_ent_ndx(r_off
);
228 gold_assert(ndx
< this->opd_ent_
.size());
229 this->opd_ent_
[ndx
].discard
= true;
234 { return this->opd_valid_
; }
238 { this->opd_valid_
= true; }
240 // Examine .rela.opd to build info about function entry points.
242 scan_opd_relocs(size_t reloc_count
,
243 const unsigned char* prelocs
,
244 const unsigned char* plocal_syms
);
246 // Returns true if a code sequence loading a TOC entry can be
247 // converted into code calculating a TOC pointer relative offset.
249 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
253 make_got_relative(Target_powerpc
<size
, big_endian
>* target
,
254 const Symbol_value
<size
>* psymval
,
258 // Perform the Sized_relobj_file method, then set up opd info from
261 do_read_relocs(Read_relocs_data
*);
264 do_find_special_sections(Read_symbols_data
* sd
);
266 // Adjust this local symbol value. Return false if the symbol
267 // should be discarded from the output file.
269 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
271 if (size
== 64 && this->opd_shndx() != 0)
274 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
276 if (this->get_opd_discard(lv
->input_value()))
284 { return &this->access_from_map_
; }
286 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
287 // section at DST_OFF.
289 add_reference(Relobj
* src_obj
,
290 unsigned int src_indx
,
291 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
293 Section_id
src_id(src_obj
, src_indx
);
294 this->access_from_map_
[dst_off
].insert(src_id
);
297 // Add a reference to the code section specified by the .opd entry
300 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
302 size_t ndx
= this->opd_ent_ndx(dst_off
);
303 if (ndx
>= this->opd_ent_
.size())
304 this->opd_ent_
.resize(ndx
+ 1);
305 this->opd_ent_
[ndx
].gc_mark
= true;
309 process_gc_mark(Symbol_table
* symtab
)
311 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
312 if (this->opd_ent_
[i
].gc_mark
)
314 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
315 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
320 set_has_small_toc_reloc()
321 { has_small_toc_reloc_
= true; }
324 has_small_toc_reloc() const
325 { return has_small_toc_reloc_
; }
328 set_has_14bit_branch(unsigned int shndx
)
330 if (shndx
>= this->has14_
.size())
331 this->has14_
.resize(shndx
+ 1);
332 this->has14_
[shndx
] = true;
336 has_14bit_branch(unsigned int shndx
) const
337 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
340 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
342 if (shndx
>= this->stub_table_index_
.size())
343 this->stub_table_index_
.resize(shndx
+ 1, -1);
344 this->stub_table_index_
[shndx
] = stub_index
;
347 Stub_table
<size
, big_endian
>*
348 stub_table(unsigned int shndx
)
350 if (shndx
< this->stub_table_index_
.size())
352 Target_powerpc
<size
, big_endian
>* target
353 = static_cast<Target_powerpc
<size
, big_endian
>*>(
354 parameters
->sized_target
<size
, big_endian
>());
355 unsigned int indx
= this->stub_table_index_
[shndx
];
356 if (indx
< target
->stub_tables().size())
357 return target
->stub_tables()[indx
];
365 this->stub_table_index_
.clear();
370 { return this->uniq_
; }
374 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
376 // Set ABI version for input and output
378 set_abiversion(int ver
);
381 st_other (unsigned int symndx
) const
383 return this->st_other_
[symndx
];
387 ppc64_local_entry_offset(const Symbol
* sym
) const
388 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
391 ppc64_local_entry_offset(unsigned int symndx
) const
392 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
395 ppc64_needs_toc(const Symbol
* sym
) const
396 { return sym
->nonvis() > 1 << 3; }
399 ppc64_needs_toc(unsigned int symndx
) const
400 { return this->st_other_
[symndx
] > 1 << 5; }
402 // The contents of the .gnu.attributes section if there is one.
403 const Attributes_section_data
*
404 attributes_section_data() const
405 { return this->attributes_section_data_
; }
416 // Return index into opd_ent_ array for .opd entry at OFF.
417 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
418 // apart when the language doesn't use the last 8-byte word, the
419 // environment pointer. Thus dividing the entry section offset by
420 // 16 will give an index into opd_ent_ that works for either layout
421 // of .opd. (It leaves some elements of the vector unused when .opd
422 // entries are spaced 24 bytes apart, but we don't know the spacing
423 // until relocations are processed, and in any case it is possible
424 // for an object to have some entries spaced 16 bytes apart and
425 // others 24 bytes apart.)
427 opd_ent_ndx(size_t off
) const
430 // Per object unique identifier
433 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
434 unsigned int special_
;
436 // For 64-bit the .rela.toc and .toc section shdnx.
437 unsigned int relatoc_
;
440 // For 64-bit, whether this object uses small model relocs to access
442 bool has_small_toc_reloc_
;
444 // Set at the start of gc_process_relocs, when we know opd_ent_
445 // vector is valid. The flag could be made atomic and set in
446 // do_read_relocs with memory_order_release and then tested with
447 // memory_order_acquire, potentially resulting in fewer entries in
452 elfcpp::Elf_Word e_flags_
;
454 // For 64-bit, an array with one entry per 64-bit word in the .toc
455 // section, set if accesses using that word cannot be optimised.
456 std::vector
<bool> no_toc_opt_
;
458 // The first 8-byte word of an OPD entry gives the address of the
459 // entry point of the function. Relocatable object files have a
460 // relocation on this word. The following vector records the
461 // section and offset specified by these relocations.
462 std::vector
<Opd_ent
> opd_ent_
;
464 // References made to this object's .opd section when running
465 // gc_process_relocs for another object, before the opd_ent_ vector
466 // is valid for this object.
467 Access_from access_from_map_
;
469 // Whether input section has a 14-bit branch reloc.
470 std::vector
<bool> has14_
;
472 // The stub table to use for a given input section.
473 std::vector
<unsigned int> stub_table_index_
;
475 // ELF st_other field for local symbols.
476 std::vector
<unsigned char> st_other_
;
478 // Object attributes if there is a .gnu.attributes section.
479 Attributes_section_data
* attributes_section_data_
;
482 template<int size
, bool big_endian
>
483 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
486 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
488 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
489 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
490 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
491 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
492 attributes_section_data_(NULL
)
494 this->set_abiversion(0);
498 { delete this->attributes_section_data_
; }
500 // Call Sized_dynobj::do_read_symbols to read the symbols then
501 // read .opd from a dynamic object, filling in opd_ent_ vector,
503 do_read_symbols(Read_symbols_data
*);
505 // The .opd section shndx.
509 return this->opd_shndx_
;
512 // The .opd section address.
516 return this->opd_address_
;
519 // Init OPD entry arrays.
521 init_opd(size_t opd_size
)
523 size_t count
= this->opd_ent_ndx(opd_size
);
524 this->opd_ent_
.resize(count
);
527 // Return section and offset of function entry for .opd + R_OFF.
529 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
531 size_t ndx
= this->opd_ent_ndx(r_off
);
532 gold_assert(ndx
< this->opd_ent_
.size());
533 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
535 *value
= this->opd_ent_
[ndx
].off
;
536 return this->opd_ent_
[ndx
].shndx
;
539 // Set section and offset of function entry for .opd + R_OFF.
541 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
543 size_t ndx
= this->opd_ent_ndx(r_off
);
544 gold_assert(ndx
< this->opd_ent_
.size());
545 this->opd_ent_
[ndx
].shndx
= shndx
;
546 this->opd_ent_
[ndx
].off
= value
;
551 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
553 // Set ABI version for input and output.
555 set_abiversion(int ver
);
557 // The contents of the .gnu.attributes section if there is one.
558 const Attributes_section_data
*
559 attributes_section_data() const
560 { return this->attributes_section_data_
; }
563 // Used to specify extent of executable sections.
566 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
567 : start(start_
), len(len_
), shndx(shndx_
)
571 operator<(const Sec_info
& that
) const
572 { return this->start
< that
.start
; }
585 // Return index into opd_ent_ array for .opd entry at OFF.
587 opd_ent_ndx(size_t off
) const
590 // For 64-bit the .opd section shndx and address.
591 unsigned int opd_shndx_
;
592 Address opd_address_
;
595 elfcpp::Elf_Word e_flags_
;
597 // The first 8-byte word of an OPD entry gives the address of the
598 // entry point of the function. Records the section and offset
599 // corresponding to the address. Note that in dynamic objects,
600 // offset is *not* relative to the section.
601 std::vector
<Opd_ent
> opd_ent_
;
603 // Object attributes if there is a .gnu.attributes section.
604 Attributes_section_data
* attributes_section_data_
;
607 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
608 // base class will emit.
610 template<int sh_type
, int size
, bool big_endian
>
611 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
614 Powerpc_copy_relocs()
615 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
618 // Emit any saved relocations which turn out to be needed. This is
619 // called after all the relocs have been scanned.
621 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
624 // The types of GOT entries needed for this platform.
625 // These values are exposed to the ABI in an incremental link, but
626 // powerpc does not support incremental linking as yet.
629 GOT_TYPE_STANDARD
= 0,
630 GOT_TYPE_TLSGD
= 1, // double entry for @got@tlsgd
631 GOT_TYPE_DTPREL
= 2, // entry for @got@dtprel
632 GOT_TYPE_TPREL
= 3, // entry for @got@tprel
634 GOT_TYPE_SMALL_TLSGD
= 5,
635 GOT_TYPE_SMALL_DTPREL
= 6,
636 GOT_TYPE_SMALL_TPREL
= 7
639 template<int size
, bool big_endian
>
640 class Target_powerpc
: public Sized_target
<size
, big_endian
>
644 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
645 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
646 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
647 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
648 static const Address invalid_address
= static_cast<Address
>(0) - 1;
649 // Offset of tp and dtp pointers from start of TLS block.
650 static const Address tp_offset
= 0x7000;
651 static const Address dtp_offset
= 0x8000;
654 : Sized_target
<size
, big_endian
>(&powerpc_info
),
655 got_(NULL
), biggot_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
),
656 brlt_section_(NULL
), glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
657 tlsld_got_offset_(-1U),
658 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
659 power10_relocs_(false), plt_thread_safe_(false), plt_localentry0_(false),
660 plt_localentry0_init_(false), has_localentry0_(false),
661 has_tls_get_addr_opt_(false), no_tprel_opt_(false),
662 relax_failed_(false), relax_fail_count_(0),
663 stub_group_size_(0), savres_section_(0),
664 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
665 attributes_section_data_(NULL
),
666 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
670 // Process the relocations to determine unreferenced sections for
671 // garbage collection.
673 gc_process_relocs(Symbol_table
* symtab
,
675 Sized_relobj_file
<size
, big_endian
>* object
,
676 unsigned int data_shndx
,
677 unsigned int sh_type
,
678 const unsigned char* prelocs
,
680 Output_section
* output_section
,
681 bool needs_special_offset_handling
,
682 size_t local_symbol_count
,
683 const unsigned char* plocal_symbols
);
685 // Scan the relocations to look for symbol adjustments.
687 scan_relocs(Symbol_table
* symtab
,
689 Sized_relobj_file
<size
, big_endian
>* object
,
690 unsigned int data_shndx
,
691 unsigned int sh_type
,
692 const unsigned char* prelocs
,
694 Output_section
* output_section
,
695 bool needs_special_offset_handling
,
696 size_t local_symbol_count
,
697 const unsigned char* plocal_symbols
);
699 // Map input .toc section to output .got section.
701 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
703 if (size
== 64 && strcmp(name
, ".toc") == 0)
711 // Provide linker defined save/restore functions.
713 define_save_restore_funcs(Layout
*, Symbol_table
*);
715 // No stubs unless a final link.
718 { return !parameters
->options().relocatable(); }
721 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
724 do_plt_fde_location(const Output_data
*, unsigned char*,
725 uint64_t*, off_t
*) const;
727 // Stash info about branches, for stub generation.
729 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
730 unsigned int data_shndx
, Address r_offset
,
731 unsigned int r_type
, unsigned int r_sym
, Address addend
)
733 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
734 this->branch_info_
.push_back(info
);
735 if (r_type
== elfcpp::R_POWERPC_REL14
736 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
737 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
738 ppc_object
->set_has_14bit_branch(data_shndx
);
741 // Return whether the last branch is a plt call, and if so, mark the
742 // branch as having an R_PPC64_TOCSAVE.
744 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
745 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
748 && !this->branch_info_
.empty()
749 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
750 r_offset
, this, symtab
));
753 // Say the given location, that of a nop in a function prologue with
754 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
755 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
757 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
758 unsigned int shndx
, Address offset
)
761 loc
.object
= ppc_object
;
764 this->tocsave_loc_
.insert(loc
);
771 return &this->tocsave_loc_
;
775 do_define_standard_symbols(Symbol_table
*, Layout
*);
777 // Finalize the sections.
779 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
781 // Return the value to use for a dynamic which requires special
784 do_dynsym_value(const Symbol
*) const;
786 // Return the PLT address to use for a local symbol.
788 do_plt_address_for_local(const Relobj
*, unsigned int) const;
790 // Return the PLT address to use for a global symbol.
792 do_plt_address_for_global(const Symbol
*) const;
794 // Return the offset to use for the GOT_INDX'th got entry which is
795 // for a local tls symbol specified by OBJECT, SYMNDX.
797 do_tls_offset_for_local(const Relobj
* object
,
799 Output_data_got_base
* got
,
800 unsigned int got_indx
,
801 uint64_t addend
) const;
803 // Return the offset to use for the GOT_INDX'th got entry which is
804 // for global tls symbol GSYM.
806 do_tls_offset_for_global(Symbol
* gsym
,
807 Output_data_got_base
* got
, unsigned int got_indx
,
808 uint64_t addend
) const;
811 do_function_location(Symbol_location
*) const;
814 do_can_check_for_function_pointers() const
817 // Adjust -fsplit-stack code which calls non-split-stack code.
819 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
820 section_offset_type fnoffset
, section_size_type fnsize
,
821 const unsigned char* prelocs
, size_t reloc_count
,
822 unsigned char* view
, section_size_type view_size
,
823 std::string
* from
, std::string
* to
) const;
825 // Relocate a section.
827 relocate_section(const Relocate_info
<size
, big_endian
>*,
828 unsigned int sh_type
,
829 const unsigned char* prelocs
,
831 Output_section
* output_section
,
832 bool needs_special_offset_handling
,
834 Address view_address
,
835 section_size_type view_size
,
836 const Reloc_symbol_changes
*);
838 // Scan the relocs during a relocatable link.
840 scan_relocatable_relocs(Symbol_table
* symtab
,
842 Sized_relobj_file
<size
, big_endian
>* object
,
843 unsigned int data_shndx
,
844 unsigned int sh_type
,
845 const unsigned char* prelocs
,
847 Output_section
* output_section
,
848 bool needs_special_offset_handling
,
849 size_t local_symbol_count
,
850 const unsigned char* plocal_symbols
,
851 Relocatable_relocs
*);
853 // Scan the relocs for --emit-relocs.
855 emit_relocs_scan(Symbol_table
* symtab
,
857 Sized_relobj_file
<size
, big_endian
>* object
,
858 unsigned int data_shndx
,
859 unsigned int sh_type
,
860 const unsigned char* prelocs
,
862 Output_section
* output_section
,
863 bool needs_special_offset_handling
,
864 size_t local_symbol_count
,
865 const unsigned char* plocal_syms
,
866 Relocatable_relocs
* rr
);
868 // Emit relocations for a section.
870 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
871 unsigned int sh_type
,
872 const unsigned char* prelocs
,
874 Output_section
* output_section
,
875 typename
elfcpp::Elf_types
<size
>::Elf_Off
876 offset_in_output_section
,
878 Address view_address
,
880 unsigned char* reloc_view
,
881 section_size_type reloc_view_size
);
883 // Return whether SYM is defined by the ABI.
885 do_is_defined_by_abi(const Symbol
* sym
) const
887 return strcmp(sym
->name(), "__tls_get_addr") == 0;
890 // Return the size of the GOT section, for incremental linking
894 gold_assert(this->got_
!= NULL
);
895 return this->got_
->data_size() + (this->biggot_
896 ? this->biggot_
->data_size() : 0);
899 // Get the PLT section.
900 const Output_data_plt_powerpc
<size
, big_endian
>*
903 gold_assert(this->plt_
!= NULL
);
907 // Get the IPLT section.
908 const Output_data_plt_powerpc
<size
, big_endian
>*
911 gold_assert(this->iplt_
!= NULL
);
915 // Get the LPLT section.
916 const Output_data_plt_powerpc
<size
, big_endian
>*
922 // Return the plt offset and section for the given global sym.
924 plt_off(const Symbol
* gsym
,
925 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
927 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
928 && gsym
->can_use_relative_reloc(false))
929 *sec
= this->iplt_section();
930 else if (!parameters
->doing_static_link())
931 *sec
= this->plt_section();
933 *sec
= this->lplt_section();
934 return gsym
->plt_offset();
937 // Return the plt offset and section for the given local sym.
939 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
940 unsigned int local_sym_index
,
941 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
943 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
944 if (lsym
->is_ifunc_symbol())
945 *sec
= this->iplt_section();
947 *sec
= this->lplt_section();
948 return relobj
->local_plt_offset(local_sym_index
);
951 // Get the .glink section.
952 const Output_data_glink
<size
, big_endian
>*
953 glink_section() const
955 gold_assert(this->glink_
!= NULL
);
959 Output_data_glink
<size
, big_endian
>*
962 gold_assert(this->glink_
!= NULL
);
966 bool has_glink() const
967 { return this->glink_
!= NULL
; }
969 // Get the GOT section.
970 const Output_data_got_powerpc
<size
, big_endian
>*
971 got_section(Got_type got_type
) const
973 gold_assert(this->got_
!= NULL
);
974 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
976 gold_assert(this->biggot_
!= NULL
);
977 return this->biggot_
;
980 // Get the GOT section, creating it if necessary.
981 Output_data_got_powerpc
<size
, big_endian
>*
982 got_section(Symbol_table
*, Layout
*, Got_type
);
984 // The toc/got pointer reg will be set to this value.
988 return this->got_
->address() + this->got_
->g_o_t();
991 // Offset of base used to access the GOT/TOC relative to the GOT section.
993 got_base_offset(Got_type got_type
) const
995 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
996 return this->got_
->g_o_t();
997 return this->toc_pointer() - this->biggot_
->address();
1001 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1002 const elfcpp::Ehdr
<size
, big_endian
>&);
1004 // Return the number of entries in the GOT.
1006 got_entry_count() const
1008 if (this->got_
== NULL
)
1010 return this->got_size() / (size
/ 8);
1013 // Return the number of entries in the PLT.
1015 plt_entry_count() const;
1017 // Return the offset of the first non-reserved PLT entry.
1019 first_plt_entry_offset() const
1023 if (this->abiversion() >= 2)
1028 // Return the size of each PLT entry.
1030 plt_entry_size() const
1034 if (this->abiversion() >= 2)
1039 Output_data_save_res
<size
, big_endian
>*
1040 savres_section() const
1042 return this->savres_section_
;
1045 // Add any special sections for this symbol to the gc work list.
1046 // For powerpc64, this adds the code section of a function
1049 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1051 // Handle target specific gc actions when adding a gc reference from
1052 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1053 // and DST_OFF. For powerpc64, this adds a referenc to the code
1054 // section of a function descriptor.
1056 do_gc_add_reference(Symbol_table
* symtab
,
1058 unsigned int src_shndx
,
1060 unsigned int dst_shndx
,
1061 Address dst_off
) const;
1063 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1066 { return this->stub_tables_
; }
1068 const Output_data_brlt_powerpc
<size
, big_endian
>*
1069 brlt_section() const
1070 { return this->brlt_section_
; }
1073 add_branch_lookup_table(Address to
)
1075 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1076 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1080 find_branch_lookup_table(Address to
)
1082 typename
Branch_lookup_table::const_iterator p
1083 = this->branch_lookup_table_
.find(to
);
1084 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1088 write_branch_lookup_table(unsigned char *oview
)
1090 for (typename
Branch_lookup_table::const_iterator p
1091 = this->branch_lookup_table_
.begin();
1092 p
!= this->branch_lookup_table_
.end();
1095 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1099 // Wrapper used after relax to define a local symbol in output data,
1100 // from the end if value < 0.
1102 define_local(Symbol_table
* symtab
, const char* name
,
1103 Output_data
* od
, Address value
, unsigned int symsize
)
1106 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1107 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1108 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1109 static_cast<Signed_address
>(value
) < 0,
1111 // We are creating this symbol late, so need to fix up things
1112 // done early in Layout::finalize.
1113 sym
->set_dynsym_index(-1U);
1117 set_power10_relocs()
1119 this->power10_relocs_
= true;
1123 power10_stubs() const
1125 return (this->power10_relocs_
1126 && (parameters
->options().power10_stubs_enum()
1127 != General_options::POWER10_STUBS_NO
));
1131 power10_stubs_auto() const
1133 return (parameters
->options().power10_stubs_enum()
1134 == General_options::POWER10_STUBS_AUTO
);
1138 plt_thread_safe() const
1139 { return this->plt_thread_safe_
; }
1142 plt_localentry0() const
1143 { return this->plt_localentry0_
; }
1146 has_localentry0() const
1147 { return this->has_localentry0_
; }
1150 set_has_localentry0()
1152 this->has_localentry0_
= true;
1156 is_elfv2_localentry0(const Symbol
* gsym
) const
1159 && this->abiversion() >= 2
1160 && this->plt_localentry0()
1161 && gsym
->type() == elfcpp::STT_FUNC
1162 && gsym
->is_defined()
1163 && gsym
->nonvis() >> 3 == 0
1164 && !gsym
->non_zero_localentry());
1168 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1169 unsigned int r_sym
) const
1171 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1172 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1175 && this->abiversion() >= 2
1176 && this->plt_localentry0()
1177 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1179 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1181 if (!psymval
->is_ifunc_symbol()
1182 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1191 { return !this->no_tprel_opt_
&& parameters
->options().tls_optimize(); }
1195 { this->no_tprel_opt_
= true; }
1197 // Remember any symbols seen with non-zero localentry, even those
1198 // not providing a definition
1200 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1205 unsigned char st_other
= sym
.get_st_other();
1206 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1207 to
->set_non_zero_localentry();
1209 // We haven't resolved anything, continue normal processing.
1215 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1218 set_abiversion(int ver
)
1220 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1221 flags
&= ~elfcpp::EF_PPC64_ABI
;
1222 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1223 this->set_processor_specific_flags(flags
);
1227 tls_get_addr_opt() const
1228 { return this->tls_get_addr_opt_
; }
1231 tls_get_addr() const
1232 { return this->tls_get_addr_
; }
1234 // If optimizing __tls_get_addr calls, whether this is the
1235 // "__tls_get_addr" symbol.
1237 is_tls_get_addr_opt(const Symbol
* gsym
) const
1239 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1240 || gsym
== this->tls_get_addr_opt_
);
1244 replace_tls_get_addr(const Symbol
* gsym
) const
1245 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1248 set_has_tls_get_addr_opt()
1249 { this->has_tls_get_addr_opt_
= true; }
1251 // Offset to toc save stack slot
1254 { return this->abiversion() < 2 ? 40 : 24; }
1256 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1257 // so use the CR save slot. Used only by __tls_get_addr call stub,
1258 // relying on __tls_get_addr not saving CR itself.
1261 { return this->abiversion() < 2 ? 32 : 8; }
1263 // Merge object attributes from input object with those in the output.
1265 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1268 symval_for_branch(const Symbol_table
* symtab
,
1269 const Sized_symbol
<size
>* gsym
,
1270 Powerpc_relobj
<size
, big_endian
>* object
,
1271 Address
*value
, unsigned int *dest_shndx
);
1287 : tls_get_addr_state_(NOT_EXPECTED
),
1288 relinfo_(NULL
), relnum_(0), r_offset_(0)
1293 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1300 if (this->relinfo_
!= NULL
)
1301 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1302 _("missing expected __tls_get_addr call"));
1306 expect_tls_get_addr_call(
1307 const Relocate_info
<size
, big_endian
>* relinfo
,
1311 this->tls_get_addr_state_
= EXPECTED
;
1312 this->relinfo_
= relinfo
;
1313 this->relnum_
= relnum
;
1314 this->r_offset_
= r_offset
;
1318 expect_tls_get_addr_call()
1319 { this->tls_get_addr_state_
= EXPECTED
; }
1322 skip_next_tls_get_addr_call()
1323 {this->tls_get_addr_state_
= SKIP
; }
1326 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1327 unsigned int r_type
, const Symbol
* gsym
)
1330 = ((r_type
== elfcpp::R_POWERPC_REL24
1331 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1332 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
1333 || r_type
== elfcpp::R_PPC_PLTREL24
1334 || is_plt16_reloc
<size
>(r_type
)
1335 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1336 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1337 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1338 || r_type
== elfcpp::R_POWERPC_PLTCALL
1339 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1340 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1342 && (gsym
== target
->tls_get_addr()
1343 || gsym
== target
->tls_get_addr_opt()));
1344 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1345 this->tls_get_addr_state_
= NOT_EXPECTED
;
1346 if (is_tls_call
&& last_tls
!= EXPECTED
)
1348 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1357 // What we're up to regarding calls to __tls_get_addr.
1358 // On powerpc, the branch and link insn making a call to
1359 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1360 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1361 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1362 // The marker relocation always comes first, and has the same
1363 // symbol as the reloc on the insn setting up the __tls_get_addr
1364 // argument. This ties the arg setup insn with the call insn,
1365 // allowing ld to safely optimize away the call. We check that
1366 // every call to __tls_get_addr has a marker relocation, and that
1367 // every marker relocation is on a call to __tls_get_addr.
1368 Tls_get_addr tls_get_addr_state_
;
1369 // Info about the last reloc for error message.
1370 const Relocate_info
<size
, big_endian
>* relinfo_
;
1375 // The class which scans relocations.
1376 class Scan
: protected Track_tls
1379 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1382 : Track_tls(), issued_non_pic_error_(false)
1386 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1389 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1390 Sized_relobj_file
<size
, big_endian
>* object
,
1391 unsigned int data_shndx
,
1392 Output_section
* output_section
,
1393 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1394 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1398 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1399 Sized_relobj_file
<size
, big_endian
>* object
,
1400 unsigned int data_shndx
,
1401 Output_section
* output_section
,
1402 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1406 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1408 Sized_relobj_file
<size
, big_endian
>* relobj
,
1411 const elfcpp::Rela
<size
, big_endian
>& ,
1412 unsigned int r_type
,
1413 const elfcpp::Sym
<size
, big_endian
>&)
1415 // PowerPC64 .opd is not folded, so any identical function text
1416 // may be folded and we'll still keep function addresses distinct.
1417 // That means no reloc is of concern here.
1420 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1421 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1422 if (ppcobj
->abiversion() == 1)
1425 // For 32-bit and ELFv2, conservatively assume anything but calls to
1426 // function code might be taking the address of the function.
1427 return !is_branch_reloc
<size
>(r_type
);
1431 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1433 Sized_relobj_file
<size
, big_endian
>* relobj
,
1436 const elfcpp::Rela
<size
, big_endian
>& ,
1437 unsigned int r_type
,
1443 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1444 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1445 if (ppcobj
->abiversion() == 1)
1448 return !is_branch_reloc
<size
>(r_type
);
1452 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1453 Sized_relobj_file
<size
, big_endian
>* object
,
1454 unsigned int r_type
, bool report_err
);
1458 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1459 unsigned int r_type
);
1462 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1463 unsigned int r_type
, Symbol
*);
1466 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1467 Target_powerpc
* target
);
1470 check_non_pic(Relobj
*, unsigned int r_type
);
1472 // Whether we have issued an error about a non-PIC compilation.
1473 bool issued_non_pic_error_
;
1476 // The class which implements relocation.
1477 class Relocate
: protected Track_tls
1480 // Use 'at' branch hints when true, 'y' when false.
1481 // FIXME maybe: set this with an option.
1482 static const bool is_isa_v2
= true;
1488 // Do a relocation. Return false if the caller should not issue
1489 // any warnings about this relocation.
1491 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1492 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1493 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1494 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1498 class Relocate_comdat_behavior
1501 // Decide what the linker should do for relocations that refer to
1502 // discarded comdat sections.
1503 inline Comdat_behavior
1504 get(const char* name
)
1506 gold::Default_comdat_behavior default_behavior
;
1507 Comdat_behavior ret
= default_behavior
.get(name
);
1508 if (ret
== CB_ERROR
)
1511 && (strcmp(name
, ".fixup") == 0
1512 || strcmp(name
, ".got2") == 0))
1515 && (strcmp(name
, ".opd") == 0
1516 || strcmp(name
, ".toc") == 0
1517 || strcmp(name
, ".toc1") == 0))
1524 // Optimize the TLS relocation type based on what we know about the
1525 // symbol. IS_FINAL is true if the final address of this symbol is
1526 // known at link time.
1528 tls::Tls_optimization
1529 optimize_tls_gd(bool is_final
)
1531 // If we are generating a shared library, then we can't do anything
1533 if (parameters
->options().shared()
1534 || !parameters
->options().tls_optimize())
1535 return tls::TLSOPT_NONE
;
1538 return tls::TLSOPT_TO_IE
;
1539 return tls::TLSOPT_TO_LE
;
1542 tls::Tls_optimization
1545 if (parameters
->options().shared()
1546 || !parameters
->options().tls_optimize())
1547 return tls::TLSOPT_NONE
;
1549 return tls::TLSOPT_TO_LE
;
1552 tls::Tls_optimization
1553 optimize_tls_ie(bool is_final
)
1556 || parameters
->options().shared()
1557 || !parameters
->options().tls_optimize())
1558 return tls::TLSOPT_NONE
;
1560 return tls::TLSOPT_TO_LE
;
1565 make_glink_section(Layout
*);
1567 // Create the PLT section.
1569 make_plt_section(Symbol_table
*, Layout
*);
1572 make_iplt_section(Symbol_table
*, Layout
*);
1575 make_lplt_section(Symbol_table
*, Layout
*);
1578 make_brlt_section(Layout
*);
1580 // Create a PLT entry for a global symbol.
1582 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1584 // Create a PLT entry for a local IFUNC symbol.
1586 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1587 Sized_relobj_file
<size
, big_endian
>*,
1590 // Create a PLT entry for a local non-IFUNC symbol.
1592 make_local_plt_entry(Symbol_table
*, Layout
*,
1593 Sized_relobj_file
<size
, big_endian
>*,
1597 make_local_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1599 // Create a GOT entry for local dynamic __tls_get_addr.
1601 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1602 Sized_relobj_file
<size
, big_endian
>* object
);
1605 tlsld_got_offset() const
1607 return this->tlsld_got_offset_
;
1610 // Get the dynamic reloc section, creating it if necessary.
1612 rela_dyn_section(Layout
*);
1614 // Similarly, but for ifunc symbols get the one for ifunc.
1616 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1618 // Copy a relocation against a global symbol.
1620 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1621 Sized_relobj_file
<size
, big_endian
>* object
,
1622 unsigned int shndx
, Output_section
* output_section
,
1623 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1625 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1626 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1627 symtab
->get_sized_symbol
<size
>(sym
),
1628 object
, shndx
, output_section
,
1629 r_type
, reloc
.get_r_offset(),
1630 reloc
.get_r_addend(),
1631 this->rela_dyn_section(layout
));
1634 // Look over all the input sections, deciding where to place stubs.
1636 group_sections(Layout
*, const Task
*, bool);
1638 // Sort output sections by address.
1639 struct Sort_sections
1642 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1643 { return sec1
->address() < sec2
->address(); }
1649 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1650 unsigned int data_shndx
,
1652 unsigned int r_type
,
1655 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1656 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1662 // Return whether this branch is going via a plt call stub, and if
1663 // so, mark it as having an R_PPC64_TOCSAVE.
1665 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1666 unsigned int shndx
, Address offset
,
1667 Target_powerpc
* target
, Symbol_table
* symtab
);
1669 // If this branch needs a plt call stub, or a long branch stub, make one.
1671 make_stub(Stub_table
<size
, big_endian
>*,
1672 Stub_table
<size
, big_endian
>*,
1673 Symbol_table
*) const;
1676 // The branch location..
1677 Powerpc_relobj
<size
, big_endian
>* object_
;
1678 unsigned int shndx_
;
1680 // ..and the branch type and destination.
1681 unsigned int r_type_
: 31;
1682 unsigned int tocsave_
: 1;
1683 unsigned int r_sym_
;
1687 // Information about this specific target which we pass to the
1688 // general Target structure.
1689 static Target::Target_info powerpc_info
;
1691 // The small GOT section used by ppc32, and by ppc64 for entries that
1692 // must be addresseed +/-32k from the got pointer.
1693 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1694 // Another GOT section used for entries that can be addressed +/- 2G
1695 // from the got pointer.
1696 Output_data_got_powerpc
<size
, big_endian
>* biggot_
;
1698 // The PLT section. This is a container for a table of addresses,
1699 // and their relocations. Each address in the PLT has a dynamic
1700 // relocation (R_*_JMP_SLOT) and each address will have a
1701 // corresponding entry in .glink for lazy resolution of the PLT.
1702 // ppc32 initialises the PLT to point at the .glink entry, while
1703 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1704 // linker adds a stub that loads the PLT entry into ctr then
1705 // branches to ctr. There may be more than one stub for each PLT
1706 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1707 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1708 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1709 // The IPLT section. Like plt_, this is a container for a table of
1710 // addresses and their relocations, specifically for STT_GNU_IFUNC
1711 // functions that resolve locally (STT_GNU_IFUNC functions that
1712 // don't resolve locally go in PLT). Unlike plt_, these have no
1713 // entry in .glink for lazy resolution, and the relocation section
1714 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1715 // the relocation section may contain relocations against
1716 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1717 // relocation section will appear at the end of other dynamic
1718 // relocations, so that ld.so applies these relocations after other
1719 // dynamic relocations. In a static executable, the relocation
1720 // section is emitted and marked with __rela_iplt_start and
1721 // __rela_iplt_end symbols.
1722 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1723 // A PLT style section for local, non-ifunc symbols
1724 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1725 // Section holding long branch destinations.
1726 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1727 // The .glink section.
1728 Output_data_glink
<size
, big_endian
>* glink_
;
1729 // The dynamic reloc section.
1730 Reloc_section
* rela_dyn_
;
1731 // Relocs saved to avoid a COPY reloc.
1732 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1733 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1734 unsigned int tlsld_got_offset_
;
1736 Stub_tables stub_tables_
;
1737 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1738 Branch_lookup_table branch_lookup_table_
;
1740 typedef std::vector
<Branch_info
> Branches
;
1741 Branches branch_info_
;
1742 Tocsave_loc tocsave_loc_
;
1744 bool power10_relocs_
;
1745 bool plt_thread_safe_
;
1746 bool plt_localentry0_
;
1747 bool plt_localentry0_init_
;
1748 bool has_localentry0_
;
1749 bool has_tls_get_addr_opt_
;
1753 int relax_fail_count_
;
1754 int32_t stub_group_size_
;
1756 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1758 // The "__tls_get_addr" symbol, if present
1759 Symbol
* tls_get_addr_
;
1760 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1761 Symbol
* tls_get_addr_opt_
;
1763 // Attributes in output.
1764 Attributes_section_data
* attributes_section_data_
;
1766 // Last input file to change various attribute tags
1767 const char* last_fp_
;
1768 const char* last_ld_
;
1769 const char* last_vec_
;
1770 const char* last_struct_
;
1774 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1777 true, // is_big_endian
1778 elfcpp::EM_PPC
, // machine_code
1779 false, // has_make_symbol
1780 false, // has_resolve
1781 false, // has_code_fill
1782 true, // is_default_stack_executable
1783 false, // can_icf_inline_merge_sections
1785 "/usr/lib/ld.so.1", // dynamic_linker
1786 0x10000000, // default_text_segment_address
1787 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1788 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1789 false, // isolate_execinstr
1791 elfcpp::SHN_UNDEF
, // small_common_shndx
1792 elfcpp::SHN_UNDEF
, // large_common_shndx
1793 0, // small_common_section_flags
1794 0, // large_common_section_flags
1795 NULL
, // attributes_section
1796 NULL
, // attributes_vendor
1797 "_start", // entry_symbol_name
1798 32, // hash_entry_size
1799 elfcpp::SHT_PROGBITS
, // unwind_section_type
1803 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1806 false, // is_big_endian
1807 elfcpp::EM_PPC
, // machine_code
1808 false, // has_make_symbol
1809 false, // has_resolve
1810 false, // has_code_fill
1811 true, // is_default_stack_executable
1812 false, // can_icf_inline_merge_sections
1814 "/usr/lib/ld.so.1", // dynamic_linker
1815 0x10000000, // default_text_segment_address
1816 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1817 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1818 false, // isolate_execinstr
1820 elfcpp::SHN_UNDEF
, // small_common_shndx
1821 elfcpp::SHN_UNDEF
, // large_common_shndx
1822 0, // small_common_section_flags
1823 0, // large_common_section_flags
1824 NULL
, // attributes_section
1825 NULL
, // attributes_vendor
1826 "_start", // entry_symbol_name
1827 32, // hash_entry_size
1828 elfcpp::SHT_PROGBITS
, // unwind_section_type
1832 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1835 true, // is_big_endian
1836 elfcpp::EM_PPC64
, // machine_code
1837 false, // has_make_symbol
1838 true, // has_resolve
1839 false, // has_code_fill
1840 false, // is_default_stack_executable
1841 false, // can_icf_inline_merge_sections
1843 "/usr/lib/ld.so.1", // dynamic_linker
1844 0x10000000, // default_text_segment_address
1845 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1846 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1847 false, // isolate_execinstr
1849 elfcpp::SHN_UNDEF
, // small_common_shndx
1850 elfcpp::SHN_UNDEF
, // large_common_shndx
1851 0, // small_common_section_flags
1852 0, // large_common_section_flags
1853 NULL
, // attributes_section
1854 NULL
, // attributes_vendor
1855 "_start", // entry_symbol_name
1856 32, // hash_entry_size
1857 elfcpp::SHT_PROGBITS
, // unwind_section_type
1861 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1864 false, // is_big_endian
1865 elfcpp::EM_PPC64
, // machine_code
1866 false, // has_make_symbol
1867 true, // has_resolve
1868 false, // has_code_fill
1869 false, // is_default_stack_executable
1870 false, // can_icf_inline_merge_sections
1872 "/usr/lib/ld.so.1", // dynamic_linker
1873 0x10000000, // default_text_segment_address
1874 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1875 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1876 false, // isolate_execinstr
1878 elfcpp::SHN_UNDEF
, // small_common_shndx
1879 elfcpp::SHN_UNDEF
, // large_common_shndx
1880 0, // small_common_section_flags
1881 0, // large_common_section_flags
1882 NULL
, // attributes_section
1883 NULL
, // attributes_vendor
1884 "_start", // entry_symbol_name
1885 32, // hash_entry_size
1886 elfcpp::SHT_PROGBITS
, // unwind_section_type
1891 is_branch_reloc(unsigned int r_type
)
1893 return (r_type
== elfcpp::R_POWERPC_REL24
1894 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1895 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
1896 || r_type
== elfcpp::R_PPC_PLTREL24
1897 || r_type
== elfcpp::R_PPC_LOCAL24PC
1898 || r_type
== elfcpp::R_POWERPC_REL14
1899 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1900 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1901 || r_type
== elfcpp::R_POWERPC_ADDR24
1902 || r_type
== elfcpp::R_POWERPC_ADDR14
1903 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1904 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1907 // Reloc resolves to plt entry.
1910 is_plt16_reloc(unsigned int r_type
)
1912 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1913 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1914 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1915 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1918 // GOT_TYPE_STANDARD or GOT_TYPE_SMALL (ie. not TLS) GOT relocs
1920 is_got_reloc(unsigned int r_type
)
1922 return (r_type
== elfcpp::R_POWERPC_GOT16
1923 || r_type
== elfcpp::R_POWERPC_GOT16_LO
1924 || r_type
== elfcpp::R_POWERPC_GOT16_HI
1925 || r_type
== elfcpp::R_POWERPC_GOT16_HA
1926 || r_type
== elfcpp::R_PPC64_GOT16_DS
1927 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
1928 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
);
1931 // If INSN is an opcode that may be used with an @tls operand, return
1932 // the transformed insn for TLS optimisation, otherwise return 0. If
1933 // REG is non-zero only match an insn with RB or RA equal to REG.
1935 at_tls_transform(uint32_t insn
, unsigned int reg
)
1937 if ((insn
& (0x3f << 26)) != 31 << 26)
1941 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1942 rtra
= insn
& ((1 << 26) - (1 << 16));
1943 else if (((insn
>> 16) & 0x1f) == reg
)
1944 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1948 if ((insn
& (0x3ff << 1)) == 266 << 1)
1951 else if ((insn
& (0x1f << 1)) == 23 << 1
1952 && ((insn
& (0x1f << 6)) < 14 << 6
1953 || ((insn
& (0x1f << 6)) >= 16 << 6
1954 && (insn
& (0x1f << 6)) < 24 << 6)))
1955 // load and store indexed -> dform
1956 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1957 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1958 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1959 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1960 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1962 insn
= (58 << 26) | 2;
1970 template<int size
, bool big_endian
>
1971 class Powerpc_relocate_functions
1991 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1992 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1993 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1995 template<int valsize
>
1997 has_overflow_signed(Address value
)
1999 // limit = 1 << (valsize - 1) without shift count exceeding size of type
2000 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2001 limit
<<= ((valsize
- 1) >> 1);
2002 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2003 return value
+ limit
> (limit
<< 1) - 1;
2006 template<int valsize
>
2008 has_overflow_unsigned(Address value
)
2010 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2011 limit
<<= ((valsize
- 1) >> 1);
2012 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2013 return value
> (limit
<< 1) - 1;
2016 template<int valsize
>
2018 has_overflow_bitfield(Address value
)
2020 return (has_overflow_unsigned
<valsize
>(value
)
2021 && has_overflow_signed
<valsize
>(value
));
2024 template<int valsize
>
2025 static inline Status
2026 overflowed(Address value
, Overflow_check overflow
)
2028 if (overflow
== CHECK_SIGNED
)
2030 if (has_overflow_signed
<valsize
>(value
))
2031 return STATUS_OVERFLOW
;
2033 else if (overflow
== CHECK_UNSIGNED
)
2035 if (has_overflow_unsigned
<valsize
>(value
))
2036 return STATUS_OVERFLOW
;
2038 else if (overflow
== CHECK_BITFIELD
)
2040 if (has_overflow_bitfield
<valsize
>(value
))
2041 return STATUS_OVERFLOW
;
2046 // Do a simple RELA relocation
2047 template<int fieldsize
, int valsize
>
2048 static inline Status
2049 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2051 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2052 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2053 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2054 return overflowed
<valsize
>(value
, overflow
);
2057 template<int fieldsize
, int valsize
>
2058 static inline Status
2059 rela(unsigned char* view
,
2060 unsigned int right_shift
,
2061 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2063 Overflow_check overflow
)
2065 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2066 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2067 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2068 if (overflow
== CHECK_SIGNED
)
2069 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2071 value
= value
>> right_shift
;
2072 Valtype reloc
= value
;
2075 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2076 return overflowed
<valsize
>(value
, overflow
);
2079 // Do a simple RELA relocation, unaligned.
2080 template<int fieldsize
, int valsize
>
2081 static inline Status
2082 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2084 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2085 return overflowed
<valsize
>(value
, overflow
);
2088 template<int fieldsize
, int valsize
>
2089 static inline Status
2090 rela_ua(unsigned char* view
,
2091 unsigned int right_shift
,
2092 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2094 Overflow_check overflow
)
2096 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2098 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2099 if (overflow
== CHECK_SIGNED
)
2100 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2102 value
= value
>> right_shift
;
2103 Valtype reloc
= value
;
2106 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2107 return overflowed
<valsize
>(value
, overflow
);
2111 // R_PPC64_ADDR64: (Symbol + Addend)
2113 addr64(unsigned char* view
, Address value
)
2114 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2116 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2118 addr64_u(unsigned char* view
, Address value
)
2119 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2121 // R_POWERPC_ADDR32: (Symbol + Addend)
2122 static inline Status
2123 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2124 { return This::template rela
<32,32>(view
, value
, overflow
); }
2126 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2127 static inline Status
2128 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2129 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2131 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2132 static inline Status
2133 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2135 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2137 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2138 stat
= STATUS_OVERFLOW
;
2142 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2143 static inline Status
2144 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2145 { return This::template rela
<16,16>(view
, value
, overflow
); }
2147 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2148 static inline Status
2149 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2150 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2152 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2153 static inline Status
2154 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2156 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2157 if ((value
& 3) != 0)
2158 stat
= STATUS_OVERFLOW
;
2162 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2163 static inline Status
2164 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2166 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2167 if ((value
& 15) != 0)
2168 stat
= STATUS_OVERFLOW
;
2172 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2174 addr16_hi(unsigned char* view
, Address value
)
2175 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2177 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2179 addr16_ha(unsigned char* view
, Address value
)
2180 { This::addr16_hi(view
, value
+ 0x8000); }
2182 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2184 addr16_hi2(unsigned char* view
, Address value
)
2185 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2187 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2189 addr16_ha2(unsigned char* view
, Address value
)
2190 { This::addr16_hi2(view
, value
+ 0x8000); }
2192 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2194 addr16_hi3(unsigned char* view
, Address value
)
2195 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2197 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2199 addr16_ha3(unsigned char* view
, Address value
)
2200 { This::addr16_hi3(view
, value
+ 0x8000); }
2202 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2203 static inline Status
2204 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2206 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2207 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2208 stat
= STATUS_OVERFLOW
;
2212 // R_POWERPC_REL16DX_HA
2213 static inline Status
2214 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2216 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2217 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2218 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2220 value
= static_cast<SignedAddress
>(value
) >> 16;
2221 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2222 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2223 return overflowed
<16>(value
, overflow
);
2227 static inline Status
2228 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2230 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2232 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2238 addr34_hi(unsigned char *view
, uint64_t value
)
2239 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2243 addr34_ha(unsigned char *view
, uint64_t value
)
2244 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2247 static inline Status
2248 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2250 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2252 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2256 // R_PPC64_ADDR16_HIGHER34
2258 addr16_higher34(unsigned char* view
, uint64_t value
)
2259 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2261 // R_PPC64_ADDR16_HIGHERA34
2263 addr16_highera34(unsigned char* view
, uint64_t value
)
2264 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2266 // R_PPC64_ADDR16_HIGHEST34
2268 addr16_highest34(unsigned char* view
, uint64_t value
)
2269 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2271 // R_PPC64_ADDR16_HIGHESTA34
2273 addr16_highesta34(unsigned char* view
, uint64_t value
)
2274 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2277 // Set ABI version for input and output.
2279 template<int size
, bool big_endian
>
2281 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2283 this->e_flags_
|= ver
;
2284 if (this->abiversion() != 0)
2286 Target_powerpc
<size
, big_endian
>* target
=
2287 static_cast<Target_powerpc
<size
, big_endian
>*>(
2288 parameters
->sized_target
<size
, big_endian
>());
2289 if (target
->abiversion() == 0)
2290 target
->set_abiversion(this->abiversion());
2291 else if (target
->abiversion() != this->abiversion())
2292 gold_error(_("%s: ABI version %d is not compatible "
2293 "with ABI version %d output"),
2294 this->name().c_str(),
2295 this->abiversion(), target
->abiversion());
2300 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2301 // relocatable object, if such sections exists.
2303 template<int size
, bool big_endian
>
2305 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2306 Read_symbols_data
* sd
)
2308 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2309 const unsigned char* namesu
= sd
->section_names
->data();
2310 const char* names
= reinterpret_cast<const char*>(namesu
);
2311 section_size_type names_size
= sd
->section_names_size
;
2312 const unsigned char* s
;
2314 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2315 size
== 32 ? ".got2" : ".opd",
2316 names
, names_size
, NULL
);
2319 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2320 this->special_
= ndx
;
2323 if (this->abiversion() == 0)
2324 this->set_abiversion(1);
2325 else if (this->abiversion() > 1)
2326 gold_error(_("%s: .opd invalid in abiv%d"),
2327 this->name().c_str(), this->abiversion());
2332 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2333 names
, names_size
, NULL
);
2336 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2337 this->relatoc_
= ndx
;
2338 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2339 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2342 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2345 // Examine .rela.opd to build info about function entry points.
2347 template<int size
, bool big_endian
>
2349 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2351 const unsigned char* prelocs
,
2352 const unsigned char* plocal_syms
)
2356 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2357 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2358 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2359 Address expected_off
= 0;
2360 bool regular
= true;
2361 unsigned int opd_ent_size
= 0;
2363 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2365 Reltype
reloc(prelocs
);
2366 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2367 = reloc
.get_r_info();
2368 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2369 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2371 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2372 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2375 if (r_sym
< this->local_symbol_count())
2377 typename
elfcpp::Sym
<size
, big_endian
>
2378 lsym(plocal_syms
+ r_sym
* sym_size
);
2379 shndx
= lsym
.get_st_shndx();
2380 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2381 value
= lsym
.get_st_value();
2384 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2386 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2387 value
+ reloc
.get_r_addend());
2390 expected_off
= reloc
.get_r_offset();
2391 opd_ent_size
= expected_off
;
2393 else if (expected_off
!= reloc
.get_r_offset())
2395 expected_off
+= opd_ent_size
;
2397 else if (r_type
== elfcpp::R_PPC64_TOC
)
2399 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2404 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2405 this->name().c_str(), r_type
);
2409 if (reloc_count
<= 2)
2410 opd_ent_size
= this->section_size(this->opd_shndx());
2411 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2415 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2416 this->name().c_str());
2422 // Returns true if a code sequence loading the TOC entry at VALUE
2423 // relative to the TOC pointer can be converted into code calculating
2424 // a TOC pointer relative offset.
2425 // If so, the TOC pointer relative offset is stored to VALUE.
2427 template<int size
, bool big_endian
>
2429 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2430 Target_powerpc
<size
, big_endian
>* target
,
2436 // With -mcmodel=medium code it is quite possible to have
2437 // toc-relative relocs referring to objects outside the TOC.
2438 // Don't try to look at a non-existent TOC.
2439 if (this->toc_shndx() == 0
2440 || this->output_section(this->toc_shndx()) == 0)
2443 // Convert VALUE back to an address by adding got_base (see below),
2444 // then to an offset in the TOC by subtracting the TOC output
2445 // section address and the TOC output offset.
2446 Address off
= (*value
+ target
->toc_pointer()
2447 - this->output_section(this->toc_shndx())->address()
2448 - this->output_section_offset(this->toc_shndx()));
2449 // Is this offset in the TOC? -mcmodel=medium code may be using
2450 // TOC relative access to variables outside the TOC. Those of
2451 // course can't be optimized. We also don't try to optimize code
2452 // that is using a different object's TOC.
2453 if (off
>= this->section_size(this->toc_shndx()))
2456 if (this->no_toc_opt(off
))
2459 section_size_type vlen
;
2460 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2461 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2463 Address got_base
= target
->toc_pointer();
2465 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2472 template<int size
, bool big_endian
>
2474 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2475 Target_powerpc
<size
, big_endian
>* target
,
2476 const Symbol_value
<size
>* psymval
,
2480 Address addr
= psymval
->value(this, addend
);
2481 Address got_base
= target
->toc_pointer();
2483 if (addr
+ 0x80008000 > 0xffffffff)
2490 // Perform the Sized_relobj_file method, then set up opd info from
2493 template<int size
, bool big_endian
>
2495 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2497 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2500 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2501 p
!= rd
->relocs
.end();
2504 if (p
->data_shndx
== this->opd_shndx())
2506 uint64_t opd_size
= this->section_size(this->opd_shndx());
2507 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2510 this->init_opd(opd_size
);
2511 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2512 rd
->local_symbols
->data());
2520 // Read the symbols then set up st_other vector.
2522 template<int size
, bool big_endian
>
2524 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2526 this->base_read_symbols(sd
);
2527 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2531 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2532 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2533 const unsigned int loccount
= this->do_local_symbol_count();
2536 this->st_other_
.resize(loccount
);
2537 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2538 off_t locsize
= loccount
* sym_size
;
2539 const unsigned int symtab_shndx
= this->symtab_shndx();
2540 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2541 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2542 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2543 locsize
, true, false);
2545 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2547 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2548 unsigned char st_other
= sym
.get_st_other();
2549 this->st_other_
[i
] = st_other
;
2550 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2552 if (this->abiversion() == 0)
2553 this->set_abiversion(2);
2554 else if (this->abiversion() < 2)
2555 gold_error(_("%s: local symbol %d has invalid st_other"
2556 " for ABI version 1"),
2557 this->name().c_str(), i
);
2563 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2564 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2565 bool merge_attributes
= false;
2566 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2568 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2569 switch (shdr
.get_sh_type())
2571 case elfcpp::SHT_GNU_ATTRIBUTES
:
2573 gold_assert(this->attributes_section_data_
== NULL
);
2574 section_offset_type section_offset
= shdr
.get_sh_offset();
2575 section_size_type section_size
=
2576 convert_to_section_size_type(shdr
.get_sh_size());
2577 const unsigned char* view
=
2578 this->get_view(section_offset
, section_size
, true, false);
2579 this->attributes_section_data_
=
2580 new Attributes_section_data(view
, section_size
);
2584 case elfcpp::SHT_SYMTAB
:
2586 // Sometimes an object has no contents except the section
2587 // name string table and an empty symbol table with the
2588 // undefined symbol. We don't want to merge
2589 // processor-specific flags from such an object.
2590 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2591 elfcpp::Elf_sizes
<size
>::sym_size
;
2592 if (shdr
.get_sh_size() > sym_size
)
2593 merge_attributes
= true;
2597 case elfcpp::SHT_STRTAB
:
2601 merge_attributes
= true;
2606 if (!merge_attributes
)
2608 // Should rarely happen.
2609 delete this->attributes_section_data_
;
2610 this->attributes_section_data_
= NULL
;
2614 template<int size
, bool big_endian
>
2616 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2618 this->e_flags_
|= ver
;
2619 if (this->abiversion() != 0)
2621 Target_powerpc
<size
, big_endian
>* target
=
2622 static_cast<Target_powerpc
<size
, big_endian
>*>(
2623 parameters
->sized_target
<size
, big_endian
>());
2624 if (target
->abiversion() == 0)
2625 target
->set_abiversion(this->abiversion());
2626 else if (target
->abiversion() != this->abiversion())
2627 gold_error(_("%s: ABI version %d is not compatible "
2628 "with ABI version %d output"),
2629 this->name().c_str(),
2630 this->abiversion(), target
->abiversion());
2635 // Call Sized_dynobj::base_read_symbols to read the symbols then
2636 // read .opd from a dynamic object, filling in opd_ent_ vector,
2638 template<int size
, bool big_endian
>
2640 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2642 this->base_read_symbols(sd
);
2643 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2644 const unsigned char* ps
=
2645 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2646 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2648 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2649 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2651 section_offset_type section_offset
= shdr
.get_sh_offset();
2652 section_size_type section_size
=
2653 convert_to_section_size_type(shdr
.get_sh_size());
2654 const unsigned char* view
=
2655 this->get_view(section_offset
, section_size
, true, false);
2656 this->attributes_section_data_
=
2657 new Attributes_section_data(view
, section_size
);
2663 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2664 const unsigned char* namesu
= sd
->section_names
->data();
2665 const char* names
= reinterpret_cast<const char*>(namesu
);
2666 const unsigned char* s
= NULL
;
2667 const unsigned char* opd
;
2668 section_size_type opd_size
;
2670 // Find and read .opd section.
2673 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2674 sd
->section_names_size
,
2679 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2680 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2681 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2683 if (this->abiversion() == 0)
2684 this->set_abiversion(1);
2685 else if (this->abiversion() > 1)
2686 gold_error(_("%s: .opd invalid in abiv%d"),
2687 this->name().c_str(), this->abiversion());
2689 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2690 this->opd_address_
= shdr
.get_sh_addr();
2691 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2692 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2698 // Build set of executable sections.
2699 // Using a set is probably overkill. There is likely to be only
2700 // a few executable sections, typically .init, .text and .fini,
2701 // and they are generally grouped together.
2702 typedef std::set
<Sec_info
> Exec_sections
;
2703 Exec_sections exec_sections
;
2705 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2707 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2708 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2709 && ((shdr
.get_sh_flags()
2710 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2711 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2712 && shdr
.get_sh_size() != 0)
2714 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2715 shdr
.get_sh_size(), i
));
2718 if (exec_sections
.empty())
2721 // Look over the OPD entries. This is complicated by the fact
2722 // that some binaries will use two-word entries while others
2723 // will use the standard three-word entries. In most cases
2724 // the third word (the environment pointer for languages like
2725 // Pascal) is unused and will be zero. If the third word is
2726 // used it should not be pointing into executable sections,
2728 this->init_opd(opd_size
);
2729 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2731 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2732 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2733 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2735 // Chances are that this is the third word of an OPD entry.
2737 typename
Exec_sections::const_iterator e
2738 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2739 if (e
!= exec_sections
.begin())
2742 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2744 // We have an address in an executable section.
2745 // VAL ought to be the function entry, set it up.
2746 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2747 // Skip second word of OPD entry, the TOC pointer.
2751 // If we didn't match any executable sections, we likely
2752 // have a non-zero third word in the OPD entry.
2757 // Relocate sections.
2759 template<int size
, bool big_endian
>
2761 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2762 const Symbol_table
* symtab
, const Layout
* layout
,
2763 const unsigned char* pshdrs
, Output_file
* of
,
2764 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2766 unsigned int start
= 1;
2768 && this->relatoc_
!= 0
2769 && !parameters
->options().relocatable())
2771 // Relocate .toc first.
2772 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2773 this->relatoc_
, this->relatoc_
);
2774 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2775 1, this->relatoc_
- 1);
2776 start
= this->relatoc_
+ 1;
2778 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2779 start
, this->shnum() - 1);
2782 // Set up some symbols.
2784 template<int size
, bool big_endian
>
2786 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2787 Symbol_table
* symtab
,
2792 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2793 // undefined when scanning relocs (and thus requires
2794 // non-relative dynamic relocs). The proper value will be
2796 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2797 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2799 Target_powerpc
<size
, big_endian
>* target
=
2800 static_cast<Target_powerpc
<size
, big_endian
>*>(
2801 parameters
->sized_target
<size
, big_endian
>());
2802 Output_data_got_powerpc
<size
, big_endian
>* got
2803 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
2804 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2805 Symbol_table::PREDEFINED
,
2809 elfcpp::STV_HIDDEN
, 0,
2813 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2814 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2815 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2817 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2819 = layout
->add_output_section_data(".sdata", 0,
2821 | elfcpp::SHF_WRITE
,
2822 sdata
, ORDER_SMALL_DATA
, false);
2823 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2824 Symbol_table::PREDEFINED
,
2825 os
, 32768, 0, elfcpp::STT_OBJECT
,
2826 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2832 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2833 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2834 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2836 Target_powerpc
<size
, big_endian
>* target
=
2837 static_cast<Target_powerpc
<size
, big_endian
>*>(
2838 parameters
->sized_target
<size
, big_endian
>());
2839 Output_data_got_powerpc
<size
, big_endian
>* got
2840 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
2841 symtab
->define_in_output_data(".TOC.", NULL
,
2842 Symbol_table::PREDEFINED
,
2846 elfcpp::STV_HIDDEN
, 0,
2851 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2852 if (parameters
->options().tls_get_addr_optimize()
2853 && this->tls_get_addr_
!= NULL
2854 && this->tls_get_addr_
->in_reg())
2855 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2856 if (this->tls_get_addr_opt_
!= NULL
)
2858 if (this->tls_get_addr_
->is_undefined()
2859 || this->tls_get_addr_
->is_from_dynobj())
2861 // Make it seem as if references to __tls_get_addr are
2862 // really to __tls_get_addr_opt, so the latter symbol is
2863 // made dynamic, not the former.
2864 this->tls_get_addr_
->clear_in_reg();
2865 this->tls_get_addr_opt_
->set_in_reg();
2867 // We have a non-dynamic definition for __tls_get_addr.
2868 // Make __tls_get_addr_opt the same, if it does not already have
2869 // a non-dynamic definition.
2870 else if (this->tls_get_addr_opt_
->is_undefined()
2871 || this->tls_get_addr_opt_
->is_from_dynobj())
2873 Sized_symbol
<size
>* from
2874 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2875 Sized_symbol
<size
>* to
2876 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2877 symtab
->clone
<size
>(to
, from
);
2882 // Set up PowerPC target specific relobj.
2884 template<int size
, bool big_endian
>
2886 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2887 const std::string
& name
,
2888 Input_file
* input_file
,
2889 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2891 int et
= ehdr
.get_e_type();
2892 // ET_EXEC files are valid input for --just-symbols/-R,
2893 // and we treat them as relocatable objects.
2894 if (et
== elfcpp::ET_REL
2895 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2897 Powerpc_relobj
<size
, big_endian
>* obj
=
2898 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2902 else if (et
== elfcpp::ET_DYN
)
2904 Powerpc_dynobj
<size
, big_endian
>* obj
=
2905 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2911 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2916 template<int size
, bool big_endian
>
2917 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2920 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2921 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2923 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
,
2925 : Output_data_got
<size
, big_endian
>(),
2926 symtab_(symtab
), layout_(layout
),
2927 header_ent_cnt_(size
== 32 ? 3 : 1),
2928 header_index_(size
== 32 ? 0x2000 : -1u)
2931 this->set_addralign(256);
2932 if (size
== 64 && (got_type
& GOT_TYPE_SMALL
))
2933 this->make_header();
2936 // Override all the Output_data_got methods we use so as to first call
2939 add_global(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2941 this->reserve_ent();
2942 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
,
2947 add_global_plt(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2949 this->reserve_ent();
2950 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
,
2955 add_global_tls(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2956 { return this->add_global_plt(gsym
, got_type
, addend
); }
2959 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2960 Output_data_reloc_generic
* rel_dyn
,
2961 unsigned int r_type
, uint64_t addend
)
2963 this->reserve_ent();
2964 Output_data_got
<size
, big_endian
>::
2965 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
, addend
);
2969 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2970 Output_data_reloc_generic
* rel_dyn
,
2971 unsigned int r_type_1
, unsigned int r_type_2
,
2974 if (gsym
->has_got_offset(got_type
))
2977 this->reserve_ent(2);
2978 Output_data_got
<size
, big_endian
>::
2979 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
,
2984 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
,
2987 this->reserve_ent();
2988 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2993 add_local_plt(Relobj
* object
, unsigned int sym_index
,
2994 unsigned int got_type
, uint64_t addend
)
2996 this->reserve_ent();
2997 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
3002 add_local_tls(Relobj
* object
, unsigned int sym_index
,
3003 unsigned int got_type
, uint64_t addend
)
3004 { return this->add_local_plt(object
, sym_index
, got_type
, addend
); }
3007 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
3008 unsigned int got_type
,
3009 Output_data_reloc_generic
* rel_dyn
,
3010 unsigned int r_type
, uint64_t addend
)
3012 if (object
->local_has_got_offset(sym_index
, got_type
, addend
))
3015 this->reserve_ent(2);
3016 Output_data_got
<size
, big_endian
>::
3017 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
, addend
);
3021 add_constant(Valtype constant
)
3023 this->reserve_ent();
3024 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
3028 add_constant_pair(Valtype c1
, Valtype c2
)
3030 this->reserve_ent(2);
3031 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3034 // Offset of _GLOBAL_OFFSET_TABLE_ and .TOC. in this section.
3039 return this->got_offset(this->header_index_
);
3040 else if (this->header_index_
!= -1u)
3041 return this->got_offset(this->header_index_
) + 0x8000;
3046 // Ensure our GOT has a header.
3048 set_final_data_size()
3050 if (size
== 32 && this->header_ent_cnt_
!= 0)
3051 this->make_header();
3052 Output_data_got
<size
, big_endian
>::set_final_data_size();
3055 // First word of GOT header needs some values that are not
3056 // handled by Output_data_got so poke them in here.
3057 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3059 do_write(Output_file
* of
)
3061 if (this->header_index_
!= -1u)
3064 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3065 val
= this->layout_
->dynamic_section()->address();
3067 val
= this->address() + this->g_o_t();
3068 this->replace_constant(this->header_index_
, val
);
3070 Output_data_got
<size
, big_endian
>::do_write(of
);
3075 reserve_ent(unsigned int cnt
= 1)
3077 if (size
!= 32 || this->header_ent_cnt_
== 0)
3079 if (this->num_entries() + cnt
> this->header_index_
)
3080 this->make_header();
3086 this->header_ent_cnt_
= 0;
3087 this->header_index_
= this->num_entries();
3090 Output_data_got
<size
, big_endian
>::add_constant(0);
3091 Output_data_got
<size
, big_endian
>::add_constant(0);
3092 Output_data_got
<size
, big_endian
>::add_constant(0);
3094 // Define _GLOBAL_OFFSET_TABLE_ at the header
3095 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3098 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3099 sym
->set_value(this->g_o_t());
3102 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3103 Symbol_table::PREDEFINED
,
3104 this, this->g_o_t(), 0,
3107 elfcpp::STV_HIDDEN
, 0,
3111 Output_data_got
<size
, big_endian
>::add_constant(0);
3114 // Stashed pointers.
3115 Symbol_table
* symtab_
;
3119 unsigned int header_ent_cnt_
;
3120 // GOT header index.
3121 unsigned int header_index_
;
3124 // Get the GOT section, creating it if necessary.
3126 template<int size
, bool big_endian
>
3127 Output_data_got_powerpc
<size
, big_endian
>*
3128 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3132 if (this->got_
== NULL
)
3134 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3137 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
,
3140 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3141 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3142 this->got_
, ORDER_DATA
, false);
3145 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
3148 if (this->biggot_
== NULL
)
3151 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
,
3154 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3155 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3156 this->biggot_
, ORDER_DATA
, false);
3159 return this->biggot_
;
3162 // Get the dynamic reloc section, creating it if necessary.
3164 template<int size
, bool big_endian
>
3165 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3166 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3168 if (this->rela_dyn_
== NULL
)
3170 gold_assert(layout
!= NULL
);
3171 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3172 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3173 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3174 ORDER_DYNAMIC_RELOCS
, false);
3176 return this->rela_dyn_
;
3179 // Similarly, but for ifunc symbols get the one for ifunc.
3181 template<int size
, bool big_endian
>
3182 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3183 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3188 return this->rela_dyn_section(layout
);
3190 if (this->iplt_
== NULL
)
3191 this->make_iplt_section(symtab
, layout
);
3192 return this->iplt_
->rel_plt();
3198 // Determine the stub group size. The group size is the absolute
3199 // value of the parameter --stub-group-size. If --stub-group-size
3200 // is passed a negative value, we restrict stubs to be always after
3201 // the stubbed branches.
3202 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3203 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3204 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3205 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3206 owner_(NULL
), output_section_(NULL
)
3210 // Return true iff input section can be handled by current stub
3213 can_add_to_stub_group(Output_section
* o
,
3214 const Output_section::Input_section
* i
,
3217 const Output_section::Input_section
*
3223 { return output_section_
; }
3226 set_output_and_owner(Output_section
* o
,
3227 const Output_section::Input_section
* i
)
3229 this->output_section_
= o
;
3238 // Adding group sections before the stubs.
3239 FINDING_STUB_SECTION
,
3240 // Adding group sections after the stubs.
3244 uint32_t stub_group_size_
;
3245 bool stubs_always_after_branch_
;
3246 bool suppress_size_errors_
;
3247 // True if a stub group can serve multiple output sections.
3250 // Current max size of group. Starts at stub_group_size_ but is
3251 // reduced to stub_group_size_/1024 on seeing a section with
3252 // external conditional branches.
3253 uint32_t group_size_
;
3254 uint64_t group_start_addr_
;
3255 // owner_ and output_section_ specify the section to which stubs are
3256 // attached. The stubs are placed at the end of this section.
3257 const Output_section::Input_section
* owner_
;
3258 Output_section
* output_section_
;
3261 // Return true iff input section can be handled by current stub
3262 // group. Sections are presented to this function in order,
3263 // so the first section is the head of the group.
3266 Stub_control::can_add_to_stub_group(Output_section
* o
,
3267 const Output_section::Input_section
* i
,
3270 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3272 uint64_t start_addr
= o
->address();
3275 // .init and .fini sections are pasted together to form a single
3276 // function. We can't be adding stubs in the middle of the function.
3277 this_size
= o
->data_size();
3280 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3281 this_size
= i
->data_size();
3284 uint64_t end_addr
= start_addr
+ this_size
;
3285 uint32_t group_size
= this->stub_group_size_
;
3287 this->group_size_
= group_size
= group_size
>> 10;
3289 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3290 gold_warning(_("%s:%s exceeds group size"),
3291 i
->relobj()->name().c_str(),
3292 i
->relobj()->section_name(i
->shndx()).c_str());
3294 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3295 has14
? " 14bit" : "",
3296 i
->relobj()->name().c_str(),
3297 i
->relobj()->section_name(i
->shndx()).c_str(),
3298 (long long) this_size
,
3299 (this->state_
== NO_GROUP
3301 : (long long) end_addr
- this->group_start_addr_
));
3303 if (this->state_
== NO_GROUP
)
3305 // Only here on very first use of Stub_control
3307 this->output_section_
= o
;
3308 this->state_
= FINDING_STUB_SECTION
;
3309 this->group_size_
= group_size
;
3310 this->group_start_addr_
= start_addr
;
3313 else if (!this->multi_os_
&& this->output_section_
!= o
)
3315 else if (this->state_
== HAS_STUB_SECTION
)
3317 // Can we add this section, which is after the stubs, to the
3319 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3322 else if (this->state_
== FINDING_STUB_SECTION
)
3324 if ((whole_sec
&& this->output_section_
== o
)
3325 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3327 // Stubs are added at the end of "owner_".
3329 this->output_section_
= o
;
3332 // The group before the stubs has reached maximum size.
3333 // Now see about adding sections after the stubs to the
3334 // group. If the current section has a 14-bit branch and
3335 // the group before the stubs exceeds group_size_ (because
3336 // they didn't have 14-bit branches), don't add sections
3337 // after the stubs: The size of stubs for such a large
3338 // group may exceed the reach of a 14-bit branch.
3339 if (!this->stubs_always_after_branch_
3340 && this_size
<= this->group_size_
3341 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3343 gold_debug(DEBUG_TARGET
, "adding after stubs");
3344 this->state_
= HAS_STUB_SECTION
;
3345 this->group_start_addr_
= start_addr
;
3352 gold_debug(DEBUG_TARGET
,
3353 !this->multi_os_
&& this->output_section_
!= o
3354 ? "nope, new output section\n"
3355 : "nope, didn't fit\n");
3357 // The section fails to fit in the current group. Set up a few
3358 // things for the next group. owner_ and output_section_ will be
3359 // set later after we've retrieved those values for the current
3361 this->state_
= FINDING_STUB_SECTION
;
3362 this->group_size_
= group_size
;
3363 this->group_start_addr_
= start_addr
;
3367 // Look over all the input sections, deciding where to place stubs.
3369 template<int size
, bool big_endian
>
3371 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3373 bool no_size_errors
)
3375 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3376 parameters
->options().stub_group_multi());
3378 // Group input sections and insert stub table
3379 Stub_table_owner
* table_owner
= NULL
;
3380 std::vector
<Stub_table_owner
*> tables
;
3381 Layout::Section_list section_list
;
3382 layout
->get_executable_sections(§ion_list
);
3383 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3384 for (Layout::Section_list::iterator o
= section_list
.begin();
3385 o
!= section_list
.end();
3388 typedef Output_section::Input_section_list Input_section_list
;
3389 for (Input_section_list::const_iterator i
3390 = (*o
)->input_sections().begin();
3391 i
!= (*o
)->input_sections().end();
3394 if (i
->is_input_section()
3395 || i
->is_relaxed_input_section())
3397 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3398 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3399 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3400 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3402 table_owner
->output_section
= stub_control
.output_section();
3403 table_owner
->owner
= stub_control
.owner();
3404 stub_control
.set_output_and_owner(*o
, &*i
);
3407 if (table_owner
== NULL
)
3409 table_owner
= new Stub_table_owner
;
3410 tables
.push_back(table_owner
);
3412 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3416 if (table_owner
!= NULL
)
3418 table_owner
->output_section
= stub_control
.output_section();
3419 table_owner
->owner
= stub_control
.owner();;
3421 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3425 Stub_table
<size
, big_endian
>* stub_table
;
3427 if ((*t
)->owner
->is_input_section())
3428 stub_table
= new Stub_table
<size
, big_endian
>(this,
3429 (*t
)->output_section
,
3431 this->stub_tables_
.size());
3432 else if ((*t
)->owner
->is_relaxed_input_section())
3433 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3434 (*t
)->owner
->relaxed_input_section());
3437 this->stub_tables_
.push_back(stub_table
);
3443 static unsigned long
3444 max_branch_delta (unsigned int r_type
)
3446 if (r_type
== elfcpp::R_POWERPC_REL14
3447 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3448 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3450 if (r_type
== elfcpp::R_POWERPC_REL24
3451 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3452 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
3453 || r_type
== elfcpp::R_PPC_PLTREL24
3454 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3459 // Return whether this branch is going via a plt call stub.
3461 template<int size
, bool big_endian
>
3463 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3464 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3467 Target_powerpc
* target
,
3468 Symbol_table
* symtab
)
3470 if (this->object_
!= ppc_object
3471 || this->shndx_
!= shndx
3472 || this->offset_
!= offset
)
3475 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3476 if (sym
!= NULL
&& sym
->is_forwarder())
3477 sym
= symtab
->resolve_forwards(sym
);
3478 if (target
->replace_tls_get_addr(sym
))
3479 sym
= target
->tls_get_addr_opt();
3480 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3482 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3483 && !target
->is_elfv2_localentry0(gsym
))
3484 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3485 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3493 // If this branch needs a plt call stub, or a long branch stub, make one.
3495 template<int size
, bool big_endian
>
3497 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3498 Stub_table
<size
, big_endian
>* stub_table
,
3499 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3500 Symbol_table
* symtab
) const
3502 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3503 Target_powerpc
<size
, big_endian
>* target
=
3504 static_cast<Target_powerpc
<size
, big_endian
>*>(
3505 parameters
->sized_target
<size
, big_endian
>());
3506 if (sym
!= NULL
&& sym
->is_forwarder())
3507 sym
= symtab
->resolve_forwards(sym
);
3508 if (target
->replace_tls_get_addr(sym
))
3509 sym
= target
->tls_get_addr_opt();
3510 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3514 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3515 : this->object_
->local_has_plt_offset(this->r_sym_
))
3519 && target
->abiversion() >= 2
3520 && !parameters
->options().output_is_position_independent()
3521 && !is_branch_reloc
<size
>(this->r_type_
))
3522 target
->glink_section()->add_global_entry(gsym
);
3525 if (stub_table
== NULL
3528 && !parameters
->options().output_is_position_independent()
3529 && !is_branch_reloc
<size
>(this->r_type_
)))
3530 stub_table
= this->object_
->stub_table(this->shndx_
);
3531 if (stub_table
== NULL
)
3533 // This is a ref from a data section to an ifunc symbol,
3534 // or a non-branch reloc for which we always want to use
3535 // one set of stubs for resolving function addresses.
3536 stub_table
= ifunc_stub_table
;
3538 gold_assert(stub_table
!= NULL
);
3539 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3540 if (from
!= invalid_address
)
3541 from
+= (this->object_
->output_section(this->shndx_
)->address()
3544 ok
= stub_table
->add_plt_call_entry(from
,
3545 this->object_
, gsym
,
3546 this->r_type_
, this->addend_
,
3549 ok
= stub_table
->add_plt_call_entry(from
,
3550 this->object_
, this->r_sym_
,
3551 this->r_type_
, this->addend_
,
3557 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3558 if (max_branch_offset
== 0)
3560 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3561 gold_assert(from
!= invalid_address
);
3562 from
+= (this->object_
->output_section(this->shndx_
)->address()
3565 unsigned int other
= 0;
3568 switch (gsym
->source())
3570 case Symbol::FROM_OBJECT
:
3572 Object
* symobj
= gsym
->object();
3573 if (symobj
->is_dynamic()
3574 || symobj
->pluginobj() != NULL
)
3577 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3578 if (shndx
== elfcpp::SHN_UNDEF
)
3583 case Symbol::IS_UNDEFINED
:
3589 Symbol_table::Compute_final_value_status status
;
3590 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3591 if (status
!= Symbol_table::CFVS_OK
)
3594 other
= gsym
->nonvis() >> 3;
3598 const Symbol_value
<size
>* psymval
3599 = this->object_
->local_symbol(this->r_sym_
);
3600 Symbol_value
<size
> symval
;
3601 if (psymval
->is_section_symbol())
3602 symval
.set_is_section_symbol();
3603 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3604 typename
ObjType::Compute_final_local_value_status status
3605 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3607 if (status
!= ObjType::CFLV_OK
3608 || !symval
.has_output_value())
3610 to
= symval
.value(this->object_
, 0);
3612 other
= this->object_
->st_other(this->r_sym_
) >> 5;
3614 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3615 to
+= this->addend_
;
3616 if (stub_table
== NULL
)
3617 stub_table
= this->object_
->stub_table(this->shndx_
);
3618 if (size
== 64 && target
->abiversion() < 2)
3620 unsigned int dest_shndx
;
3621 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3625 unsigned int local_ent
= 0;
3627 && this->r_type_
!= elfcpp::R_PPC64_REL24_NOTOC
3628 && this->r_type_
!= elfcpp::R_PPC64_REL24_P9NOTOC
)
3629 local_ent
= elfcpp::ppc64_decode_local_entry(other
);
3630 Address delta
= to
+ local_ent
- from
;
3631 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3633 && (this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3634 || this->r_type_
== elfcpp::R_PPC64_REL24_P9NOTOC
)
3636 ? this->object_
->ppc64_needs_toc(gsym
)
3637 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3639 if (stub_table
== NULL
)
3641 gold_warning(_("%s:%s: branch in non-executable section,"
3642 " no long branch stub for you"),
3643 this->object_
->name().c_str(),
3644 this->object_
->section_name(this->shndx_
).c_str());
3647 bool save_res
= (size
== 64
3649 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3650 && gsym
->output_data() == target
->savres_section());
3651 ok
= stub_table
->add_long_branch_entry(this->r_type_
,
3652 from
, to
, other
, save_res
);
3656 gold_debug(DEBUG_TARGET
,
3657 "branch at %s:%s+%#lx\n"
3658 "can't reach stub attached to %s:%s",
3659 this->object_
->name().c_str(),
3660 this->object_
->section_name(this->shndx_
).c_str(),
3661 (unsigned long) this->offset_
,
3662 stub_table
->relobj()->name().c_str(),
3663 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3668 // Relaxation hook. This is where we do stub generation.
3670 template<int size
, bool big_endian
>
3672 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3673 const Input_objects
*,
3674 Symbol_table
* symtab
,
3678 unsigned int prev_brlt_size
= 0;
3682 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3684 && this->abiversion() < 2
3686 && !parameters
->options().user_set_plt_thread_safe())
3688 static const char* const thread_starter
[] =
3692 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3694 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3695 "mq_notify", "create_timer",
3700 "GOMP_parallel_start",
3701 "GOMP_parallel_loop_static",
3702 "GOMP_parallel_loop_static_start",
3703 "GOMP_parallel_loop_dynamic",
3704 "GOMP_parallel_loop_dynamic_start",
3705 "GOMP_parallel_loop_guided",
3706 "GOMP_parallel_loop_guided_start",
3707 "GOMP_parallel_loop_runtime",
3708 "GOMP_parallel_loop_runtime_start",
3709 "GOMP_parallel_sections",
3710 "GOMP_parallel_sections_start",
3715 if (parameters
->options().shared())
3719 for (unsigned int i
= 0;
3720 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3723 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3724 thread_safe
= (sym
!= NULL
3726 && sym
->in_real_elf());
3732 this->plt_thread_safe_
= thread_safe
;
3737 this->stub_group_size_
= parameters
->options().stub_group_size();
3738 bool no_size_errors
= true;
3739 if (this->stub_group_size_
== 1)
3740 this->stub_group_size_
= 0x1c00000;
3741 else if (this->stub_group_size_
== -1)
3742 this->stub_group_size_
= -0x1e00000;
3744 no_size_errors
= false;
3745 this->group_sections(layout
, task
, no_size_errors
);
3747 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3749 this->branch_lookup_table_
.clear();
3750 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3751 p
!= this->stub_tables_
.end();
3754 (*p
)->clear_stubs(true);
3756 this->stub_tables_
.clear();
3757 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3758 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3759 program_name
, this->stub_group_size_
);
3760 this->group_sections(layout
, task
, true);
3763 // We need address of stub tables valid for make_stub.
3764 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3765 p
!= this->stub_tables_
.end();
3768 const Powerpc_relobj
<size
, big_endian
>* object
3769 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3770 Address off
= object
->get_output_section_offset((*p
)->shndx());
3771 gold_assert(off
!= invalid_address
);
3772 Output_section
* os
= (*p
)->output_section();
3773 (*p
)->set_address_and_size(os
, off
);
3778 // Clear plt call stubs, long branch stubs and branch lookup table.
3779 prev_brlt_size
= this->branch_lookup_table_
.size();
3780 this->branch_lookup_table_
.clear();
3781 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3782 p
!= this->stub_tables_
.end();
3785 (*p
)->clear_stubs(false);
3789 // Build all the stubs.
3790 this->relax_failed_
= false;
3791 Stub_table
<size
, big_endian
>* ifunc_stub_table
3792 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3793 Stub_table
<size
, big_endian
>* one_stub_table
3794 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3795 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3796 b
!= this->branch_info_
.end();
3799 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3800 && !this->relax_failed_
)
3802 this->relax_failed_
= true;
3803 this->relax_fail_count_
++;
3804 if (this->relax_fail_count_
< 3)
3808 bool do_resize
= false;
3809 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3810 p
!= this->stub_tables_
.end();
3812 if ((*p
)->need_resize())
3819 this->branch_lookup_table_
.clear();
3820 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3821 p
!= this->stub_tables_
.end();
3823 (*p
)->set_resizing(true);
3824 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3825 b
!= this->branch_info_
.end();
3828 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3829 && !this->relax_failed_
)
3831 this->relax_failed_
= true;
3832 this->relax_fail_count_
++;
3833 if (this->relax_fail_count_
< 3)
3837 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3838 p
!= this->stub_tables_
.end();
3840 (*p
)->set_resizing(false);
3843 // Did anything change size?
3844 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3845 bool again
= num_huge_branches
!= prev_brlt_size
;
3846 if (size
== 64 && num_huge_branches
!= 0)
3847 this->make_brlt_section(layout
);
3848 if (size
== 64 && again
)
3849 this->brlt_section_
->set_current_size(num_huge_branches
);
3851 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3852 p
!= this->stub_tables_
.rend();
3854 (*p
)->remove_eh_frame(layout
);
3856 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3857 p
!= this->stub_tables_
.end();
3859 (*p
)->add_eh_frame(layout
);
3861 typedef Unordered_set
<Output_section
*> Output_sections
;
3862 Output_sections os_need_update
;
3863 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3864 p
!= this->stub_tables_
.end();
3867 if ((*p
)->size_update())
3870 os_need_update
.insert((*p
)->output_section());
3874 // Set output section offsets for all input sections in an output
3875 // section that just changed size. Anything past the stubs will
3877 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3878 p
!= os_need_update
.end();
3881 Output_section
* os
= *p
;
3883 typedef Output_section::Input_section_list Input_section_list
;
3884 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3885 i
!= os
->input_sections().end();
3888 off
= align_address(off
, i
->addralign());
3889 if (i
->is_input_section() || i
->is_relaxed_input_section())
3890 i
->relobj()->set_section_offset(i
->shndx(), off
);
3891 if (i
->is_relaxed_input_section())
3893 Stub_table
<size
, big_endian
>* stub_table
3894 = static_cast<Stub_table
<size
, big_endian
>*>(
3895 i
->relaxed_input_section());
3896 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3897 off
+= stub_table_size
;
3898 // After a few iterations, set current stub table size
3899 // as min size threshold, so later stub tables can only
3902 stub_table
->set_min_size_threshold(stub_table_size
);
3905 off
+= i
->data_size();
3907 // If .branch_lt is part of this output section, then we have
3908 // just done the offset adjustment.
3909 os
->clear_section_offsets_need_adjustment();
3914 && num_huge_branches
!= 0
3915 && parameters
->options().output_is_position_independent())
3917 // Fill in the BRLT relocs.
3918 this->brlt_section_
->reset_brlt_sizes();
3919 for (typename
Branch_lookup_table::const_iterator p
3920 = this->branch_lookup_table_
.begin();
3921 p
!= this->branch_lookup_table_
.end();
3924 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3926 this->brlt_section_
->finalize_brlt_sizes();
3930 && (parameters
->options().user_set_emit_stub_syms()
3931 ? parameters
->options().emit_stub_syms()
3933 || parameters
->options().output_is_position_independent()
3934 || parameters
->options().emit_relocs())))
3936 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3937 p
!= this->stub_tables_
.end();
3939 (*p
)->define_stub_syms(symtab
);
3941 if (this->glink_
!= NULL
)
3943 int stub_size
= this->glink_
->pltresolve_size();
3944 Address value
= -stub_size
;
3950 this->define_local(symtab
, "__glink_PLTresolve",
3951 this->glink_
, value
, stub_size
);
3954 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3961 template<int size
, bool big_endian
>
3963 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3964 unsigned char* oview
,
3968 uint64_t address
= plt
->address();
3969 off_t len
= plt
->data_size();
3971 if (plt
== this->glink_
)
3973 // See Output_data_glink::do_write() for glink contents.
3976 // Static linking may need stubs, to support ifunc and long
3977 // branches. We need to create an output section for
3978 // .eh_frame early in the link process, to have a place to
3979 // attach stub .eh_frame info. We also need to have
3980 // registered a CIE that matches the stub CIE. Both of
3981 // these requirements are satisfied by creating an FDE and
3982 // CIE for .glink, even though static linking will leave
3983 // .glink zero length.
3984 // ??? Hopefully generating an FDE with a zero address range
3985 // won't confuse anything that consumes .eh_frame info.
3987 else if (size
== 64)
3989 // There is one word before __glink_PLTresolve
3993 else if (parameters
->options().output_is_position_independent())
3995 // There are two FDEs for a position independent glink.
3996 // The first covers the branch table, the second
3997 // __glink_PLTresolve at the end of glink.
3998 off_t resolve_size
= this->glink_
->pltresolve_size();
3999 if (oview
[9] == elfcpp::DW_CFA_nop
)
4000 len
-= resolve_size
;
4003 address
+= len
- resolve_size
;
4010 // Must be a stub table.
4011 const Stub_table
<size
, big_endian
>* stub_table
4012 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
4013 uint64_t stub_address
= stub_table
->stub_address();
4014 len
-= stub_address
- address
;
4015 address
= stub_address
;
4018 *paddress
= address
;
4022 // A class to handle the PLT data.
4024 template<int size
, bool big_endian
>
4025 class Output_data_plt_powerpc
: public Output_section_data_build
4028 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4029 size
, big_endian
> Reloc_section
;
4031 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4032 Symbol_table
* symtab
,
4033 Reloc_section
* plt_rel
,
4035 : Output_section_data_build(size
== 32 ? 4 : 8),
4036 rel_(plt_rel
), targ_(targ
), symtab_(symtab
), name_(name
), sym_ents_()
4039 // Add an entry to the PLT.
4041 add_entry(Symbol
*, bool = false);
4044 add_ifunc_entry(Symbol
*);
4047 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4050 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4052 // Return the .rela.plt section data.
4059 // Return the number of PLT entries.
4063 if (this->current_data_size() == 0)
4065 return ((this->current_data_size() - this->first_plt_entry_offset())
4066 / this->plt_entry_size());
4071 do_adjust_output_section(Output_section
* os
)
4076 // Write to a map file.
4078 do_print_to_mapfile(Mapfile
* mapfile
) const
4079 { mapfile
->print_output_data(this, this->name_
); }
4082 struct Local_plt_ent
4084 Local_plt_ent(Sized_relobj_file
<size
, big_endian
>* obj
, unsigned int rsym
)
4085 { rsym_
= rsym
; u
.obj_
= obj
; }
4086 Local_plt_ent(Symbol
* sym
)
4087 { rsym_
= -1u; u
.gsym_
= sym
; }
4094 Sized_relobj_file
<size
, big_endian
>* obj_
;
4099 // Return the offset of the first non-reserved PLT entry.
4101 first_plt_entry_offset() const
4103 // IPLT and LPLT have no reserved entry.
4104 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4106 return this->targ_
->first_plt_entry_offset();
4109 // Return the size of each PLT entry.
4111 plt_entry_size() const
4113 return this->targ_
->plt_entry_size();
4116 // Write out the PLT data.
4118 do_write(Output_file
*);
4120 // The reloc section.
4121 Reloc_section
* rel_
;
4122 // Allows access to .glink for do_write.
4123 Target_powerpc
<size
, big_endian
>* targ_
;
4124 Symbol_table
* symtab_
;
4125 // What to report in map file.
4128 std::vector
<Local_plt_ent
> sym_ents_
;
4131 // Add an entry to the PLT.
4133 template<int size
, bool big_endian
>
4135 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
,
4138 if (!gsym
->has_plt_offset())
4140 section_size_type off
= this->current_data_size();
4142 off
+= this->first_plt_entry_offset();
4143 gsym
->set_plt_offset(off
);
4146 gsym
->set_needs_dynsym_entry();
4147 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4148 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4150 off
+= this->plt_entry_size();
4151 this->set_current_data_size(off
);
4154 Local_plt_ent
sym(gsym
);
4155 this->sym_ents_
.push_back(sym
);
4160 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4162 template<int size
, bool big_endian
>
4164 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4166 if (!gsym
->has_plt_offset())
4168 section_size_type off
= this->current_data_size();
4169 gsym
->set_plt_offset(off
);
4170 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4171 if (size
== 64 && this->targ_
->abiversion() < 2)
4172 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4173 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4174 off
+= this->plt_entry_size();
4175 this->set_current_data_size(off
);
4179 // Add an entry for a local symbol to the PLT.
4181 template<int size
, bool big_endian
>
4183 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4184 Sized_relobj_file
<size
, big_endian
>* relobj
,
4185 unsigned int local_sym_index
)
4187 if (!relobj
->local_has_plt_offset(local_sym_index
))
4189 section_size_type off
= this->current_data_size();
4190 relobj
->set_local_plt_offset(local_sym_index
, off
);
4193 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4194 if (size
== 64 && this->targ_
->abiversion() < 2)
4195 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4196 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4197 dynrel
, this, off
, 0);
4199 off
+= this->plt_entry_size();
4200 this->set_current_data_size(off
);
4201 Local_plt_ent
sym(relobj
, local_sym_index
);
4202 this->sym_ents_
.push_back(sym
);
4206 // Add an entry for a local ifunc symbol to the IPLT.
4208 template<int size
, bool big_endian
>
4210 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4211 Sized_relobj_file
<size
, big_endian
>* relobj
,
4212 unsigned int local_sym_index
)
4214 if (!relobj
->local_has_plt_offset(local_sym_index
))
4216 section_size_type off
= this->current_data_size();
4217 relobj
->set_local_plt_offset(local_sym_index
, off
);
4218 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4219 if (size
== 64 && this->targ_
->abiversion() < 2)
4220 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4221 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4223 off
+= this->plt_entry_size();
4224 this->set_current_data_size(off
);
4228 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4229 static const uint32_t add_2_2_11
= 0x7c425a14;
4230 static const uint32_t add_2_2_12
= 0x7c426214;
4231 static const uint32_t add_3_3_2
= 0x7c631214;
4232 static const uint32_t add_3_3_13
= 0x7c636a14;
4233 static const uint32_t add_3_12_2
= 0x7c6c1214;
4234 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4235 static const uint32_t add_11_0_11
= 0x7d605a14;
4236 static const uint32_t add_11_2_11
= 0x7d625a14;
4237 static const uint32_t add_11_11_2
= 0x7d6b1214;
4238 static const uint32_t add_12_11_12
= 0x7d8b6214;
4239 static const uint32_t addi_0_12
= 0x380c0000;
4240 static const uint32_t addi_2_2
= 0x38420000;
4241 static const uint32_t addi_3_3
= 0x38630000;
4242 static const uint32_t addi_11_11
= 0x396b0000;
4243 static const uint32_t addi_12_1
= 0x39810000;
4244 static const uint32_t addi_12_11
= 0x398b0000;
4245 static const uint32_t addi_12_12
= 0x398c0000;
4246 static const uint32_t addis_0_2
= 0x3c020000;
4247 static const uint32_t addis_0_13
= 0x3c0d0000;
4248 static const uint32_t addis_2_12
= 0x3c4c0000;
4249 static const uint32_t addis_11_2
= 0x3d620000;
4250 static const uint32_t addis_11_11
= 0x3d6b0000;
4251 static const uint32_t addis_11_30
= 0x3d7e0000;
4252 static const uint32_t addis_12_1
= 0x3d810000;
4253 static const uint32_t addis_12_2
= 0x3d820000;
4254 static const uint32_t addis_12_11
= 0x3d8b0000;
4255 static const uint32_t addis_12_12
= 0x3d8c0000;
4256 static const uint32_t b
= 0x48000000;
4257 static const uint32_t bcl_20_31
= 0x429f0005;
4258 static const uint32_t bctr
= 0x4e800420;
4259 static const uint32_t bctrl
= 0x4e800421;
4260 static const uint32_t beqlr
= 0x4d820020;
4261 static const uint32_t blr
= 0x4e800020;
4262 static const uint32_t bnectr_p4
= 0x4ce20420;
4263 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4264 static const uint32_t cmpldi_2_0
= 0x28220000;
4265 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4266 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4267 static const uint32_t cror_15_15_15
= 0x4def7b82;
4268 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4269 static const uint32_t ld_0_1
= 0xe8010000;
4270 static const uint32_t ld_0_11
= 0xe80b0000;
4271 static const uint32_t ld_0_12
= 0xe80c0000;
4272 static const uint32_t ld_2_1
= 0xe8410000;
4273 static const uint32_t ld_2_2
= 0xe8420000;
4274 static const uint32_t ld_2_11
= 0xe84b0000;
4275 static const uint32_t ld_2_12
= 0xe84c0000;
4276 static const uint32_t ld_11_1
= 0xe9610000;
4277 static const uint32_t ld_11_2
= 0xe9620000;
4278 static const uint32_t ld_11_3
= 0xe9630000;
4279 static const uint32_t ld_11_11
= 0xe96b0000;
4280 static const uint32_t ld_12_2
= 0xe9820000;
4281 static const uint32_t ld_12_3
= 0xe9830000;
4282 static const uint32_t ld_12_11
= 0xe98b0000;
4283 static const uint32_t ld_12_12
= 0xe98c0000;
4284 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4285 static const uint32_t lfd_0_1
= 0xc8010000;
4286 static const uint32_t li_0_0
= 0x38000000;
4287 static const uint32_t li_11_0
= 0x39600000;
4288 static const uint32_t li_12_0
= 0x39800000;
4289 static const uint32_t lis_0
= 0x3c000000;
4290 static const uint32_t lis_2
= 0x3c400000;
4291 static const uint32_t lis_11
= 0x3d600000;
4292 static const uint32_t lis_12
= 0x3d800000;
4293 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4294 static const uint32_t lwz_0_12
= 0x800c0000;
4295 static const uint32_t lwz_11_3
= 0x81630000;
4296 static const uint32_t lwz_11_11
= 0x816b0000;
4297 static const uint32_t lwz_11_30
= 0x817e0000;
4298 static const uint32_t lwz_12_3
= 0x81830000;
4299 static const uint32_t lwz_12_12
= 0x818c0000;
4300 static const uint32_t lwzu_0_12
= 0x840c0000;
4301 static const uint32_t mflr_0
= 0x7c0802a6;
4302 static const uint32_t mflr_11
= 0x7d6802a6;
4303 static const uint32_t mflr_12
= 0x7d8802a6;
4304 static const uint32_t mr_0_3
= 0x7c601b78;
4305 static const uint32_t mr_3_0
= 0x7c030378;
4306 static const uint32_t mtctr_0
= 0x7c0903a6;
4307 static const uint32_t mtctr_11
= 0x7d6903a6;
4308 static const uint32_t mtctr_12
= 0x7d8903a6;
4309 static const uint32_t mtlr_0
= 0x7c0803a6;
4310 static const uint32_t mtlr_11
= 0x7d6803a6;
4311 static const uint32_t mtlr_12
= 0x7d8803a6;
4312 static const uint32_t nop
= 0x60000000;
4313 static const uint32_t ori_0_0_0
= 0x60000000;
4314 static const uint32_t ori_11_11_0
= 0x616b0000;
4315 static const uint32_t ori_12_12_0
= 0x618c0000;
4316 static const uint32_t oris_12_12_0
= 0x658c0000;
4317 static const uint32_t sldi_11_11_34
= 0x796b1746;
4318 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4319 static const uint32_t srdi_0_0_2
= 0x7800f082;
4320 static const uint32_t std_0_1
= 0xf8010000;
4321 static const uint32_t std_0_12
= 0xf80c0000;
4322 static const uint32_t std_2_1
= 0xf8410000;
4323 static const uint32_t std_11_1
= 0xf9610000;
4324 static const uint32_t stfd_0_1
= 0xd8010000;
4325 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4326 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4327 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4328 static const uint32_t xor_2_12_12
= 0x7d826278;
4329 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4331 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4332 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4333 static const uint64_t pnop
= 0x0700000000000000ULL
;
4335 // Write out the PLT.
4337 template<int size
, bool big_endian
>
4339 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4341 if (!this->sym_ents_
.empty()
4342 && !parameters
->options().output_is_position_independent())
4344 const section_size_type offset
= this->offset();
4345 const section_size_type oview_size
4346 = convert_to_section_size_type(this->data_size());
4347 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4348 unsigned char* pov
= oview
;
4349 unsigned char* endpov
= oview
+ oview_size
;
4351 for (typename
std::vector
<Local_plt_ent
>::iterator e
4352 = this->sym_ents_
.begin();
4353 e
!= this->sym_ents_
.end();
4356 typename
elfcpp::Elf_types
<size
>::Elf_Addr val
;
4357 Sized_symbol
<size
>* gsym
= NULL
;
4358 Powerpc_relobj
<size
, big_endian
>* obj
= NULL
;
4359 if (e
->rsym_
== -1u)
4361 gsym
= static_cast<Sized_symbol
<size
>*>(e
->u
.gsym_
);
4362 val
= gsym
->value();
4366 obj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(e
->u
.obj_
);
4367 val
= obj
->local_symbol(e
->rsym_
)->value(obj
, 0);
4369 if (this->targ_
->abiversion() >= 2)
4371 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4377 this->targ_
->symval_for_branch(this->symtab_
, gsym
, obj
,
4379 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4381 val
= this->targ_
->toc_pointer();
4382 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4384 if (this->plt_entry_size() > 16)
4386 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, 0);
4391 gold_assert(pov
== endpov
);
4394 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4396 const section_size_type offset
= this->offset();
4397 const section_size_type oview_size
4398 = convert_to_section_size_type(this->data_size());
4399 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4400 unsigned char* pov
= oview
;
4401 unsigned char* endpov
= oview
+ oview_size
;
4403 // The address of the .glink branch table
4404 const Output_data_glink
<size
, big_endian
>* glink
4405 = this->targ_
->glink_section();
4406 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4408 while (pov
< endpov
)
4410 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4415 of
->write_output_view(offset
, oview_size
, oview
);
4419 // Create the PLT section.
4421 template<int size
, bool big_endian
>
4423 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4426 if (this->plt_
== NULL
)
4428 if (this->got_
== NULL
)
4429 this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
4431 if (this->glink_
== NULL
)
4432 make_glink_section(layout
);
4434 // Ensure that .rela.dyn always appears before .rela.plt This is
4435 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4436 // needs to include .rela.plt in its range.
4437 this->rela_dyn_section(layout
);
4439 Reloc_section
* plt_rel
= new Reloc_section(false);
4440 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4441 elfcpp::SHF_ALLOC
, plt_rel
,
4442 ORDER_DYNAMIC_PLT_RELOCS
, false);
4444 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, plt_rel
,
4446 layout
->add_output_section_data(".plt",
4448 ? elfcpp::SHT_PROGBITS
4449 : elfcpp::SHT_NOBITS
),
4450 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4457 Output_section
* rela_plt_os
= plt_rel
->output_section();
4458 rela_plt_os
->set_info_section(this->plt_
->output_section());
4462 // Create the IPLT section.
4464 template<int size
, bool big_endian
>
4466 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4469 if (this->iplt_
== NULL
)
4471 this->make_plt_section(symtab
, layout
);
4472 this->make_lplt_section(symtab
, layout
);
4474 Reloc_section
* iplt_rel
= new Reloc_section(false);
4475 if (this->rela_dyn_
->output_section())
4476 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4478 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, iplt_rel
,
4480 if (this->plt_
->output_section())
4481 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4485 // Create the LPLT section.
4487 template<int size
, bool big_endian
>
4489 Target_powerpc
<size
, big_endian
>::make_lplt_section(Symbol_table
* symtab
,
4492 if (this->lplt_
== NULL
)
4494 Reloc_section
* lplt_rel
= NULL
;
4495 if (parameters
->options().output_is_position_independent())
4497 lplt_rel
= new Reloc_section(false);
4498 this->rela_dyn_section(layout
);
4499 if (this->rela_dyn_
->output_section())
4500 this->rela_dyn_
->output_section()
4501 ->add_output_section_data(lplt_rel
);
4504 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, lplt_rel
,
4506 this->make_brlt_section(layout
);
4507 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4508 this->brlt_section_
->output_section()
4509 ->add_output_section_data(this->lplt_
);
4511 layout
->add_output_section_data(".branch_lt",
4512 elfcpp::SHT_PROGBITS
,
4513 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4520 // A section for huge long branch addresses, similar to plt section.
4522 template<int size
, bool big_endian
>
4523 class Output_data_brlt_powerpc
: public Output_section_data_build
4526 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4527 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4528 size
, big_endian
> Reloc_section
;
4530 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4531 Reloc_section
* brlt_rel
)
4532 : Output_section_data_build(size
== 32 ? 4 : 8),
4540 this->reset_data_size();
4541 this->rel_
->reset_data_size();
4545 finalize_brlt_sizes()
4547 this->finalize_data_size();
4548 this->rel_
->finalize_data_size();
4551 // Add a reloc for an entry in the BRLT.
4553 add_reloc(Address to
, unsigned int off
)
4554 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4556 // Update section and reloc section size.
4558 set_current_size(unsigned int num_branches
)
4560 this->reset_address_and_file_offset();
4561 this->set_current_data_size(num_branches
* 16);
4562 this->finalize_data_size();
4563 Output_section
* os
= this->output_section();
4564 os
->set_section_offsets_need_adjustment();
4565 if (this->rel_
!= NULL
)
4567 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4568 this->rel_
->reset_address_and_file_offset();
4569 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4570 this->rel_
->finalize_data_size();
4571 Output_section
* os
= this->rel_
->output_section();
4572 os
->set_section_offsets_need_adjustment();
4578 do_adjust_output_section(Output_section
* os
)
4583 // Write to a map file.
4585 do_print_to_mapfile(Mapfile
* mapfile
) const
4586 { mapfile
->print_output_data(this, "** BRLT"); }
4589 // Write out the BRLT data.
4591 do_write(Output_file
*);
4593 // The reloc section.
4594 Reloc_section
* rel_
;
4595 Target_powerpc
<size
, big_endian
>* targ_
;
4598 // Make the branch lookup table section.
4600 template<int size
, bool big_endian
>
4602 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4604 if (size
== 64 && this->brlt_section_
== NULL
)
4606 Reloc_section
* brlt_rel
= NULL
;
4607 bool is_pic
= parameters
->options().output_is_position_independent();
4610 // When PIC we can't fill in .branch_lt but must initialise at
4611 // runtime via dynamic relocations.
4612 this->rela_dyn_section(layout
);
4613 brlt_rel
= new Reloc_section(false);
4614 if (this->rela_dyn_
->output_section())
4615 this->rela_dyn_
->output_section()
4616 ->add_output_section_data(brlt_rel
);
4619 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4620 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4621 this->plt_
->output_section()
4622 ->add_output_section_data(this->brlt_section_
);
4624 layout
->add_output_section_data(".branch_lt",
4625 elfcpp::SHT_PROGBITS
,
4626 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4627 this->brlt_section_
,
4633 // Write out .branch_lt when non-PIC.
4635 template<int size
, bool big_endian
>
4637 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4639 if (size
== 64 && !parameters
->options().output_is_position_independent())
4641 const section_size_type offset
= this->offset();
4642 const section_size_type oview_size
4643 = convert_to_section_size_type(this->data_size());
4644 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4646 this->targ_
->write_branch_lookup_table(oview
);
4647 of
->write_output_view(offset
, oview_size
, oview
);
4651 static inline uint32_t
4657 static inline uint32_t
4663 static inline uint32_t
4666 return hi(a
+ 0x8000);
4669 static inline uint64_t
4672 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4675 static inline uint64_t
4678 return (v
+ (1ULL << 33)) >> 34;
4684 static const unsigned char eh_frame_cie
[12];
4688 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4691 'z', 'R', 0, // Augmentation string.
4692 4, // Code alignment.
4693 0x80 - size
/ 8 , // Data alignment.
4695 1, // Augmentation size.
4696 (elfcpp::DW_EH_PE_pcrel
4697 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4698 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4701 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4702 static const unsigned char glink_eh_frame_fde_64v1
[] =
4704 0, 0, 0, 0, // Replaced with offset to .glink.
4705 0, 0, 0, 0, // Replaced with size of .glink.
4706 0, // Augmentation size.
4707 elfcpp::DW_CFA_advance_loc
+ 2,
4708 elfcpp::DW_CFA_register
, 65, 12,
4709 elfcpp::DW_CFA_advance_loc
+ 4,
4710 elfcpp::DW_CFA_restore_extended
, 65
4713 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4714 static const unsigned char glink_eh_frame_fde_64v2
[] =
4716 0, 0, 0, 0, // Replaced with offset to .glink.
4717 0, 0, 0, 0, // Replaced with size of .glink.
4718 0, // Augmentation size.
4719 elfcpp::DW_CFA_advance_loc
+ 2,
4720 elfcpp::DW_CFA_register
, 65, 0,
4721 elfcpp::DW_CFA_advance_loc
+ 2,
4722 elfcpp::DW_CFA_restore_extended
, 65
4725 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4727 0, 0, 0, 0, // Replaced with offset to .glink.
4728 0, 0, 0, 0, // Replaced with size of .glink.
4729 0, // Augmentation size.
4730 elfcpp::DW_CFA_advance_loc
+ 3,
4731 elfcpp::DW_CFA_register
, 65, 0,
4732 elfcpp::DW_CFA_advance_loc
+ 2,
4733 elfcpp::DW_CFA_restore_extended
, 65
4736 // Describe __glink_PLTresolve use of LR, 32-bit version.
4737 static const unsigned char glink_eh_frame_fde_32
[] =
4739 0, 0, 0, 0, // Replaced with offset to .glink.
4740 0, 0, 0, 0, // Replaced with size of .glink.
4741 0, // Augmentation size.
4742 elfcpp::DW_CFA_advance_loc
+ 2,
4743 elfcpp::DW_CFA_register
, 65, 0,
4744 elfcpp::DW_CFA_advance_loc
+ 4,
4745 elfcpp::DW_CFA_restore_extended
, 65
4748 static const unsigned char default_fde
[] =
4750 0, 0, 0, 0, // Replaced with offset to stubs.
4751 0, 0, 0, 0, // Replaced with size of stubs.
4752 0, // Augmentation size.
4753 elfcpp::DW_CFA_nop
, // Pad.
4758 template<bool big_endian
>
4760 write_insn(unsigned char* p
, uint32_t v
)
4762 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4766 static inline unsigned int
4769 if (!parameters
->options().user_set_plt_align())
4770 return size
== 64 ? 32 : 8;
4771 return 1 << parameters
->options().plt_align();
4774 // Stub_table holds information about plt and long branch stubs.
4775 // Stubs are built in an area following some input section determined
4776 // by group_sections(). This input section is converted to a relaxed
4777 // input section allowing it to be resized to accommodate the stubs
4779 template<int size
, bool big_endian
>
4780 class Stub_table
: public Output_relaxed_input_section
4785 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4786 : off_(off
), indx_(indx
), tocoff_(0), p9off_(0), tsize_ (0), iter_(0),
4787 toc_(0), notoc_(0), p9notoc_(0), r2save_(0), localentry0_(0)
4792 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4793 // toc stub, p9off_ is offset to p9notoc stub
4794 unsigned int tocoff_
: 8;
4795 unsigned int p9off_
: 8;
4796 // The size of the toc stub, used to locate blr on tls_get_addr stub.
4797 unsigned int tsize_
: 8;
4798 // Stub revision management
4799 unsigned int iter_
: 1;
4800 // The three types of stubs.
4801 unsigned int toc_
: 1;
4802 unsigned int notoc_
: 1;
4803 unsigned int p9notoc_
: 1;
4804 // Each with a possible variant saving r2 first
4805 unsigned int r2save_
: 1;
4806 // Handy cached info from symbol
4807 unsigned int localentry0_
: 1;
4809 struct Branch_stub_ent
4811 Branch_stub_ent(unsigned int off
)
4812 : off_(off
), tocoff_(0), p9off_(0), iter_(0), toc_(0), notoc_(0),
4813 p9notoc_(0), save_res_(0), other_(0)
4817 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4818 // toc stub, p9off_ is offset to p9notoc stub
4819 unsigned int tocoff_
: 8;
4820 unsigned int p9off_
: 8;
4821 // Stub revision management
4822 unsigned int iter_
: 1;
4823 // Four types of stubs.
4824 unsigned int toc_
: 1;
4825 unsigned int notoc_
: 1;
4826 unsigned int p9notoc_
: 1;
4827 unsigned int save_res_
: 1;
4828 // Handy cached info from symbol
4829 unsigned int other_
: 3;
4831 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4832 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4834 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4835 Output_section
* output_section
,
4836 const Output_section::Input_section
* owner
,
4838 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4840 ->section_addralign(owner
->shndx())),
4841 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4842 orig_data_size_(owner
->current_data_size()),
4843 plt_size_(0), last_plt_size_(0),
4844 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4845 need_save_res_(false), need_resize_(false), resizing_(false),
4848 this->set_output_section(output_section
);
4850 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4851 new_relaxed
.push_back(this);
4852 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4855 // Add a plt call stub.
4857 add_plt_call_entry(Address
,
4858 const Sized_relobj_file
<size
, big_endian
>*,
4865 add_plt_call_entry(Address
,
4866 const Sized_relobj_file
<size
, big_endian
>*,
4872 // Find a given plt call stub.
4874 find_plt_call_entry(const Symbol
*) const;
4877 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4878 unsigned int) const;
4881 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4887 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4892 // Add a long branch stub.
4894 add_long_branch_entry(unsigned int, Address
, Address
, unsigned int, bool);
4896 const Branch_stub_ent
*
4897 find_long_branch_entry(Address
) const;
4900 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4902 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4903 if (max_branch_offset
== 0)
4905 gold_assert(from
!= invalid_address
);
4906 Address loc
= off
+ this->stub_address();
4907 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4911 clear_stubs(bool all
)
4913 this->plt_call_stubs_
.clear();
4914 this->plt_size_
= 0;
4915 this->long_branch_stubs_
.clear();
4916 this->branch_size_
= 0;
4917 this->need_save_res_
= false;
4920 this->last_plt_size_
= 0;
4921 this->last_branch_size_
= 0;
4927 { return need_resize_
; }
4930 set_resizing(bool val
)
4932 this->resizing_
= val
;
4935 this->need_resize_
= false;
4936 this->plt_size_
= 0;
4937 this->branch_size_
= 0;
4938 this->need_save_res_
= false;
4943 set_address_and_size(const Output_section
* os
, Address off
)
4945 Address start_off
= off
;
4946 off
+= this->orig_data_size_
;
4947 Address my_size
= this->plt_size_
+ this->branch_size_
;
4948 if (this->need_save_res_
)
4949 my_size
+= this->targ_
->savres_section()->data_size();
4951 off
= align_address(off
, this->stub_align());
4952 // Include original section size and alignment padding in size
4953 my_size
+= off
- start_off
;
4954 // Ensure new size is always larger than min size
4955 // threshold. Alignment requirement is included in "my_size", so
4956 // increase "my_size" does not invalidate alignment.
4957 if (my_size
< this->min_size_threshold_
)
4958 my_size
= this->min_size_threshold_
;
4959 this->reset_address_and_file_offset();
4960 this->set_current_data_size(my_size
);
4961 this->set_address_and_file_offset(os
->address() + start_off
,
4962 os
->offset() + start_off
);
4967 stub_address() const
4969 return align_address(this->address() + this->orig_data_size_
,
4970 this->stub_align());
4976 return align_address(this->offset() + this->orig_data_size_
,
4977 this->stub_align());
4982 { return this->plt_size_
; }
4986 { return this->branch_size_
; }
4989 set_min_size_threshold(Address min_size
)
4990 { this->min_size_threshold_
= min_size
; }
4993 define_stub_syms(Symbol_table
*);
4998 Output_section
* os
= this->output_section();
4999 if (os
->addralign() < this->stub_align())
5001 os
->set_addralign(this->stub_align());
5002 // FIXME: get rid of the insane checkpointing.
5003 // We can't increase alignment of the input section to which
5004 // stubs are attached; The input section may be .init which
5005 // is pasted together with other .init sections to form a
5006 // function. Aligning might insert zero padding resulting in
5007 // sigill. However we do need to increase alignment of the
5008 // output section so that the align_address() on offset in
5009 // set_address_and_size() adds the same padding as the
5010 // align_address() on address in stub_address().
5011 // What's more, we need this alignment for the layout done in
5012 // relaxation_loop_body() so that the output section starts at
5013 // a suitably aligned address.
5014 os
->checkpoint_set_addralign(this->stub_align());
5016 if (this->last_plt_size_
!= this->plt_size_
5017 || this->last_branch_size_
!= this->branch_size_
)
5019 this->last_plt_size_
= this->plt_size_
;
5020 this->last_branch_size_
= this->branch_size_
;
5026 // Add .eh_frame info for this stub section.
5028 add_eh_frame(Layout
* layout
);
5030 // Remove .eh_frame info for this stub section.
5032 remove_eh_frame(Layout
* layout
);
5034 Target_powerpc
<size
, big_endian
>*
5040 class Plt_stub_key_hash
;
5041 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
5042 Plt_stub_key_hash
> Plt_stub_entries
;
5043 class Branch_stub_key
;
5044 class Branch_stub_key_hash
;
5045 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
5046 Branch_stub_key_hash
> Branch_stub_entries
;
5048 // Alignment of stub section.
5052 unsigned int min_align
= size
== 64 ? 32 : 16;
5053 unsigned int user_align
= 1 << parameters
->options().plt_align();
5054 return std::max(user_align
, min_align
);
5057 // Return the plt offset for the given call stub.
5059 plt_off(typename
Plt_stub_entries::const_iterator p
,
5060 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
5062 const Symbol
* gsym
= p
->first
.sym_
;
5064 return this->targ_
->plt_off(gsym
, sec
);
5067 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
5068 unsigned int local_sym_index
= p
->first
.locsym_
;
5069 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
5073 // Size of a given plt call stub.
5075 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
5078 plt_call_align(unsigned int bytes
) const
5080 unsigned int align
= param_plt_align
<size
>();
5081 return (bytes
+ align
- 1) & -align
;
5084 // Return long branch stub size.
5086 branch_stub_size(typename
Branch_stub_entries::iterator p
,
5090 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
5093 build_tls_opt_tail(unsigned char* p
);
5096 plt_error(const Plt_stub_key
& p
);
5100 do_write(Output_file
*);
5102 // Plt call stub keys.
5106 Plt_stub_key(const Symbol
* sym
)
5107 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5110 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5111 unsigned int locsym_index
)
5112 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5115 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5117 unsigned int r_type
,
5119 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5122 this->addend_
= addend
;
5123 else if (parameters
->options().output_is_position_independent()
5124 && (r_type
== elfcpp::R_PPC_PLTREL24
5125 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5127 this->addend_
= addend
;
5128 if (this->addend_
>= 32768)
5129 this->object_
= object
;
5133 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5134 unsigned int locsym_index
,
5135 unsigned int r_type
,
5137 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5140 this->addend_
= addend
;
5141 else if (parameters
->options().output_is_position_independent()
5142 && (r_type
== elfcpp::R_PPC_PLTREL24
5143 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5144 this->addend_
= addend
;
5147 bool operator==(const Plt_stub_key
& that
) const
5149 return (this->sym_
== that
.sym_
5150 && this->object_
== that
.object_
5151 && this->addend_
== that
.addend_
5152 && this->locsym_
== that
.locsym_
);
5156 const Sized_relobj_file
<size
, big_endian
>* object_
;
5157 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5158 unsigned int locsym_
;
5161 class Plt_stub_key_hash
5164 size_t operator()(const Plt_stub_key
& ent
) const
5166 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5167 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5173 // Long branch stub keys.
5174 class Branch_stub_key
5177 Branch_stub_key(Address to
)
5181 bool operator==(const Branch_stub_key
& that
) const
5183 return this->dest_
== that
.dest_
;
5189 class Branch_stub_key_hash
5192 size_t operator()(const Branch_stub_key
& key
) const
5193 { return key
.dest_
; }
5196 // In a sane world this would be a global.
5197 Target_powerpc
<size
, big_endian
>* targ_
;
5198 // Map sym/object/addend to stub offset.
5199 Plt_stub_entries plt_call_stubs_
;
5200 // Map destination address to stub offset.
5201 Branch_stub_entries long_branch_stubs_
;
5202 // size of input section
5203 section_size_type orig_data_size_
;
5205 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5206 // Some rare cases cause (PR/20529) fluctuation in stub table
5207 // size, which leads to an endless relax loop. This is to be fixed
5208 // by, after the first few iterations, allowing only increase of
5209 // stub table size. This variable sets the minimal possible size of
5210 // a stub table, it is zero for the first few iterations, then
5211 // increases monotonically.
5212 Address min_size_threshold_
;
5213 // Set if this stub group needs a copy of out-of-line register
5214 // save/restore functions.
5215 bool need_save_res_
;
5216 // Set when notoc_/r2save_ changes after sizing a stub
5218 // Set when resizing stubs
5220 // Per stub table unique identifier.
5224 // Add a plt call stub, if we do not already have one for this
5225 // sym/object/addend combo.
5227 template<int size
, bool big_endian
>
5229 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5231 const Sized_relobj_file
<size
, big_endian
>* object
,
5233 unsigned int r_type
,
5237 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5238 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5239 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5240 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5244 && this->targ_
->is_elfv2_localentry0(gsym
))
5246 p
.first
->second
.localentry0_
= 1;
5247 this->targ_
->set_has_localentry0();
5249 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5250 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5252 if (this->targ_
->power10_stubs()
5253 && (!this->targ_
->power10_stubs_auto()
5254 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5256 if (!p
.second
&& !p
.first
->second
.notoc_
)
5257 this->need_resize_
= true;
5258 p
.first
->second
.notoc_
= 1;
5262 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5263 this->need_resize_
= true;
5264 p
.first
->second
.p9notoc_
= 1;
5269 if (!p
.second
&& !p
.first
->second
.toc_
)
5270 this->need_resize_
= true;
5271 p
.first
->second
.toc_
= 1;
5272 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5274 if (!p
.second
&& !p
.first
->second
.r2save_
)
5275 this->need_resize_
= true;
5276 p
.first
->second
.r2save_
= 1;
5280 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5282 if (this->resizing_
)
5284 p
.first
->second
.iter_
= 1;
5285 p
.first
->second
.off_
= this->plt_size_
;
5287 this->plt_size_
+= this->plt_call_size(p
.first
);
5288 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5289 this->targ_
->set_has_tls_get_addr_opt();
5291 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5294 template<int size
, bool big_endian
>
5296 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5298 const Sized_relobj_file
<size
, big_endian
>* object
,
5299 unsigned int locsym_index
,
5300 unsigned int r_type
,
5304 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5305 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5306 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5307 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5311 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5313 p
.first
->second
.localentry0_
= 1;
5314 this->targ_
->set_has_localentry0();
5316 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5317 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5319 if (this->targ_
->power10_stubs()
5320 && (!this->targ_
->power10_stubs_auto()
5321 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5323 if (!p
.second
&& !p
.first
->second
.notoc_
)
5324 this->need_resize_
= true;
5325 p
.first
->second
.notoc_
= 1;
5329 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5330 this->need_resize_
= true;
5331 p
.first
->second
.p9notoc_
= 1;
5336 if (!p
.second
&& !p
.first
->second
.toc_
)
5337 this->need_resize_
= true;
5338 p
.first
->second
.toc_
= 1;
5339 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5341 if (!p
.second
&& !p
.first
->second
.r2save_
)
5342 this->need_resize_
= true;
5343 p
.first
->second
.r2save_
= 1;
5347 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5349 if (this->resizing_
)
5351 p
.first
->second
.iter_
= 1;
5352 p
.first
->second
.off_
= this->plt_size_
;
5354 this->plt_size_
+= this->plt_call_size(p
.first
);
5356 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5359 // Find a plt call stub.
5361 template<int size
, bool big_endian
>
5362 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5363 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5364 const Sized_relobj_file
<size
, big_endian
>* object
,
5366 unsigned int r_type
,
5367 Address addend
) const
5369 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5370 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5371 if (p
== this->plt_call_stubs_
.end())
5376 template<int size
, bool big_endian
>
5377 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5378 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5380 Plt_stub_key
key(gsym
);
5381 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5382 if (p
== this->plt_call_stubs_
.end())
5387 template<int size
, bool big_endian
>
5388 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5389 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5390 const Sized_relobj_file
<size
, big_endian
>* object
,
5391 unsigned int locsym_index
,
5392 unsigned int r_type
,
5393 Address addend
) const
5395 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5396 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5397 if (p
== this->plt_call_stubs_
.end())
5402 template<int size
, bool big_endian
>
5403 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5404 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5405 const Sized_relobj_file
<size
, big_endian
>* object
,
5406 unsigned int locsym_index
) const
5408 Plt_stub_key
key(object
, locsym_index
);
5409 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5410 if (p
== this->plt_call_stubs_
.end())
5415 // Add a long branch stub if we don't already have one to given
5418 template<int size
, bool big_endian
>
5420 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5421 unsigned int r_type
,
5427 Branch_stub_key
key(to
);
5428 Branch_stub_ent
ent(this->branch_size_
);
5429 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5430 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5433 if (!p
.second
&& !p
.first
->second
.save_res_
)
5434 this->need_resize_
= true;
5435 p
.first
->second
.save_res_
= true;
5438 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5439 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
))
5441 if (this->targ_
->power10_stubs()
5442 && (!this->targ_
->power10_stubs_auto()
5443 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5445 if (!p
.second
&& !p
.first
->second
.notoc_
)
5446 this->need_resize_
= true;
5447 p
.first
->second
.notoc_
= true;
5451 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5452 this->need_resize_
= true;
5453 p
.first
->second
.p9notoc_
= true;
5458 if (!p
.second
&& !p
.first
->second
.toc_
)
5459 this->need_resize_
= true;
5460 p
.first
->second
.toc_
= true;
5462 if (size
== 64 && p
.first
->second
.other_
== 0)
5463 p
.first
->second
.other_
= other
;
5464 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5466 if (this->resizing_
)
5468 p
.first
->second
.iter_
= 1;
5469 p
.first
->second
.off_
= this->branch_size_
;
5472 this->need_save_res_
= true;
5475 bool need_lt
= false;
5476 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5477 this->branch_size_
+= stub_size
;
5478 if (size
== 64 && need_lt
)
5479 this->targ_
->add_branch_lookup_table(to
);
5482 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5485 // Find long branch stub offset.
5487 template<int size
, bool big_endian
>
5488 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5489 Stub_table
<size
, big_endian
>::find_long_branch_entry(Address to
) const
5491 Branch_stub_key
key(to
);
5492 typename
Branch_stub_entries::const_iterator p
5493 = this->long_branch_stubs_
.find(key
);
5494 if (p
== this->long_branch_stubs_
.end())
5499 template<bool big_endian
>
5501 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5505 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5506 else if (delta
< 256)
5508 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5509 fde
.push_back(delta
);
5511 else if (delta
< 65536)
5513 fde
.resize(fde
.size() + 3);
5514 unsigned char *p
= &*fde
.end() - 3;
5515 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5516 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5520 fde
.resize(fde
.size() + 5);
5521 unsigned char *p
= &*fde
.end() - 5;
5522 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5523 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5527 template<typename T
>
5529 stub_sort(T s1
, T s2
)
5531 return s1
->second
.off_
< s2
->second
.off_
;
5534 // Add .eh_frame info for this stub section. Unlike other linker
5535 // generated .eh_frame this is added late in the link, because we
5536 // only want the .eh_frame info if this particular stub section is
5539 template<int size
, bool big_endian
>
5541 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5544 || !parameters
->options().ld_generated_unwind_info())
5547 // Since we add stub .eh_frame info late, it must be placed
5548 // after all other linker generated .eh_frame info so that
5549 // merge mapping need not be updated for input sections.
5550 // There is no provision to use a different CIE to that used
5552 if (!this->targ_
->has_glink())
5555 typedef typename
Plt_stub_entries::iterator plt_iter
;
5556 std::vector
<plt_iter
> calls
;
5557 if (!this->plt_call_stubs_
.empty())
5558 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5559 cs
!= this->plt_call_stubs_
.end();
5561 if (cs
->second
.p9notoc_
5563 && cs
->second
.r2save_
5564 && !cs
->second
.localentry0_
5565 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)))
5566 calls
.push_back(cs
);
5567 if (calls
.size() > 1)
5568 std::stable_sort(calls
.begin(), calls
.end(),
5569 stub_sort
<plt_iter
>);
5571 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5572 std::vector
<branch_iter
> branches
;
5573 if (!this->long_branch_stubs_
.empty()
5574 && !this->targ_
->power10_stubs())
5575 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5576 bs
!= this->long_branch_stubs_
.end();
5578 if (bs
->second
.notoc_
)
5579 branches
.push_back(bs
);
5580 if (branches
.size() > 1)
5581 std::stable_sort(branches
.begin(), branches
.end(),
5582 stub_sort
<branch_iter
>);
5584 if (calls
.empty() && branches
.empty())
5587 unsigned int last_eh_loc
= 0;
5588 // offset pcrel sdata4, size udata4, and augmentation size byte.
5589 std::vector
<unsigned char> fde(9, 0);
5591 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5593 plt_iter cs
= calls
[i
];
5594 unsigned int off
= cs
->second
.off_
;
5595 // The __tls_get_addr_opt call stub needs to describe where
5596 // it saves LR, to support exceptions that might be thrown
5597 // from __tls_get_addr, and to support asynchronous exceptions.
5598 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5602 && cs
->second
.r2save_
5603 && !cs
->second
.localentry0_
)
5605 off
+= cs
->second
.tocoff_
+ 2 * 4;
5606 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5607 fde
.resize(fde
.size() + 6);
5608 unsigned char* p
= &*fde
.end() - 6;
5609 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5611 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5612 unsigned int delta
= cs
->second
.tsize_
- 9 * 4 - 4;
5613 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5614 *p
++ = elfcpp::DW_CFA_restore_extended
;
5616 last_eh_loc
= off
+ delta
;
5617 off
= cs
->second
.off_
+ 7 * 4;
5620 // notoc stubs also should describe LR changes, to support
5621 // asynchronous exceptions.
5622 if (cs
->second
.p9notoc_
)
5624 off
+= cs
->second
.p9off_
;
5625 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5626 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5627 fde
.resize(fde
.size() + 6);
5628 unsigned char* p
= &*fde
.end() - 6;
5629 *p
++ = elfcpp::DW_CFA_register
;
5632 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5633 *p
++ = elfcpp::DW_CFA_restore_extended
;
5635 last_eh_loc
= off
+ 8;
5639 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5641 branch_iter bs
= branches
[i
];
5642 unsigned int off
= bs
->second
.off_
+ 8;
5643 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5644 fde
.resize(fde
.size() + 6);
5645 unsigned char* p
= &*fde
.end() - 6;
5646 *p
++ = elfcpp::DW_CFA_register
;
5649 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5650 *p
++ = elfcpp::DW_CFA_restore_extended
;
5652 last_eh_loc
= off
+ 8;
5655 layout
->add_eh_frame_for_plt(this,
5656 Eh_cie
<size
>::eh_frame_cie
,
5657 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5658 &*fde
.begin(), fde
.size());
5661 template<int size
, bool big_endian
>
5663 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5666 && parameters
->options().ld_generated_unwind_info()
5667 && this->targ_
->has_glink())
5668 layout
->remove_eh_frame_for_plt(this,
5669 Eh_cie
<size
>::eh_frame_cie
,
5670 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5673 // A class to handle .glink.
5675 template<int size
, bool big_endian
>
5676 class Output_data_glink
: public Output_section_data
5679 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5680 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5682 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5683 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5684 end_branch_table_(), ge_size_(0)
5688 add_eh_frame(Layout
* layout
);
5691 add_global_entry(const Symbol
*);
5694 find_global_entry(const Symbol
*) const;
5697 global_entry_align(unsigned int off
) const
5699 unsigned int align
= param_plt_align
<size
>();
5700 return (off
+ align
- 1) & -align
;
5704 global_entry_off() const
5706 return this->global_entry_align(this->end_branch_table_
);
5710 global_entry_address() const
5712 gold_assert(this->is_data_size_valid());
5713 return this->address() + this->global_entry_off();
5717 pltresolve_size() const
5721 + (this->targ_
->abiversion() < 2 ? 11 * 4
5722 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5727 // Write to a map file.
5729 do_print_to_mapfile(Mapfile
* mapfile
) const
5730 { mapfile
->print_output_data(this, _("** glink")); }
5734 set_final_data_size();
5738 do_write(Output_file
*);
5740 // Allows access to .got and .plt for do_write.
5741 Target_powerpc
<size
, big_endian
>* targ_
;
5743 // Map sym to stub offset.
5744 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5745 Global_entry_stub_entries global_entry_stubs_
;
5747 unsigned int end_branch_table_
, ge_size_
;
5750 template<int size
, bool big_endian
>
5752 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5754 if (!parameters
->options().ld_generated_unwind_info())
5759 if (this->targ_
->abiversion() < 2)
5760 layout
->add_eh_frame_for_plt(this,
5761 Eh_cie
<64>::eh_frame_cie
,
5762 sizeof (Eh_cie
<64>::eh_frame_cie
),
5763 glink_eh_frame_fde_64v1
,
5764 sizeof (glink_eh_frame_fde_64v1
));
5765 else if (this->targ_
->has_localentry0())
5766 layout
->add_eh_frame_for_plt(this,
5767 Eh_cie
<64>::eh_frame_cie
,
5768 sizeof (Eh_cie
<64>::eh_frame_cie
),
5769 glink_eh_frame_fde_64v2_localentry0
,
5770 sizeof (glink_eh_frame_fde_64v2
));
5772 layout
->add_eh_frame_for_plt(this,
5773 Eh_cie
<64>::eh_frame_cie
,
5774 sizeof (Eh_cie
<64>::eh_frame_cie
),
5775 glink_eh_frame_fde_64v2
,
5776 sizeof (glink_eh_frame_fde_64v2
));
5780 // 32-bit .glink can use the default since the CIE return
5781 // address reg, LR, is valid.
5782 layout
->add_eh_frame_for_plt(this,
5783 Eh_cie
<32>::eh_frame_cie
,
5784 sizeof (Eh_cie
<32>::eh_frame_cie
),
5786 sizeof (default_fde
));
5787 // Except where LR is used in a PIC __glink_PLTresolve.
5788 if (parameters
->options().output_is_position_independent())
5789 layout
->add_eh_frame_for_plt(this,
5790 Eh_cie
<32>::eh_frame_cie
,
5791 sizeof (Eh_cie
<32>::eh_frame_cie
),
5792 glink_eh_frame_fde_32
,
5793 sizeof (glink_eh_frame_fde_32
));
5797 template<int size
, bool big_endian
>
5799 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5801 unsigned int off
= this->global_entry_align(this->ge_size_
);
5802 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5803 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5805 this->ge_size_
= off
+ 16;
5808 template<int size
, bool big_endian
>
5809 typename Output_data_glink
<size
, big_endian
>::Address
5810 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5812 typename
Global_entry_stub_entries::const_iterator p
5813 = this->global_entry_stubs_
.find(gsym
);
5814 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5817 template<int size
, bool big_endian
>
5819 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5821 unsigned int count
= this->targ_
->plt_entry_count();
5822 section_size_type total
= 0;
5828 // space for branch table
5829 total
+= 4 * (count
- 1);
5831 total
+= -total
& 15;
5832 total
+= this->pltresolve_size();
5836 total
+= this->pltresolve_size();
5838 // space for branch table
5840 if (this->targ_
->abiversion() < 2)
5844 total
+= 4 * (count
- 0x8000);
5848 this->end_branch_table_
= total
;
5849 total
= this->global_entry_align(total
);
5850 total
+= this->ge_size_
;
5852 this->set_data_size(total
);
5855 // Define symbols on stubs, identifying the stub.
5857 template<int size
, bool big_endian
>
5859 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5861 if (!this->plt_call_stubs_
.empty())
5863 // The key for the plt call stub hash table includes addresses,
5864 // therefore traversal order depends on those addresses, which
5865 // can change between runs if gold is a PIE. Unfortunately the
5866 // output .symtab ordering depends on the order in which symbols
5867 // are added to the linker symtab. We want reproducible output
5868 // so must sort the call stub symbols.
5869 typedef typename
Plt_stub_entries::iterator plt_iter
;
5870 std::vector
<plt_iter
> sorted
;
5871 sorted
.resize(this->plt_call_stubs_
.size());
5873 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5874 cs
!= this->plt_call_stubs_
.end();
5876 sorted
[cs
->second
.indx_
] = cs
;
5878 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5880 plt_iter cs
= sorted
[i
];
5883 if (cs
->first
.addend_
!= 0)
5884 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5887 if (cs
->first
.object_
)
5889 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5890 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5891 sprintf(obj
, "%x:", ppcobj
->uniq());
5894 const char *symname
;
5895 if (cs
->first
.sym_
== NULL
)
5897 sprintf(localname
, "%x", cs
->first
.locsym_
);
5898 symname
= localname
;
5900 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5901 symname
= this->targ_
->tls_get_addr_opt()->name();
5903 symname
= cs
->first
.sym_
->name();
5904 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5905 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5907 = this->stub_address() - this->address() + cs
->second
.off_
;
5908 unsigned int stub_size
= this->plt_call_size(cs
);
5909 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5913 typedef typename
Branch_stub_entries::iterator branch_iter
;
5914 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5915 bs
!= this->long_branch_stubs_
.end();
5918 if (bs
->second
.save_res_
)
5921 char* name
= new char[8 + 13 + 16 + 1];
5922 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5923 static_cast<unsigned long long>(bs
->first
.dest_
));
5924 Address value
= (this->stub_address() - this->address()
5925 + this->plt_size_
+ bs
->second
.off_
);
5926 bool need_lt
= false;
5927 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5928 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5932 // Emit the start of a __tls_get_addr_opt plt call stub.
5934 template<int size
, bool big_endian
>
5936 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5939 unsigned char* p
= *pp
;
5942 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5944 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5946 write_insn
<big_endian
>(p
, mr_0_3
);
5948 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5950 write_insn
<big_endian
>(p
, add_3_12_13
);
5952 write_insn
<big_endian
>(p
, beqlr
);
5954 write_insn
<big_endian
>(p
, mr_3_0
);
5958 write_insn
<big_endian
>(p
, mflr_11
);
5960 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5966 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5968 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5970 write_insn
<big_endian
>(p
, mr_0_3
);
5972 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5974 write_insn
<big_endian
>(p
, add_3_12_2
);
5976 write_insn
<big_endian
>(p
, beqlr
);
5978 write_insn
<big_endian
>(p
, mr_3_0
);
5980 write_insn
<big_endian
>(p
, nop
);
5986 // Emit the tail of a __tls_get_addr_opt plt call stub.
5988 template<int size
, bool big_endian
>
5990 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5992 write_insn
<big_endian
>(p
, bctrl
);
5994 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5996 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5998 write_insn
<big_endian
>(p
, mtlr_11
);
6000 write_insn
<big_endian
>(p
, blr
);
6003 // Emit pc-relative plt call stub code.
6005 template<bool big_endian
>
6006 static unsigned char*
6007 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
6010 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6015 write_insn
<big_endian
>(p
, nop
);
6023 write_insn
<big_endian
>(p
, insn
>> 32);
6025 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6027 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6030 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
6034 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6037 insn
= paddi_12_pc
| d34(off
);
6038 write_insn
<big_endian
>(p
, insn
>> 32);
6040 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6044 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6048 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6050 write_insn
<big_endian
>(p
, add_12_11_12
);
6055 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
6057 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
6061 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6064 insn
= paddi_12_pc
| d34(off
);
6065 write_insn
<big_endian
>(p
, insn
>> 32);
6067 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6071 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6075 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6077 write_insn
<big_endian
>(p
, add_12_11_12
);
6083 // Gets the address of a label (1:) in r11 and builds an offset in r12,
6084 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
6089 // lis %r12,xxx-1b@highest
6090 // ori %r12,%r12,xxx-1b@higher
6091 // sldi %r12,%r12,32
6092 // oris %r12,%r12,xxx-1b@high
6093 // ori %r12,%r12,xxx-1b@l
6094 // add/ldx %r12,%r11,%r12
6096 template<bool big_endian
>
6097 static unsigned char*
6098 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
6100 write_insn
<big_endian
>(p
, mflr_12
);
6102 write_insn
<big_endian
>(p
, bcl_20_31
);
6104 write_insn
<big_endian
>(p
, mflr_11
);
6106 write_insn
<big_endian
>(p
, mtlr_12
);
6108 if (off
+ 0x8000 < 0x10000)
6111 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6113 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
6115 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6117 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
6120 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6122 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
6126 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
6128 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
6133 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
6135 if (((off
>> 32) & 0xffff) != 0)
6137 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
6141 if (((off
>> 32) & 0xffffffffULL
) != 0)
6143 write_insn
<big_endian
>(p
, sldi_12_12_32
);
6148 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
6153 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6157 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6159 write_insn
<big_endian
>(p
, add_12_11_12
);
6165 // Size of a given plt call stub.
6167 template<int size
, bool big_endian
>
6169 Stub_table
<size
, big_endian
>::plt_call_size(
6170 typename
Plt_stub_entries::iterator p
) const
6174 unsigned int bytes
= 4 * 4;
6175 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6177 return this->plt_call_align(bytes
);
6180 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6181 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6182 plt_addr
+= plt
->address();
6183 if (this->targ_
->power10_stubs()
6184 && this->targ_
->power10_stubs_auto())
6186 unsigned int bytes
= 0;
6187 if (p
->second
.notoc_
)
6189 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6191 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6192 uint64_t odd
= from
& 4;
6193 uint64_t off
= plt_addr
- from
;
6194 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6195 bytes
+= odd
+ 4 * 4;
6196 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6200 bytes
= this->plt_call_align(bytes
);
6204 p
->second
.tocoff_
= bytes
;
6205 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6208 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6209 bytes
+= 2 * 4 + 4 * 4;
6211 if (p
->second
.r2save_
)
6213 uint64_t got_addr
= this->targ_
->toc_pointer();
6214 uint64_t off
= plt_addr
- got_addr
;
6215 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6216 p
->second
.tsize_
= bytes
- p
->second
.tocoff_
;
6217 bytes
= this->plt_call_align(bytes
);
6219 if (p
->second
.p9notoc_
)
6221 p
->second
.p9off_
= bytes
;
6222 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6224 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6225 uint64_t off
= plt_addr
- from
;
6226 if (off
+ 0x8000 < 0x10000)
6228 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6233 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6234 && ((off
>> 32) & 0xffff) != 0)
6236 if (((off
>> 32) & 0xffffffffULL
) != 0)
6243 bytes
= this->plt_call_align(bytes
);
6249 unsigned int bytes
= 0;
6250 unsigned int tail
= 0;
6251 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6254 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6261 if (p
->second
.r2save_
)
6264 if (this->targ_
->power10_stubs())
6266 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6267 uint64_t odd
= from
& 4;
6268 uint64_t off
= plt_addr
- from
;
6269 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6270 bytes
+= odd
+ 4 * 4;
6271 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6275 return this->plt_call_align(bytes
+ tail
);
6278 if (p
->second
.p9notoc_
)
6280 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6281 uint64_t off
= plt_addr
- from
;
6282 if (off
+ 0x8000 < 0x10000)
6284 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6289 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6290 && ((off
>> 32) & 0xffff) != 0)
6292 if (((off
>> 32) & 0xffffffffULL
) != 0)
6299 return this->plt_call_align(bytes
+ tail
);
6302 uint64_t got_addr
= this->targ_
->toc_pointer();
6303 uint64_t off
= plt_addr
- got_addr
;
6304 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6305 if (this->targ_
->abiversion() < 2)
6307 bool static_chain
= parameters
->options().plt_static_chain();
6308 bool thread_safe
= this->targ_
->plt_thread_safe();
6312 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6314 return this->plt_call_align(bytes
+ tail
);
6318 // Return long branch stub size.
6320 template<int size
, bool big_endian
>
6322 Stub_table
<size
, big_endian
>::branch_stub_size(
6323 typename
Branch_stub_entries::iterator p
,
6326 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6329 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6331 if (parameters
->options().output_is_position_independent())
6336 uint64_t off
= p
->first
.dest_
- loc
;
6337 unsigned int bytes
= 0;
6338 if (p
->second
.notoc_
)
6340 if (this->targ_
->power10_stubs())
6342 Address odd
= loc
& 4;
6343 if (off
+ (1 << 25) < 2 << 25)
6345 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6347 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6351 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6353 p
->second
.tocoff_
= bytes
;
6358 if (off
+ 0x8000 < 0x10000)
6360 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6362 if (off
+ 24 + (1 << 25) < 2 << 25)
6368 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6369 && ((off
>> 32) & 0xffff) != 0)
6371 if (((off
>> 32) & 0xffffffffULL
) != 0)
6381 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6382 if (off
+ (1 << 25) < 2 << 25)
6384 if (!this->targ_
->power10_stubs()
6385 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6390 template<int size
, bool big_endian
>
6392 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6395 gold_error(_("linkage table error against `%s'"),
6396 p
.sym_
->demangled_name().c_str());
6398 gold_error(_("linkage table error against `%s:[local %u]'"),
6399 p
.object_
->name().c_str(),
6403 // Write out plt and long branch stub code.
6405 template<int size
, bool big_endian
>
6407 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6409 if (this->plt_call_stubs_
.empty()
6410 && this->long_branch_stubs_
.empty())
6413 const section_size_type start_off
= this->offset();
6414 const section_size_type off
= this->stub_offset();
6415 const section_size_type oview_size
=
6416 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6417 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6421 && this->targ_
->power10_stubs())
6423 if (!this->plt_call_stubs_
.empty())
6425 // Write out plt call stubs.
6426 typename
Plt_stub_entries::const_iterator cs
;
6427 for (cs
= this->plt_call_stubs_
.begin();
6428 cs
!= this->plt_call_stubs_
.end();
6431 p
= oview
+ cs
->second
.off_
;
6432 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6433 Address pltoff
= this->plt_off(cs
, &plt
);
6434 Address plt_addr
= pltoff
+ plt
->address();
6435 if (this->targ_
->power10_stubs_auto())
6437 if (cs
->second
.notoc_
)
6439 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6440 this->build_tls_opt_head(&p
, false);
6441 Address from
= this->stub_address() + (p
- oview
);
6442 Address delta
= plt_addr
- from
;
6443 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6445 write_insn
<big_endian
>(p
, mtctr_12
);
6447 write_insn
<big_endian
>(p
, bctr
);
6449 p
= oview
+ this->plt_call_align(p
- oview
);
6451 if (cs
->second
.toc_
)
6453 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6456 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6457 this->build_tls_opt_head(&p
, save_lr
);
6459 Address got_addr
= this->targ_
->toc_pointer();
6460 Address off
= plt_addr
- got_addr
;
6462 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6463 this->plt_error(cs
->first
);
6465 if (cs
->second
.r2save_
)
6467 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6472 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6474 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6479 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6482 write_insn
<big_endian
>(p
, mtctr_12
);
6484 if (cs
->second
.r2save_
6485 && !cs
->second
.localentry0_
6486 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6487 this->build_tls_opt_tail(p
);
6489 write_insn
<big_endian
>(p
, bctr
);
6491 if (cs
->second
.p9notoc_
)
6493 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6494 this->build_tls_opt_head(&p
, false);
6495 Address from
= this->stub_address() + (p
- oview
);
6496 Address delta
= plt_addr
- from
;
6497 p
= build_notoc_offset
<big_endian
>(p
, delta
, true);
6498 write_insn
<big_endian
>(p
, mtctr_12
);
6500 write_insn
<big_endian
>(p
, bctr
);
6502 p
= oview
+ this->plt_call_align(p
- oview
);
6507 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6510 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6511 this->build_tls_opt_head(&p
, save_lr
);
6513 if (cs
->second
.r2save_
)
6515 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6518 Address from
= this->stub_address() + (p
- oview
);
6519 Address delta
= plt_addr
- from
;
6520 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6521 write_insn
<big_endian
>(p
, mtctr_12
);
6523 if (cs
->second
.r2save_
6524 && !cs
->second
.localentry0_
6525 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6526 this->build_tls_opt_tail(p
);
6528 write_insn
<big_endian
>(p
, bctr
);
6533 // Write out long branch stubs.
6534 typename
Branch_stub_entries::const_iterator bs
;
6535 for (bs
= this->long_branch_stubs_
.begin();
6536 bs
!= this->long_branch_stubs_
.end();
6539 if (bs
->second
.save_res_
)
6541 Address off
= this->plt_size_
+ bs
->second
.off_
;
6543 Address loc
= this->stub_address() + off
;
6544 Address delta
= bs
->first
.dest_
- loc
;
6545 if (this->targ_
->power10_stubs_auto())
6547 if (bs
->second
.notoc_
)
6549 unsigned char* startp
= p
;
6550 p
= build_power10_offset
<big_endian
>(p
, delta
,
6552 delta
-= p
- startp
;
6554 if (delta
+ (1 << 25) < 2 << 25)
6555 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6558 write_insn
<big_endian
>(p
, mtctr_12
);
6560 write_insn
<big_endian
>(p
, bctr
);
6563 delta
-= p
- startp
;
6565 if (bs
->second
.toc_
)
6567 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6568 if (delta
+ (1 << 25) >= 2 << 25)
6571 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6572 gold_assert(brlt_addr
!= invalid_address
);
6573 brlt_addr
+= this->targ_
->brlt_section()->address();
6574 Address got_addr
= this->targ_
->toc_pointer();
6575 Address brltoff
= brlt_addr
- got_addr
;
6576 if (ha(brltoff
) == 0)
6578 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6583 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6585 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6589 if (delta
+ (1 << 25) < 2 << 25)
6590 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6593 write_insn
<big_endian
>(p
, mtctr_12
);
6595 write_insn
<big_endian
>(p
, bctr
);
6598 if (bs
->second
.p9notoc_
)
6600 unsigned char* startp
= p
;
6601 p
= build_notoc_offset
<big_endian
>(p
, delta
, false);
6602 delta
-= p
- startp
;
6604 if (delta
+ (1 << 25) < 2 << 25)
6605 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6608 write_insn
<big_endian
>(p
, mtctr_12
);
6610 write_insn
<big_endian
>(p
, bctr
);
6613 delta
-= p
- startp
;
6618 if (!bs
->second
.notoc_
)
6619 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6620 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6622 unsigned char* startp
= p
;
6623 p
= build_power10_offset
<big_endian
>(p
, delta
,
6625 delta
-= p
- startp
;
6627 if (delta
+ (1 << 25) < 2 << 25)
6628 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6631 write_insn
<big_endian
>(p
, mtctr_12
);
6633 write_insn
<big_endian
>(p
, bctr
);
6638 else if (size
== 64)
6641 if (!this->plt_call_stubs_
.empty()
6642 && this->targ_
->abiversion() >= 2)
6644 // Write out plt call stubs for ELFv2.
6645 typename
Plt_stub_entries::const_iterator cs
;
6646 for (cs
= this->plt_call_stubs_
.begin();
6647 cs
!= this->plt_call_stubs_
.end();
6650 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6651 Address pltoff
= this->plt_off(cs
, &plt
);
6652 Address plt_addr
= pltoff
+ plt
->address();
6654 p
= oview
+ cs
->second
.off_
;
6655 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6657 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6658 this->build_tls_opt_head(&p
, save_lr
);
6660 if (cs
->second
.r2save_
)
6662 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6665 if (cs
->second
.p9notoc_
)
6667 Address from
= this->stub_address() + (p
- oview
) + 8;
6668 Address off
= plt_addr
- from
;
6669 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6673 Address got_addr
= this->targ_
->toc_pointer();
6674 Address off
= plt_addr
- got_addr
;
6676 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6677 this->plt_error(cs
->first
);
6681 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6683 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6688 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6692 write_insn
<big_endian
>(p
, mtctr_12
);
6694 if (cs
->second
.r2save_
6695 && !cs
->second
.localentry0_
6696 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6697 this->build_tls_opt_tail(p
);
6699 write_insn
<big_endian
>(p
, bctr
);
6702 else if (!this->plt_call_stubs_
.empty())
6704 // Write out plt call stubs for ELFv1.
6705 typename
Plt_stub_entries::const_iterator cs
;
6706 for (cs
= this->plt_call_stubs_
.begin();
6707 cs
!= this->plt_call_stubs_
.end();
6710 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6711 Address pltoff
= this->plt_off(cs
, &plt
);
6712 Address plt_addr
= pltoff
+ plt
->address();
6713 Address got_addr
= this->targ_
->toc_pointer();
6714 Address off
= plt_addr
- got_addr
;
6716 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6717 || cs
->second
.notoc_
)
6718 this->plt_error(cs
->first
);
6720 bool static_chain
= parameters
->options().plt_static_chain();
6721 bool thread_safe
= this->targ_
->plt_thread_safe();
6722 bool use_fake_dep
= false;
6723 Address cmp_branch_off
= 0;
6726 unsigned int pltindex
6727 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6728 / this->targ_
->plt_entry_size());
6730 = (this->targ_
->glink_section()->pltresolve_size()
6732 if (pltindex
> 32768)
6733 glinkoff
+= (pltindex
- 32768) * 4;
6735 = this->targ_
->glink_section()->address() + glinkoff
;
6737 = (this->stub_address() + cs
->second
.off_
+ 20
6738 + 4 * cs
->second
.r2save_
6739 + 4 * (ha(off
) != 0)
6740 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6741 + 4 * static_chain
);
6742 cmp_branch_off
= to
- from
;
6743 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6746 p
= oview
+ cs
->second
.off_
;
6747 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6749 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6750 this->build_tls_opt_head(&p
, save_lr
);
6751 use_fake_dep
= thread_safe
;
6753 if (cs
->second
.r2save_
)
6755 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6760 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6762 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6764 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6766 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6770 write_insn
<big_endian
>(p
, mtctr_12
);
6774 write_insn
<big_endian
>(p
, xor_2_12_12
);
6776 write_insn
<big_endian
>(p
, add_11_11_2
);
6779 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6783 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6789 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6791 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6793 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6797 write_insn
<big_endian
>(p
, mtctr_12
);
6801 write_insn
<big_endian
>(p
, xor_11_12_12
);
6803 write_insn
<big_endian
>(p
, add_2_2_11
);
6808 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6811 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6814 if (cs
->second
.r2save_
6815 && !cs
->second
.localentry0_
6816 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6817 this->build_tls_opt_tail(p
);
6818 else if (thread_safe
&& !use_fake_dep
)
6820 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6822 write_insn
<big_endian
>(p
, bnectr_p4
);
6824 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6827 write_insn
<big_endian
>(p
, bctr
);
6831 // Write out long branch stubs.
6832 typename
Branch_stub_entries::const_iterator bs
;
6833 for (bs
= this->long_branch_stubs_
.begin();
6834 bs
!= this->long_branch_stubs_
.end();
6837 if (bs
->second
.save_res_
)
6839 Address off
= this->plt_size_
+ bs
->second
.off_
;
6841 Address loc
= this->stub_address() + off
;
6842 Address delta
= bs
->first
.dest_
- loc
;
6843 if (!bs
->second
.p9notoc_
)
6844 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6845 if (bs
->second
.p9notoc_
)
6847 unsigned char* startp
= p
;
6848 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6849 delta
-= p
- startp
;
6851 else if (delta
+ (1 << 25) >= 2 << 25)
6854 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6855 gold_assert(brlt_addr
!= invalid_address
);
6856 brlt_addr
+= this->targ_
->brlt_section()->address();
6857 Address got_addr
= this->targ_
->toc_pointer();
6858 Address brltoff
= brlt_addr
- got_addr
;
6859 if (ha(brltoff
) == 0)
6861 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6866 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6868 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6872 if (delta
+ (1 << 25) < 2 << 25)
6873 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6876 write_insn
<big_endian
>(p
, mtctr_12
);
6878 write_insn
<big_endian
>(p
, bctr
);
6884 if (!this->plt_call_stubs_
.empty())
6886 // The address of _GLOBAL_OFFSET_TABLE_.
6887 Address g_o_t
= invalid_address
;
6889 // Write out plt call stubs.
6890 typename
Plt_stub_entries::const_iterator cs
;
6891 for (cs
= this->plt_call_stubs_
.begin();
6892 cs
!= this->plt_call_stubs_
.end();
6895 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6896 Address plt_addr
= this->plt_off(cs
, &plt
);
6897 plt_addr
+= plt
->address();
6899 p
= oview
+ cs
->second
.off_
;
6900 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6901 this->build_tls_opt_head(&p
, false);
6902 if (parameters
->options().output_is_position_independent())
6905 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6906 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6907 (cs
->first
.object_
));
6908 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6910 unsigned int got2
= ppcobj
->got2_shndx();
6911 got_addr
= ppcobj
->get_output_section_offset(got2
);
6912 gold_assert(got_addr
!= invalid_address
);
6913 got_addr
+= (ppcobj
->output_section(got2
)->address()
6914 + cs
->first
.addend_
);
6918 if (g_o_t
== invalid_address
)
6919 g_o_t
= this->targ_
->toc_pointer();
6923 Address off
= plt_addr
- got_addr
;
6925 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6928 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6930 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6935 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6937 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6940 write_insn
<big_endian
>(p
, mtctr_11
);
6942 write_insn
<big_endian
>(p
, bctr
);
6946 // Write out long branch stubs.
6947 typename
Branch_stub_entries::const_iterator bs
;
6948 for (bs
= this->long_branch_stubs_
.begin();
6949 bs
!= this->long_branch_stubs_
.end();
6952 if (bs
->second
.save_res_
)
6954 Address off
= this->plt_size_
+ bs
->second
.off_
;
6956 Address loc
= this->stub_address() + off
;
6957 Address delta
= bs
->first
.dest_
- loc
;
6958 if (delta
+ (1 << 25) < 2 << 25)
6959 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6960 else if (!parameters
->options().output_is_position_independent())
6962 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6964 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6969 write_insn
<big_endian
>(p
, mflr_0
);
6971 write_insn
<big_endian
>(p
, bcl_20_31
);
6973 write_insn
<big_endian
>(p
, mflr_12
);
6975 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6977 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6979 write_insn
<big_endian
>(p
, mtlr_0
);
6982 write_insn
<big_endian
>(p
, mtctr_12
);
6984 write_insn
<big_endian
>(p
, bctr
);
6987 if (this->need_save_res_
)
6989 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6990 memcpy (p
, this->targ_
->savres_section()->contents(),
6991 this->targ_
->savres_section()->data_size());
6995 // Write out .glink.
6997 template<int size
, bool big_endian
>
6999 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
7001 const section_size_type off
= this->offset();
7002 const section_size_type oview_size
=
7003 convert_to_section_size_type(this->data_size());
7004 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7007 // The base address of the .plt section.
7008 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
7009 Address plt_base
= this->targ_
->plt_section()->address();
7013 if (this->end_branch_table_
!= 0)
7015 // Write pltresolve stub.
7017 Address after_bcl
= this->address() + 16;
7018 Address pltoff
= plt_base
- after_bcl
;
7020 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
7022 if (this->targ_
->abiversion() < 2)
7024 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
7025 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7026 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7027 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
7028 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
7029 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
7030 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7031 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
7032 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7033 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
7037 if (this->targ_
->has_localentry0())
7039 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
7041 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
7042 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7043 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7044 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
7045 if (this->targ_
->has_localentry0())
7047 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
7051 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
7053 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
7054 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
7055 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
7056 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7057 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
7058 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7059 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
7061 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
7062 gold_assert(p
== oview
+ this->pltresolve_size());
7064 // Write lazy link call stubs.
7066 while (p
< oview
+ this->end_branch_table_
)
7068 if (this->targ_
->abiversion() < 2)
7072 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
7076 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
7077 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
7080 uint32_t branch_off
= 8 - (p
- oview
);
7081 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
7086 Address plt_base
= this->targ_
->plt_section()->address();
7087 Address iplt_base
= invalid_address
;
7088 unsigned int global_entry_off
= this->global_entry_off();
7089 Address global_entry_base
= this->address() + global_entry_off
;
7090 typename
Global_entry_stub_entries::const_iterator ge
;
7091 for (ge
= this->global_entry_stubs_
.begin();
7092 ge
!= this->global_entry_stubs_
.end();
7095 p
= oview
+ global_entry_off
+ ge
->second
;
7096 Address plt_addr
= ge
->first
->plt_offset();
7097 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
7098 && ge
->first
->can_use_relative_reloc(false))
7100 if (iplt_base
== invalid_address
)
7101 iplt_base
= this->targ_
->iplt_section()->address();
7102 plt_addr
+= iplt_base
;
7105 plt_addr
+= plt_base
;
7106 Address my_addr
= global_entry_base
+ ge
->second
;
7107 Address off
= plt_addr
- my_addr
;
7109 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
7110 gold_error(_("linkage table error against `%s'"),
7111 ge
->first
->demangled_name().c_str());
7113 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
7114 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
7115 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7116 write_insn
<big_endian
>(p
, bctr
);
7121 // The address of _GLOBAL_OFFSET_TABLE_.
7122 Address g_o_t
= this->targ_
->toc_pointer();
7124 // Write out pltresolve branch table.
7126 unsigned int the_end
= oview_size
- this->pltresolve_size();
7127 unsigned char* end_p
= oview
+ the_end
;
7128 while (p
< end_p
- 8 * 4)
7129 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
7131 write_insn
<big_endian
>(p
, nop
), p
+= 4;
7133 // Write out pltresolve call stub.
7134 end_p
= oview
+ oview_size
;
7135 if (parameters
->options().output_is_position_independent())
7137 Address res0_off
= 0;
7138 Address after_bcl_off
= the_end
+ 12;
7139 Address bcl_res0
= after_bcl_off
- res0_off
;
7141 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
7143 write_insn
<big_endian
>(p
, mflr_0
);
7145 write_insn
<big_endian
>(p
, bcl_20_31
);
7147 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
7149 write_insn
<big_endian
>(p
, mflr_12
);
7151 write_insn
<big_endian
>(p
, mtlr_0
);
7153 write_insn
<big_endian
>(p
, sub_11_11_12
);
7156 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
7158 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
7160 if (ha(got_bcl
) == ha(got_bcl
+ 4))
7162 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
7164 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
7168 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
7170 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7173 write_insn
<big_endian
>(p
, mtctr_0
);
7175 write_insn
<big_endian
>(p
, add_0_11_11
);
7177 write_insn
<big_endian
>(p
, add_11_0_11
);
7181 Address res0
= this->address();
7183 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7185 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7187 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7188 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7190 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7192 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7194 write_insn
<big_endian
>(p
, mtctr_0
);
7196 write_insn
<big_endian
>(p
, add_0_11_11
);
7198 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7199 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7201 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7203 write_insn
<big_endian
>(p
, add_11_0_11
);
7206 write_insn
<big_endian
>(p
, bctr
);
7210 write_insn
<big_endian
>(p
, nop
);
7215 of
->write_output_view(off
, oview_size
, oview
);
7219 // A class to handle linker generated save/restore functions.
7221 template<int size
, bool big_endian
>
7222 class Output_data_save_res
: public Output_section_data_build
7225 Output_data_save_res(Symbol_table
* symtab
);
7227 const unsigned char*
7234 // Write to a map file.
7236 do_print_to_mapfile(Mapfile
* mapfile
) const
7237 { mapfile
->print_output_data(this, _("** save/restore")); }
7240 do_write(Output_file
*);
7243 // The maximum size of save/restore contents.
7244 static const unsigned int savres_max
= 218*4;
7247 savres_define(Symbol_table
* symtab
,
7249 unsigned int lo
, unsigned int hi
,
7250 unsigned char* write_ent(unsigned char*, int),
7251 unsigned char* write_tail(unsigned char*, int));
7253 unsigned char *contents_
;
7256 template<bool big_endian
>
7257 static unsigned char*
7258 savegpr0(unsigned char* p
, int r
)
7260 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7261 write_insn
<big_endian
>(p
, insn
);
7265 template<bool big_endian
>
7266 static unsigned char*
7267 savegpr0_tail(unsigned char* p
, int r
)
7269 p
= savegpr0
<big_endian
>(p
, r
);
7270 uint32_t insn
= std_0_1
+ 16;
7271 write_insn
<big_endian
>(p
, insn
);
7273 write_insn
<big_endian
>(p
, blr
);
7277 template<bool big_endian
>
7278 static unsigned char*
7279 restgpr0(unsigned char* p
, int r
)
7281 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7282 write_insn
<big_endian
>(p
, insn
);
7286 template<bool big_endian
>
7287 static unsigned char*
7288 restgpr0_tail(unsigned char* p
, int r
)
7290 uint32_t insn
= ld_0_1
+ 16;
7291 write_insn
<big_endian
>(p
, insn
);
7293 p
= restgpr0
<big_endian
>(p
, r
);
7294 write_insn
<big_endian
>(p
, mtlr_0
);
7298 p
= restgpr0
<big_endian
>(p
, 30);
7299 p
= restgpr0
<big_endian
>(p
, 31);
7301 write_insn
<big_endian
>(p
, blr
);
7305 template<bool big_endian
>
7306 static unsigned char*
7307 savegpr1(unsigned char* p
, int r
)
7309 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7310 write_insn
<big_endian
>(p
, insn
);
7314 template<bool big_endian
>
7315 static unsigned char*
7316 savegpr1_tail(unsigned char* p
, int r
)
7318 p
= savegpr1
<big_endian
>(p
, r
);
7319 write_insn
<big_endian
>(p
, blr
);
7323 template<bool big_endian
>
7324 static unsigned char*
7325 restgpr1(unsigned char* p
, int r
)
7327 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7328 write_insn
<big_endian
>(p
, insn
);
7332 template<bool big_endian
>
7333 static unsigned char*
7334 restgpr1_tail(unsigned char* p
, int r
)
7336 p
= restgpr1
<big_endian
>(p
, r
);
7337 write_insn
<big_endian
>(p
, blr
);
7341 template<bool big_endian
>
7342 static unsigned char*
7343 savefpr(unsigned char* p
, int r
)
7345 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7346 write_insn
<big_endian
>(p
, insn
);
7350 template<bool big_endian
>
7351 static unsigned char*
7352 savefpr0_tail(unsigned char* p
, int r
)
7354 p
= savefpr
<big_endian
>(p
, r
);
7355 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7357 write_insn
<big_endian
>(p
, blr
);
7361 template<bool big_endian
>
7362 static unsigned char*
7363 restfpr(unsigned char* p
, int r
)
7365 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7366 write_insn
<big_endian
>(p
, insn
);
7370 template<bool big_endian
>
7371 static unsigned char*
7372 restfpr0_tail(unsigned char* p
, int r
)
7374 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7376 p
= restfpr
<big_endian
>(p
, r
);
7377 write_insn
<big_endian
>(p
, mtlr_0
);
7381 p
= restfpr
<big_endian
>(p
, 30);
7382 p
= restfpr
<big_endian
>(p
, 31);
7384 write_insn
<big_endian
>(p
, blr
);
7388 template<bool big_endian
>
7389 static unsigned char*
7390 savefpr1_tail(unsigned char* p
, int r
)
7392 p
= savefpr
<big_endian
>(p
, r
);
7393 write_insn
<big_endian
>(p
, blr
);
7397 template<bool big_endian
>
7398 static unsigned char*
7399 restfpr1_tail(unsigned char* p
, int r
)
7401 p
= restfpr
<big_endian
>(p
, r
);
7402 write_insn
<big_endian
>(p
, blr
);
7406 template<bool big_endian
>
7407 static unsigned char*
7408 savevr(unsigned char* p
, int r
)
7410 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7411 write_insn
<big_endian
>(p
, insn
);
7413 insn
= stvx_0_12_0
+ (r
<< 21);
7414 write_insn
<big_endian
>(p
, insn
);
7418 template<bool big_endian
>
7419 static unsigned char*
7420 savevr_tail(unsigned char* p
, int r
)
7422 p
= savevr
<big_endian
>(p
, r
);
7423 write_insn
<big_endian
>(p
, blr
);
7427 template<bool big_endian
>
7428 static unsigned char*
7429 restvr(unsigned char* p
, int r
)
7431 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7432 write_insn
<big_endian
>(p
, insn
);
7434 insn
= lvx_0_12_0
+ (r
<< 21);
7435 write_insn
<big_endian
>(p
, insn
);
7439 template<bool big_endian
>
7440 static unsigned char*
7441 restvr_tail(unsigned char* p
, int r
)
7443 p
= restvr
<big_endian
>(p
, r
);
7444 write_insn
<big_endian
>(p
, blr
);
7449 template<int size
, bool big_endian
>
7450 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7451 Symbol_table
* symtab
)
7452 : Output_section_data_build(4),
7455 this->savres_define(symtab
,
7456 "_savegpr0_", 14, 31,
7457 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7458 this->savres_define(symtab
,
7459 "_restgpr0_", 14, 29,
7460 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7461 this->savres_define(symtab
,
7462 "_restgpr0_", 30, 31,
7463 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7464 this->savres_define(symtab
,
7465 "_savegpr1_", 14, 31,
7466 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7467 this->savres_define(symtab
,
7468 "_restgpr1_", 14, 31,
7469 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7470 this->savres_define(symtab
,
7471 "_savefpr_", 14, 31,
7472 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7473 this->savres_define(symtab
,
7474 "_restfpr_", 14, 29,
7475 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7476 this->savres_define(symtab
,
7477 "_restfpr_", 30, 31,
7478 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7479 this->savres_define(symtab
,
7481 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7482 this->savres_define(symtab
,
7484 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7485 this->savres_define(symtab
,
7487 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7488 this->savres_define(symtab
,
7490 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7493 template<int size
, bool big_endian
>
7495 Output_data_save_res
<size
, big_endian
>::savres_define(
7496 Symbol_table
* symtab
,
7498 unsigned int lo
, unsigned int hi
,
7499 unsigned char* write_ent(unsigned char*, int),
7500 unsigned char* write_tail(unsigned char*, int))
7502 size_t len
= strlen(name
);
7503 bool writing
= false;
7506 memcpy(sym
, name
, len
);
7509 for (unsigned int i
= lo
; i
<= hi
; i
++)
7511 sym
[len
+ 0] = i
/ 10 + '0';
7512 sym
[len
+ 1] = i
% 10 + '0';
7513 Symbol
* gsym
= symtab
->lookup(sym
);
7514 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7515 writing
= writing
|| refd
;
7518 if (this->contents_
== NULL
)
7519 this->contents_
= new unsigned char[this->savres_max
];
7521 section_size_type value
= this->current_data_size();
7522 unsigned char* p
= this->contents_
+ value
;
7524 p
= write_ent(p
, i
);
7526 p
= write_tail(p
, i
);
7527 section_size_type cur_size
= p
- this->contents_
;
7528 this->set_current_data_size(cur_size
);
7530 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7531 this, value
, cur_size
- value
,
7532 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7533 elfcpp::STV_HIDDEN
, 0, false, false);
7538 // Write out save/restore.
7540 template<int size
, bool big_endian
>
7542 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7544 const section_size_type off
= this->offset();
7545 const section_size_type oview_size
=
7546 convert_to_section_size_type(this->data_size());
7547 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7548 memcpy(oview
, this->contents_
, oview_size
);
7549 of
->write_output_view(off
, oview_size
, oview
);
7553 // Create the glink section.
7555 template<int size
, bool big_endian
>
7557 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7559 if (this->glink_
== NULL
)
7561 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7562 this->glink_
->add_eh_frame(layout
);
7563 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7564 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7565 this->glink_
, ORDER_TEXT
, false);
7569 // Create a PLT entry for a global symbol.
7571 template<int size
, bool big_endian
>
7573 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7577 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7578 && gsym
->can_use_relative_reloc(false))
7580 if (this->iplt_
== NULL
)
7581 this->make_iplt_section(symtab
, layout
);
7582 this->iplt_
->add_ifunc_entry(gsym
);
7586 if (this->plt_
== NULL
)
7587 this->make_plt_section(symtab
, layout
);
7588 this->plt_
->add_entry(gsym
);
7592 // Make a PLT entry for a local symbol.
7594 template<int size
, bool big_endian
>
7596 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7597 Symbol_table
* symtab
,
7599 Sized_relobj_file
<size
, big_endian
>* relobj
,
7602 if (this->lplt_
== NULL
)
7603 this->make_lplt_section(symtab
, layout
);
7604 this->lplt_
->add_local_entry(relobj
, r_sym
);
7607 template<int size
, bool big_endian
>
7609 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(Symbol_table
* symtab
,
7613 if (this->lplt_
== NULL
)
7614 this->make_lplt_section(symtab
, layout
);
7615 this->lplt_
->add_entry(gsym
, true);
7618 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7620 template<int size
, bool big_endian
>
7622 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7623 Symbol_table
* symtab
,
7625 Sized_relobj_file
<size
, big_endian
>* relobj
,
7628 if (this->iplt_
== NULL
)
7629 this->make_iplt_section(symtab
, layout
);
7630 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7633 // Return the number of entries in the PLT.
7635 template<int size
, bool big_endian
>
7637 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7639 if (this->plt_
== NULL
)
7641 return this->plt_
->entry_count();
7644 // Create a GOT entry for local dynamic __tls_get_addr calls.
7646 template<int size
, bool big_endian
>
7648 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7649 Symbol_table
* symtab
,
7651 Sized_relobj_file
<size
, big_endian
>* object
)
7653 if (this->tlsld_got_offset_
== -1U)
7655 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7656 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7657 Output_data_got_powerpc
<size
, big_endian
>* got
7658 = this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
7659 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7660 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7662 this->tlsld_got_offset_
= got_offset
;
7664 return this->tlsld_got_offset_
;
7667 // Get the Reference_flags for a particular relocation.
7669 template<int size
, bool big_endian
>
7671 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7672 unsigned int r_type
,
7673 const Target_powerpc
* target
)
7679 case elfcpp::R_PPC64_TOC
:
7683 case elfcpp::R_POWERPC_NONE
:
7684 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7685 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7686 // No symbol reference.
7689 case elfcpp::R_PPC64_ADDR64
:
7690 case elfcpp::R_PPC64_UADDR64
:
7691 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7692 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7693 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7694 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7695 case elfcpp::R_PPC64_D34
:
7696 case elfcpp::R_PPC64_D34_LO
:
7697 case elfcpp::R_PPC64_D34_HI30
:
7698 case elfcpp::R_PPC64_D34_HA30
:
7699 case elfcpp::R_PPC64_D28
:
7703 case elfcpp::R_POWERPC_ADDR32
:
7704 case elfcpp::R_POWERPC_UADDR32
:
7705 case elfcpp::R_POWERPC_ADDR16
:
7706 case elfcpp::R_POWERPC_UADDR16
:
7707 case elfcpp::R_POWERPC_ADDR16_LO
:
7708 case elfcpp::R_POWERPC_ADDR16_HI
:
7709 case elfcpp::R_POWERPC_ADDR16_HA
:
7710 ref
= Symbol::ABSOLUTE_REF
;
7713 case elfcpp::R_POWERPC_ADDR24
:
7714 case elfcpp::R_POWERPC_ADDR14
:
7715 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7716 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7717 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7720 case elfcpp::R_PPC_LOCAL24PC
:
7724 ref
= Symbol::RELATIVE_REF
;
7727 case elfcpp::R_PPC64_REL64
:
7728 case elfcpp::R_PPC64_REL16_HIGH
:
7729 case elfcpp::R_PPC64_REL16_HIGHA
:
7730 case elfcpp::R_PPC64_REL16_HIGHER
:
7731 case elfcpp::R_PPC64_REL16_HIGHERA
:
7732 case elfcpp::R_PPC64_REL16_HIGHEST
:
7733 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7734 case elfcpp::R_PPC64_PCREL34
:
7735 case elfcpp::R_PPC64_REL16_HIGHER34
:
7736 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7737 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7738 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7739 case elfcpp::R_PPC64_PCREL28
:
7743 case elfcpp::R_POWERPC_REL32
:
7744 case elfcpp::R_POWERPC_REL16
:
7745 case elfcpp::R_POWERPC_REL16_LO
:
7746 case elfcpp::R_POWERPC_REL16_HI
:
7747 case elfcpp::R_POWERPC_REL16_HA
:
7748 ref
= Symbol::RELATIVE_REF
;
7751 case elfcpp::R_PPC_PLTREL24
:
7754 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7757 case elfcpp::R_PPC64_REL24_NOTOC
:
7758 case elfcpp::R_PPC64_REL24_P9NOTOC
:
7759 case elfcpp::R_PPC64_PLT16_LO_DS
:
7760 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7761 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7762 case elfcpp::R_PPC64_PLT_PCREL34
:
7763 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7767 case elfcpp::R_POWERPC_REL24
:
7768 case elfcpp::R_POWERPC_REL14
:
7769 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7770 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7771 case elfcpp::R_POWERPC_PLT16_LO
:
7772 case elfcpp::R_POWERPC_PLT16_HI
:
7773 case elfcpp::R_POWERPC_PLT16_HA
:
7774 case elfcpp::R_POWERPC_PLTSEQ
:
7775 case elfcpp::R_POWERPC_PLTCALL
:
7776 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7779 case elfcpp::R_PPC64_GOT16_DS
:
7780 case elfcpp::R_PPC64_GOT16_LO_DS
:
7781 case elfcpp::R_PPC64_GOT_PCREL34
:
7782 case elfcpp::R_PPC64_TOC16
:
7783 case elfcpp::R_PPC64_TOC16_LO
:
7784 case elfcpp::R_PPC64_TOC16_HI
:
7785 case elfcpp::R_PPC64_TOC16_HA
:
7786 case elfcpp::R_PPC64_TOC16_DS
:
7787 case elfcpp::R_PPC64_TOC16_LO_DS
:
7791 case elfcpp::R_POWERPC_GOT16
:
7792 case elfcpp::R_POWERPC_GOT16_LO
:
7793 case elfcpp::R_POWERPC_GOT16_HI
:
7794 case elfcpp::R_POWERPC_GOT16_HA
:
7795 ref
= Symbol::RELATIVE_REF
;
7798 case elfcpp::R_PPC64_TLSGD
:
7799 case elfcpp::R_PPC64_TLSLD
:
7800 case elfcpp::R_PPC64_TPREL34
:
7801 case elfcpp::R_PPC64_DTPREL34
:
7802 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7803 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7804 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7805 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7809 case elfcpp::R_POWERPC_GOT_TPREL16
:
7810 case elfcpp::R_POWERPC_TLS
:
7811 ref
= Symbol::TLS_REF
;
7814 case elfcpp::R_POWERPC_COPY
:
7815 case elfcpp::R_POWERPC_GLOB_DAT
:
7816 case elfcpp::R_POWERPC_JMP_SLOT
:
7817 case elfcpp::R_POWERPC_RELATIVE
:
7818 case elfcpp::R_POWERPC_DTPMOD
:
7820 // Not expected. We will give an error later.
7824 if (size
== 64 && target
->abiversion() < 2)
7825 ref
|= Symbol::FUNC_DESC_ABI
;
7829 // Report an unsupported relocation against a local symbol.
7831 template<int size
, bool big_endian
>
7833 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7834 Sized_relobj_file
<size
, big_endian
>* object
,
7835 unsigned int r_type
)
7837 gold_error(_("%s: unsupported reloc %u against local symbol"),
7838 object
->name().c_str(), r_type
);
7841 // We are about to emit a dynamic relocation of type R_TYPE. If the
7842 // dynamic linker does not support it, issue an error.
7844 template<int size
, bool big_endian
>
7846 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7847 unsigned int r_type
)
7849 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7851 // These are the relocation types supported by glibc for both 32-bit
7852 // and 64-bit powerpc.
7855 case elfcpp::R_POWERPC_NONE
:
7856 case elfcpp::R_POWERPC_RELATIVE
:
7857 case elfcpp::R_POWERPC_GLOB_DAT
:
7858 case elfcpp::R_POWERPC_DTPMOD
:
7859 case elfcpp::R_POWERPC_DTPREL
:
7860 case elfcpp::R_POWERPC_TPREL
:
7861 case elfcpp::R_POWERPC_JMP_SLOT
:
7862 case elfcpp::R_POWERPC_COPY
:
7863 case elfcpp::R_POWERPC_IRELATIVE
:
7864 case elfcpp::R_POWERPC_ADDR32
:
7865 case elfcpp::R_POWERPC_UADDR32
:
7866 case elfcpp::R_POWERPC_ADDR24
:
7867 case elfcpp::R_POWERPC_ADDR16
:
7868 case elfcpp::R_POWERPC_UADDR16
:
7869 case elfcpp::R_POWERPC_ADDR16_LO
:
7870 case elfcpp::R_POWERPC_ADDR16_HI
:
7871 case elfcpp::R_POWERPC_ADDR16_HA
:
7872 case elfcpp::R_POWERPC_ADDR14
:
7873 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7874 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7875 case elfcpp::R_POWERPC_REL32
:
7876 case elfcpp::R_POWERPC_TPREL16
:
7877 case elfcpp::R_POWERPC_TPREL16_LO
:
7878 case elfcpp::R_POWERPC_TPREL16_HI
:
7879 case elfcpp::R_POWERPC_TPREL16_HA
:
7890 // These are the relocation types supported only on 64-bit.
7891 case elfcpp::R_PPC64_ADDR64
:
7892 case elfcpp::R_PPC64_UADDR64
:
7893 case elfcpp::R_PPC64_JMP_IREL
:
7894 case elfcpp::R_PPC64_ADDR16_DS
:
7895 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7896 case elfcpp::R_PPC64_ADDR16_HIGH
:
7897 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7898 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7899 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7900 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7901 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7902 case elfcpp::R_PPC64_REL64
:
7903 case elfcpp::R_POWERPC_ADDR30
:
7904 case elfcpp::R_PPC64_TPREL16_DS
:
7905 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7906 case elfcpp::R_PPC64_TPREL16_HIGH
:
7907 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7908 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7909 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7910 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7911 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7922 // These are the relocation types supported only on 32-bit.
7923 // ??? glibc ld.so doesn't need to support these.
7924 case elfcpp::R_POWERPC_REL24
:
7925 case elfcpp::R_POWERPC_DTPREL16
:
7926 case elfcpp::R_POWERPC_DTPREL16_LO
:
7927 case elfcpp::R_POWERPC_DTPREL16_HI
:
7928 case elfcpp::R_POWERPC_DTPREL16_HA
:
7936 // This prevents us from issuing more than one error per reloc
7937 // section. But we can still wind up issuing more than one
7938 // error per object file.
7939 if (this->issued_non_pic_error_
)
7941 gold_assert(parameters
->options().output_is_position_independent());
7942 object
->error(_("requires unsupported dynamic reloc; "
7943 "recompile with -fPIC"));
7944 this->issued_non_pic_error_
= true;
7948 // Return whether we need to make a PLT entry for a relocation of the
7949 // given type against a STT_GNU_IFUNC symbol.
7951 template<int size
, bool big_endian
>
7953 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7954 Target_powerpc
<size
, big_endian
>* target
,
7955 Sized_relobj_file
<size
, big_endian
>* object
,
7956 unsigned int r_type
,
7959 // In non-pic code any reference will resolve to the plt call stub
7960 // for the ifunc symbol.
7961 if ((size
== 32 || target
->abiversion() >= 2)
7962 && !parameters
->options().output_is_position_independent())
7967 // Word size refs from data sections are OK, but don't need a PLT entry.
7968 case elfcpp::R_POWERPC_ADDR32
:
7969 case elfcpp::R_POWERPC_UADDR32
:
7974 case elfcpp::R_PPC64_ADDR64
:
7975 case elfcpp::R_PPC64_UADDR64
:
7980 // GOT refs are good, but also don't need a PLT entry.
7981 case elfcpp::R_POWERPC_GOT16
:
7982 case elfcpp::R_POWERPC_GOT16_LO
:
7983 case elfcpp::R_POWERPC_GOT16_HI
:
7984 case elfcpp::R_POWERPC_GOT16_HA
:
7985 case elfcpp::R_PPC64_GOT16_DS
:
7986 case elfcpp::R_PPC64_GOT16_LO_DS
:
7987 case elfcpp::R_PPC64_GOT_PCREL34
:
7990 // PLT relocs are OK and need a PLT entry.
7991 case elfcpp::R_POWERPC_PLT16_LO
:
7992 case elfcpp::R_POWERPC_PLT16_HI
:
7993 case elfcpp::R_POWERPC_PLT16_HA
:
7994 case elfcpp::R_PPC64_PLT16_LO_DS
:
7995 case elfcpp::R_POWERPC_PLTSEQ
:
7996 case elfcpp::R_POWERPC_PLTCALL
:
7997 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7998 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7999 case elfcpp::R_PPC64_PLT_PCREL34
:
8000 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8004 // Function calls are good, and these do need a PLT entry.
8005 case elfcpp::R_PPC64_REL24_NOTOC
:
8009 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8010 case elfcpp::R_POWERPC_ADDR24
:
8011 case elfcpp::R_POWERPC_ADDR14
:
8012 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8013 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8014 case elfcpp::R_POWERPC_REL24
:
8015 case elfcpp::R_PPC_PLTREL24
:
8016 case elfcpp::R_POWERPC_REL14
:
8017 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8018 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8025 // Anything else is a problem.
8026 // If we are building a static executable, the libc startup function
8027 // responsible for applying indirect function relocations is going
8028 // to complain about the reloc type.
8029 // If we are building a dynamic executable, we will have a text
8030 // relocation. The dynamic loader will set the text segment
8031 // writable and non-executable to apply text relocations. So we'll
8032 // segfault when trying to run the indirection function to resolve
8035 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
8036 object
->name().c_str(), r_type
);
8040 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
8044 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
8046 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8047 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8048 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8049 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8050 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8051 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8052 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8053 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8054 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8055 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8056 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8057 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8058 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8059 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8060 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8061 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8062 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8063 /* Exclude lfqu by testing reloc. If relocs are ever
8064 defined for the reduced D field in psq_lu then those
8065 will need testing too. */
8066 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8067 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8068 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8070 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8071 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8072 /* Exclude stfqu. psq_stu as above for psq_lu. */
8073 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8074 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8075 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8076 && (insn
& 1) == 0));
8079 // Scan a relocation for a local symbol.
8081 template<int size
, bool big_endian
>
8083 Target_powerpc
<size
, big_endian
>::Scan::local(
8084 Symbol_table
* symtab
,
8086 Target_powerpc
<size
, big_endian
>* target
,
8087 Sized_relobj_file
<size
, big_endian
>* object
,
8088 unsigned int data_shndx
,
8089 Output_section
* output_section
,
8090 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8091 unsigned int r_type
,
8092 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8095 Powerpc_relobj
<size
, big_endian
>* ppc_object
8096 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8098 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
8100 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8101 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8103 this->expect_tls_get_addr_call();
8104 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8105 if (tls_type
!= tls::TLSOPT_NONE
)
8106 this->skip_next_tls_get_addr_call();
8108 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8109 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8111 this->expect_tls_get_addr_call();
8112 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8113 if (tls_type
!= tls::TLSOPT_NONE
)
8114 this->skip_next_tls_get_addr_call();
8120 && data_shndx
== ppc_object
->opd_shndx()
8121 && r_type
== elfcpp::R_PPC64_ADDR64
)
8122 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8126 // A local STT_GNU_IFUNC symbol may require a PLT entry.
8127 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
8128 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8130 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8131 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8132 r_type
, r_sym
, reloc
.get_r_addend());
8133 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
8138 case elfcpp::R_POWERPC_NONE
:
8139 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8140 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8141 case elfcpp::R_POWERPC_TLS
:
8142 case elfcpp::R_PPC64_ENTRY
:
8143 case elfcpp::R_POWERPC_PLTSEQ
:
8144 case elfcpp::R_POWERPC_PLTCALL
:
8145 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8146 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8147 case elfcpp::R_PPC64_PCREL_OPT
:
8148 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8149 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8150 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8151 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8152 case elfcpp::R_PPC64_REL16_HIGHER34
:
8153 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8154 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8155 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8156 case elfcpp::R_PPC64_D34
:
8157 case elfcpp::R_PPC64_D34_LO
:
8158 case elfcpp::R_PPC64_D34_HI30
:
8159 case elfcpp::R_PPC64_D34_HA30
:
8160 case elfcpp::R_PPC64_D28
:
8161 case elfcpp::R_PPC64_PCREL34
:
8162 case elfcpp::R_PPC64_PCREL28
:
8163 case elfcpp::R_PPC64_TPREL34
:
8164 case elfcpp::R_PPC64_DTPREL34
:
8167 case elfcpp::R_PPC64_TOC
:
8169 Output_data_got_powerpc
<size
, big_endian
>* got
8170 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8171 if (parameters
->options().output_is_position_independent())
8173 Address off
= reloc
.get_r_offset();
8175 && target
->abiversion() < 2
8176 && data_shndx
== ppc_object
->opd_shndx()
8177 && ppc_object
->get_opd_discard(off
- 8))
8180 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8181 Address got_off
= got
->g_o_t();
8182 rela_dyn
->add_output_section_relative(got
->output_section(),
8183 elfcpp::R_POWERPC_RELATIVE
,
8185 object
, data_shndx
, off
,
8191 case elfcpp::R_PPC64_ADDR64
:
8192 case elfcpp::R_PPC64_UADDR64
:
8193 case elfcpp::R_POWERPC_ADDR32
:
8194 case elfcpp::R_POWERPC_UADDR32
:
8195 case elfcpp::R_POWERPC_ADDR24
:
8196 case elfcpp::R_POWERPC_ADDR16
:
8197 case elfcpp::R_POWERPC_ADDR16_LO
:
8198 case elfcpp::R_POWERPC_ADDR16_HI
:
8199 case elfcpp::R_POWERPC_ADDR16_HA
:
8200 case elfcpp::R_POWERPC_UADDR16
:
8201 case elfcpp::R_PPC64_ADDR16_HIGH
:
8202 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8203 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8204 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8205 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8206 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8207 case elfcpp::R_PPC64_ADDR16_DS
:
8208 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8209 case elfcpp::R_POWERPC_ADDR14
:
8210 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8211 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8212 // If building a shared library (or a position-independent
8213 // executable), we need to create a dynamic relocation for
8215 if (parameters
->options().output_is_position_independent()
8216 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8218 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8220 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8221 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8222 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8224 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8225 : elfcpp::R_POWERPC_RELATIVE
);
8226 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8227 output_section
, data_shndx
,
8228 reloc
.get_r_offset(),
8229 reloc
.get_r_addend(), false);
8231 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8233 check_non_pic(object
, r_type
);
8234 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8235 data_shndx
, reloc
.get_r_offset(),
8236 reloc
.get_r_addend());
8240 gold_assert(lsym
.get_st_value() == 0);
8241 unsigned int shndx
= lsym
.get_st_shndx();
8243 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8246 object
->error(_("section symbol %u has bad shndx %u"),
8249 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8250 output_section
, data_shndx
,
8251 reloc
.get_r_offset());
8256 case elfcpp::R_PPC64_PLT_PCREL34
:
8257 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8258 case elfcpp::R_POWERPC_PLT16_LO
:
8259 case elfcpp::R_POWERPC_PLT16_HI
:
8260 case elfcpp::R_POWERPC_PLT16_HA
:
8261 case elfcpp::R_PPC64_PLT16_LO_DS
:
8264 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8265 target
->make_local_plt_entry(symtab
, layout
, object
, r_sym
);
8269 case elfcpp::R_PPC64_REL24_NOTOC
:
8273 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8274 case elfcpp::R_POWERPC_REL24
:
8275 case elfcpp::R_PPC_PLTREL24
:
8276 case elfcpp::R_PPC_LOCAL24PC
:
8277 case elfcpp::R_POWERPC_REL14
:
8278 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8279 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8282 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8283 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8284 r_type
, r_sym
, reloc
.get_r_addend());
8288 case elfcpp::R_PPC64_TOCSAVE
:
8289 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8290 // caller has already saved r2 and thus a plt call stub need not
8293 && target
->mark_pltcall(ppc_object
, data_shndx
,
8294 reloc
.get_r_offset() - 4, symtab
))
8296 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8297 unsigned int shndx
= lsym
.get_st_shndx();
8299 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8301 object
->error(_("tocsave symbol %u has bad shndx %u"),
8304 target
->add_tocsave(ppc_object
, shndx
,
8305 lsym
.get_st_value() + reloc
.get_r_addend());
8309 case elfcpp::R_PPC64_REL64
:
8310 case elfcpp::R_POWERPC_REL32
:
8311 case elfcpp::R_POWERPC_REL16
:
8312 case elfcpp::R_POWERPC_REL16_LO
:
8313 case elfcpp::R_POWERPC_REL16_HI
:
8314 case elfcpp::R_POWERPC_REL16_HA
:
8315 case elfcpp::R_POWERPC_REL16DX_HA
:
8316 case elfcpp::R_PPC64_REL16_HIGH
:
8317 case elfcpp::R_PPC64_REL16_HIGHA
:
8318 case elfcpp::R_PPC64_REL16_HIGHER
:
8319 case elfcpp::R_PPC64_REL16_HIGHERA
:
8320 case elfcpp::R_PPC64_REL16_HIGHEST
:
8321 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8322 case elfcpp::R_POWERPC_SECTOFF
:
8323 case elfcpp::R_POWERPC_SECTOFF_LO
:
8324 case elfcpp::R_POWERPC_SECTOFF_HI
:
8325 case elfcpp::R_POWERPC_SECTOFF_HA
:
8326 case elfcpp::R_PPC64_SECTOFF_DS
:
8327 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8328 case elfcpp::R_POWERPC_TPREL16
:
8329 case elfcpp::R_POWERPC_TPREL16_LO
:
8330 case elfcpp::R_POWERPC_TPREL16_HI
:
8331 case elfcpp::R_POWERPC_TPREL16_HA
:
8332 case elfcpp::R_PPC64_TPREL16_DS
:
8333 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8334 case elfcpp::R_PPC64_TPREL16_HIGH
:
8335 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8336 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8337 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8338 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8339 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8340 case elfcpp::R_POWERPC_DTPREL16
:
8341 case elfcpp::R_POWERPC_DTPREL16_LO
:
8342 case elfcpp::R_POWERPC_DTPREL16_HI
:
8343 case elfcpp::R_POWERPC_DTPREL16_HA
:
8344 case elfcpp::R_PPC64_DTPREL16_DS
:
8345 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8346 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8347 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8348 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8349 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8350 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8351 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8352 case elfcpp::R_PPC64_TLSGD
:
8353 case elfcpp::R_PPC64_TLSLD
:
8354 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8357 case elfcpp::R_PPC64_GOT_PCREL34
:
8358 case elfcpp::R_POWERPC_GOT16
:
8359 case elfcpp::R_POWERPC_GOT16_LO
:
8360 case elfcpp::R_POWERPC_GOT16_HI
:
8361 case elfcpp::R_POWERPC_GOT16_HA
:
8362 case elfcpp::R_PPC64_GOT16_DS
:
8363 case elfcpp::R_PPC64_GOT16_LO_DS
:
8365 // The symbol requires a GOT entry.
8366 Got_type got_type
= ((size
== 32
8367 || r_type
== elfcpp::R_POWERPC_GOT16
8368 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8369 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8370 Output_data_got_powerpc
<size
, big_endian
>* got
8371 = target
->got_section(symtab
, layout
, got_type
);
8372 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8373 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8375 if (!parameters
->options().output_is_position_independent())
8378 && (size
== 32 || target
->abiversion() >= 2))
8379 got
->add_local_plt(object
, r_sym
, got_type
, addend
);
8381 got
->add_local(object
, r_sym
, got_type
, addend
);
8383 else if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8385 // If we are generating a shared object or a pie, this
8386 // symbol's GOT entry will be set by a dynamic relocation.
8388 off
= got
->add_constant(0);
8389 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8391 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8393 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8394 : elfcpp::R_POWERPC_RELATIVE
);
8395 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8396 got
, off
, addend
, false);
8401 case elfcpp::R_PPC64_TOC16
:
8402 case elfcpp::R_PPC64_TOC16_LO
:
8403 case elfcpp::R_PPC64_TOC16_HI
:
8404 case elfcpp::R_PPC64_TOC16_HA
:
8405 case elfcpp::R_PPC64_TOC16_DS
:
8406 case elfcpp::R_PPC64_TOC16_LO_DS
:
8407 // We need a GOT section.
8408 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8411 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8412 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8413 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8414 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8415 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8417 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8418 if (tls_type
== tls::TLSOPT_NONE
)
8420 Got_type got_type
= ((size
== 32
8421 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8422 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8423 Output_data_got_powerpc
<size
, big_endian
>* got
8424 = target
->got_section(symtab
, layout
, got_type
);
8425 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8426 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8427 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8428 got
->add_local_tls_pair(object
, r_sym
, got_type
,
8429 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
,
8432 else if (tls_type
== tls::TLSOPT_TO_LE
)
8434 // no GOT relocs needed for Local Exec.
8441 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8442 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8443 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8444 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8445 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8447 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8448 if (tls_type
== tls::TLSOPT_NONE
)
8449 target
->tlsld_got_offset(symtab
, layout
, object
);
8450 else if (tls_type
== tls::TLSOPT_TO_LE
)
8452 // no GOT relocs needed for Local Exec.
8453 if (parameters
->options().emit_relocs())
8455 Output_section
* os
= layout
->tls_segment()->first_section();
8456 gold_assert(os
!= NULL
);
8457 os
->set_needs_symtab_index();
8465 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8466 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8467 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8468 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8469 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8471 Got_type got_type
= ((size
== 32
8472 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
8473 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
8474 Output_data_got_powerpc
<size
, big_endian
>* got
8475 = target
->got_section(symtab
, layout
, got_type
);
8476 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8477 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8478 got
->add_local_tls(object
, r_sym
, got_type
, addend
);
8482 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8483 case elfcpp::R_POWERPC_GOT_TPREL16
:
8484 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8485 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8486 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8488 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8489 if (tls_type
== tls::TLSOPT_NONE
)
8491 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8492 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8493 Got_type got_type
= ((size
== 32
8494 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
8495 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
8496 if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8498 Output_data_got_powerpc
<size
, big_endian
>* got
8499 = target
->got_section(symtab
, layout
, got_type
);
8500 unsigned int off
= got
->add_constant(0);
8501 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8503 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8504 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8505 elfcpp::R_POWERPC_TPREL
,
8509 else if (tls_type
== tls::TLSOPT_TO_LE
)
8511 // no GOT relocs needed for Local Exec.
8519 unsupported_reloc_local(object
, r_type
);
8524 && parameters
->options().toc_optimize())
8526 if (data_shndx
== ppc_object
->toc_shndx())
8529 if (r_type
!= elfcpp::R_PPC64_ADDR64
8530 || (is_ifunc
&& target
->abiversion() < 2))
8532 else if (parameters
->options().output_is_position_independent())
8538 unsigned int shndx
= lsym
.get_st_shndx();
8539 if (shndx
>= elfcpp::SHN_LORESERVE
8540 && shndx
!= elfcpp::SHN_XINDEX
)
8545 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8548 enum {no_check
, check_lo
, check_ha
} insn_check
;
8552 insn_check
= no_check
;
8555 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8556 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8557 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8558 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8559 case elfcpp::R_POWERPC_GOT16_HA
:
8560 case elfcpp::R_PPC64_TOC16_HA
:
8561 insn_check
= check_ha
;
8564 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8565 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8566 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8567 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8568 case elfcpp::R_POWERPC_GOT16_LO
:
8569 case elfcpp::R_PPC64_GOT16_LO_DS
:
8570 case elfcpp::R_PPC64_TOC16_LO
:
8571 case elfcpp::R_PPC64_TOC16_LO_DS
:
8572 insn_check
= check_lo
;
8576 section_size_type slen
;
8577 const unsigned char* view
= NULL
;
8578 if (insn_check
!= no_check
)
8580 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8581 section_size_type off
=
8582 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8585 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8586 if (insn_check
== check_lo
8587 ? !ok_lo_toc_insn(insn
, r_type
)
8588 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8589 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8591 ppc_object
->set_no_toc_opt();
8592 gold_warning(_("%s: toc optimization is not supported "
8593 "for %#08x instruction"),
8594 ppc_object
->name().c_str(), insn
);
8603 case elfcpp::R_PPC64_TOC16
:
8604 case elfcpp::R_PPC64_TOC16_LO
:
8605 case elfcpp::R_PPC64_TOC16_HI
:
8606 case elfcpp::R_PPC64_TOC16_HA
:
8607 case elfcpp::R_PPC64_TOC16_DS
:
8608 case elfcpp::R_PPC64_TOC16_LO_DS
:
8609 unsigned int shndx
= lsym
.get_st_shndx();
8610 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8612 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8613 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8615 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8616 if (dst_off
< ppc_object
->section_size(shndx
))
8619 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8621 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8623 // Need to check that the insn is a ld
8625 view
= ppc_object
->section_contents(data_shndx
,
8628 section_size_type off
=
8629 (convert_to_section_size_type(reloc
.get_r_offset())
8630 + (big_endian
? -2 : 3));
8632 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8636 ppc_object
->set_no_toc_opt(dst_off
);
8647 case elfcpp::R_POWERPC_REL32
:
8648 if (ppc_object
->got2_shndx() != 0
8649 && parameters
->options().output_is_position_independent())
8651 unsigned int shndx
= lsym
.get_st_shndx();
8652 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8654 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8655 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8656 && (ppc_object
->section_flags(data_shndx
)
8657 & elfcpp::SHF_EXECINSTR
) != 0)
8658 gold_error(_("%s: unsupported -mbss-plt code"),
8659 ppc_object
->name().c_str());
8669 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8670 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8671 case elfcpp::R_POWERPC_GOT_TPREL16
:
8672 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8673 case elfcpp::R_POWERPC_GOT16
:
8674 case elfcpp::R_PPC64_GOT16_DS
:
8675 case elfcpp::R_PPC64_TOC16
:
8676 case elfcpp::R_PPC64_TOC16_DS
:
8677 ppc_object
->set_has_small_toc_reloc();
8685 case elfcpp::R_PPC64_TPREL16_DS
:
8686 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8687 case elfcpp::R_PPC64_TPREL16_HIGH
:
8688 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8689 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8690 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8691 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8692 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8693 case elfcpp::R_PPC64_TPREL34
:
8697 case elfcpp::R_POWERPC_TPREL16
:
8698 case elfcpp::R_POWERPC_TPREL16_LO
:
8699 case elfcpp::R_POWERPC_TPREL16_HI
:
8700 case elfcpp::R_POWERPC_TPREL16_HA
:
8701 layout
->set_has_static_tls();
8709 case elfcpp::R_POWERPC_TPREL16_HA
:
8710 if (target
->tprel_opt())
8712 section_size_type slen
;
8713 const unsigned char* view
= NULL
;
8714 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8715 section_size_type off
8716 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8719 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8720 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8721 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8722 target
->set_no_tprel_opt();
8727 case elfcpp::R_PPC64_TPREL16_HIGH
:
8728 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8729 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8730 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8731 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8732 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8736 case elfcpp::R_POWERPC_TPREL16_HI
:
8737 target
->set_no_tprel_opt();
8745 case elfcpp::R_PPC64_D34
:
8746 case elfcpp::R_PPC64_D34_LO
:
8747 case elfcpp::R_PPC64_D34_HI30
:
8748 case elfcpp::R_PPC64_D34_HA30
:
8749 case elfcpp::R_PPC64_D28
:
8750 case elfcpp::R_PPC64_PCREL34
:
8751 case elfcpp::R_PPC64_PCREL28
:
8752 case elfcpp::R_PPC64_TPREL34
:
8753 case elfcpp::R_PPC64_DTPREL34
:
8754 case elfcpp::R_PPC64_PLT_PCREL34
:
8755 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8756 case elfcpp::R_PPC64_GOT_PCREL34
:
8757 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8758 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8759 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8760 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8761 target
->set_power10_relocs();
8768 // Report an unsupported relocation against a global symbol.
8770 template<int size
, bool big_endian
>
8772 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8773 Sized_relobj_file
<size
, big_endian
>* object
,
8774 unsigned int r_type
,
8777 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8778 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8781 // Scan a relocation for a global symbol.
8783 template<int size
, bool big_endian
>
8785 Target_powerpc
<size
, big_endian
>::Scan::global(
8786 Symbol_table
* symtab
,
8788 Target_powerpc
<size
, big_endian
>* target
,
8789 Sized_relobj_file
<size
, big_endian
>* object
,
8790 unsigned int data_shndx
,
8791 Output_section
* output_section
,
8792 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8793 unsigned int r_type
,
8796 Powerpc_relobj
<size
, big_endian
>* ppc_object
8797 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8799 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8801 case Track_tls::SKIP
:
8807 if (target
->replace_tls_get_addr(gsym
))
8808 // Change a __tls_get_addr reference to __tls_get_addr_opt
8809 // so dynamic relocs are emitted against the latter symbol.
8810 gsym
= target
->tls_get_addr_opt();
8812 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8813 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8815 this->expect_tls_get_addr_call();
8816 bool final
= gsym
->final_value_is_known();
8817 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8818 if (tls_type
!= tls::TLSOPT_NONE
)
8819 this->skip_next_tls_get_addr_call();
8821 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8822 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8824 this->expect_tls_get_addr_call();
8825 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8826 if (tls_type
!= tls::TLSOPT_NONE
)
8827 this->skip_next_tls_get_addr_call();
8830 // A STT_GNU_IFUNC symbol may require a PLT entry.
8831 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8832 bool pushed_ifunc
= false;
8833 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8835 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8836 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8837 r_type
, r_sym
, reloc
.get_r_addend());
8838 target
->make_plt_entry(symtab
, layout
, gsym
);
8839 pushed_ifunc
= true;
8844 case elfcpp::R_POWERPC_NONE
:
8845 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8846 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8847 case elfcpp::R_PPC_LOCAL24PC
:
8848 case elfcpp::R_POWERPC_TLS
:
8849 case elfcpp::R_PPC64_ENTRY
:
8850 case elfcpp::R_POWERPC_PLTSEQ
:
8851 case elfcpp::R_POWERPC_PLTCALL
:
8852 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8853 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8854 case elfcpp::R_PPC64_PCREL_OPT
:
8855 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8856 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8857 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8858 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8859 case elfcpp::R_PPC64_REL16_HIGHER34
:
8860 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8861 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8862 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8863 case elfcpp::R_PPC64_D34
:
8864 case elfcpp::R_PPC64_D34_LO
:
8865 case elfcpp::R_PPC64_D34_HI30
:
8866 case elfcpp::R_PPC64_D34_HA30
:
8867 case elfcpp::R_PPC64_D28
:
8868 case elfcpp::R_PPC64_PCREL34
:
8869 case elfcpp::R_PPC64_PCREL28
:
8870 case elfcpp::R_PPC64_TPREL34
:
8871 case elfcpp::R_PPC64_DTPREL34
:
8874 case elfcpp::R_PPC64_TOC
:
8876 Output_data_got_powerpc
<size
, big_endian
>* got
8877 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8878 if (parameters
->options().output_is_position_independent())
8880 Address off
= reloc
.get_r_offset();
8882 && data_shndx
== ppc_object
->opd_shndx()
8883 && ppc_object
->get_opd_discard(off
- 8))
8886 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8887 Address got_off
= got
->g_o_t();
8888 rela_dyn
->add_output_section_relative(got
->output_section(),
8889 elfcpp::R_POWERPC_RELATIVE
,
8891 object
, data_shndx
, off
,
8897 case elfcpp::R_PPC64_ADDR64
:
8899 && target
->abiversion() < 2
8900 && data_shndx
== ppc_object
->opd_shndx()
8901 && (gsym
->is_defined_in_discarded_section()
8902 || gsym
->object() != object
))
8904 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8908 case elfcpp::R_PPC64_UADDR64
:
8909 case elfcpp::R_POWERPC_ADDR32
:
8910 case elfcpp::R_POWERPC_UADDR32
:
8911 case elfcpp::R_POWERPC_ADDR24
:
8912 case elfcpp::R_POWERPC_ADDR16
:
8913 case elfcpp::R_POWERPC_ADDR16_LO
:
8914 case elfcpp::R_POWERPC_ADDR16_HI
:
8915 case elfcpp::R_POWERPC_ADDR16_HA
:
8916 case elfcpp::R_POWERPC_UADDR16
:
8917 case elfcpp::R_PPC64_ADDR16_HIGH
:
8918 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8919 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8920 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8921 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8922 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8923 case elfcpp::R_PPC64_ADDR16_DS
:
8924 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8925 case elfcpp::R_POWERPC_ADDR14
:
8926 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8927 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8929 // Make a PLT entry if necessary.
8930 if (gsym
->needs_plt_entry())
8932 // Since this is not a PC-relative relocation, we may be
8933 // taking the address of a function. In that case we need to
8934 // set the entry in the dynamic symbol table to the address of
8935 // the PLT call stub.
8936 bool need_ifunc_plt
= false;
8937 if ((size
== 32 || target
->abiversion() >= 2)
8938 && gsym
->is_from_dynobj()
8939 && !parameters
->options().output_is_position_independent())
8941 gsym
->set_needs_dynsym_value();
8942 need_ifunc_plt
= true;
8944 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8946 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8947 target
->push_branch(ppc_object
, data_shndx
,
8948 reloc
.get_r_offset(), r_type
, r_sym
,
8949 reloc
.get_r_addend());
8950 target
->make_plt_entry(symtab
, layout
, gsym
);
8953 // Make a dynamic relocation if necessary.
8954 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8955 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8957 if (!parameters
->options().output_is_position_independent()
8958 && gsym
->may_need_copy_reloc())
8960 target
->copy_reloc(symtab
, layout
, object
,
8961 data_shndx
, output_section
, gsym
, reloc
);
8963 else if ((((size
== 32
8964 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8966 && r_type
== elfcpp::R_PPC64_ADDR64
8967 && target
->abiversion() >= 2))
8968 && gsym
->can_use_relative_reloc(false)
8969 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8970 && parameters
->options().shared()))
8972 && r_type
== elfcpp::R_PPC64_ADDR64
8973 && target
->abiversion() < 2
8974 && (gsym
->can_use_relative_reloc(false)
8975 || data_shndx
== ppc_object
->opd_shndx())))
8977 Reloc_section
* rela_dyn
8978 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8979 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8980 : elfcpp::R_POWERPC_RELATIVE
);
8981 rela_dyn
->add_symbolless_global_addend(
8982 gsym
, dynrel
, output_section
, object
, data_shndx
,
8983 reloc
.get_r_offset(), reloc
.get_r_addend());
8987 Reloc_section
* rela_dyn
8988 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8989 check_non_pic(object
, r_type
);
8990 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8992 reloc
.get_r_offset(),
8993 reloc
.get_r_addend());
8996 && parameters
->options().toc_optimize()
8997 && data_shndx
== ppc_object
->toc_shndx())
8998 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9004 case elfcpp::R_PPC64_PLT_PCREL34
:
9005 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9006 case elfcpp::R_POWERPC_PLT16_LO
:
9007 case elfcpp::R_POWERPC_PLT16_HI
:
9008 case elfcpp::R_POWERPC_PLT16_HA
:
9009 case elfcpp::R_PPC64_PLT16_LO_DS
:
9012 if (!parameters
->doing_static_link())
9013 target
->make_plt_entry(symtab
, layout
, gsym
);
9015 target
->make_local_plt_entry(symtab
, layout
, gsym
);
9019 case elfcpp::R_PPC64_REL24_NOTOC
:
9023 case elfcpp::R_PPC64_REL24_P9NOTOC
:
9024 case elfcpp::R_PPC_PLTREL24
:
9025 case elfcpp::R_POWERPC_REL24
:
9028 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9029 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9030 r_type
, r_sym
, reloc
.get_r_addend());
9031 if (gsym
->needs_plt_entry()
9032 || (!gsym
->final_value_is_known()
9033 && (gsym
->is_undefined()
9034 || gsym
->is_from_dynobj()
9035 || gsym
->is_preemptible())))
9036 target
->make_plt_entry(symtab
, layout
, gsym
);
9040 case elfcpp::R_PPC64_REL64
:
9041 case elfcpp::R_POWERPC_REL32
:
9042 // Make a dynamic relocation if necessary.
9043 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
9045 if (!parameters
->options().output_is_position_independent()
9046 && gsym
->may_need_copy_reloc())
9048 target
->copy_reloc(symtab
, layout
, object
,
9049 data_shndx
, output_section
, gsym
,
9054 Reloc_section
* rela_dyn
9055 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9056 check_non_pic(object
, r_type
);
9057 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
9058 data_shndx
, reloc
.get_r_offset(),
9059 reloc
.get_r_addend());
9064 case elfcpp::R_POWERPC_REL14
:
9065 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9066 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9069 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9070 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9071 r_type
, r_sym
, reloc
.get_r_addend());
9075 case elfcpp::R_PPC64_TOCSAVE
:
9076 // R_PPC64_TOCSAVE follows a call instruction to indicate the
9077 // caller has already saved r2 and thus a plt call stub need not
9080 && target
->mark_pltcall(ppc_object
, data_shndx
,
9081 reloc
.get_r_offset() - 4, symtab
))
9083 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9085 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9087 object
->error(_("tocsave symbol %u has bad shndx %u"),
9091 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9092 target
->add_tocsave(ppc_object
, shndx
,
9093 sym
->value() + reloc
.get_r_addend());
9098 case elfcpp::R_POWERPC_REL16
:
9099 case elfcpp::R_POWERPC_REL16_LO
:
9100 case elfcpp::R_POWERPC_REL16_HI
:
9101 case elfcpp::R_POWERPC_REL16_HA
:
9102 case elfcpp::R_POWERPC_REL16DX_HA
:
9103 case elfcpp::R_PPC64_REL16_HIGH
:
9104 case elfcpp::R_PPC64_REL16_HIGHA
:
9105 case elfcpp::R_PPC64_REL16_HIGHER
:
9106 case elfcpp::R_PPC64_REL16_HIGHERA
:
9107 case elfcpp::R_PPC64_REL16_HIGHEST
:
9108 case elfcpp::R_PPC64_REL16_HIGHESTA
:
9109 case elfcpp::R_POWERPC_SECTOFF
:
9110 case elfcpp::R_POWERPC_SECTOFF_LO
:
9111 case elfcpp::R_POWERPC_SECTOFF_HI
:
9112 case elfcpp::R_POWERPC_SECTOFF_HA
:
9113 case elfcpp::R_PPC64_SECTOFF_DS
:
9114 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9115 case elfcpp::R_POWERPC_TPREL16
:
9116 case elfcpp::R_POWERPC_TPREL16_LO
:
9117 case elfcpp::R_POWERPC_TPREL16_HI
:
9118 case elfcpp::R_POWERPC_TPREL16_HA
:
9119 case elfcpp::R_PPC64_TPREL16_DS
:
9120 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9121 case elfcpp::R_PPC64_TPREL16_HIGH
:
9122 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9123 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9124 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9125 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9126 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9127 case elfcpp::R_POWERPC_DTPREL16
:
9128 case elfcpp::R_POWERPC_DTPREL16_LO
:
9129 case elfcpp::R_POWERPC_DTPREL16_HI
:
9130 case elfcpp::R_POWERPC_DTPREL16_HA
:
9131 case elfcpp::R_PPC64_DTPREL16_DS
:
9132 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
9133 case elfcpp::R_PPC64_DTPREL16_HIGH
:
9134 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
9135 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
9136 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
9137 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
9138 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
9139 case elfcpp::R_PPC64_TLSGD
:
9140 case elfcpp::R_PPC64_TLSLD
:
9141 case elfcpp::R_PPC64_ADDR64_LOCAL
:
9144 case elfcpp::R_PPC64_GOT_PCREL34
:
9145 case elfcpp::R_POWERPC_GOT16
:
9146 case elfcpp::R_POWERPC_GOT16_LO
:
9147 case elfcpp::R_POWERPC_GOT16_HI
:
9148 case elfcpp::R_POWERPC_GOT16_HA
:
9149 case elfcpp::R_PPC64_GOT16_DS
:
9150 case elfcpp::R_PPC64_GOT16_LO_DS
:
9152 // The symbol requires a GOT entry.
9153 Output_data_got_powerpc
<size
, big_endian
>* got
;
9154 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9155 Got_type got_type
= ((size
== 32
9156 || r_type
== elfcpp::R_POWERPC_GOT16
9157 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
9158 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
9160 got
= target
->got_section(symtab
, layout
, got_type
);
9161 if (gsym
->final_value_is_known())
9164 && (size
== 32 || target
->abiversion() >= 2))
9165 got
->add_global_plt(gsym
, got_type
, addend
);
9167 got
->add_global(gsym
, got_type
, addend
);
9169 else if (!gsym
->has_got_offset(got_type
, addend
))
9171 // If we are generating a shared object or a pie, this
9172 // symbol's GOT entry will be set by a dynamic relocation.
9173 unsigned int off
= got
->add_constant(0);
9174 gsym
->set_got_offset(got_type
, off
, addend
);
9176 Reloc_section
* rela_dyn
9177 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9179 if (gsym
->can_use_relative_reloc(false)
9181 || target
->abiversion() >= 2)
9182 && gsym
->visibility() == elfcpp::STV_PROTECTED
9183 && parameters
->options().shared()))
9185 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
9186 : elfcpp::R_POWERPC_RELATIVE
);
9187 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
,
9192 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
9193 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, addend
);
9199 case elfcpp::R_PPC64_TOC16
:
9200 case elfcpp::R_PPC64_TOC16_LO
:
9201 case elfcpp::R_PPC64_TOC16_HI
:
9202 case elfcpp::R_PPC64_TOC16_HA
:
9203 case elfcpp::R_PPC64_TOC16_DS
:
9204 case elfcpp::R_PPC64_TOC16_LO_DS
:
9205 // We need a GOT section.
9206 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
9209 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9210 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9211 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9212 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9213 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9215 bool final
= gsym
->final_value_is_known();
9216 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9217 if (tls_type
== tls::TLSOPT_NONE
)
9219 Got_type got_type
= ((size
== 32
9220 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9221 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
9222 Output_data_got_powerpc
<size
, big_endian
>* got
9223 = target
->got_section(symtab
, layout
, got_type
);
9224 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9225 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9226 got
->add_global_pair_with_rel(gsym
, got_type
, rela_dyn
,
9227 elfcpp::R_POWERPC_DTPMOD
,
9228 elfcpp::R_POWERPC_DTPREL
,
9231 else if (tls_type
== tls::TLSOPT_TO_IE
)
9233 Got_type got_type
= ((size
== 32
9234 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9235 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9236 if (!gsym
->has_got_offset(got_type
))
9238 Output_data_got_powerpc
<size
, big_endian
>* got
9239 = target
->got_section(symtab
, layout
, got_type
);
9240 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9241 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9242 if (gsym
->is_undefined()
9243 || gsym
->is_from_dynobj())
9245 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9246 elfcpp::R_POWERPC_TPREL
, addend
);
9250 unsigned int off
= got
->add_constant(0);
9251 gsym
->set_got_offset(got_type
, off
);
9252 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9253 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9258 else if (tls_type
== tls::TLSOPT_TO_LE
)
9260 // no GOT relocs needed for Local Exec.
9267 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9268 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9269 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9270 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9271 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9273 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9274 if (tls_type
== tls::TLSOPT_NONE
)
9275 target
->tlsld_got_offset(symtab
, layout
, object
);
9276 else if (tls_type
== tls::TLSOPT_TO_LE
)
9278 // no GOT relocs needed for Local Exec.
9279 if (parameters
->options().emit_relocs())
9281 Output_section
* os
= layout
->tls_segment()->first_section();
9282 gold_assert(os
!= NULL
);
9283 os
->set_needs_symtab_index();
9291 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9292 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9293 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9294 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9295 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9297 Got_type got_type
= ((size
== 32
9298 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
9299 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
9300 Output_data_got_powerpc
<size
, big_endian
>* got
9301 = target
->got_section(symtab
, layout
, got_type
);
9302 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9303 if (!gsym
->final_value_is_known()
9304 && (gsym
->is_from_dynobj()
9305 || gsym
->is_undefined()
9306 || gsym
->is_preemptible()))
9307 got
->add_global_with_rel(gsym
, got_type
,
9308 target
->rela_dyn_section(layout
),
9309 elfcpp::R_POWERPC_DTPREL
, addend
);
9311 got
->add_global_tls(gsym
, got_type
, addend
);
9315 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9316 case elfcpp::R_POWERPC_GOT_TPREL16
:
9317 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9318 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9319 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9321 bool final
= gsym
->final_value_is_known();
9322 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9323 if (tls_type
== tls::TLSOPT_NONE
)
9325 Got_type got_type
= ((size
== 32
9326 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
9327 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9328 if (!gsym
->has_got_offset(got_type
))
9330 Output_data_got_powerpc
<size
, big_endian
>* got
9331 = target
->got_section(symtab
, layout
, got_type
);
9332 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9333 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9334 if (gsym
->is_undefined()
9335 || gsym
->is_from_dynobj())
9337 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9338 elfcpp::R_POWERPC_TPREL
, addend
);
9342 unsigned int off
= got
->add_constant(0);
9343 gsym
->set_got_offset(got_type
, off
);
9344 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9345 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9350 else if (tls_type
== tls::TLSOPT_TO_LE
)
9352 // no GOT relocs needed for Local Exec.
9360 unsupported_reloc_global(object
, r_type
, gsym
);
9365 && parameters
->options().toc_optimize())
9367 if (data_shndx
== ppc_object
->toc_shndx())
9370 if (r_type
!= elfcpp::R_PPC64_ADDR64
9371 || (is_ifunc
&& target
->abiversion() < 2))
9373 else if (parameters
->options().output_is_position_independent()
9374 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9377 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9380 enum {no_check
, check_lo
, check_ha
} insn_check
;
9384 insn_check
= no_check
;
9387 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9388 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9389 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9390 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9391 case elfcpp::R_POWERPC_GOT16_HA
:
9392 case elfcpp::R_PPC64_TOC16_HA
:
9393 insn_check
= check_ha
;
9396 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9397 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9398 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9399 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9400 case elfcpp::R_POWERPC_GOT16_LO
:
9401 case elfcpp::R_PPC64_GOT16_LO_DS
:
9402 case elfcpp::R_PPC64_TOC16_LO
:
9403 case elfcpp::R_PPC64_TOC16_LO_DS
:
9404 insn_check
= check_lo
;
9408 section_size_type slen
;
9409 const unsigned char* view
= NULL
;
9410 if (insn_check
!= no_check
)
9412 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9413 section_size_type off
=
9414 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9417 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9418 if (insn_check
== check_lo
9419 ? !ok_lo_toc_insn(insn
, r_type
)
9420 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9421 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9423 ppc_object
->set_no_toc_opt();
9424 gold_warning(_("%s: toc optimization is not supported "
9425 "for %#08x instruction"),
9426 ppc_object
->name().c_str(), insn
);
9435 case elfcpp::R_PPC64_TOC16
:
9436 case elfcpp::R_PPC64_TOC16_LO
:
9437 case elfcpp::R_PPC64_TOC16_HI
:
9438 case elfcpp::R_PPC64_TOC16_HA
:
9439 case elfcpp::R_PPC64_TOC16_DS
:
9440 case elfcpp::R_PPC64_TOC16_LO_DS
:
9441 if (gsym
->source() == Symbol::FROM_OBJECT
9442 && !gsym
->object()->is_dynamic())
9444 Powerpc_relobj
<size
, big_endian
>* sym_object
9445 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9447 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9448 if (shndx
== sym_object
->toc_shndx())
9450 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9451 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9452 if (dst_off
< sym_object
->section_size(shndx
))
9455 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9457 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9459 // Need to check that the insn is a ld
9461 view
= ppc_object
->section_contents(data_shndx
,
9464 section_size_type off
=
9465 (convert_to_section_size_type(reloc
.get_r_offset())
9466 + (big_endian
? -2 : 3));
9468 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9472 sym_object
->set_no_toc_opt(dst_off
);
9484 case elfcpp::R_PPC_LOCAL24PC
:
9485 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9486 gold_error(_("%s: unsupported -mbss-plt code"),
9487 ppc_object
->name().c_str());
9496 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9497 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9498 case elfcpp::R_POWERPC_GOT_TPREL16
:
9499 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9500 case elfcpp::R_POWERPC_GOT16
:
9501 case elfcpp::R_PPC64_GOT16_DS
:
9502 case elfcpp::R_PPC64_TOC16
:
9503 case elfcpp::R_PPC64_TOC16_DS
:
9504 ppc_object
->set_has_small_toc_reloc();
9512 case elfcpp::R_PPC64_TPREL16_DS
:
9513 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9514 case elfcpp::R_PPC64_TPREL16_HIGH
:
9515 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9516 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9517 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9518 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9519 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9520 case elfcpp::R_PPC64_TPREL34
:
9524 case elfcpp::R_POWERPC_TPREL16
:
9525 case elfcpp::R_POWERPC_TPREL16_LO
:
9526 case elfcpp::R_POWERPC_TPREL16_HI
:
9527 case elfcpp::R_POWERPC_TPREL16_HA
:
9528 layout
->set_has_static_tls();
9536 case elfcpp::R_POWERPC_TPREL16_HA
:
9537 if (target
->tprel_opt())
9539 section_size_type slen
;
9540 const unsigned char* view
= NULL
;
9541 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9542 section_size_type off
9543 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9546 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9547 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9548 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9549 target
->set_no_tprel_opt();
9554 case elfcpp::R_PPC64_TPREL16_HIGH
:
9555 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9556 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9557 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9558 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9559 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9563 case elfcpp::R_POWERPC_TPREL16_HI
:
9564 target
->set_no_tprel_opt();
9572 case elfcpp::R_PPC64_D34
:
9573 case elfcpp::R_PPC64_D34_LO
:
9574 case elfcpp::R_PPC64_D34_HI30
:
9575 case elfcpp::R_PPC64_D34_HA30
:
9576 case elfcpp::R_PPC64_D28
:
9577 case elfcpp::R_PPC64_PCREL34
:
9578 case elfcpp::R_PPC64_PCREL28
:
9579 case elfcpp::R_PPC64_TPREL34
:
9580 case elfcpp::R_PPC64_DTPREL34
:
9581 case elfcpp::R_PPC64_PLT_PCREL34
:
9582 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9583 case elfcpp::R_PPC64_GOT_PCREL34
:
9584 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9585 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9586 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9587 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9588 target
->set_power10_relocs();
9595 // Process relocations for gc.
9597 template<int size
, bool big_endian
>
9599 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9600 Symbol_table
* symtab
,
9602 Sized_relobj_file
<size
, big_endian
>* object
,
9603 unsigned int data_shndx
,
9605 const unsigned char* prelocs
,
9607 Output_section
* output_section
,
9608 bool needs_special_offset_handling
,
9609 size_t local_symbol_count
,
9610 const unsigned char* plocal_symbols
)
9612 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9613 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9616 Powerpc_relobj
<size
, big_endian
>* ppc_object
9617 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9619 ppc_object
->set_opd_valid();
9620 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9622 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9623 for (p
= ppc_object
->access_from_map()->begin();
9624 p
!= ppc_object
->access_from_map()->end();
9627 Address dst_off
= p
->first
;
9628 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9629 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9630 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9632 Relobj
* src_obj
= s
->first
;
9633 unsigned int src_indx
= s
->second
;
9634 symtab
->gc()->add_reference(src_obj
, src_indx
,
9635 ppc_object
, dst_indx
);
9639 ppc_object
->access_from_map()->clear();
9640 ppc_object
->process_gc_mark(symtab
);
9641 // Don't look at .opd relocs as .opd will reference everything.
9645 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9654 needs_special_offset_handling
,
9659 // Handle target specific gc actions when adding a gc reference from
9660 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9661 // and DST_OFF. For powerpc64, this adds a referenc to the code
9662 // section of a function descriptor.
9664 template<int size
, bool big_endian
>
9666 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9667 Symbol_table
* symtab
,
9669 unsigned int src_shndx
,
9671 unsigned int dst_shndx
,
9672 Address dst_off
) const
9674 if (size
!= 64 || dst_obj
->is_dynamic())
9677 Powerpc_relobj
<size
, big_endian
>* ppc_object
9678 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9679 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9681 if (ppc_object
->opd_valid())
9683 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9684 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9688 // If we haven't run scan_opd_relocs, we must delay
9689 // processing this function descriptor reference.
9690 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9695 // Add any special sections for this symbol to the gc work list.
9696 // For powerpc64, this adds the code section of a function
9699 template<int size
, bool big_endian
>
9701 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9702 Symbol_table
* symtab
,
9705 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9707 Powerpc_relobj
<size
, big_endian
>* ppc_object
9708 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9710 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9711 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9713 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9714 Address dst_off
= gsym
->value();
9715 if (ppc_object
->opd_valid())
9717 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9718 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9722 ppc_object
->add_gc_mark(dst_off
);
9727 // For a symbol location in .opd, set LOC to the location of the
9730 template<int size
, bool big_endian
>
9732 Target_powerpc
<size
, big_endian
>::do_function_location(
9733 Symbol_location
* loc
) const
9735 if (size
== 64 && loc
->shndx
!= 0)
9737 if (loc
->object
->is_dynamic())
9739 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9740 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9741 if (loc
->shndx
== ppc_object
->opd_shndx())
9744 Address off
= loc
->offset
- ppc_object
->opd_address();
9745 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9746 loc
->offset
= dest_off
;
9751 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9752 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9753 if (loc
->shndx
== ppc_object
->opd_shndx())
9756 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9757 loc
->offset
= dest_off
;
9763 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9764 // compiled with -fsplit-stack. The function calls non-split-stack
9765 // code. Change the function to ensure it has enough stack space to
9766 // call some random function.
9768 template<int size
, bool big_endian
>
9770 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9773 section_offset_type fnoffset
,
9774 section_size_type fnsize
,
9775 const unsigned char* prelocs
,
9777 unsigned char* view
,
9778 section_size_type view_size
,
9780 std::string
* to
) const
9782 // 32-bit not supported.
9786 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9787 prelocs
, reloc_count
, view
, view_size
,
9792 // The function always starts with
9793 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9794 // addis %r12,%r1,-allocate@ha
9795 // addi %r12,%r12,-allocate@l
9797 // but note that the addis or addi may be replaced with a nop
9799 unsigned char *entry
= view
+ fnoffset
;
9800 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9802 if ((insn
& 0xffff0000) == addis_2_12
)
9804 /* Skip ELFv2 global entry code. */
9806 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9809 unsigned char *pinsn
= entry
;
9811 const uint32_t ld_private_ss
= 0xe80d8fc0;
9812 if (insn
== ld_private_ss
)
9814 int32_t allocate
= 0;
9818 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9819 if ((insn
& 0xffff0000) == addis_12_1
)
9820 allocate
+= (insn
& 0xffff) << 16;
9821 else if ((insn
& 0xffff0000) == addi_12_1
9822 || (insn
& 0xffff0000) == addi_12_12
)
9823 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9824 else if (insn
!= nop
)
9827 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9829 int extra
= parameters
->options().split_stack_adjust_size();
9831 if (allocate
>= 0 || extra
< 0)
9833 object
->error(_("split-stack stack size overflow at "
9834 "section %u offset %0zx"),
9835 shndx
, static_cast<size_t>(fnoffset
));
9839 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9840 if (insn
!= addis_12_1
)
9842 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9844 insn
= addi_12_12
| (allocate
& 0xffff);
9845 if (insn
!= addi_12_12
)
9847 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9853 insn
= addi_12_1
| (allocate
& 0xffff);
9854 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9857 if (pinsn
!= entry
+ 12)
9858 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9866 if (!object
->has_no_split_stack())
9867 object
->error(_("failed to match split-stack sequence at "
9868 "section %u offset %0zx"),
9869 shndx
, static_cast<size_t>(fnoffset
));
9873 // Scan relocations for a section.
9875 template<int size
, bool big_endian
>
9877 Target_powerpc
<size
, big_endian
>::scan_relocs(
9878 Symbol_table
* symtab
,
9880 Sized_relobj_file
<size
, big_endian
>* object
,
9881 unsigned int data_shndx
,
9882 unsigned int sh_type
,
9883 const unsigned char* prelocs
,
9885 Output_section
* output_section
,
9886 bool needs_special_offset_handling
,
9887 size_t local_symbol_count
,
9888 const unsigned char* plocal_symbols
)
9890 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9891 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9894 if (!this->plt_localentry0_init_
)
9896 bool plt_localentry0
= false;
9898 && this->abiversion() >= 2)
9900 if (parameters
->options().user_set_plt_localentry())
9901 plt_localentry0
= parameters
->options().plt_localentry();
9903 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9904 gold_warning(_("--plt-localentry is especially dangerous without "
9905 "ld.so support to detect ABI violations"));
9907 this->plt_localentry0_
= plt_localentry0
;
9908 this->plt_localentry0_init_
= true;
9911 if (sh_type
== elfcpp::SHT_REL
)
9913 gold_error(_("%s: unsupported REL reloc section"),
9914 object
->name().c_str());
9918 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9927 needs_special_offset_handling
,
9931 if (this->plt_localentry0_
&& this->power10_relocs_
)
9933 gold_warning(_("--plt-localentry is incompatible with "
9934 "power10 pc-relative code"));
9935 this->plt_localentry0_
= false;
9939 // Functor class for processing the global symbol table.
9940 // Removes symbols defined on discarded opd entries.
9942 template<bool big_endian
>
9943 class Global_symbol_visitor_opd
9946 Global_symbol_visitor_opd()
9950 operator()(Sized_symbol
<64>* sym
)
9952 if (sym
->has_symtab_index()
9953 || sym
->source() != Symbol::FROM_OBJECT
9954 || !sym
->in_real_elf())
9957 if (sym
->object()->is_dynamic())
9960 Powerpc_relobj
<64, big_endian
>* symobj
9961 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9962 if (symobj
->opd_shndx() == 0)
9966 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9967 if (shndx
== symobj
->opd_shndx()
9968 && symobj
->get_opd_discard(sym
->value()))
9970 sym
->set_undefined();
9971 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9972 sym
->set_is_defined_in_discarded_section();
9973 sym
->set_symtab_index(-1U);
9978 template<int size
, bool big_endian
>
9980 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9982 Symbol_table
* symtab
)
9986 Output_data_save_res
<size
, big_endian
>* savres
9987 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9988 this->savres_section_
= savres
;
9989 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9990 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9991 savres
, ORDER_TEXT
, false);
9995 // Sort linker created .got section first (for the header), then input
9996 // sections belonging to files using small model code.
9998 template<bool big_endian
>
9999 class Sort_toc_sections
10001 const Output_section_data
*
10002 small_got_section() const
10004 return (static_cast<Target_powerpc
<64, big_endian
>*>(
10005 parameters
->sized_target
<64, big_endian
>())
10006 ->got_section(GOT_TYPE_SMALL
));
10010 rank(const Output_section::Input_section
& isec
) const
10012 if (!isec
.is_input_section())
10014 if (isec
.output_section_data() == this->small_got_section())
10018 if (static_cast<const Powerpc_relobj
<64, big_endian
>*>(isec
.relobj())
10019 ->has_small_toc_reloc())
10026 operator()(const Output_section::Input_section
& is1
,
10027 const Output_section::Input_section
& is2
) const
10029 return rank(is1
) < rank(is2
);
10033 // Finalize the sections.
10035 template<int size
, bool big_endian
>
10037 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
10039 const Input_objects
* input_objects
,
10040 Symbol_table
* symtab
)
10042 if (parameters
->doing_static_link())
10044 // At least some versions of glibc elf-init.o have a strong
10045 // reference to __rela_iplt marker syms. A weak ref would be
10047 if (this->iplt_
!= NULL
)
10049 Reloc_section
* rel
= this->iplt_
->rel_plt();
10050 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
10051 Symbol_table::PREDEFINED
, rel
, 0, 0,
10052 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10053 elfcpp::STV_HIDDEN
, 0, false, true);
10054 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
10055 Symbol_table::PREDEFINED
, rel
, 0, 0,
10056 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10057 elfcpp::STV_HIDDEN
, 0, true, true);
10061 symtab
->define_as_constant("__rela_iplt_start", NULL
,
10062 Symbol_table::PREDEFINED
, 0, 0,
10063 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10064 elfcpp::STV_HIDDEN
, 0, true, false);
10065 symtab
->define_as_constant("__rela_iplt_end", NULL
,
10066 Symbol_table::PREDEFINED
, 0, 0,
10067 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10068 elfcpp::STV_HIDDEN
, 0, true, false);
10074 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
10075 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
10077 if (!parameters
->options().relocatable())
10079 this->define_save_restore_funcs(layout
, symtab
);
10081 // Annoyingly, we need to make these sections now whether or
10082 // not we need them. If we delay until do_relax then we
10083 // need to mess with the relaxation machinery checkpointing.
10084 this->got_section(symtab
, layout
, GOT_TYPE_STANDARD
);
10085 this->make_brlt_section(layout
);
10087 // FIXME, maybe. Here we could run through all the got
10088 // entries in the small got section, removing any duplicates
10089 // found in the big got section and renumbering offsets.
10091 if (parameters
->options().toc_sort())
10093 Output_section
* os
= this->got_
->output_section();
10094 if (os
!= NULL
&& os
->input_sections().size() > 1)
10095 std::stable_sort(os
->input_sections().begin(),
10096 os
->input_sections().end(),
10097 Sort_toc_sections
<big_endian
>());
10102 // Fill in some more dynamic tags.
10103 Output_data_dynamic
* odyn
= layout
->dynamic_data();
10106 const Reloc_section
* rel_plt
= (this->plt_
== NULL
10108 : this->plt_
->rel_plt());
10109 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
10110 this->rela_dyn_
, true, size
== 32);
10114 if (this->got_
!= NULL
)
10116 this->got_
->finalize_data_size();
10117 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
10118 this->got_
, this->got_
->g_o_t());
10120 if (this->has_tls_get_addr_opt_
)
10121 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
10125 if (this->glink_
!= NULL
)
10127 this->glink_
->finalize_data_size();
10128 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
10130 (this->glink_
->pltresolve_size()
10133 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
10134 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
10135 ((this->has_localentry0_
10136 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
10137 | (this->has_tls_get_addr_opt_
10138 ? elfcpp::PPC64_OPT_TLS
: 0)));
10142 // Emit any relocs we saved in an attempt to avoid generating COPY
10144 if (this->copy_relocs_
.any_saved_relocs())
10145 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
10147 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
10148 p
!= input_objects
->relobj_end();
10151 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
10152 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
10153 if (ppc_relobj
->attributes_section_data())
10154 this->merge_object_attributes(ppc_relobj
,
10155 ppc_relobj
->attributes_section_data());
10157 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
10158 p
!= input_objects
->dynobj_end();
10161 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
10162 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
10163 if (ppc_dynobj
->attributes_section_data())
10164 this->merge_object_attributes(ppc_dynobj
,
10165 ppc_dynobj
->attributes_section_data());
10168 // Create a .gnu.attributes section if we have merged any attributes
10170 if (this->attributes_section_data_
!= NULL
10171 && this->attributes_section_data_
->size() != 0)
10173 Output_attributes_section_data
* attributes_section
10174 = new Output_attributes_section_data(*this->attributes_section_data_
);
10175 layout
->add_output_section_data(".gnu.attributes",
10176 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
10177 attributes_section
, ORDER_INVALID
, false);
10181 // Merge object attributes from input file called NAME with those of the
10182 // output. The input object attributes are in the object pointed by PASD.
10184 template<int size
, bool big_endian
>
10186 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
10188 const Attributes_section_data
* pasd
)
10190 // Return if there is no attributes section data.
10194 // Create output object attributes.
10195 if (this->attributes_section_data_
== NULL
)
10196 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
10198 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
10199 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
10200 Object_attribute
* out_attr
10201 = this->attributes_section_data_
->known_attributes(vendor
);
10203 const char* name
= obj
->name().c_str();
10206 const char* second
;
10207 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
10208 int in_fp
= in_attr
[tag
].int_value() & 0xf;
10209 int out_fp
= out_attr
[tag
].int_value() & 0xf;
10210 bool warn_only
= obj
->is_dynamic();
10211 if (in_fp
!= out_fp
)
10214 if ((in_fp
& 3) == 0)
10216 else if ((out_fp
& 3) == 0)
10220 out_fp
|= in_fp
& 3;
10221 out_attr
[tag
].set_int_value(out_fp
);
10222 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10223 this->last_fp_
= name
;
10226 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
10228 err
= N_("%s uses hard float, %s uses soft float");
10229 first
= this->last_fp_
;
10232 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10234 err
= N_("%s uses hard float, %s uses soft float");
10236 second
= this->last_fp_
;
10238 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10240 err
= N_("%s uses double-precision hard float, "
10241 "%s uses single-precision hard float");
10242 first
= this->last_fp_
;
10245 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10247 err
= N_("%s uses double-precision hard float, "
10248 "%s uses single-precision hard float");
10250 second
= this->last_fp_
;
10253 if (err
|| (in_fp
& 0xc) == 0)
10255 else if ((out_fp
& 0xc) == 0)
10259 out_fp
|= in_fp
& 0xc;
10260 out_attr
[tag
].set_int_value(out_fp
);
10261 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10262 this->last_ld_
= name
;
10265 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10267 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10269 second
= this->last_ld_
;
10271 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10273 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10274 first
= this->last_ld_
;
10277 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10279 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10280 first
= this->last_ld_
;
10283 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10285 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10287 second
= this->last_ld_
;
10292 if (parameters
->options().warn_mismatch())
10295 gold_warning(_(err
), first
, second
);
10297 gold_error(_(err
), first
, second
);
10299 // Arrange for this attribute to be deleted. It's better to
10300 // say "don't know" about a file than to wrongly claim compliance.
10302 out_attr
[tag
].set_type(0);
10308 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10309 int in_vec
= in_attr
[tag
].int_value() & 3;
10310 int out_vec
= out_attr
[tag
].int_value() & 3;
10311 if (in_vec
!= out_vec
)
10316 else if (out_vec
== 0)
10319 out_attr
[tag
].set_int_value(out_vec
);
10320 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10321 this->last_vec_
= name
;
10323 // For now, allow generic to transition to AltiVec or SPE
10324 // without a warning. If GCC marked files with their stack
10325 // alignment and used don't-care markings for files which are
10326 // not affected by the vector ABI, we could warn about this
10328 else if (in_vec
== 1)
10330 else if (out_vec
== 1)
10333 out_attr
[tag
].set_int_value(out_vec
);
10334 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10335 this->last_vec_
= name
;
10337 else if (out_vec
< in_vec
)
10339 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10340 first
= this->last_vec_
;
10343 else if (out_vec
> in_vec
)
10345 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10347 second
= this->last_vec_
;
10351 if (parameters
->options().warn_mismatch())
10352 gold_error(_(err
), first
, second
);
10353 out_attr
[tag
].set_type(0);
10357 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10358 int in_struct
= in_attr
[tag
].int_value() & 3;
10359 int out_struct
= out_attr
[tag
].int_value() & 3;
10360 if (in_struct
!= out_struct
)
10363 if (in_struct
== 0 || in_struct
== 3)
10365 else if (out_struct
== 0)
10367 out_struct
= in_struct
;
10368 out_attr
[tag
].set_int_value(out_struct
);
10369 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10370 this->last_struct_
= name
;
10372 else if (out_struct
< in_struct
)
10374 err
= N_("%s uses r3/r4 for small structure returns, "
10376 first
= this->last_struct_
;
10379 else if (out_struct
> in_struct
)
10381 err
= N_("%s uses r3/r4 for small structure returns, "
10384 second
= this->last_struct_
;
10388 if (parameters
->options().warn_mismatch())
10389 gold_error(_(err
), first
, second
);
10390 out_attr
[tag
].set_type(0);
10395 // Merge Tag_compatibility attributes and any common GNU ones.
10396 this->attributes_section_data_
->merge(name
, pasd
);
10399 // Emit any saved relocs, and mark toc entries using any of these
10400 // relocs as not optimizable.
10402 template<int sh_type
, int size
, bool big_endian
>
10404 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10405 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10408 && parameters
->options().toc_optimize())
10410 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10411 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10412 p
!= this->entries_
.end();
10415 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10418 // If the symbol is no longer defined in a dynamic object,
10419 // then we emitted a COPY relocation. If it is still
10420 // dynamic then we'll need dynamic relocations and thus
10421 // can't optimize toc entries.
10422 if (entry
.sym_
->is_from_dynobj())
10424 Powerpc_relobj
<size
, big_endian
>* ppc_object
10425 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10426 if (entry
.shndx_
== ppc_object
->toc_shndx())
10427 ppc_object
->set_no_toc_opt(entry
.address_
);
10432 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10435 // Return the value to use for a branch relocation.
10437 template<int size
, bool big_endian
>
10439 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10440 const Symbol_table
* symtab
,
10441 const Sized_symbol
<size
>* gsym
,
10442 Powerpc_relobj
<size
, big_endian
>* object
,
10444 unsigned int *dest_shndx
)
10446 if (size
== 32 || this->abiversion() >= 2)
10447 gold_unreachable();
10450 // If the symbol is defined in an opd section, ie. is a function
10451 // descriptor, use the function descriptor code entry address
10452 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10454 && (gsym
->source() != Symbol::FROM_OBJECT
10455 || gsym
->object()->is_dynamic()))
10458 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10459 unsigned int shndx
= symobj
->opd_shndx();
10462 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10463 if (opd_addr
== invalid_address
)
10465 opd_addr
+= symobj
->output_section_address(shndx
);
10466 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10469 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10470 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10473 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10474 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10475 *dest_shndx
= folded
.second
;
10477 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10478 if (sec_addr
== invalid_address
)
10481 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10482 *value
= sec_addr
+ sec_off
;
10489 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10491 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10494 if (gsym
->is_from_dynobj()
10495 || gsym
->is_undefined()
10496 || gsym
->is_preemptible())
10499 if (gsym
->is_absolute())
10500 return !parameters
->options().output_is_position_independent();
10507 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10509 if (psymval
->is_ifunc_symbol())
10513 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10515 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10518 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10519 // pld ra,symbol@got@pcrel
10520 // load/store rt,0(ra)
10522 // pla ra,symbol@pcrel
10523 // load/store rt,0(ra)
10524 // may be translated to
10525 // pload/pstore rt,symbol@pcrel
10527 // This function returns true if the optimization is possible, placing
10528 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10530 // On entry to this function, the linker has already determined that
10531 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10532 // while *PINSN2 is the second instruction.
10535 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10537 uint32_t insn2
= *pinsn2
>> 32;
10540 // Check that regs match.
10541 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10544 switch ((insn2
>> 26) & 63)
10560 // These are the PMLS cases, where we just need to tack a prefix
10561 // on the insn. Check that the D field is zero.
10562 if ((insn2
& 0xffff) != 0)
10564 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10565 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10568 case 58: // lwa, ld
10569 if ((insn2
& 0xfffd) != 0)
10571 i1new
= ((1ULL << 58) | (1ULL << 52)
10572 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10573 | (insn2
& (31ULL << 21)));
10576 case 57: // lxsd, lxssp
10577 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10579 i1new
= ((1ULL << 58) | (1ULL << 52)
10580 | ((40ULL | (insn2
& 3)) << 26)
10581 | (insn2
& (31ULL << 21)));
10584 case 61: // stxsd, stxssp, lxv, stxv
10585 if ((insn2
& 3) == 0)
10587 else if ((insn2
& 3) >= 2)
10589 if ((insn2
& 0xfffc) != 0)
10591 i1new
= ((1ULL << 58) | (1ULL << 52)
10592 | ((44ULL | (insn2
& 3)) << 26)
10593 | (insn2
& (31ULL << 21)));
10597 if ((insn2
& 0xfff0) != 0)
10599 i1new
= ((1ULL << 58) | (1ULL << 52)
10600 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10601 | (insn2
& (31ULL << 21)));
10606 if ((insn2
& 0xffff) != 0)
10608 i1new
= ((1ULL << 58) | (1ULL << 52)
10609 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10612 case 62: // std, stq
10613 if ((insn2
& 0xfffd) != 0)
10615 i1new
= ((1ULL << 58) | (1ULL << 52)
10616 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10617 | (insn2
& (31ULL << 21)));
10622 *pinsn2
= (uint64_t) nop
<< 32;
10626 // Perform a relocation.
10628 template<int size
, bool big_endian
>
10630 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10631 const Relocate_info
<size
, big_endian
>* relinfo
,
10633 Target_powerpc
* target
,
10634 Output_section
* os
,
10636 const unsigned char* preloc
,
10637 const Sized_symbol
<size
>* gsym
,
10638 const Symbol_value
<size
>* psymval
,
10639 unsigned char* view
,
10641 section_size_type view_size
)
10643 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10644 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10645 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10650 if (target
->replace_tls_get_addr(gsym
))
10651 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10653 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10654 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10655 Powerpc_relobj
<size
, big_endian
>* const object
10656 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10657 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10659 case Track_tls::NOT_EXPECTED
:
10660 // No warning. This will result in really old code without tls
10661 // marker relocs being mis-optimised, but there shouldn't be too
10662 // much of that code around. The problem with warning is that
10663 // glibc and libphobos both construct direct calls to
10664 // __tls_get_addr in a way that is harmless.
10666 case Track_tls::EXPECTED
:
10667 // We have already complained.
10669 case Track_tls::SKIP
:
10670 if (is_plt16_reloc
<size
>(r_type
)
10671 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10672 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10674 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10675 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10677 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10679 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10680 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10682 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10683 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10685 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10686 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10687 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10690 case Track_tls::NORMAL
:
10694 // Offset from start of insn to d-field reloc.
10695 const int d_offset
= big_endian
? 2 : 0;
10698 bool has_stub_value
= false;
10699 bool localentry0
= false;
10700 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10701 bool pltcall_to_direct
= false;
10703 if (is_plt16_reloc
<size
>(r_type
)
10704 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10705 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10706 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10707 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
10708 || r_type
== elfcpp::R_POWERPC_PLTCALL
10709 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10711 // It would be possible to replace inline plt calls with direct
10712 // calls if the PLTCALL is in range. The only difficulty is
10713 // that the decision depends on the PLTCALL reloc, and we don't
10714 // know the address of that instruction when processing others
10715 // in the sequence. So the decision needs to be made in
10717 pltcall_to_direct
= !(gsym
!= NULL
10718 ? gsym
->has_plt_offset()
10719 : object
->local_has_plt_offset(r_sym
));
10721 else if ((gsym
!= NULL
10722 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10723 : psymval
->is_ifunc_symbol() && object
->local_has_plt_offset(r_sym
))
10724 && !is_got_reloc(r_type
)
10725 && (!psymval
->is_ifunc_symbol()
10726 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
,
10731 && target
->abiversion() >= 2
10732 && !parameters
->options().output_is_position_independent()
10733 && !is_branch_reloc
<size
>(r_type
))
10735 Address off
= target
->glink_section()->find_global_entry(gsym
);
10736 if (off
!= invalid_address
)
10738 value
= target
->glink_section()->global_entry_address() + off
;
10739 has_stub_value
= true;
10744 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10745 if (target
->stub_tables().size() == 1)
10746 stub_table
= target
->stub_tables()[0];
10747 if (stub_table
== NULL
10750 && !parameters
->options().output_is_position_independent()
10751 && !is_branch_reloc
<size
>(r_type
)))
10752 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10753 if (stub_table
== NULL
)
10755 // This is a ref from a data section to an ifunc symbol,
10756 // or a non-branch reloc for which we always want to use
10757 // one set of stubs for resolving function addresses.
10758 if (target
->stub_tables().size() != 0)
10759 stub_table
= target
->stub_tables()[0];
10761 if (stub_table
!= NULL
)
10763 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10765 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10766 rela
.get_r_addend());
10768 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10769 rela
.get_r_addend());
10772 value
= stub_table
->stub_address() + ent
->off_
;
10773 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10774 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10775 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10778 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10781 value
+= ent
->p9off_
;
10783 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10784 value
+= ent
->p9off_
;
10786 value
+= ent
->tocoff_
;
10791 && target
->is_tls_get_addr_opt(gsym
)))
10793 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
10794 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10796 if (!(target
->power10_stubs()
10797 && target
->power10_stubs_auto()))
10800 else if (relnum
< reloc_count
- 1)
10802 Reltype
next_rela(preloc
+ reloc_size
);
10803 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10804 == elfcpp::R_PPC64_TOCSAVE
10805 && (next_rela
.get_r_offset()
10806 == rela
.get_r_offset() + 4))
10810 localentry0
= ent
->localentry0_
;
10811 has_stub_value
= true;
10815 // We don't care too much about bogus debug references to
10816 // non-local functions, but otherwise there had better be a plt
10817 // call stub or global entry stub as appropriate.
10818 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10821 if (!pltcall_to_direct
&& (is_plt16_reloc
<size
>(r_type
)
10822 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10823 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10825 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10827 value
= target
->plt_off(gsym
, &plt
);
10829 value
= target
->plt_off(object
, r_sym
, &plt
);
10830 value
+= plt
->address();
10834 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10835 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10836 value
-= target
->toc_pointer();
10838 else if (parameters
->options().output_is_position_independent())
10840 if (rela
.get_r_addend() >= 32768)
10842 unsigned int got2
= object
->got2_shndx();
10843 value
-= (object
->get_output_section_offset(got2
)
10844 + object
->output_section(got2
)->address()
10845 + rela
.get_r_addend());
10848 value
-= target
->toc_pointer();
10851 else if (pltcall_to_direct
10852 && (is_plt16_reloc
<size
>(r_type
)
10853 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10854 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10856 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10857 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10858 r_type
= elfcpp::R_POWERPC_NONE
;
10860 else if (pltcall_to_direct
10861 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10862 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10864 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10865 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10866 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10867 r_type
= elfcpp::R_POWERPC_NONE
;
10869 else if (is_got_reloc(r_type
))
10871 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10872 Got_type got_type
= ((size
== 32
10873 || r_type
== elfcpp::R_POWERPC_GOT16
10874 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
10875 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10877 value
= gsym
->got_offset(got_type
, addend
);
10879 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10880 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10881 value
+= target
->got_section(got_type
)->address();
10883 value
-= target
->got_base_offset(got_type
);
10885 else if (r_type
== elfcpp::R_PPC64_TOC
)
10887 value
= target
->toc_pointer();
10889 else if (gsym
!= NULL
10890 && (r_type
== elfcpp::R_POWERPC_REL24
10891 || r_type
== elfcpp::R_PPC_PLTREL24
)
10896 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10897 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10898 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10899 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10901 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10902 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10903 if ((insn
& 1) != 0
10905 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10907 elfcpp::Swap
<32, big_endian
>::
10908 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10909 can_plt_call
= true;
10914 // If we don't have a branch and link followed by a nop,
10915 // we can't go via the plt because there is no place to
10916 // put a toc restoring instruction.
10917 // Unless we know we won't be returning.
10918 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10919 can_plt_call
= true;
10923 // g++ as of 20130507 emits self-calls without a
10924 // following nop. This is arguably wrong since we have
10925 // conflicting information. On the one hand a global
10926 // symbol and on the other a local call sequence, but
10927 // don't error for this special case.
10928 // It isn't possible to cheaply verify we have exactly
10929 // such a call. Allow all calls to the same section.
10931 Address code
= value
;
10932 if (gsym
->source() == Symbol::FROM_OBJECT
10933 && gsym
->object() == object
)
10935 unsigned int dest_shndx
= 0;
10936 if (target
->abiversion() < 2)
10938 Address addend
= rela
.get_r_addend();
10939 code
= psymval
->value(object
, addend
);
10940 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10941 &code
, &dest_shndx
);
10944 if (dest_shndx
== 0)
10945 dest_shndx
= gsym
->shndx(&is_ordinary
);
10946 ok
= dest_shndx
== relinfo
->data_shndx
;
10950 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10951 _("call lacks nop, can't restore toc; "
10952 "recompile with -fPIC"));
10958 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10959 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10960 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10961 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10962 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10964 // First instruction of a global dynamic sequence, arg setup insn.
10965 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10966 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10967 Got_type got_type
= ((size
== 32
10968 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
10969 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10970 if (tls_type
== tls::TLSOPT_NONE
)
10971 got_type
= Got_type(got_type
| GOT_TYPE_TLSGD
);
10972 else if (tls_type
== tls::TLSOPT_TO_IE
)
10973 got_type
= Got_type(got_type
| GOT_TYPE_TPREL
);
10974 if ((got_type
& ~GOT_TYPE_SMALL
) != GOT_TYPE_STANDARD
)
10976 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10978 value
= gsym
->got_offset(got_type
, addend
);
10980 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10981 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10982 value
+= target
->got_section(got_type
)->address();
10984 value
-= target
->got_base_offset(got_type
);
10986 if (tls_type
== tls::TLSOPT_TO_IE
)
10988 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10990 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10991 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10993 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10995 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10996 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10997 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10998 pinsn
& 0xffffffff);
10999 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
11003 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11004 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11006 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11007 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11008 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
11010 insn
|= 32 << 26; // lwz
11012 insn
|= 58 << 26; // ld
11013 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11015 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11016 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11019 else if (tls_type
== tls::TLSOPT_TO_LE
)
11021 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11023 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11024 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11026 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11027 // pla pcrel -> paddi r13
11028 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11029 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11030 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11031 pinsn
& 0xffffffff);
11032 r_type
= elfcpp::R_PPC64_TPREL34
;
11033 value
= psymval
->value(object
, rela
.get_r_addend());
11037 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11038 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11040 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11041 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11042 insn
&= (1 << 26) - (1 << 21); // extract rt
11046 insn
|= addis_0_13
;
11047 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11048 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11049 value
= psymval
->value(object
, rela
.get_r_addend());
11053 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11055 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11056 r_type
= elfcpp::R_POWERPC_NONE
;
11061 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11062 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11063 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11064 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
11065 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11067 // First instruction of a local dynamic sequence, arg setup insn.
11068 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11069 if (tls_type
== tls::TLSOPT_NONE
)
11071 value
= target
->tlsld_got_offset();
11072 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11073 value
+= target
->got_section(GOT_TYPE_SMALL
)->address();
11075 value
-= target
->got_base_offset(GOT_TYPE_SMALL
);
11079 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11080 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11082 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11083 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11085 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11086 // pla pcrel -> paddi r13
11087 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11088 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11089 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11090 pinsn
& 0xffffffff);
11091 r_type
= elfcpp::R_PPC64_TPREL34
;
11092 value
= dtp_offset
;
11094 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11095 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11097 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11098 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11099 insn
&= (1 << 26) - (1 << 21); // extract rt
11103 insn
|= addis_0_13
;
11104 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11105 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11106 value
= dtp_offset
;
11110 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11112 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11113 r_type
= elfcpp::R_POWERPC_NONE
;
11117 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
11118 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
11119 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
11120 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
11121 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11123 // Accesses relative to a local dynamic sequence address,
11124 // no optimisation here.
11125 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11126 Got_type got_type
= ((size
== 32
11127 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
11128 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
11130 value
= gsym
->got_offset(got_type
, addend
);
11132 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11133 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11134 value
+= target
->got_section(got_type
)->address();
11136 value
-= target
->got_base_offset(got_type
);
11138 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11139 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11140 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11141 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
11142 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11144 // First instruction of initial exec sequence.
11145 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11146 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11147 if (tls_type
== tls::TLSOPT_NONE
)
11149 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11150 Got_type got_type
= ((size
== 32
11151 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
11152 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
11154 value
= gsym
->got_offset(got_type
, addend
);
11156 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11157 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11158 value
+= target
->got_section(got_type
)->address();
11160 value
-= target
->got_base_offset(got_type
);
11164 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11165 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11167 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11168 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11170 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11171 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
11172 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
11173 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
11174 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11175 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11176 pinsn
& 0xffffffff);
11177 r_type
= elfcpp::R_PPC64_TPREL34
;
11178 value
= psymval
->value(object
, rela
.get_r_addend());
11180 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11181 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11183 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11184 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11185 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
11189 insn
|= addis_0_13
;
11190 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11191 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11192 value
= psymval
->value(object
, rela
.get_r_addend());
11196 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11198 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11199 r_type
= elfcpp::R_POWERPC_NONE
;
11203 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11204 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11206 // Second instruction of a global dynamic sequence,
11207 // the __tls_get_addr call
11208 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11209 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11210 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
11211 if (tls_type
!= tls::TLSOPT_NONE
)
11213 if (tls_type
== tls::TLSOPT_TO_IE
)
11215 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11216 Insn insn
= add_3_3_13
;
11219 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11220 r_type
= elfcpp::R_POWERPC_NONE
;
11224 bool is_pcrel
= false;
11225 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11226 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11227 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11228 if (relnum
< reloc_count
- 1)
11230 Reltype
next_rela(preloc
+ reloc_size
);
11231 unsigned int r_type2
11232 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11233 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11234 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11235 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11236 && next_rela
.get_r_offset() == rela
.get_r_offset())
11239 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11242 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11243 r_type
= elfcpp::R_POWERPC_NONE
;
11247 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11248 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11250 value
= psymval
->value(object
, rela
.get_r_addend());
11253 this->skip_next_tls_get_addr_call();
11256 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11257 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11259 // Second instruction of a local dynamic sequence,
11260 // the __tls_get_addr call
11261 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11262 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11263 if (tls_type
== tls::TLSOPT_TO_LE
)
11265 bool is_pcrel
= false;
11266 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11267 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11268 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11269 if (relnum
< reloc_count
- 1)
11271 Reltype
next_rela(preloc
+ reloc_size
);
11272 unsigned int r_type2
11273 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11274 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11275 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11276 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11277 && next_rela
.get_r_offset() == rela
.get_r_offset())
11280 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11283 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11284 r_type
= elfcpp::R_POWERPC_NONE
;
11288 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11289 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11291 value
= dtp_offset
;
11293 this->skip_next_tls_get_addr_call();
11296 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11298 // Second instruction of an initial exec sequence
11299 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11300 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11301 if (tls_type
== tls::TLSOPT_TO_LE
)
11303 Address roff
= rela
.get_r_offset() & 3;
11304 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11305 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11306 unsigned int reg
= size
== 32 ? 2 : 13;
11307 insn
= at_tls_transform(insn
, reg
);
11308 gold_assert(insn
!= 0);
11311 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11312 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11314 value
= psymval
->value(object
, rela
.get_r_addend());
11316 else if (roff
== 1)
11318 // For pcrel IE to LE we already have the full offset
11319 // and thus don't need an addi here. A nop or mr will do.
11320 if ((insn
& (0x3f << 26)) == 14 << 26)
11322 // Extract regs from addi rt,ra,si.
11323 unsigned int rt
= (insn
>> 21) & 0x1f;
11324 unsigned int ra
= (insn
>> 16) & 0x1f;
11329 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11330 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11331 insn
|= (31u << 26) | (444u << 1);
11334 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11335 r_type
= elfcpp::R_POWERPC_NONE
;
11339 else if (!has_stub_value
)
11341 if (pltcall_to_direct
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11342 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11344 // PLTCALL without plt entry => convert to direct call
11345 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11346 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11347 insn
= (insn
& 1) | b
;
11348 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11350 r_type
= elfcpp::R_PPC_PLTREL24
;
11351 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11352 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11354 r_type
= elfcpp::R_POWERPC_REL24
;
11356 Address addend
= 0;
11358 && (r_type
== elfcpp::R_PPC_PLTREL24
11359 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11360 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11361 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11362 addend
= rela
.get_r_addend();
11363 value
= psymval
->value(object
, addend
);
11364 unsigned int local_ent
= 0;
11365 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11367 if (target
->abiversion() >= 2)
11370 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11372 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11376 unsigned int dest_shndx
;
11377 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11378 &value
, &dest_shndx
);
11381 Address max_branch
= max_branch_delta
<size
>(r_type
);
11382 if (max_branch
!= 0
11383 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11385 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
11386 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11388 ? object
->ppc64_needs_toc(gsym
)
11389 : object
->ppc64_needs_toc(r_sym
)))))
11391 Stub_table
<size
, big_endian
>* stub_table
11392 = object
->stub_table(relinfo
->data_shndx
);
11393 if (stub_table
!= NULL
)
11395 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11396 = stub_table
->find_long_branch_entry(value
);
11399 if (ent
->save_res_
)
11400 value
= (value
- target
->savres_section()->address()
11401 + stub_table
->stub_address()
11402 + stub_table
->plt_size()
11403 + stub_table
->branch_size());
11406 value
= (stub_table
->stub_address()
11407 + stub_table
->plt_size()
11411 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11414 value
+= ent
->p9off_
;
11416 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
11417 value
+= ent
->p9off_
;
11419 value
+= ent
->tocoff_
;
11422 has_stub_value
= true;
11426 if (!has_stub_value
)
11427 value
+= local_ent
;
11432 case elfcpp::R_PPC64_REL24_NOTOC
:
11436 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11437 case elfcpp::R_PPC64_REL64
:
11438 case elfcpp::R_POWERPC_REL32
:
11439 case elfcpp::R_POWERPC_REL24
:
11440 case elfcpp::R_PPC_PLTREL24
:
11441 case elfcpp::R_PPC_LOCAL24PC
:
11442 case elfcpp::R_POWERPC_REL16
:
11443 case elfcpp::R_POWERPC_REL16_LO
:
11444 case elfcpp::R_POWERPC_REL16_HI
:
11445 case elfcpp::R_POWERPC_REL16_HA
:
11446 case elfcpp::R_POWERPC_REL16DX_HA
:
11447 case elfcpp::R_PPC64_REL16_HIGH
:
11448 case elfcpp::R_PPC64_REL16_HIGHA
:
11449 case elfcpp::R_PPC64_REL16_HIGHER
:
11450 case elfcpp::R_PPC64_REL16_HIGHERA
:
11451 case elfcpp::R_PPC64_REL16_HIGHEST
:
11452 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11453 case elfcpp::R_POWERPC_REL14
:
11454 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11455 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11456 case elfcpp::R_PPC64_PCREL34
:
11457 case elfcpp::R_PPC64_GOT_PCREL34
:
11458 case elfcpp::R_PPC64_PLT_PCREL34
:
11459 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11460 case elfcpp::R_PPC64_PCREL28
:
11461 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11462 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11463 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11464 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11465 case elfcpp::R_PPC64_REL16_HIGHER34
:
11466 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11467 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11468 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11472 case elfcpp::R_PPC64_TOC16
:
11473 case elfcpp::R_PPC64_TOC16_LO
:
11474 case elfcpp::R_PPC64_TOC16_HI
:
11475 case elfcpp::R_PPC64_TOC16_HA
:
11476 case elfcpp::R_PPC64_TOC16_DS
:
11477 case elfcpp::R_PPC64_TOC16_LO_DS
:
11478 // Subtract the TOC base address.
11479 value
-= target
->toc_pointer();
11482 case elfcpp::R_POWERPC_SECTOFF
:
11483 case elfcpp::R_POWERPC_SECTOFF_LO
:
11484 case elfcpp::R_POWERPC_SECTOFF_HI
:
11485 case elfcpp::R_POWERPC_SECTOFF_HA
:
11486 case elfcpp::R_PPC64_SECTOFF_DS
:
11487 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11489 value
-= os
->address();
11492 case elfcpp::R_PPC64_TPREL16_DS
:
11493 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11494 case elfcpp::R_PPC64_TPREL16_HIGH
:
11495 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11497 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11500 case elfcpp::R_POWERPC_TPREL16
:
11501 case elfcpp::R_POWERPC_TPREL16_LO
:
11502 case elfcpp::R_POWERPC_TPREL16_HI
:
11503 case elfcpp::R_POWERPC_TPREL16_HA
:
11504 case elfcpp::R_POWERPC_TPREL
:
11505 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11506 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11507 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11508 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11509 case elfcpp::R_PPC64_TPREL34
:
11510 // tls symbol values are relative to tls_segment()->vaddr()
11511 value
-= tp_offset
;
11514 case elfcpp::R_PPC64_DTPREL16_DS
:
11515 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11516 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11517 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11518 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11519 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11521 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11522 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11525 case elfcpp::R_POWERPC_DTPREL16
:
11526 case elfcpp::R_POWERPC_DTPREL16_LO
:
11527 case elfcpp::R_POWERPC_DTPREL16_HI
:
11528 case elfcpp::R_POWERPC_DTPREL16_HA
:
11529 case elfcpp::R_POWERPC_DTPREL
:
11530 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11531 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11532 case elfcpp::R_PPC64_DTPREL34
:
11533 // tls symbol values are relative to tls_segment()->vaddr()
11534 value
-= dtp_offset
;
11537 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11539 value
+= object
->ppc64_local_entry_offset(gsym
);
11541 value
+= object
->ppc64_local_entry_offset(r_sym
);
11548 Insn branch_bit
= 0;
11551 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11552 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11553 branch_bit
= 1 << 21;
11555 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11556 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11558 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11559 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11560 insn
&= ~(1 << 21);
11561 insn
|= branch_bit
;
11562 if (this->is_isa_v2
)
11564 // Set 'a' bit. This is 0b00010 in BO field for branch
11565 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11566 // for branch on CTR insns (BO == 1a00t or 1a01t).
11567 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11568 insn
|= 0x02 << 21;
11569 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11570 insn
|= 0x08 << 21;
11576 // Invert 'y' bit if not the default.
11577 if (static_cast<Signed_address
>(value
) < 0)
11580 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11584 case elfcpp::R_POWERPC_PLT16_HA
:
11586 && !parameters
->options().output_is_position_independent())
11588 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11589 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11591 // Convert addis to lis.
11592 if ((insn
& (0x3f << 26)) == 15u << 26
11593 && (insn
& (0x1f << 16)) != 0)
11595 insn
&= ~(0x1f << 16);
11596 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11606 ? relative_value_is_known(gsym
)
11607 : relative_value_is_known(psymval
))
11612 uint64_t pinsn
, pinsn2
;
11619 // Multi-instruction sequences that access the GOT/TOC can
11620 // be optimized, eg.
11621 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11622 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11624 // addis ra,r2,0; addi rb,ra,x@toc@l;
11625 // to nop; addi rb,r2,x@toc;
11626 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11627 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11628 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11629 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11630 case elfcpp::R_POWERPC_GOT16_HA
:
11631 case elfcpp::R_PPC64_TOC16_HA
:
11632 if (size
== 64 && parameters
->options().toc_optimize())
11634 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11635 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11636 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11637 && object
->make_toc_relative(target
, &value
))
11638 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11639 && object
->make_got_relative(target
, psymval
,
11640 rela
.get_r_addend(),
11643 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11644 == ((15u << 26) | (2 << 16)));
11646 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11647 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11648 && value
+ 0x8000 < 0x10000)
11650 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11656 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11657 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11658 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11659 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11660 case elfcpp::R_POWERPC_GOT16_LO
:
11661 case elfcpp::R_PPC64_GOT16_LO_DS
:
11662 case elfcpp::R_PPC64_TOC16_LO
:
11663 case elfcpp::R_PPC64_TOC16_LO_DS
:
11664 if (size
== 64 && parameters
->options().toc_optimize())
11666 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11667 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11668 bool changed
= false;
11669 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11670 && object
->make_toc_relative(target
, &value
))
11671 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11672 && object
->make_got_relative(target
, psymval
,
11673 rela
.get_r_addend(),
11676 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11677 insn
^= (14u << 26) ^ (58u << 26);
11678 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11681 if (ok_lo_toc_insn(insn
, r_type
)
11682 && value
+ 0x8000 < 0x10000)
11684 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11686 // Transform addic to addi when we change reg.
11687 insn
&= ~((0x3f << 26) | (0x1f << 16));
11688 insn
|= (14u << 26) | (2 << 16);
11692 insn
&= ~(0x1f << 16);
11698 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11702 case elfcpp::R_PPC64_GOT_PCREL34
:
11703 if (size
== 64 && parameters
->options().toc_optimize())
11705 iview
= reinterpret_cast<Insn
*>(view
);
11706 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11708 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11709 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11710 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11713 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11715 if (relval
+ (1ULL << 33) < 1ULL << 34)
11718 // Replace with paddi
11719 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11720 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11721 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11722 pinsn
& 0xffffffff);
11728 case elfcpp::R_PPC64_PCREL34
:
11731 iview
= reinterpret_cast<Insn
*>(view
);
11732 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11734 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11735 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11736 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11737 | (14ULL << 26) /* paddi */))
11741 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11742 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11743 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11744 if (relnum
>= reloc_count
- 1)
11747 Reltype
next_rela(preloc
+ reloc_size
);
11748 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11749 != elfcpp::R_PPC64_PCREL_OPT
)
11750 || next_rela
.get_r_offset() != rela
.get_r_offset())
11753 Address off
= next_rela
.get_r_addend();
11755 off
= 8; // zero means next insn.
11756 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11759 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11760 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11762 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11764 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11766 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11767 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11768 pinsn
& 0xffffffff);
11769 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11774 case elfcpp::R_POWERPC_TPREL16_HA
:
11775 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11777 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11778 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11783 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11785 // R_PPC_TLSGD, R_PPC_TLSLD
11788 case elfcpp::R_POWERPC_TPREL16_LO
:
11789 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11791 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11792 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11793 insn
&= ~(0x1f << 16);
11794 insn
|= (size
== 32 ? 2 : 13) << 16;
11795 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11799 case elfcpp::R_PPC64_ENTRY
:
11802 value
= target
->toc_pointer();
11803 if (value
+ 0x80008000 <= 0xffffffff
11804 && !parameters
->options().output_is_position_independent())
11806 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11807 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11808 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11810 if ((insn1
& ~0xfffc) == ld_2_12
11811 && insn2
== add_2_2_12
)
11813 insn1
= lis_2
+ ha(value
);
11814 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11815 insn2
= addi_2_2
+ l(value
);
11816 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11823 if (value
+ 0x80008000 <= 0xffffffff)
11825 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11826 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11827 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11829 if ((insn1
& ~0xfffc) == ld_2_12
11830 && insn2
== add_2_2_12
)
11832 insn1
= addis_2_12
+ ha(value
);
11833 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11834 insn2
= addi_2_2
+ l(value
);
11835 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11843 case elfcpp::R_POWERPC_REL16_LO
:
11844 // If we are generating a non-PIC executable, edit
11845 // 0: addis 2,12,.TOC.-0b@ha
11846 // addi 2,2,.TOC.-0b@l
11847 // used by ELFv2 global entry points to set up r2, to
11849 // addi 2,2,.TOC.@l
11850 // if .TOC. is in range. */
11852 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11855 && target
->abiversion() >= 2
11856 && !parameters
->options().output_is_position_independent()
11857 && rela
.get_r_addend() == d_offset
+ 4
11859 && strcmp(gsym
->name(), ".TOC.") == 0)
11861 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11862 Reltype
prev_rela(preloc
- reloc_size
);
11863 if ((prev_rela
.get_r_info()
11864 == elfcpp::elf_r_info
<size
>(r_sym
,
11865 elfcpp::R_POWERPC_REL16_HA
))
11866 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11867 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11869 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11870 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11871 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11873 if ((insn1
& 0xffff0000) == addis_2_12
11874 && (insn2
& 0xffff0000) == addi_2_2
)
11876 insn1
= lis_2
+ ha(value
+ address
- 4);
11877 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11878 insn2
= addi_2_2
+ l(value
+ address
- 4);
11879 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11882 relinfo
->rr
->set_strategy(relnum
- 1,
11883 Relocatable_relocs::RELOC_SPECIAL
);
11884 relinfo
->rr
->set_strategy(relnum
,
11885 Relocatable_relocs::RELOC_SPECIAL
);
11895 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11896 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11899 case elfcpp::R_POWERPC_ADDR32
:
11900 case elfcpp::R_POWERPC_UADDR32
:
11902 overflow
= Reloc::CHECK_BITFIELD
;
11905 case elfcpp::R_POWERPC_REL32
:
11906 case elfcpp::R_POWERPC_REL16DX_HA
:
11908 overflow
= Reloc::CHECK_SIGNED
;
11911 case elfcpp::R_POWERPC_UADDR16
:
11912 overflow
= Reloc::CHECK_BITFIELD
;
11915 case elfcpp::R_POWERPC_ADDR16
:
11916 // We really should have three separate relocations,
11917 // one for 16-bit data, one for insns with 16-bit signed fields,
11918 // and one for insns with 16-bit unsigned fields.
11919 overflow
= Reloc::CHECK_BITFIELD
;
11920 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11921 overflow
= Reloc::CHECK_LOW_INSN
;
11924 case elfcpp::R_POWERPC_ADDR16_HI
:
11925 case elfcpp::R_POWERPC_ADDR16_HA
:
11926 case elfcpp::R_POWERPC_GOT16_HI
:
11927 case elfcpp::R_POWERPC_GOT16_HA
:
11928 case elfcpp::R_POWERPC_PLT16_HI
:
11929 case elfcpp::R_POWERPC_PLT16_HA
:
11930 case elfcpp::R_POWERPC_SECTOFF_HI
:
11931 case elfcpp::R_POWERPC_SECTOFF_HA
:
11932 case elfcpp::R_PPC64_TOC16_HI
:
11933 case elfcpp::R_PPC64_TOC16_HA
:
11934 case elfcpp::R_PPC64_PLTGOT16_HI
:
11935 case elfcpp::R_PPC64_PLTGOT16_HA
:
11936 case elfcpp::R_POWERPC_TPREL16_HI
:
11937 case elfcpp::R_POWERPC_TPREL16_HA
:
11938 case elfcpp::R_POWERPC_DTPREL16_HI
:
11939 case elfcpp::R_POWERPC_DTPREL16_HA
:
11940 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11941 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11942 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11943 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11944 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11945 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11946 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11947 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11948 case elfcpp::R_POWERPC_REL16_HI
:
11949 case elfcpp::R_POWERPC_REL16_HA
:
11951 overflow
= Reloc::CHECK_HIGH_INSN
;
11954 case elfcpp::R_POWERPC_REL16
:
11955 case elfcpp::R_PPC64_TOC16
:
11956 case elfcpp::R_POWERPC_GOT16
:
11957 case elfcpp::R_POWERPC_SECTOFF
:
11958 case elfcpp::R_POWERPC_TPREL16
:
11959 case elfcpp::R_POWERPC_DTPREL16
:
11960 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11961 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11962 case elfcpp::R_POWERPC_GOT_TPREL16
:
11963 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11964 overflow
= Reloc::CHECK_LOW_INSN
;
11967 case elfcpp::R_PPC64_REL24_NOTOC
:
11971 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11972 case elfcpp::R_POWERPC_ADDR24
:
11973 case elfcpp::R_POWERPC_ADDR14
:
11974 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11975 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11976 case elfcpp::R_PPC64_ADDR16_DS
:
11977 case elfcpp::R_POWERPC_REL24
:
11978 case elfcpp::R_PPC_PLTREL24
:
11979 case elfcpp::R_PPC_LOCAL24PC
:
11980 case elfcpp::R_PPC64_TPREL16_DS
:
11981 case elfcpp::R_PPC64_DTPREL16_DS
:
11982 case elfcpp::R_PPC64_TOC16_DS
:
11983 case elfcpp::R_PPC64_GOT16_DS
:
11984 case elfcpp::R_PPC64_SECTOFF_DS
:
11985 case elfcpp::R_POWERPC_REL14
:
11986 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11987 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11988 case elfcpp::R_PPC64_D34
:
11989 case elfcpp::R_PPC64_PCREL34
:
11990 case elfcpp::R_PPC64_GOT_PCREL34
:
11991 case elfcpp::R_PPC64_PLT_PCREL34
:
11992 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11993 case elfcpp::R_PPC64_D28
:
11994 case elfcpp::R_PPC64_PCREL28
:
11995 case elfcpp::R_PPC64_TPREL34
:
11996 case elfcpp::R_PPC64_DTPREL34
:
11997 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11998 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11999 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12000 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12001 overflow
= Reloc::CHECK_SIGNED
;
12005 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
12008 if (overflow
== Reloc::CHECK_LOW_INSN
12009 || overflow
== Reloc::CHECK_HIGH_INSN
)
12011 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12013 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
12014 overflow
= Reloc::CHECK_BITFIELD
;
12015 else if (overflow
== Reloc::CHECK_LOW_INSN
12016 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
12017 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
12018 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
12019 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
12020 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
12021 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
12022 overflow
= Reloc::CHECK_UNSIGNED
;
12024 overflow
= Reloc::CHECK_SIGNED
;
12027 bool maybe_dq_reloc
= false;
12028 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
12029 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
12032 case elfcpp::R_POWERPC_NONE
:
12033 case elfcpp::R_POWERPC_TLS
:
12034 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
12035 case elfcpp::R_POWERPC_GNU_VTENTRY
:
12036 case elfcpp::R_POWERPC_PLTSEQ
:
12037 case elfcpp::R_POWERPC_PLTCALL
:
12038 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
12039 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
12040 case elfcpp::R_PPC64_PCREL_OPT
:
12043 case elfcpp::R_PPC64_ADDR64
:
12044 case elfcpp::R_PPC64_REL64
:
12045 case elfcpp::R_PPC64_TOC
:
12046 case elfcpp::R_PPC64_ADDR64_LOCAL
:
12047 Reloc::addr64(view
, value
);
12050 case elfcpp::R_POWERPC_TPREL
:
12051 case elfcpp::R_POWERPC_DTPREL
:
12053 Reloc::addr64(view
, value
);
12055 status
= Reloc::addr32(view
, value
, overflow
);
12058 case elfcpp::R_PPC64_UADDR64
:
12059 Reloc::addr64_u(view
, value
);
12062 case elfcpp::R_POWERPC_ADDR32
:
12063 status
= Reloc::addr32(view
, value
, overflow
);
12066 case elfcpp::R_POWERPC_REL32
:
12067 case elfcpp::R_POWERPC_UADDR32
:
12068 status
= Reloc::addr32_u(view
, value
, overflow
);
12071 case elfcpp::R_PPC64_REL24_NOTOC
:
12073 goto unsupp
; // R_PPC_EMB_RELSDA
12075 case elfcpp::R_PPC64_REL24_P9NOTOC
:
12076 case elfcpp::R_POWERPC_ADDR24
:
12077 case elfcpp::R_POWERPC_REL24
:
12078 case elfcpp::R_PPC_PLTREL24
:
12079 case elfcpp::R_PPC_LOCAL24PC
:
12080 status
= Reloc::addr24(view
, value
, overflow
);
12083 case elfcpp::R_POWERPC_GOT_DTPREL16
:
12084 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
12085 case elfcpp::R_POWERPC_GOT_TPREL16
:
12086 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
12089 // On ppc64 these are all ds form
12090 maybe_dq_reloc
= true;
12094 case elfcpp::R_POWERPC_ADDR16
:
12095 case elfcpp::R_POWERPC_REL16
:
12096 case elfcpp::R_PPC64_TOC16
:
12097 case elfcpp::R_POWERPC_GOT16
:
12098 case elfcpp::R_POWERPC_SECTOFF
:
12099 case elfcpp::R_POWERPC_TPREL16
:
12100 case elfcpp::R_POWERPC_DTPREL16
:
12101 case elfcpp::R_POWERPC_GOT_TLSGD16
:
12102 case elfcpp::R_POWERPC_GOT_TLSLD16
:
12103 case elfcpp::R_POWERPC_ADDR16_LO
:
12104 case elfcpp::R_POWERPC_REL16_LO
:
12105 case elfcpp::R_PPC64_TOC16_LO
:
12106 case elfcpp::R_POWERPC_GOT16_LO
:
12107 case elfcpp::R_POWERPC_PLT16_LO
:
12108 case elfcpp::R_POWERPC_SECTOFF_LO
:
12109 case elfcpp::R_POWERPC_TPREL16_LO
:
12110 case elfcpp::R_POWERPC_DTPREL16_LO
:
12111 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
12112 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
12114 status
= Reloc::addr16(view
, value
, overflow
);
12116 maybe_dq_reloc
= true;
12119 case elfcpp::R_POWERPC_UADDR16
:
12120 status
= Reloc::addr16_u(view
, value
, overflow
);
12123 case elfcpp::R_PPC64_ADDR16_HIGH
:
12124 case elfcpp::R_PPC64_TPREL16_HIGH
:
12125 case elfcpp::R_PPC64_DTPREL16_HIGH
:
12127 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
12130 case elfcpp::R_POWERPC_ADDR16_HI
:
12131 case elfcpp::R_POWERPC_REL16_HI
:
12132 case elfcpp::R_PPC64_REL16_HIGH
:
12133 case elfcpp::R_PPC64_TOC16_HI
:
12134 case elfcpp::R_POWERPC_GOT16_HI
:
12135 case elfcpp::R_POWERPC_PLT16_HI
:
12136 case elfcpp::R_POWERPC_SECTOFF_HI
:
12137 case elfcpp::R_POWERPC_TPREL16_HI
:
12138 case elfcpp::R_POWERPC_DTPREL16_HI
:
12139 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
12140 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
12141 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
12142 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
12143 Reloc::addr16_hi(view
, value
);
12146 case elfcpp::R_PPC64_ADDR16_HIGHA
:
12147 case elfcpp::R_PPC64_TPREL16_HIGHA
:
12148 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
12150 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
12153 case elfcpp::R_POWERPC_ADDR16_HA
:
12154 case elfcpp::R_POWERPC_REL16_HA
:
12155 case elfcpp::R_PPC64_REL16_HIGHA
:
12156 case elfcpp::R_PPC64_TOC16_HA
:
12157 case elfcpp::R_POWERPC_GOT16_HA
:
12158 case elfcpp::R_POWERPC_PLT16_HA
:
12159 case elfcpp::R_POWERPC_SECTOFF_HA
:
12160 case elfcpp::R_POWERPC_TPREL16_HA
:
12161 case elfcpp::R_POWERPC_DTPREL16_HA
:
12162 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
12163 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
12164 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
12165 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
12166 Reloc::addr16_ha(view
, value
);
12169 case elfcpp::R_POWERPC_REL16DX_HA
:
12170 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
12173 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
12175 // R_PPC_EMB_NADDR16_LO
12178 case elfcpp::R_PPC64_ADDR16_HIGHER
:
12179 case elfcpp::R_PPC64_REL16_HIGHER
:
12180 case elfcpp::R_PPC64_TPREL16_HIGHER
:
12181 Reloc::addr16_hi2(view
, value
);
12184 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
12186 // R_PPC_EMB_NADDR16_HI
12189 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
12190 case elfcpp::R_PPC64_REL16_HIGHERA
:
12191 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
12192 Reloc::addr16_ha2(view
, value
);
12195 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
12197 // R_PPC_EMB_NADDR16_HA
12200 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
12201 case elfcpp::R_PPC64_REL16_HIGHEST
:
12202 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
12203 Reloc::addr16_hi3(view
, value
);
12206 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
12208 // R_PPC_EMB_SDAI16
12211 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
12212 case elfcpp::R_PPC64_REL16_HIGHESTA
:
12213 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
12214 Reloc::addr16_ha3(view
, value
);
12217 case elfcpp::R_PPC64_DTPREL16_DS
:
12218 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
12220 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
12223 case elfcpp::R_PPC64_TPREL16_DS
:
12224 case elfcpp::R_PPC64_TPREL16_LO_DS
:
12226 // R_PPC_TLSGD, R_PPC_TLSLD
12229 case elfcpp::R_PPC64_ADDR16_DS
:
12230 case elfcpp::R_PPC64_ADDR16_LO_DS
:
12231 case elfcpp::R_PPC64_TOC16_DS
:
12232 case elfcpp::R_PPC64_TOC16_LO_DS
:
12233 case elfcpp::R_PPC64_GOT16_DS
:
12234 case elfcpp::R_PPC64_GOT16_LO_DS
:
12235 case elfcpp::R_PPC64_PLT16_LO_DS
:
12236 case elfcpp::R_PPC64_SECTOFF_DS
:
12237 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
12238 maybe_dq_reloc
= true;
12241 case elfcpp::R_POWERPC_ADDR14
:
12242 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
12243 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12244 case elfcpp::R_POWERPC_REL14
:
12245 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12246 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12247 status
= Reloc::addr14(view
, value
, overflow
);
12250 case elfcpp::R_POWERPC_COPY
:
12251 case elfcpp::R_POWERPC_GLOB_DAT
:
12252 case elfcpp::R_POWERPC_JMP_SLOT
:
12253 case elfcpp::R_POWERPC_RELATIVE
:
12254 case elfcpp::R_POWERPC_DTPMOD
:
12255 case elfcpp::R_PPC64_JMP_IREL
:
12256 case elfcpp::R_POWERPC_IRELATIVE
:
12257 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12258 _("unexpected reloc %u in object file"),
12262 case elfcpp::R_PPC64_TOCSAVE
:
12268 Symbol_location loc
;
12269 loc
.object
= relinfo
->object
;
12270 loc
.shndx
= relinfo
->data_shndx
;
12271 loc
.offset
= rela
.get_r_offset();
12272 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12273 if (tocsave
->find(loc
) != tocsave
->end())
12275 // If we've generated plt calls using this tocsave, then
12276 // the nop needs to be changed to save r2.
12277 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12278 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12279 elfcpp::Swap
<32, big_endian
>::
12280 writeval(iview
, std_2_1
+ target
->stk_toc());
12285 case elfcpp::R_PPC_EMB_SDA2I16
:
12286 case elfcpp::R_PPC_EMB_SDA2REL
:
12289 // R_PPC64_TLSGD, R_PPC64_TLSLD
12292 case elfcpp::R_PPC64_D34
:
12293 case elfcpp::R_PPC64_D34_LO
:
12294 case elfcpp::R_PPC64_PCREL34
:
12295 case elfcpp::R_PPC64_GOT_PCREL34
:
12296 case elfcpp::R_PPC64_PLT_PCREL34
:
12297 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12298 case elfcpp::R_PPC64_TPREL34
:
12299 case elfcpp::R_PPC64_DTPREL34
:
12300 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12301 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12302 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12303 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12306 status
= Reloc::addr34(view
, value
, overflow
);
12309 case elfcpp::R_PPC64_D34_HI30
:
12312 Reloc::addr34_hi(view
, value
);
12315 case elfcpp::R_PPC64_D34_HA30
:
12318 Reloc::addr34_ha(view
, value
);
12321 case elfcpp::R_PPC64_D28
:
12322 case elfcpp::R_PPC64_PCREL28
:
12325 status
= Reloc::addr28(view
, value
, overflow
);
12328 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12329 case elfcpp::R_PPC64_REL16_HIGHER34
:
12332 Reloc::addr16_higher34(view
, value
);
12335 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12336 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12339 Reloc::addr16_highera34(view
, value
);
12342 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12343 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12346 Reloc::addr16_highest34(view
, value
);
12349 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12350 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12353 Reloc::addr16_highesta34(view
, value
);
12356 case elfcpp::R_POWERPC_PLT32
:
12357 case elfcpp::R_POWERPC_PLTREL32
:
12358 case elfcpp::R_PPC_SDAREL16
:
12359 case elfcpp::R_POWERPC_ADDR30
:
12360 case elfcpp::R_PPC64_PLT64
:
12361 case elfcpp::R_PPC64_PLTREL64
:
12362 case elfcpp::R_PPC64_PLTGOT16
:
12363 case elfcpp::R_PPC64_PLTGOT16_LO
:
12364 case elfcpp::R_PPC64_PLTGOT16_HI
:
12365 case elfcpp::R_PPC64_PLTGOT16_HA
:
12366 case elfcpp::R_PPC64_PLTGOT16_DS
:
12367 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12368 case elfcpp::R_PPC_TOC16
:
12371 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12372 _("unsupported reloc %u"),
12377 if (maybe_dq_reloc
)
12380 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12382 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12383 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12384 && (insn
& 3) == 1))
12385 status
= Reloc::addr16_dq(view
, value
, overflow
);
12386 else if (size
== 64
12387 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12388 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12389 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12390 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12391 status
= Reloc::addr16_ds(view
, value
, overflow
);
12393 status
= Reloc::addr16(view
, value
, overflow
);
12396 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12399 && gsym
->is_undefined()
12400 && is_branch_reloc
<size
>(r_type
))))
12402 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12403 _("relocation overflow"));
12404 if (has_stub_value
)
12405 gold_info(_("try relinking with a smaller --stub-group-size"));
12411 // Relocate section data.
12413 template<int size
, bool big_endian
>
12415 Target_powerpc
<size
, big_endian
>::relocate_section(
12416 const Relocate_info
<size
, big_endian
>* relinfo
,
12417 unsigned int sh_type
,
12418 const unsigned char* prelocs
,
12419 size_t reloc_count
,
12420 Output_section
* output_section
,
12421 bool needs_special_offset_handling
,
12422 unsigned char* view
,
12424 section_size_type view_size
,
12425 const Reloc_symbol_changes
* reloc_symbol_changes
)
12427 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12428 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12429 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12430 Powerpc_comdat_behavior
;
12431 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12434 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12436 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12437 Powerpc_comdat_behavior
, Classify_reloc
>(
12443 needs_special_offset_handling
,
12447 reloc_symbol_changes
);
12450 template<int size
, bool big_endian
>
12451 class Powerpc_scan_relocatable_reloc
12454 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12455 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12456 static const int sh_type
= elfcpp::SHT_RELA
;
12458 // Return the symbol referred to by the relocation.
12459 static inline unsigned int
12460 get_r_sym(const Reltype
* reloc
)
12461 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12463 // Return the type of the relocation.
12464 static inline unsigned int
12465 get_r_type(const Reltype
* reloc
)
12466 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12468 // Return the strategy to use for a local symbol which is not a
12469 // section symbol, given the relocation type.
12470 inline Relocatable_relocs::Reloc_strategy
12471 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12473 if (r_type
== 0 && r_sym
== 0)
12474 return Relocatable_relocs::RELOC_DISCARD
;
12475 return Relocatable_relocs::RELOC_COPY
;
12478 // Return the strategy to use for a local symbol which is a section
12479 // symbol, given the relocation type.
12480 inline Relocatable_relocs::Reloc_strategy
12481 local_section_strategy(unsigned int, Relobj
*)
12483 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12486 // Return the strategy to use for a global symbol, given the
12487 // relocation type, the object, and the symbol index.
12488 inline Relocatable_relocs::Reloc_strategy
12489 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12492 && (r_type
== elfcpp::R_PPC_PLTREL24
12493 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12494 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12495 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12496 return Relocatable_relocs::RELOC_SPECIAL
;
12497 return Relocatable_relocs::RELOC_COPY
;
12501 // Scan the relocs during a relocatable link.
12503 template<int size
, bool big_endian
>
12505 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12506 Symbol_table
* symtab
,
12508 Sized_relobj_file
<size
, big_endian
>* object
,
12509 unsigned int data_shndx
,
12510 unsigned int sh_type
,
12511 const unsigned char* prelocs
,
12512 size_t reloc_count
,
12513 Output_section
* output_section
,
12514 bool needs_special_offset_handling
,
12515 size_t local_symbol_count
,
12516 const unsigned char* plocal_symbols
,
12517 Relocatable_relocs
* rr
)
12519 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12521 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12523 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12531 needs_special_offset_handling
,
12532 local_symbol_count
,
12537 // Scan the relocs for --emit-relocs.
12539 template<int size
, bool big_endian
>
12541 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12542 Symbol_table
* symtab
,
12544 Sized_relobj_file
<size
, big_endian
>* object
,
12545 unsigned int data_shndx
,
12546 unsigned int sh_type
,
12547 const unsigned char* prelocs
,
12548 size_t reloc_count
,
12549 Output_section
* output_section
,
12550 bool needs_special_offset_handling
,
12551 size_t local_symbol_count
,
12552 const unsigned char* plocal_syms
,
12553 Relocatable_relocs
* rr
)
12555 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12557 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12558 Emit_relocs_strategy
;
12560 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12562 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12570 needs_special_offset_handling
,
12571 local_symbol_count
,
12576 // Emit relocations for a section.
12577 // This is a modified version of the function by the same name in
12578 // target-reloc.h. Using relocate_special_relocatable for
12579 // R_PPC_PLTREL24 would require duplication of the entire body of the
12580 // loop, so we may as well duplicate the whole thing.
12582 template<int size
, bool big_endian
>
12584 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12585 const Relocate_info
<size
, big_endian
>* relinfo
,
12586 unsigned int sh_type
,
12587 const unsigned char* prelocs
,
12588 size_t reloc_count
,
12589 Output_section
* output_section
,
12590 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12592 Address view_address
,
12594 unsigned char* reloc_view
,
12595 section_size_type reloc_view_size
)
12597 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12599 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12600 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12601 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12602 // Offset from start of insn to d-field reloc.
12603 const int d_offset
= big_endian
? 2 : 0;
12605 Powerpc_relobj
<size
, big_endian
>* const object
12606 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12607 const unsigned int local_count
= object
->local_symbol_count();
12608 unsigned int got2_shndx
= object
->got2_shndx();
12609 Address got2_addend
= 0;
12610 if (got2_shndx
!= 0)
12612 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12613 gold_assert(got2_addend
!= invalid_address
);
12616 const bool relocatable
= parameters
->options().relocatable();
12618 unsigned char* pwrite
= reloc_view
;
12619 bool zap_next
= false;
12620 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12622 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12623 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12626 Reltype
reloc(prelocs
);
12627 Reltype_write
reloc_write(pwrite
);
12629 Address offset
= reloc
.get_r_offset();
12630 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12631 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12632 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12633 const unsigned int orig_r_sym
= r_sym
;
12634 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12635 = reloc
.get_r_addend();
12636 const Symbol
* gsym
= NULL
;
12640 // We could arrange to discard these and other relocs for
12641 // tls optimised sequences in the strategy methods, but for
12642 // now do as BFD ld does.
12643 r_type
= elfcpp::R_POWERPC_NONE
;
12647 // Get the new symbol index.
12648 Output_section
* os
= NULL
;
12649 if (r_sym
< local_count
)
12653 case Relocatable_relocs::RELOC_COPY
:
12654 case Relocatable_relocs::RELOC_SPECIAL
:
12657 r_sym
= object
->symtab_index(r_sym
);
12658 gold_assert(r_sym
!= -1U);
12662 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12664 // We are adjusting a section symbol. We need to find
12665 // the symbol table index of the section symbol for
12666 // the output section corresponding to input section
12667 // in which this symbol is defined.
12668 gold_assert(r_sym
< local_count
);
12670 unsigned int shndx
=
12671 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12672 gold_assert(is_ordinary
);
12673 os
= object
->output_section(shndx
);
12674 gold_assert(os
!= NULL
);
12675 gold_assert(os
->needs_symtab_index());
12676 r_sym
= os
->symtab_index();
12681 gold_unreachable();
12686 gsym
= object
->global_symbol(r_sym
);
12687 gold_assert(gsym
!= NULL
);
12688 if (gsym
->is_forwarder())
12689 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12691 gold_assert(gsym
->has_symtab_index());
12692 r_sym
= gsym
->symtab_index();
12695 // Get the new offset--the location in the output section where
12696 // this relocation should be applied.
12697 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12698 offset
+= offset_in_output_section
;
12701 section_offset_type sot_offset
=
12702 convert_types
<section_offset_type
, Address
>(offset
);
12703 section_offset_type new_sot_offset
=
12704 output_section
->output_offset(object
, relinfo
->data_shndx
,
12706 gold_assert(new_sot_offset
!= -1);
12707 offset
= new_sot_offset
;
12710 // In an object file, r_offset is an offset within the section.
12711 // In an executable or dynamic object, generated by
12712 // --emit-relocs, r_offset is an absolute address.
12715 offset
+= view_address
;
12716 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12717 offset
-= offset_in_output_section
;
12720 // Handle the reloc addend based on the strategy.
12721 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12723 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12725 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12726 addend
= psymval
->value(object
, addend
);
12727 // In a relocatable link, the symbol value is relative to
12728 // the start of the output section. For a non-relocatable
12729 // link, we need to adjust the addend.
12732 gold_assert(os
!= NULL
);
12733 addend
-= os
->address();
12736 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12740 if (addend
>= 32768)
12741 addend
+= got2_addend
;
12743 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12745 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12746 addend
-= d_offset
;
12748 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12750 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12751 addend
-= d_offset
+ 4;
12755 gold_unreachable();
12759 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12760 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12761 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12762 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12764 // First instruction of a global dynamic sequence,
12766 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12767 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12770 case tls::TLSOPT_TO_IE
:
12771 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12772 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12774 case tls::TLSOPT_TO_LE
:
12775 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12776 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12777 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12780 r_type
= elfcpp::R_POWERPC_NONE
;
12781 offset
-= d_offset
;
12788 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12789 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12790 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12791 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12793 // First instruction of a local dynamic sequence,
12795 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12796 if (tls_type
== tls::TLSOPT_TO_LE
)
12798 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12799 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12801 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12802 const Output_section
* os
= relinfo
->layout
->tls_segment()
12804 gold_assert(os
!= NULL
);
12805 gold_assert(os
->needs_symtab_index());
12806 r_sym
= os
->symtab_index();
12807 addend
= dtp_offset
;
12811 r_type
= elfcpp::R_POWERPC_NONE
;
12812 offset
-= d_offset
;
12816 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12817 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12818 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12819 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12821 // First instruction of initial exec sequence.
12822 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12823 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12825 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12826 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12827 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12830 r_type
= elfcpp::R_POWERPC_NONE
;
12831 offset
-= d_offset
;
12835 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12836 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12838 // Second instruction of a global dynamic sequence,
12839 // the __tls_get_addr call
12840 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12841 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12844 case tls::TLSOPT_TO_IE
:
12845 r_type
= elfcpp::R_POWERPC_NONE
;
12848 case tls::TLSOPT_TO_LE
:
12849 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12850 offset
+= d_offset
;
12857 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12858 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12860 // Second instruction of a local dynamic sequence,
12861 // the __tls_get_addr call
12862 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12863 if (tls_type
== tls::TLSOPT_TO_LE
)
12865 const Output_section
* os
= relinfo
->layout
->tls_segment()
12867 gold_assert(os
!= NULL
);
12868 gold_assert(os
->needs_symtab_index());
12869 r_sym
= os
->symtab_index();
12870 addend
= dtp_offset
;
12871 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12872 offset
+= d_offset
;
12876 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12878 // Second instruction of an initial exec sequence
12879 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12880 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12882 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12883 offset
+= d_offset
;
12888 reloc_write
.put_r_offset(offset
);
12889 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12890 reloc_write
.put_r_addend(addend
);
12892 pwrite
+= reloc_size
;
12895 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12896 == reloc_view_size
);
12899 // Return the value to use for a dynamic symbol which requires special
12900 // treatment. This is how we support equality comparisons of function
12901 // pointers across shared library boundaries, as described in the
12902 // processor specific ABI supplement.
12904 template<int size
, bool big_endian
>
12906 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12910 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12911 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12912 p
!= this->stub_tables_
.end();
12915 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12916 = (*p
)->find_plt_call_entry(gsym
);
12918 return (*p
)->stub_address() + ent
->off_
;
12921 else if (this->abiversion() >= 2)
12923 Address off
= this->glink_section()->find_global_entry(gsym
);
12924 if (off
!= invalid_address
)
12925 return this->glink_section()->global_entry_address() + off
;
12927 gold_unreachable();
12930 // Return the PLT address to use for a local symbol.
12931 template<int size
, bool big_endian
>
12933 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12934 const Relobj
* object
,
12935 unsigned int symndx
) const
12939 const Sized_relobj
<size
, big_endian
>* relobj
12940 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12941 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12942 p
!= this->stub_tables_
.end();
12945 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12946 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12948 return (*p
)->stub_address() + ent
->off_
;
12951 gold_unreachable();
12954 // Return the PLT address to use for a global symbol.
12955 template<int size
, bool big_endian
>
12957 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12958 const Symbol
* gsym
) const
12962 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12963 p
!= this->stub_tables_
.end();
12966 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12967 = (*p
)->find_plt_call_entry(gsym
);
12969 return (*p
)->stub_address() + ent
->off_
;
12972 else if (this->abiversion() >= 2)
12974 Address off
= this->glink_section()->find_global_entry(gsym
);
12975 if (off
!= invalid_address
)
12976 return this->glink_section()->global_entry_address() + off
;
12978 gold_unreachable();
12981 // Return the offset to use for the GOT_INDX'th got entry which is
12982 // for a local tls symbol specified by OBJECT, SYMNDX.
12983 template<int size
, bool big_endian
>
12985 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12986 const Relobj
* object
,
12987 unsigned int symndx
,
12988 Output_data_got_base
* got
,
12989 unsigned int got_indx
,
12990 uint64_t addend
) const
12992 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12993 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12994 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12996 for (Got_type got_type
= (size
== 32
12997 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
12998 got_type
<= GOT_TYPE_SMALL_TPREL
;
12999 got_type
= Got_type(got_type
+ 1))
13000 if (got_type
!= GOT_TYPE_SMALL
13001 && ppc_object
->local_has_got_offset(symndx
, got_type
, addend
))
13004 = ppc_object
->local_got_offset(symndx
, got_type
, addend
);
13005 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13007 if (off
== got_indx
* (size
/ 8)
13008 && (size
== 32 || got
== this->got_section(got_type
)))
13010 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13013 return -dtp_offset
;
13017 gold_unreachable();
13020 // Return the offset to use for the GOT_INDX'th got entry which is
13021 // for global tls symbol GSYM.
13022 template<int size
, bool big_endian
>
13024 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
13026 Output_data_got_base
* got
,
13027 unsigned int got_indx
,
13028 uint64_t addend
) const
13030 if (gsym
->type() == elfcpp::STT_TLS
)
13032 for (Got_type got_type
= (size
== 32
13033 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13034 got_type
<= GOT_TYPE_SMALL_TPREL
;
13035 got_type
= Got_type(got_type
+ 1))
13036 if (got_type
!= GOT_TYPE_SMALL
13037 && gsym
->has_got_offset(got_type
, addend
))
13039 unsigned int off
= gsym
->got_offset(got_type
, addend
);
13040 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13042 if (off
== got_indx
* (size
/ 8)
13043 && (size
== 32 || got
== this->got_section(got_type
)))
13045 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13048 return -dtp_offset
;
13052 gold_unreachable();
13055 // The selector for powerpc object files.
13057 template<int size
, bool big_endian
>
13058 class Target_selector_powerpc
: public Target_selector
13061 Target_selector_powerpc()
13062 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
13065 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
13066 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
13068 ? (big_endian
? "elf64ppc" : "elf64lppc")
13069 : (big_endian
? "elf32ppc" : "elf32lppc")))
13073 do_instantiate_target()
13074 { return new Target_powerpc
<size
, big_endian
>(); }
13077 Target_selector_powerpc
<32, true> target_selector_ppc32
;
13078 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
13079 Target_selector_powerpc
<64, true> target_selector_ppc64
;
13080 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
13082 // Instantiate these constants for -O0
13083 template<int size
, bool big_endian
>
13084 const typename Output_data_glink
<size
, big_endian
>::Address
13085 Output_data_glink
<size
, big_endian
>::invalid_address
;
13086 template<int size
, bool big_endian
>
13087 const typename Stub_table
<size
, big_endian
>::Address
13088 Stub_table
<size
, big_endian
>::invalid_address
;
13089 template<int size
, bool big_endian
>
13090 const typename Target_powerpc
<size
, big_endian
>::Address
13091 Target_powerpc
<size
, big_endian
>::invalid_address
;
13093 } // End anonymous namespace.