1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2022 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())
4343 const section_size_type offset
= this->offset();
4344 const section_size_type oview_size
4345 = convert_to_section_size_type(this->data_size());
4346 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4347 unsigned char* pov
= oview
;
4348 unsigned char* endpov
= oview
+ oview_size
;
4350 for (typename
std::vector
<Local_plt_ent
>::iterator e
4351 = this->sym_ents_
.begin();
4352 e
!= this->sym_ents_
.end();
4355 typename
elfcpp::Elf_types
<size
>::Elf_Addr val
;
4356 Sized_symbol
<size
>* gsym
= NULL
;
4357 Powerpc_relobj
<size
, big_endian
>* obj
= NULL
;
4358 if (e
->rsym_
== -1u)
4360 gsym
= static_cast<Sized_symbol
<size
>*>(e
->u
.gsym_
);
4361 val
= gsym
->value();
4365 obj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(e
->u
.obj_
);
4366 val
= obj
->local_symbol(e
->rsym_
)->value(obj
, 0);
4368 if (this->targ_
->abiversion() >= 2)
4370 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4376 this->targ_
->symval_for_branch(this->symtab_
, gsym
, obj
,
4378 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4380 val
= this->targ_
->toc_pointer();
4381 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, val
);
4383 if (this->plt_entry_size() > 16)
4385 elfcpp::Swap
<size
, big_endian
>::writeval(pov
, 0);
4390 gold_assert(pov
== endpov
);
4393 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4395 const section_size_type offset
= this->offset();
4396 const section_size_type oview_size
4397 = convert_to_section_size_type(this->data_size());
4398 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4399 unsigned char* pov
= oview
;
4400 unsigned char* endpov
= oview
+ oview_size
;
4402 // The address of the .glink branch table
4403 const Output_data_glink
<size
, big_endian
>* glink
4404 = this->targ_
->glink_section();
4405 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4407 while (pov
< endpov
)
4409 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4414 of
->write_output_view(offset
, oview_size
, oview
);
4418 // Create the PLT section.
4420 template<int size
, bool big_endian
>
4422 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4425 if (this->plt_
== NULL
)
4427 if (this->got_
== NULL
)
4428 this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
4430 if (this->glink_
== NULL
)
4431 make_glink_section(layout
);
4433 // Ensure that .rela.dyn always appears before .rela.plt This is
4434 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4435 // needs to include .rela.plt in its range.
4436 this->rela_dyn_section(layout
);
4438 Reloc_section
* plt_rel
= new Reloc_section(false);
4439 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4440 elfcpp::SHF_ALLOC
, plt_rel
,
4441 ORDER_DYNAMIC_PLT_RELOCS
, false);
4443 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, plt_rel
,
4445 layout
->add_output_section_data(".plt",
4447 ? elfcpp::SHT_PROGBITS
4448 : elfcpp::SHT_NOBITS
),
4449 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4456 Output_section
* rela_plt_os
= plt_rel
->output_section();
4457 rela_plt_os
->set_info_section(this->plt_
->output_section());
4461 // Create the IPLT section.
4463 template<int size
, bool big_endian
>
4465 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4468 if (this->iplt_
== NULL
)
4470 this->make_plt_section(symtab
, layout
);
4471 this->make_lplt_section(symtab
, layout
);
4473 Reloc_section
* iplt_rel
= new Reloc_section(false);
4474 if (this->rela_dyn_
->output_section())
4475 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4477 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, iplt_rel
,
4479 if (this->plt_
->output_section())
4480 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4484 // Create the LPLT section.
4486 template<int size
, bool big_endian
>
4488 Target_powerpc
<size
, big_endian
>::make_lplt_section(Symbol_table
* symtab
,
4491 if (this->lplt_
== NULL
)
4493 Reloc_section
* lplt_rel
= NULL
;
4494 if (parameters
->options().output_is_position_independent())
4496 lplt_rel
= new Reloc_section(false);
4497 this->rela_dyn_section(layout
);
4498 if (this->rela_dyn_
->output_section())
4499 this->rela_dyn_
->output_section()
4500 ->add_output_section_data(lplt_rel
);
4503 = new Output_data_plt_powerpc
<size
, big_endian
>(this, symtab
, lplt_rel
,
4505 this->make_brlt_section(layout
);
4506 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4507 this->brlt_section_
->output_section()
4508 ->add_output_section_data(this->lplt_
);
4510 layout
->add_output_section_data(".branch_lt",
4511 elfcpp::SHT_PROGBITS
,
4512 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4519 // A section for huge long branch addresses, similar to plt section.
4521 template<int size
, bool big_endian
>
4522 class Output_data_brlt_powerpc
: public Output_section_data_build
4525 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4526 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4527 size
, big_endian
> Reloc_section
;
4529 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4530 Reloc_section
* brlt_rel
)
4531 : Output_section_data_build(size
== 32 ? 4 : 8),
4539 this->reset_data_size();
4540 this->rel_
->reset_data_size();
4544 finalize_brlt_sizes()
4546 this->finalize_data_size();
4547 this->rel_
->finalize_data_size();
4550 // Add a reloc for an entry in the BRLT.
4552 add_reloc(Address to
, unsigned int off
)
4553 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4555 // Update section and reloc section size.
4557 set_current_size(unsigned int num_branches
)
4559 this->reset_address_and_file_offset();
4560 this->set_current_data_size(num_branches
* 16);
4561 this->finalize_data_size();
4562 Output_section
* os
= this->output_section();
4563 os
->set_section_offsets_need_adjustment();
4564 if (this->rel_
!= NULL
)
4566 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4567 this->rel_
->reset_address_and_file_offset();
4568 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4569 this->rel_
->finalize_data_size();
4570 Output_section
* os
= this->rel_
->output_section();
4571 os
->set_section_offsets_need_adjustment();
4577 do_adjust_output_section(Output_section
* os
)
4582 // Write to a map file.
4584 do_print_to_mapfile(Mapfile
* mapfile
) const
4585 { mapfile
->print_output_data(this, "** BRLT"); }
4588 // Write out the BRLT data.
4590 do_write(Output_file
*);
4592 // The reloc section.
4593 Reloc_section
* rel_
;
4594 Target_powerpc
<size
, big_endian
>* targ_
;
4597 // Make the branch lookup table section.
4599 template<int size
, bool big_endian
>
4601 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4603 if (size
== 64 && this->brlt_section_
== NULL
)
4605 Reloc_section
* brlt_rel
= NULL
;
4606 bool is_pic
= parameters
->options().output_is_position_independent();
4609 // When PIC we can't fill in .branch_lt but must initialise at
4610 // runtime via dynamic relocations.
4611 this->rela_dyn_section(layout
);
4612 brlt_rel
= new Reloc_section(false);
4613 if (this->rela_dyn_
->output_section())
4614 this->rela_dyn_
->output_section()
4615 ->add_output_section_data(brlt_rel
);
4618 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4619 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4620 this->plt_
->output_section()
4621 ->add_output_section_data(this->brlt_section_
);
4623 layout
->add_output_section_data(".branch_lt",
4624 elfcpp::SHT_PROGBITS
,
4625 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4626 this->brlt_section_
,
4632 // Write out .branch_lt when non-PIC.
4634 template<int size
, bool big_endian
>
4636 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4638 if (size
== 64 && !parameters
->options().output_is_position_independent())
4640 const section_size_type offset
= this->offset();
4641 const section_size_type oview_size
4642 = convert_to_section_size_type(this->data_size());
4643 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4645 this->targ_
->write_branch_lookup_table(oview
);
4646 of
->write_output_view(offset
, oview_size
, oview
);
4650 static inline uint32_t
4656 static inline uint32_t
4662 static inline uint32_t
4665 return hi(a
+ 0x8000);
4668 static inline uint64_t
4671 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4674 static inline uint64_t
4677 return (v
+ (1ULL << 33)) >> 34;
4683 static const unsigned char eh_frame_cie
[12];
4687 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4690 'z', 'R', 0, // Augmentation string.
4691 4, // Code alignment.
4692 0x80 - size
/ 8 , // Data alignment.
4694 1, // Augmentation size.
4695 (elfcpp::DW_EH_PE_pcrel
4696 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4697 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4700 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4701 static const unsigned char glink_eh_frame_fde_64v1
[] =
4703 0, 0, 0, 0, // Replaced with offset to .glink.
4704 0, 0, 0, 0, // Replaced with size of .glink.
4705 0, // Augmentation size.
4706 elfcpp::DW_CFA_advance_loc
+ 2,
4707 elfcpp::DW_CFA_register
, 65, 12,
4708 elfcpp::DW_CFA_advance_loc
+ 4,
4709 elfcpp::DW_CFA_restore_extended
, 65
4712 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4713 static const unsigned char glink_eh_frame_fde_64v2
[] =
4715 0, 0, 0, 0, // Replaced with offset to .glink.
4716 0, 0, 0, 0, // Replaced with size of .glink.
4717 0, // Augmentation size.
4718 elfcpp::DW_CFA_advance_loc
+ 2,
4719 elfcpp::DW_CFA_register
, 65, 0,
4720 elfcpp::DW_CFA_advance_loc
+ 2,
4721 elfcpp::DW_CFA_restore_extended
, 65
4724 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4726 0, 0, 0, 0, // Replaced with offset to .glink.
4727 0, 0, 0, 0, // Replaced with size of .glink.
4728 0, // Augmentation size.
4729 elfcpp::DW_CFA_advance_loc
+ 3,
4730 elfcpp::DW_CFA_register
, 65, 0,
4731 elfcpp::DW_CFA_advance_loc
+ 2,
4732 elfcpp::DW_CFA_restore_extended
, 65
4735 // Describe __glink_PLTresolve use of LR, 32-bit version.
4736 static const unsigned char glink_eh_frame_fde_32
[] =
4738 0, 0, 0, 0, // Replaced with offset to .glink.
4739 0, 0, 0, 0, // Replaced with size of .glink.
4740 0, // Augmentation size.
4741 elfcpp::DW_CFA_advance_loc
+ 2,
4742 elfcpp::DW_CFA_register
, 65, 0,
4743 elfcpp::DW_CFA_advance_loc
+ 4,
4744 elfcpp::DW_CFA_restore_extended
, 65
4747 static const unsigned char default_fde
[] =
4749 0, 0, 0, 0, // Replaced with offset to stubs.
4750 0, 0, 0, 0, // Replaced with size of stubs.
4751 0, // Augmentation size.
4752 elfcpp::DW_CFA_nop
, // Pad.
4757 template<bool big_endian
>
4759 write_insn(unsigned char* p
, uint32_t v
)
4761 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4765 static inline unsigned int
4768 if (!parameters
->options().user_set_plt_align())
4769 return size
== 64 ? 32 : 8;
4770 return 1 << parameters
->options().plt_align();
4773 // Stub_table holds information about plt and long branch stubs.
4774 // Stubs are built in an area following some input section determined
4775 // by group_sections(). This input section is converted to a relaxed
4776 // input section allowing it to be resized to accommodate the stubs
4778 template<int size
, bool big_endian
>
4779 class Stub_table
: public Output_relaxed_input_section
4784 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4785 : off_(off
), indx_(indx
), tocoff_(0), p9off_(0), tsize_ (0), iter_(0),
4786 toc_(0), notoc_(0), p9notoc_(0), r2save_(0), localentry0_(0)
4791 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4792 // toc stub, p9off_ is offset to p9notoc stub
4793 unsigned int tocoff_
: 8;
4794 unsigned int p9off_
: 8;
4795 // The size of the toc stub, used to locate blr on tls_get_addr stub.
4796 unsigned int tsize_
: 8;
4797 // Stub revision management
4798 unsigned int iter_
: 1;
4799 // The three types of stubs.
4800 unsigned int toc_
: 1;
4801 unsigned int notoc_
: 1;
4802 unsigned int p9notoc_
: 1;
4803 // Each with a possible variant saving r2 first
4804 unsigned int r2save_
: 1;
4805 // Handy cached info from symbol
4806 unsigned int localentry0_
: 1;
4808 struct Branch_stub_ent
4810 Branch_stub_ent(unsigned int off
)
4811 : off_(off
), tocoff_(0), p9off_(0), iter_(0), toc_(0), notoc_(0),
4812 p9notoc_(0), save_res_(0), other_(0)
4816 // off_ points at p10 notoc stub, tocoff_ is offset from there to
4817 // toc stub, p9off_ is offset to p9notoc stub
4818 unsigned int tocoff_
: 8;
4819 unsigned int p9off_
: 8;
4820 // Stub revision management
4821 unsigned int iter_
: 1;
4822 // Four types of stubs.
4823 unsigned int toc_
: 1;
4824 unsigned int notoc_
: 1;
4825 unsigned int p9notoc_
: 1;
4826 unsigned int save_res_
: 1;
4827 // Handy cached info from symbol
4828 unsigned int other_
: 3;
4830 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4831 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4833 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4834 Output_section
* output_section
,
4835 const Output_section::Input_section
* owner
,
4837 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4839 ->section_addralign(owner
->shndx())),
4840 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4841 orig_data_size_(owner
->current_data_size()),
4842 plt_size_(0), last_plt_size_(0),
4843 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4844 need_save_res_(false), need_resize_(false), resizing_(false),
4847 this->set_output_section(output_section
);
4849 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4850 new_relaxed
.push_back(this);
4851 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4854 // Add a plt call stub.
4856 add_plt_call_entry(Address
,
4857 const Sized_relobj_file
<size
, big_endian
>*,
4864 add_plt_call_entry(Address
,
4865 const Sized_relobj_file
<size
, big_endian
>*,
4871 // Find a given plt call stub.
4873 find_plt_call_entry(const Symbol
*) const;
4876 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4877 unsigned int) const;
4880 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4886 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4891 // Add a long branch stub.
4893 add_long_branch_entry(unsigned int, Address
, Address
, unsigned int, bool);
4895 const Branch_stub_ent
*
4896 find_long_branch_entry(Address
) const;
4899 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4901 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4902 if (max_branch_offset
== 0)
4904 gold_assert(from
!= invalid_address
);
4905 Address loc
= off
+ this->stub_address();
4906 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4910 clear_stubs(bool all
)
4912 this->plt_call_stubs_
.clear();
4913 this->plt_size_
= 0;
4914 this->long_branch_stubs_
.clear();
4915 this->branch_size_
= 0;
4916 this->need_save_res_
= false;
4919 this->last_plt_size_
= 0;
4920 this->last_branch_size_
= 0;
4926 { return need_resize_
; }
4929 set_resizing(bool val
)
4931 this->resizing_
= val
;
4934 this->need_resize_
= false;
4935 this->plt_size_
= 0;
4936 this->branch_size_
= 0;
4937 this->need_save_res_
= false;
4942 set_address_and_size(const Output_section
* os
, Address off
)
4944 Address start_off
= off
;
4945 off
+= this->orig_data_size_
;
4946 Address my_size
= this->plt_size_
+ this->branch_size_
;
4947 if (this->need_save_res_
)
4948 my_size
+= this->targ_
->savres_section()->data_size();
4950 off
= align_address(off
, this->stub_align());
4951 // Include original section size and alignment padding in size
4952 my_size
+= off
- start_off
;
4953 // Ensure new size is always larger than min size
4954 // threshold. Alignment requirement is included in "my_size", so
4955 // increase "my_size" does not invalidate alignment.
4956 if (my_size
< this->min_size_threshold_
)
4957 my_size
= this->min_size_threshold_
;
4958 this->reset_address_and_file_offset();
4959 this->set_current_data_size(my_size
);
4960 this->set_address_and_file_offset(os
->address() + start_off
,
4961 os
->offset() + start_off
);
4966 stub_address() const
4968 return align_address(this->address() + this->orig_data_size_
,
4969 this->stub_align());
4975 return align_address(this->offset() + this->orig_data_size_
,
4976 this->stub_align());
4981 { return this->plt_size_
; }
4985 { return this->branch_size_
; }
4988 set_min_size_threshold(Address min_size
)
4989 { this->min_size_threshold_
= min_size
; }
4992 define_stub_syms(Symbol_table
*);
4997 Output_section
* os
= this->output_section();
4998 if (os
->addralign() < this->stub_align())
5000 os
->set_addralign(this->stub_align());
5001 // FIXME: get rid of the insane checkpointing.
5002 // We can't increase alignment of the input section to which
5003 // stubs are attached; The input section may be .init which
5004 // is pasted together with other .init sections to form a
5005 // function. Aligning might insert zero padding resulting in
5006 // sigill. However we do need to increase alignment of the
5007 // output section so that the align_address() on offset in
5008 // set_address_and_size() adds the same padding as the
5009 // align_address() on address in stub_address().
5010 // What's more, we need this alignment for the layout done in
5011 // relaxation_loop_body() so that the output section starts at
5012 // a suitably aligned address.
5013 os
->checkpoint_set_addralign(this->stub_align());
5015 if (this->last_plt_size_
!= this->plt_size_
5016 || this->last_branch_size_
!= this->branch_size_
)
5018 this->last_plt_size_
= this->plt_size_
;
5019 this->last_branch_size_
= this->branch_size_
;
5025 // Add .eh_frame info for this stub section.
5027 add_eh_frame(Layout
* layout
);
5029 // Remove .eh_frame info for this stub section.
5031 remove_eh_frame(Layout
* layout
);
5033 Target_powerpc
<size
, big_endian
>*
5039 class Plt_stub_key_hash
;
5040 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
5041 Plt_stub_key_hash
> Plt_stub_entries
;
5042 class Branch_stub_key
;
5043 class Branch_stub_key_hash
;
5044 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
5045 Branch_stub_key_hash
> Branch_stub_entries
;
5047 // Alignment of stub section.
5051 unsigned int min_align
= size
== 64 ? 32 : 16;
5052 unsigned int user_align
= 1 << parameters
->options().plt_align();
5053 return std::max(user_align
, min_align
);
5056 // Return the plt offset for the given call stub.
5058 plt_off(typename
Plt_stub_entries::const_iterator p
,
5059 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
5061 const Symbol
* gsym
= p
->first
.sym_
;
5063 return this->targ_
->plt_off(gsym
, sec
);
5066 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
5067 unsigned int local_sym_index
= p
->first
.locsym_
;
5068 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
5072 // Size of a given plt call stub.
5074 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
5077 plt_call_align(unsigned int bytes
) const
5079 unsigned int align
= param_plt_align
<size
>();
5080 return (bytes
+ align
- 1) & -align
;
5083 // Return long branch stub size.
5085 branch_stub_size(typename
Branch_stub_entries::iterator p
,
5089 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
5092 build_tls_opt_tail(unsigned char* p
);
5095 plt_error(const Plt_stub_key
& p
);
5099 do_write(Output_file
*);
5101 // Plt call stub keys.
5105 Plt_stub_key(const Symbol
* sym
)
5106 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5109 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5110 unsigned int locsym_index
)
5111 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5114 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5116 unsigned int r_type
,
5118 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5121 this->addend_
= addend
;
5122 else if (parameters
->options().output_is_position_independent()
5123 && (r_type
== elfcpp::R_PPC_PLTREL24
5124 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5126 this->addend_
= addend
;
5127 if (this->addend_
>= 32768)
5128 this->object_
= object
;
5132 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5133 unsigned int locsym_index
,
5134 unsigned int r_type
,
5136 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5139 this->addend_
= addend
;
5140 else if (parameters
->options().output_is_position_independent()
5141 && (r_type
== elfcpp::R_PPC_PLTREL24
5142 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5143 this->addend_
= addend
;
5146 bool operator==(const Plt_stub_key
& that
) const
5148 return (this->sym_
== that
.sym_
5149 && this->object_
== that
.object_
5150 && this->addend_
== that
.addend_
5151 && this->locsym_
== that
.locsym_
);
5155 const Sized_relobj_file
<size
, big_endian
>* object_
;
5156 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5157 unsigned int locsym_
;
5160 class Plt_stub_key_hash
5163 size_t operator()(const Plt_stub_key
& ent
) const
5165 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5166 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5172 // Long branch stub keys.
5173 class Branch_stub_key
5176 Branch_stub_key(Address to
)
5180 bool operator==(const Branch_stub_key
& that
) const
5182 return this->dest_
== that
.dest_
;
5188 class Branch_stub_key_hash
5191 size_t operator()(const Branch_stub_key
& key
) const
5192 { return key
.dest_
; }
5195 // In a sane world this would be a global.
5196 Target_powerpc
<size
, big_endian
>* targ_
;
5197 // Map sym/object/addend to stub offset.
5198 Plt_stub_entries plt_call_stubs_
;
5199 // Map destination address to stub offset.
5200 Branch_stub_entries long_branch_stubs_
;
5201 // size of input section
5202 section_size_type orig_data_size_
;
5204 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5205 // Some rare cases cause (PR/20529) fluctuation in stub table
5206 // size, which leads to an endless relax loop. This is to be fixed
5207 // by, after the first few iterations, allowing only increase of
5208 // stub table size. This variable sets the minimal possible size of
5209 // a stub table, it is zero for the first few iterations, then
5210 // increases monotonically.
5211 Address min_size_threshold_
;
5212 // Set if this stub group needs a copy of out-of-line register
5213 // save/restore functions.
5214 bool need_save_res_
;
5215 // Set when notoc_/r2save_ changes after sizing a stub
5217 // Set when resizing stubs
5219 // Per stub table unique identifier.
5223 // Add a plt call stub, if we do not already have one for this
5224 // sym/object/addend combo.
5226 template<int size
, bool big_endian
>
5228 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5230 const Sized_relobj_file
<size
, big_endian
>* object
,
5232 unsigned int r_type
,
5236 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5237 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5238 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5239 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5243 && this->targ_
->is_elfv2_localentry0(gsym
))
5245 p
.first
->second
.localentry0_
= 1;
5246 this->targ_
->set_has_localentry0();
5248 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5249 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5251 if (this->targ_
->power10_stubs()
5252 && (!this->targ_
->power10_stubs_auto()
5253 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5255 if (!p
.second
&& !p
.first
->second
.notoc_
)
5256 this->need_resize_
= true;
5257 p
.first
->second
.notoc_
= 1;
5261 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5262 this->need_resize_
= true;
5263 p
.first
->second
.p9notoc_
= 1;
5268 if (!p
.second
&& !p
.first
->second
.toc_
)
5269 this->need_resize_
= true;
5270 p
.first
->second
.toc_
= 1;
5271 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5273 if (!p
.second
&& !p
.first
->second
.r2save_
)
5274 this->need_resize_
= true;
5275 p
.first
->second
.r2save_
= 1;
5279 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5281 if (this->resizing_
)
5283 p
.first
->second
.iter_
= 1;
5284 p
.first
->second
.off_
= this->plt_size_
;
5286 this->plt_size_
+= this->plt_call_size(p
.first
);
5287 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5288 this->targ_
->set_has_tls_get_addr_opt();
5290 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5293 template<int size
, bool big_endian
>
5295 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5297 const Sized_relobj_file
<size
, big_endian
>* object
,
5298 unsigned int locsym_index
,
5299 unsigned int r_type
,
5303 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5304 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5305 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5306 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5310 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5312 p
.first
->second
.localentry0_
= 1;
5313 this->targ_
->set_has_localentry0();
5315 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5316 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
5318 if (this->targ_
->power10_stubs()
5319 && (!this->targ_
->power10_stubs_auto()
5320 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5322 if (!p
.second
&& !p
.first
->second
.notoc_
)
5323 this->need_resize_
= true;
5324 p
.first
->second
.notoc_
= 1;
5328 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5329 this->need_resize_
= true;
5330 p
.first
->second
.p9notoc_
= 1;
5335 if (!p
.second
&& !p
.first
->second
.toc_
)
5336 this->need_resize_
= true;
5337 p
.first
->second
.toc_
= 1;
5338 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5340 if (!p
.second
&& !p
.first
->second
.r2save_
)
5341 this->need_resize_
= true;
5342 p
.first
->second
.r2save_
= 1;
5346 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5348 if (this->resizing_
)
5350 p
.first
->second
.iter_
= 1;
5351 p
.first
->second
.off_
= this->plt_size_
;
5353 this->plt_size_
+= this->plt_call_size(p
.first
);
5355 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5358 // Find a plt call stub.
5360 template<int size
, bool big_endian
>
5361 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5362 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5363 const Sized_relobj_file
<size
, big_endian
>* object
,
5365 unsigned int r_type
,
5366 Address addend
) const
5368 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5369 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5370 if (p
== this->plt_call_stubs_
.end())
5375 template<int size
, bool big_endian
>
5376 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5377 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5379 Plt_stub_key
key(gsym
);
5380 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5381 if (p
== this->plt_call_stubs_
.end())
5386 template<int size
, bool big_endian
>
5387 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5388 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5389 const Sized_relobj_file
<size
, big_endian
>* object
,
5390 unsigned int locsym_index
,
5391 unsigned int r_type
,
5392 Address addend
) const
5394 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5395 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5396 if (p
== this->plt_call_stubs_
.end())
5401 template<int size
, bool big_endian
>
5402 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5403 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5404 const Sized_relobj_file
<size
, big_endian
>* object
,
5405 unsigned int locsym_index
) const
5407 Plt_stub_key
key(object
, locsym_index
);
5408 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5409 if (p
== this->plt_call_stubs_
.end())
5414 // Add a long branch stub if we don't already have one to given
5417 template<int size
, bool big_endian
>
5419 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5420 unsigned int r_type
,
5426 Branch_stub_key
key(to
);
5427 Branch_stub_ent
ent(this->branch_size_
);
5428 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5429 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5432 if (!p
.second
&& !p
.first
->second
.save_res_
)
5433 this->need_resize_
= true;
5434 p
.first
->second
.save_res_
= true;
5437 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
5438 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
))
5440 if (this->targ_
->power10_stubs()
5441 && (!this->targ_
->power10_stubs_auto()
5442 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
))
5444 if (!p
.second
&& !p
.first
->second
.notoc_
)
5445 this->need_resize_
= true;
5446 p
.first
->second
.notoc_
= true;
5450 if (!p
.second
&& !p
.first
->second
.p9notoc_
)
5451 this->need_resize_
= true;
5452 p
.first
->second
.p9notoc_
= true;
5457 if (!p
.second
&& !p
.first
->second
.toc_
)
5458 this->need_resize_
= true;
5459 p
.first
->second
.toc_
= true;
5461 if (size
== 64 && p
.first
->second
.other_
== 0)
5462 p
.first
->second
.other_
= other
;
5463 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5465 if (this->resizing_
)
5467 p
.first
->second
.iter_
= 1;
5468 p
.first
->second
.off_
= this->branch_size_
;
5471 this->need_save_res_
= true;
5474 bool need_lt
= false;
5475 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5476 this->branch_size_
+= stub_size
;
5477 if (size
== 64 && need_lt
)
5478 this->targ_
->add_branch_lookup_table(to
);
5481 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5484 // Find long branch stub offset.
5486 template<int size
, bool big_endian
>
5487 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5488 Stub_table
<size
, big_endian
>::find_long_branch_entry(Address to
) const
5490 Branch_stub_key
key(to
);
5491 typename
Branch_stub_entries::const_iterator p
5492 = this->long_branch_stubs_
.find(key
);
5493 if (p
== this->long_branch_stubs_
.end())
5498 template<bool big_endian
>
5500 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5504 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5505 else if (delta
< 256)
5507 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5508 fde
.push_back(delta
);
5510 else if (delta
< 65536)
5512 fde
.resize(fde
.size() + 3);
5513 unsigned char *p
= &*fde
.end() - 3;
5514 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5515 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5519 fde
.resize(fde
.size() + 5);
5520 unsigned char *p
= &*fde
.end() - 5;
5521 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5522 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5526 template<typename T
>
5528 stub_sort(T s1
, T s2
)
5530 return s1
->second
.off_
< s2
->second
.off_
;
5533 // Add .eh_frame info for this stub section. Unlike other linker
5534 // generated .eh_frame this is added late in the link, because we
5535 // only want the .eh_frame info if this particular stub section is
5538 template<int size
, bool big_endian
>
5540 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5543 || !parameters
->options().ld_generated_unwind_info())
5546 // Since we add stub .eh_frame info late, it must be placed
5547 // after all other linker generated .eh_frame info so that
5548 // merge mapping need not be updated for input sections.
5549 // There is no provision to use a different CIE to that used
5551 if (!this->targ_
->has_glink())
5554 typedef typename
Plt_stub_entries::iterator plt_iter
;
5555 std::vector
<plt_iter
> calls
;
5556 if (!this->plt_call_stubs_
.empty())
5557 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5558 cs
!= this->plt_call_stubs_
.end();
5560 if (cs
->second
.p9notoc_
5562 && cs
->second
.r2save_
5563 && !cs
->second
.localentry0_
5564 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)))
5565 calls
.push_back(cs
);
5566 if (calls
.size() > 1)
5567 std::stable_sort(calls
.begin(), calls
.end(),
5568 stub_sort
<plt_iter
>);
5570 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5571 std::vector
<branch_iter
> branches
;
5572 if (!this->long_branch_stubs_
.empty()
5573 && !this->targ_
->power10_stubs())
5574 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5575 bs
!= this->long_branch_stubs_
.end();
5577 if (bs
->second
.notoc_
)
5578 branches
.push_back(bs
);
5579 if (branches
.size() > 1)
5580 std::stable_sort(branches
.begin(), branches
.end(),
5581 stub_sort
<branch_iter
>);
5583 if (calls
.empty() && branches
.empty())
5586 unsigned int last_eh_loc
= 0;
5587 // offset pcrel sdata4, size udata4, and augmentation size byte.
5588 std::vector
<unsigned char> fde(9, 0);
5590 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5592 plt_iter cs
= calls
[i
];
5593 unsigned int off
= cs
->second
.off_
;
5594 // The __tls_get_addr_opt call stub needs to describe where
5595 // it saves LR, to support exceptions that might be thrown
5596 // from __tls_get_addr, and to support asynchronous exceptions.
5597 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5601 && cs
->second
.r2save_
5602 && !cs
->second
.localentry0_
)
5604 off
+= cs
->second
.tocoff_
+ 2 * 4;
5605 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5606 fde
.resize(fde
.size() + 6);
5607 unsigned char* p
= &*fde
.end() - 6;
5608 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5610 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5611 unsigned int delta
= cs
->second
.tsize_
- 9 * 4 - 4;
5612 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5613 *p
++ = elfcpp::DW_CFA_restore_extended
;
5615 last_eh_loc
= off
+ delta
;
5616 off
= cs
->second
.off_
+ 7 * 4;
5619 // notoc stubs also should describe LR changes, to support
5620 // asynchronous exceptions.
5621 if (cs
->second
.p9notoc_
)
5623 off
+= cs
->second
.p9off_
;
5624 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5625 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5626 fde
.resize(fde
.size() + 6);
5627 unsigned char* p
= &*fde
.end() - 6;
5628 *p
++ = elfcpp::DW_CFA_register
;
5631 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5632 *p
++ = elfcpp::DW_CFA_restore_extended
;
5634 last_eh_loc
= off
+ 8;
5638 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5640 branch_iter bs
= branches
[i
];
5641 unsigned int off
= bs
->second
.off_
+ 8;
5642 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5643 fde
.resize(fde
.size() + 6);
5644 unsigned char* p
= &*fde
.end() - 6;
5645 *p
++ = elfcpp::DW_CFA_register
;
5648 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5649 *p
++ = elfcpp::DW_CFA_restore_extended
;
5651 last_eh_loc
= off
+ 8;
5654 layout
->add_eh_frame_for_plt(this,
5655 Eh_cie
<size
>::eh_frame_cie
,
5656 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5657 &*fde
.begin(), fde
.size());
5660 template<int size
, bool big_endian
>
5662 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5665 && parameters
->options().ld_generated_unwind_info()
5666 && this->targ_
->has_glink())
5667 layout
->remove_eh_frame_for_plt(this,
5668 Eh_cie
<size
>::eh_frame_cie
,
5669 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5672 // A class to handle .glink.
5674 template<int size
, bool big_endian
>
5675 class Output_data_glink
: public Output_section_data
5678 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5679 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5681 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5682 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5683 end_branch_table_(), ge_size_(0)
5687 add_eh_frame(Layout
* layout
);
5690 add_global_entry(const Symbol
*);
5693 find_global_entry(const Symbol
*) const;
5696 global_entry_align(unsigned int off
) const
5698 unsigned int align
= param_plt_align
<size
>();
5699 return (off
+ align
- 1) & -align
;
5703 global_entry_off() const
5705 return this->global_entry_align(this->end_branch_table_
);
5709 global_entry_address() const
5711 gold_assert(this->is_data_size_valid());
5712 return this->address() + this->global_entry_off();
5716 pltresolve_size() const
5720 + (this->targ_
->abiversion() < 2 ? 11 * 4
5721 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5726 // Write to a map file.
5728 do_print_to_mapfile(Mapfile
* mapfile
) const
5729 { mapfile
->print_output_data(this, _("** glink")); }
5733 set_final_data_size();
5737 do_write(Output_file
*);
5739 // Allows access to .got and .plt for do_write.
5740 Target_powerpc
<size
, big_endian
>* targ_
;
5742 // Map sym to stub offset.
5743 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5744 Global_entry_stub_entries global_entry_stubs_
;
5746 unsigned int end_branch_table_
, ge_size_
;
5749 template<int size
, bool big_endian
>
5751 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5753 if (!parameters
->options().ld_generated_unwind_info())
5758 if (this->targ_
->abiversion() < 2)
5759 layout
->add_eh_frame_for_plt(this,
5760 Eh_cie
<64>::eh_frame_cie
,
5761 sizeof (Eh_cie
<64>::eh_frame_cie
),
5762 glink_eh_frame_fde_64v1
,
5763 sizeof (glink_eh_frame_fde_64v1
));
5764 else if (this->targ_
->has_localentry0())
5765 layout
->add_eh_frame_for_plt(this,
5766 Eh_cie
<64>::eh_frame_cie
,
5767 sizeof (Eh_cie
<64>::eh_frame_cie
),
5768 glink_eh_frame_fde_64v2_localentry0
,
5769 sizeof (glink_eh_frame_fde_64v2
));
5771 layout
->add_eh_frame_for_plt(this,
5772 Eh_cie
<64>::eh_frame_cie
,
5773 sizeof (Eh_cie
<64>::eh_frame_cie
),
5774 glink_eh_frame_fde_64v2
,
5775 sizeof (glink_eh_frame_fde_64v2
));
5779 // 32-bit .glink can use the default since the CIE return
5780 // address reg, LR, is valid.
5781 layout
->add_eh_frame_for_plt(this,
5782 Eh_cie
<32>::eh_frame_cie
,
5783 sizeof (Eh_cie
<32>::eh_frame_cie
),
5785 sizeof (default_fde
));
5786 // Except where LR is used in a PIC __glink_PLTresolve.
5787 if (parameters
->options().output_is_position_independent())
5788 layout
->add_eh_frame_for_plt(this,
5789 Eh_cie
<32>::eh_frame_cie
,
5790 sizeof (Eh_cie
<32>::eh_frame_cie
),
5791 glink_eh_frame_fde_32
,
5792 sizeof (glink_eh_frame_fde_32
));
5796 template<int size
, bool big_endian
>
5798 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5800 unsigned int off
= this->global_entry_align(this->ge_size_
);
5801 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5802 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5804 this->ge_size_
= off
+ 16;
5807 template<int size
, bool big_endian
>
5808 typename Output_data_glink
<size
, big_endian
>::Address
5809 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5811 typename
Global_entry_stub_entries::const_iterator p
5812 = this->global_entry_stubs_
.find(gsym
);
5813 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5816 template<int size
, bool big_endian
>
5818 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5820 unsigned int count
= this->targ_
->plt_entry_count();
5821 section_size_type total
= 0;
5827 // space for branch table
5828 total
+= 4 * (count
- 1);
5830 total
+= -total
& 15;
5831 total
+= this->pltresolve_size();
5835 total
+= this->pltresolve_size();
5837 // space for branch table
5839 if (this->targ_
->abiversion() < 2)
5843 total
+= 4 * (count
- 0x8000);
5847 this->end_branch_table_
= total
;
5848 total
= this->global_entry_align(total
);
5849 total
+= this->ge_size_
;
5851 this->set_data_size(total
);
5854 // Define symbols on stubs, identifying the stub.
5856 template<int size
, bool big_endian
>
5858 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5860 if (!this->plt_call_stubs_
.empty())
5862 // The key for the plt call stub hash table includes addresses,
5863 // therefore traversal order depends on those addresses, which
5864 // can change between runs if gold is a PIE. Unfortunately the
5865 // output .symtab ordering depends on the order in which symbols
5866 // are added to the linker symtab. We want reproducible output
5867 // so must sort the call stub symbols.
5868 typedef typename
Plt_stub_entries::iterator plt_iter
;
5869 std::vector
<plt_iter
> sorted
;
5870 sorted
.resize(this->plt_call_stubs_
.size());
5872 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5873 cs
!= this->plt_call_stubs_
.end();
5875 sorted
[cs
->second
.indx_
] = cs
;
5877 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5879 plt_iter cs
= sorted
[i
];
5882 if (cs
->first
.addend_
!= 0)
5883 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5886 if (cs
->first
.object_
)
5888 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5889 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5890 sprintf(obj
, "%x:", ppcobj
->uniq());
5893 const char *symname
;
5894 if (cs
->first
.sym_
== NULL
)
5896 sprintf(localname
, "%x", cs
->first
.locsym_
);
5897 symname
= localname
;
5899 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5900 symname
= this->targ_
->tls_get_addr_opt()->name();
5902 symname
= cs
->first
.sym_
->name();
5903 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5904 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5906 = this->stub_address() - this->address() + cs
->second
.off_
;
5907 unsigned int stub_size
= this->plt_call_size(cs
);
5908 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5912 typedef typename
Branch_stub_entries::iterator branch_iter
;
5913 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5914 bs
!= this->long_branch_stubs_
.end();
5917 if (bs
->second
.save_res_
)
5920 char* name
= new char[8 + 13 + 16 + 1];
5921 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5922 static_cast<unsigned long long>(bs
->first
.dest_
));
5923 Address value
= (this->stub_address() - this->address()
5924 + this->plt_size_
+ bs
->second
.off_
);
5925 bool need_lt
= false;
5926 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5927 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5931 // Emit the start of a __tls_get_addr_opt plt call stub.
5933 template<int size
, bool big_endian
>
5935 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5938 unsigned char* p
= *pp
;
5941 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5943 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5945 write_insn
<big_endian
>(p
, mr_0_3
);
5947 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5949 write_insn
<big_endian
>(p
, add_3_12_13
);
5951 write_insn
<big_endian
>(p
, beqlr
);
5953 write_insn
<big_endian
>(p
, mr_3_0
);
5957 write_insn
<big_endian
>(p
, mflr_11
);
5959 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5965 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5967 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5969 write_insn
<big_endian
>(p
, mr_0_3
);
5971 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5973 write_insn
<big_endian
>(p
, add_3_12_2
);
5975 write_insn
<big_endian
>(p
, beqlr
);
5977 write_insn
<big_endian
>(p
, mr_3_0
);
5979 write_insn
<big_endian
>(p
, nop
);
5985 // Emit the tail of a __tls_get_addr_opt plt call stub.
5987 template<int size
, bool big_endian
>
5989 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5991 write_insn
<big_endian
>(p
, bctrl
);
5993 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5995 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5997 write_insn
<big_endian
>(p
, mtlr_11
);
5999 write_insn
<big_endian
>(p
, blr
);
6002 // Emit pc-relative plt call stub code.
6004 template<bool big_endian
>
6005 static unsigned char*
6006 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
6009 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6014 write_insn
<big_endian
>(p
, nop
);
6022 write_insn
<big_endian
>(p
, insn
>> 32);
6024 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6026 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6029 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
6033 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6036 insn
= paddi_12_pc
| d34(off
);
6037 write_insn
<big_endian
>(p
, insn
>> 32);
6039 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6043 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6047 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6049 write_insn
<big_endian
>(p
, add_12_11_12
);
6054 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
6056 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
6060 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6063 insn
= paddi_12_pc
| d34(off
);
6064 write_insn
<big_endian
>(p
, insn
>> 32);
6066 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
6070 write_insn
<big_endian
>(p
, sldi_11_11_34
);
6074 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6076 write_insn
<big_endian
>(p
, add_12_11_12
);
6082 // Gets the address of a label (1:) in r11 and builds an offset in r12,
6083 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
6088 // lis %r12,xxx-1b@highest
6089 // ori %r12,%r12,xxx-1b@higher
6090 // sldi %r12,%r12,32
6091 // oris %r12,%r12,xxx-1b@high
6092 // ori %r12,%r12,xxx-1b@l
6093 // add/ldx %r12,%r11,%r12
6095 template<bool big_endian
>
6096 static unsigned char*
6097 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
6099 write_insn
<big_endian
>(p
, mflr_12
);
6101 write_insn
<big_endian
>(p
, bcl_20_31
);
6103 write_insn
<big_endian
>(p
, mflr_11
);
6105 write_insn
<big_endian
>(p
, mtlr_12
);
6107 if (off
+ 0x8000 < 0x10000)
6110 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6112 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
6114 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6116 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
6119 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6121 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
6125 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
6127 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
6132 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
6134 if (((off
>> 32) & 0xffff) != 0)
6136 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
6140 if (((off
>> 32) & 0xffffffffULL
) != 0)
6142 write_insn
<big_endian
>(p
, sldi_12_12_32
);
6147 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
6152 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6156 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6158 write_insn
<big_endian
>(p
, add_12_11_12
);
6164 // Size of a given plt call stub.
6166 template<int size
, bool big_endian
>
6168 Stub_table
<size
, big_endian
>::plt_call_size(
6169 typename
Plt_stub_entries::iterator p
) const
6173 unsigned int bytes
= 4 * 4;
6174 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6176 return this->plt_call_align(bytes
);
6179 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6180 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6181 plt_addr
+= plt
->address();
6182 if (this->targ_
->power10_stubs()
6183 && this->targ_
->power10_stubs_auto())
6185 unsigned int bytes
= 0;
6186 if (p
->second
.notoc_
)
6188 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6190 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6191 uint64_t odd
= from
& 4;
6192 uint64_t off
= plt_addr
- from
;
6193 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6194 bytes
+= odd
+ 4 * 4;
6195 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6199 bytes
= this->plt_call_align(bytes
);
6203 p
->second
.tocoff_
= bytes
;
6204 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6207 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6208 bytes
+= 2 * 4 + 4 * 4;
6210 if (p
->second
.r2save_
)
6212 uint64_t got_addr
= this->targ_
->toc_pointer();
6213 uint64_t off
= plt_addr
- got_addr
;
6214 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6215 p
->second
.tsize_
= bytes
- p
->second
.tocoff_
;
6216 bytes
= this->plt_call_align(bytes
);
6218 if (p
->second
.p9notoc_
)
6220 p
->second
.p9off_
= bytes
;
6221 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6223 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6224 uint64_t off
= plt_addr
- from
;
6225 if (off
+ 0x8000 < 0x10000)
6227 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6232 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6233 && ((off
>> 32) & 0xffff) != 0)
6235 if (((off
>> 32) & 0xffffffffULL
) != 0)
6242 bytes
= this->plt_call_align(bytes
);
6248 unsigned int bytes
= 0;
6249 unsigned int tail
= 0;
6250 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6253 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6260 if (p
->second
.r2save_
)
6263 if (this->targ_
->power10_stubs())
6265 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6266 uint64_t odd
= from
& 4;
6267 uint64_t off
= plt_addr
- from
;
6268 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6269 bytes
+= odd
+ 4 * 4;
6270 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6274 return this->plt_call_align(bytes
+ tail
);
6277 if (p
->second
.p9notoc_
)
6279 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6280 uint64_t off
= plt_addr
- from
;
6281 if (off
+ 0x8000 < 0x10000)
6283 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6288 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6289 && ((off
>> 32) & 0xffff) != 0)
6291 if (((off
>> 32) & 0xffffffffULL
) != 0)
6298 return this->plt_call_align(bytes
+ tail
);
6301 uint64_t got_addr
= this->targ_
->toc_pointer();
6302 uint64_t off
= plt_addr
- got_addr
;
6303 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6304 if (this->targ_
->abiversion() < 2)
6306 bool static_chain
= parameters
->options().plt_static_chain();
6307 bool thread_safe
= this->targ_
->plt_thread_safe();
6311 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6313 return this->plt_call_align(bytes
+ tail
);
6317 // Return long branch stub size.
6319 template<int size
, bool big_endian
>
6321 Stub_table
<size
, big_endian
>::branch_stub_size(
6322 typename
Branch_stub_entries::iterator p
,
6325 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6328 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6330 if (parameters
->options().output_is_position_independent())
6335 uint64_t off
= p
->first
.dest_
- loc
;
6336 unsigned int bytes
= 0;
6337 if (p
->second
.notoc_
)
6339 if (this->targ_
->power10_stubs())
6341 Address odd
= loc
& 4;
6342 if (off
+ (1 << 25) < 2 << 25)
6344 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6346 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6350 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6352 p
->second
.tocoff_
= bytes
;
6357 if (off
+ 0x8000 < 0x10000)
6359 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6361 if (off
+ 24 + (1 << 25) < 2 << 25)
6367 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6368 && ((off
>> 32) & 0xffff) != 0)
6370 if (((off
>> 32) & 0xffffffffULL
) != 0)
6380 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6381 if (off
+ (1 << 25) < 2 << 25)
6383 if (!this->targ_
->power10_stubs()
6384 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6389 template<int size
, bool big_endian
>
6391 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6394 gold_error(_("linkage table error against `%s'"),
6395 p
.sym_
->demangled_name().c_str());
6397 gold_error(_("linkage table error against `%s:[local %u]'"),
6398 p
.object_
->name().c_str(),
6402 // Write out plt and long branch stub code.
6404 template<int size
, bool big_endian
>
6406 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6408 if (this->plt_call_stubs_
.empty()
6409 && this->long_branch_stubs_
.empty())
6412 const section_size_type start_off
= this->offset();
6413 const section_size_type off
= this->stub_offset();
6414 const section_size_type oview_size
=
6415 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6416 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6420 && this->targ_
->power10_stubs())
6422 if (!this->plt_call_stubs_
.empty())
6424 // Write out plt call stubs.
6425 typename
Plt_stub_entries::const_iterator cs
;
6426 for (cs
= this->plt_call_stubs_
.begin();
6427 cs
!= this->plt_call_stubs_
.end();
6430 p
= oview
+ cs
->second
.off_
;
6431 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6432 Address pltoff
= this->plt_off(cs
, &plt
);
6433 Address plt_addr
= pltoff
+ plt
->address();
6434 if (this->targ_
->power10_stubs_auto())
6436 if (cs
->second
.notoc_
)
6438 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6439 this->build_tls_opt_head(&p
, false);
6440 Address from
= this->stub_address() + (p
- oview
);
6441 Address delta
= plt_addr
- from
;
6442 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6444 write_insn
<big_endian
>(p
, mtctr_12
);
6446 write_insn
<big_endian
>(p
, bctr
);
6448 p
= oview
+ this->plt_call_align(p
- oview
);
6450 if (cs
->second
.toc_
)
6452 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6455 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6456 this->build_tls_opt_head(&p
, save_lr
);
6458 Address got_addr
= this->targ_
->toc_pointer();
6459 Address off
= plt_addr
- got_addr
;
6461 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6462 this->plt_error(cs
->first
);
6464 if (cs
->second
.r2save_
)
6466 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6471 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6473 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6478 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6481 write_insn
<big_endian
>(p
, mtctr_12
);
6483 if (cs
->second
.r2save_
6484 && !cs
->second
.localentry0_
6485 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6486 this->build_tls_opt_tail(p
);
6488 write_insn
<big_endian
>(p
, bctr
);
6490 if (cs
->second
.p9notoc_
)
6492 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6493 this->build_tls_opt_head(&p
, false);
6494 Address from
= this->stub_address() + (p
- oview
);
6495 Address delta
= plt_addr
- from
;
6496 p
= build_notoc_offset
<big_endian
>(p
, delta
, true);
6497 write_insn
<big_endian
>(p
, mtctr_12
);
6499 write_insn
<big_endian
>(p
, bctr
);
6501 p
= oview
+ this->plt_call_align(p
- oview
);
6506 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6509 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6510 this->build_tls_opt_head(&p
, save_lr
);
6512 if (cs
->second
.r2save_
)
6514 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6517 Address from
= this->stub_address() + (p
- oview
);
6518 Address delta
= plt_addr
- from
;
6519 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6520 write_insn
<big_endian
>(p
, mtctr_12
);
6522 if (cs
->second
.r2save_
6523 && !cs
->second
.localentry0_
6524 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6525 this->build_tls_opt_tail(p
);
6527 write_insn
<big_endian
>(p
, bctr
);
6532 // Write out long branch stubs.
6533 typename
Branch_stub_entries::const_iterator bs
;
6534 for (bs
= this->long_branch_stubs_
.begin();
6535 bs
!= this->long_branch_stubs_
.end();
6538 if (bs
->second
.save_res_
)
6540 Address off
= this->plt_size_
+ bs
->second
.off_
;
6542 Address loc
= this->stub_address() + off
;
6543 Address delta
= bs
->first
.dest_
- loc
;
6544 if (this->targ_
->power10_stubs_auto())
6546 if (bs
->second
.notoc_
)
6548 unsigned char* startp
= p
;
6549 p
= build_power10_offset
<big_endian
>(p
, delta
,
6551 delta
-= p
- startp
;
6553 if (delta
+ (1 << 25) < 2 << 25)
6554 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6557 write_insn
<big_endian
>(p
, mtctr_12
);
6559 write_insn
<big_endian
>(p
, bctr
);
6562 delta
-= p
- startp
;
6564 if (bs
->second
.toc_
)
6566 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6567 if (delta
+ (1 << 25) >= 2 << 25)
6570 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6571 gold_assert(brlt_addr
!= invalid_address
);
6572 brlt_addr
+= this->targ_
->brlt_section()->address();
6573 Address got_addr
= this->targ_
->toc_pointer();
6574 Address brltoff
= brlt_addr
- got_addr
;
6575 if (ha(brltoff
) == 0)
6577 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6582 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6584 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6588 if (delta
+ (1 << 25) < 2 << 25)
6589 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6592 write_insn
<big_endian
>(p
, mtctr_12
);
6594 write_insn
<big_endian
>(p
, bctr
);
6597 if (bs
->second
.p9notoc_
)
6599 unsigned char* startp
= p
;
6600 p
= build_notoc_offset
<big_endian
>(p
, delta
, false);
6601 delta
-= p
- startp
;
6603 if (delta
+ (1 << 25) < 2 << 25)
6604 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6607 write_insn
<big_endian
>(p
, mtctr_12
);
6609 write_insn
<big_endian
>(p
, bctr
);
6612 delta
-= p
- startp
;
6617 if (!bs
->second
.notoc_
)
6618 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6619 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6621 unsigned char* startp
= p
;
6622 p
= build_power10_offset
<big_endian
>(p
, delta
,
6624 delta
-= p
- startp
;
6626 if (delta
+ (1 << 25) < 2 << 25)
6627 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6630 write_insn
<big_endian
>(p
, mtctr_12
);
6632 write_insn
<big_endian
>(p
, bctr
);
6637 else if (size
== 64)
6640 if (!this->plt_call_stubs_
.empty()
6641 && this->targ_
->abiversion() >= 2)
6643 // Write out plt call stubs for ELFv2.
6644 typename
Plt_stub_entries::const_iterator cs
;
6645 for (cs
= this->plt_call_stubs_
.begin();
6646 cs
!= this->plt_call_stubs_
.end();
6649 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6650 Address pltoff
= this->plt_off(cs
, &plt
);
6651 Address plt_addr
= pltoff
+ plt
->address();
6653 p
= oview
+ cs
->second
.off_
;
6654 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6656 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6657 this->build_tls_opt_head(&p
, save_lr
);
6659 if (cs
->second
.r2save_
)
6661 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6664 if (cs
->second
.p9notoc_
)
6666 Address from
= this->stub_address() + (p
- oview
) + 8;
6667 Address off
= plt_addr
- from
;
6668 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6672 Address got_addr
= this->targ_
->toc_pointer();
6673 Address off
= plt_addr
- got_addr
;
6675 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6676 this->plt_error(cs
->first
);
6680 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6682 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6687 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6691 write_insn
<big_endian
>(p
, mtctr_12
);
6693 if (cs
->second
.r2save_
6694 && !cs
->second
.localentry0_
6695 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6696 this->build_tls_opt_tail(p
);
6698 write_insn
<big_endian
>(p
, bctr
);
6701 else if (!this->plt_call_stubs_
.empty())
6703 // Write out plt call stubs for ELFv1.
6704 typename
Plt_stub_entries::const_iterator cs
;
6705 for (cs
= this->plt_call_stubs_
.begin();
6706 cs
!= this->plt_call_stubs_
.end();
6709 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6710 Address pltoff
= this->plt_off(cs
, &plt
);
6711 Address plt_addr
= pltoff
+ plt
->address();
6712 Address got_addr
= this->targ_
->toc_pointer();
6713 Address off
= plt_addr
- got_addr
;
6715 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6716 || cs
->second
.notoc_
)
6717 this->plt_error(cs
->first
);
6719 bool static_chain
= parameters
->options().plt_static_chain();
6720 bool thread_safe
= this->targ_
->plt_thread_safe();
6721 bool use_fake_dep
= false;
6722 Address cmp_branch_off
= 0;
6725 unsigned int pltindex
6726 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6727 / this->targ_
->plt_entry_size());
6729 = (this->targ_
->glink_section()->pltresolve_size()
6731 if (pltindex
> 32768)
6732 glinkoff
+= (pltindex
- 32768) * 4;
6734 = this->targ_
->glink_section()->address() + glinkoff
;
6736 = (this->stub_address() + cs
->second
.off_
+ 20
6737 + 4 * cs
->second
.r2save_
6738 + 4 * (ha(off
) != 0)
6739 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6740 + 4 * static_chain
);
6741 cmp_branch_off
= to
- from
;
6742 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6745 p
= oview
+ cs
->second
.off_
;
6746 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6748 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6749 this->build_tls_opt_head(&p
, save_lr
);
6750 use_fake_dep
= thread_safe
;
6752 if (cs
->second
.r2save_
)
6754 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6759 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6761 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6763 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6765 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6769 write_insn
<big_endian
>(p
, mtctr_12
);
6773 write_insn
<big_endian
>(p
, xor_2_12_12
);
6775 write_insn
<big_endian
>(p
, add_11_11_2
);
6778 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6782 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6788 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6790 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6792 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6796 write_insn
<big_endian
>(p
, mtctr_12
);
6800 write_insn
<big_endian
>(p
, xor_11_12_12
);
6802 write_insn
<big_endian
>(p
, add_2_2_11
);
6807 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6810 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6813 if (cs
->second
.r2save_
6814 && !cs
->second
.localentry0_
6815 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6816 this->build_tls_opt_tail(p
);
6817 else if (thread_safe
&& !use_fake_dep
)
6819 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6821 write_insn
<big_endian
>(p
, bnectr_p4
);
6823 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6826 write_insn
<big_endian
>(p
, bctr
);
6830 // Write out long branch stubs.
6831 typename
Branch_stub_entries::const_iterator bs
;
6832 for (bs
= this->long_branch_stubs_
.begin();
6833 bs
!= this->long_branch_stubs_
.end();
6836 if (bs
->second
.save_res_
)
6838 Address off
= this->plt_size_
+ bs
->second
.off_
;
6840 Address loc
= this->stub_address() + off
;
6841 Address delta
= bs
->first
.dest_
- loc
;
6842 if (!bs
->second
.p9notoc_
)
6843 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6844 if (bs
->second
.p9notoc_
)
6846 unsigned char* startp
= p
;
6847 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6848 delta
-= p
- startp
;
6850 else if (delta
+ (1 << 25) >= 2 << 25)
6853 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6854 gold_assert(brlt_addr
!= invalid_address
);
6855 brlt_addr
+= this->targ_
->brlt_section()->address();
6856 Address got_addr
= this->targ_
->toc_pointer();
6857 Address brltoff
= brlt_addr
- got_addr
;
6858 if (ha(brltoff
) == 0)
6860 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6865 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6867 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6871 if (delta
+ (1 << 25) < 2 << 25)
6872 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6875 write_insn
<big_endian
>(p
, mtctr_12
);
6877 write_insn
<big_endian
>(p
, bctr
);
6883 if (!this->plt_call_stubs_
.empty())
6885 // The address of _GLOBAL_OFFSET_TABLE_.
6886 Address g_o_t
= invalid_address
;
6888 // Write out plt call stubs.
6889 typename
Plt_stub_entries::const_iterator cs
;
6890 for (cs
= this->plt_call_stubs_
.begin();
6891 cs
!= this->plt_call_stubs_
.end();
6894 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6895 Address plt_addr
= this->plt_off(cs
, &plt
);
6896 plt_addr
+= plt
->address();
6898 p
= oview
+ cs
->second
.off_
;
6899 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6900 this->build_tls_opt_head(&p
, false);
6901 if (parameters
->options().output_is_position_independent())
6904 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6905 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6906 (cs
->first
.object_
));
6907 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6909 unsigned int got2
= ppcobj
->got2_shndx();
6910 got_addr
= ppcobj
->get_output_section_offset(got2
);
6911 gold_assert(got_addr
!= invalid_address
);
6912 got_addr
+= (ppcobj
->output_section(got2
)->address()
6913 + cs
->first
.addend_
);
6917 if (g_o_t
== invalid_address
)
6918 g_o_t
= this->targ_
->toc_pointer();
6922 Address off
= plt_addr
- got_addr
;
6924 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6927 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6929 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6934 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6936 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6939 write_insn
<big_endian
>(p
, mtctr_11
);
6941 write_insn
<big_endian
>(p
, bctr
);
6945 // Write out long branch stubs.
6946 typename
Branch_stub_entries::const_iterator bs
;
6947 for (bs
= this->long_branch_stubs_
.begin();
6948 bs
!= this->long_branch_stubs_
.end();
6951 if (bs
->second
.save_res_
)
6953 Address off
= this->plt_size_
+ bs
->second
.off_
;
6955 Address loc
= this->stub_address() + off
;
6956 Address delta
= bs
->first
.dest_
- loc
;
6957 if (delta
+ (1 << 25) < 2 << 25)
6958 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6959 else if (!parameters
->options().output_is_position_independent())
6961 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6963 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6968 write_insn
<big_endian
>(p
, mflr_0
);
6970 write_insn
<big_endian
>(p
, bcl_20_31
);
6972 write_insn
<big_endian
>(p
, mflr_12
);
6974 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6976 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6978 write_insn
<big_endian
>(p
, mtlr_0
);
6981 write_insn
<big_endian
>(p
, mtctr_12
);
6983 write_insn
<big_endian
>(p
, bctr
);
6986 if (this->need_save_res_
)
6988 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6989 memcpy (p
, this->targ_
->savres_section()->contents(),
6990 this->targ_
->savres_section()->data_size());
6994 // Write out .glink.
6996 template<int size
, bool big_endian
>
6998 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
7000 const section_size_type off
= this->offset();
7001 const section_size_type oview_size
=
7002 convert_to_section_size_type(this->data_size());
7003 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7006 // The base address of the .plt section.
7007 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
7008 Address plt_base
= this->targ_
->plt_section()->address();
7012 if (this->end_branch_table_
!= 0)
7014 // Write pltresolve stub.
7016 Address after_bcl
= this->address() + 16;
7017 Address pltoff
= plt_base
- after_bcl
;
7019 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
7021 if (this->targ_
->abiversion() < 2)
7023 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
7024 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7025 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7026 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
7027 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
7028 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
7029 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7030 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
7031 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7032 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
7036 if (this->targ_
->has_localentry0())
7038 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
7040 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
7041 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
7042 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
7043 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
7044 if (this->targ_
->has_localentry0())
7046 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
7050 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
7052 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
7053 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
7054 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
7055 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
7056 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
7057 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7058 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
7060 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
7061 gold_assert(p
== oview
+ this->pltresolve_size());
7063 // Write lazy link call stubs.
7065 while (p
< oview
+ this->end_branch_table_
)
7067 if (this->targ_
->abiversion() < 2)
7071 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
7075 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
7076 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
7079 uint32_t branch_off
= 8 - (p
- oview
);
7080 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
7085 Address plt_base
= this->targ_
->plt_section()->address();
7086 Address iplt_base
= invalid_address
;
7087 unsigned int global_entry_off
= this->global_entry_off();
7088 Address global_entry_base
= this->address() + global_entry_off
;
7089 typename
Global_entry_stub_entries::const_iterator ge
;
7090 for (ge
= this->global_entry_stubs_
.begin();
7091 ge
!= this->global_entry_stubs_
.end();
7094 p
= oview
+ global_entry_off
+ ge
->second
;
7095 Address plt_addr
= ge
->first
->plt_offset();
7096 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
7097 && ge
->first
->can_use_relative_reloc(false))
7099 if (iplt_base
== invalid_address
)
7100 iplt_base
= this->targ_
->iplt_section()->address();
7101 plt_addr
+= iplt_base
;
7104 plt_addr
+= plt_base
;
7105 Address my_addr
= global_entry_base
+ ge
->second
;
7106 Address off
= plt_addr
- my_addr
;
7108 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
7109 gold_error(_("linkage table error against `%s'"),
7110 ge
->first
->demangled_name().c_str());
7112 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
7113 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
7114 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
7115 write_insn
<big_endian
>(p
, bctr
);
7120 // The address of _GLOBAL_OFFSET_TABLE_.
7121 Address g_o_t
= this->targ_
->toc_pointer();
7123 // Write out pltresolve branch table.
7125 unsigned int the_end
= oview_size
- this->pltresolve_size();
7126 unsigned char* end_p
= oview
+ the_end
;
7127 while (p
< end_p
- 8 * 4)
7128 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
7130 write_insn
<big_endian
>(p
, nop
), p
+= 4;
7132 // Write out pltresolve call stub.
7133 end_p
= oview
+ oview_size
;
7134 if (parameters
->options().output_is_position_independent())
7136 Address res0_off
= 0;
7137 Address after_bcl_off
= the_end
+ 12;
7138 Address bcl_res0
= after_bcl_off
- res0_off
;
7140 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
7142 write_insn
<big_endian
>(p
, mflr_0
);
7144 write_insn
<big_endian
>(p
, bcl_20_31
);
7146 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
7148 write_insn
<big_endian
>(p
, mflr_12
);
7150 write_insn
<big_endian
>(p
, mtlr_0
);
7152 write_insn
<big_endian
>(p
, sub_11_11_12
);
7155 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
7157 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
7159 if (ha(got_bcl
) == ha(got_bcl
+ 4))
7161 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
7163 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
7167 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
7169 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7172 write_insn
<big_endian
>(p
, mtctr_0
);
7174 write_insn
<big_endian
>(p
, add_0_11_11
);
7176 write_insn
<big_endian
>(p
, add_11_0_11
);
7180 Address res0
= this->address();
7182 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7184 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7186 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7187 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7189 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7191 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7193 write_insn
<big_endian
>(p
, mtctr_0
);
7195 write_insn
<big_endian
>(p
, add_0_11_11
);
7197 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7198 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7200 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7202 write_insn
<big_endian
>(p
, add_11_0_11
);
7205 write_insn
<big_endian
>(p
, bctr
);
7209 write_insn
<big_endian
>(p
, nop
);
7214 of
->write_output_view(off
, oview_size
, oview
);
7218 // A class to handle linker generated save/restore functions.
7220 template<int size
, bool big_endian
>
7221 class Output_data_save_res
: public Output_section_data_build
7224 Output_data_save_res(Symbol_table
* symtab
);
7226 const unsigned char*
7233 // Write to a map file.
7235 do_print_to_mapfile(Mapfile
* mapfile
) const
7236 { mapfile
->print_output_data(this, _("** save/restore")); }
7239 do_write(Output_file
*);
7242 // The maximum size of save/restore contents.
7243 static const unsigned int savres_max
= 218*4;
7246 savres_define(Symbol_table
* symtab
,
7248 unsigned int lo
, unsigned int hi
,
7249 unsigned char* write_ent(unsigned char*, int),
7250 unsigned char* write_tail(unsigned char*, int));
7252 unsigned char *contents_
;
7255 template<bool big_endian
>
7256 static unsigned char*
7257 savegpr0(unsigned char* p
, int r
)
7259 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7260 write_insn
<big_endian
>(p
, insn
);
7264 template<bool big_endian
>
7265 static unsigned char*
7266 savegpr0_tail(unsigned char* p
, int r
)
7268 p
= savegpr0
<big_endian
>(p
, r
);
7269 uint32_t insn
= std_0_1
+ 16;
7270 write_insn
<big_endian
>(p
, insn
);
7272 write_insn
<big_endian
>(p
, blr
);
7276 template<bool big_endian
>
7277 static unsigned char*
7278 restgpr0(unsigned char* p
, int r
)
7280 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7281 write_insn
<big_endian
>(p
, insn
);
7285 template<bool big_endian
>
7286 static unsigned char*
7287 restgpr0_tail(unsigned char* p
, int r
)
7289 uint32_t insn
= ld_0_1
+ 16;
7290 write_insn
<big_endian
>(p
, insn
);
7292 p
= restgpr0
<big_endian
>(p
, r
);
7293 write_insn
<big_endian
>(p
, mtlr_0
);
7297 p
= restgpr0
<big_endian
>(p
, 30);
7298 p
= restgpr0
<big_endian
>(p
, 31);
7300 write_insn
<big_endian
>(p
, blr
);
7304 template<bool big_endian
>
7305 static unsigned char*
7306 savegpr1(unsigned char* p
, int r
)
7308 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7309 write_insn
<big_endian
>(p
, insn
);
7313 template<bool big_endian
>
7314 static unsigned char*
7315 savegpr1_tail(unsigned char* p
, int r
)
7317 p
= savegpr1
<big_endian
>(p
, r
);
7318 write_insn
<big_endian
>(p
, blr
);
7322 template<bool big_endian
>
7323 static unsigned char*
7324 restgpr1(unsigned char* p
, int r
)
7326 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7327 write_insn
<big_endian
>(p
, insn
);
7331 template<bool big_endian
>
7332 static unsigned char*
7333 restgpr1_tail(unsigned char* p
, int r
)
7335 p
= restgpr1
<big_endian
>(p
, r
);
7336 write_insn
<big_endian
>(p
, blr
);
7340 template<bool big_endian
>
7341 static unsigned char*
7342 savefpr(unsigned char* p
, int r
)
7344 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7345 write_insn
<big_endian
>(p
, insn
);
7349 template<bool big_endian
>
7350 static unsigned char*
7351 savefpr0_tail(unsigned char* p
, int r
)
7353 p
= savefpr
<big_endian
>(p
, r
);
7354 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7356 write_insn
<big_endian
>(p
, blr
);
7360 template<bool big_endian
>
7361 static unsigned char*
7362 restfpr(unsigned char* p
, int r
)
7364 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7365 write_insn
<big_endian
>(p
, insn
);
7369 template<bool big_endian
>
7370 static unsigned char*
7371 restfpr0_tail(unsigned char* p
, int r
)
7373 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7375 p
= restfpr
<big_endian
>(p
, r
);
7376 write_insn
<big_endian
>(p
, mtlr_0
);
7380 p
= restfpr
<big_endian
>(p
, 30);
7381 p
= restfpr
<big_endian
>(p
, 31);
7383 write_insn
<big_endian
>(p
, blr
);
7387 template<bool big_endian
>
7388 static unsigned char*
7389 savefpr1_tail(unsigned char* p
, int r
)
7391 p
= savefpr
<big_endian
>(p
, r
);
7392 write_insn
<big_endian
>(p
, blr
);
7396 template<bool big_endian
>
7397 static unsigned char*
7398 restfpr1_tail(unsigned char* p
, int r
)
7400 p
= restfpr
<big_endian
>(p
, r
);
7401 write_insn
<big_endian
>(p
, blr
);
7405 template<bool big_endian
>
7406 static unsigned char*
7407 savevr(unsigned char* p
, int r
)
7409 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7410 write_insn
<big_endian
>(p
, insn
);
7412 insn
= stvx_0_12_0
+ (r
<< 21);
7413 write_insn
<big_endian
>(p
, insn
);
7417 template<bool big_endian
>
7418 static unsigned char*
7419 savevr_tail(unsigned char* p
, int r
)
7421 p
= savevr
<big_endian
>(p
, r
);
7422 write_insn
<big_endian
>(p
, blr
);
7426 template<bool big_endian
>
7427 static unsigned char*
7428 restvr(unsigned char* p
, int r
)
7430 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7431 write_insn
<big_endian
>(p
, insn
);
7433 insn
= lvx_0_12_0
+ (r
<< 21);
7434 write_insn
<big_endian
>(p
, insn
);
7438 template<bool big_endian
>
7439 static unsigned char*
7440 restvr_tail(unsigned char* p
, int r
)
7442 p
= restvr
<big_endian
>(p
, r
);
7443 write_insn
<big_endian
>(p
, blr
);
7448 template<int size
, bool big_endian
>
7449 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7450 Symbol_table
* symtab
)
7451 : Output_section_data_build(4),
7454 this->savres_define(symtab
,
7455 "_savegpr0_", 14, 31,
7456 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7457 this->savres_define(symtab
,
7458 "_restgpr0_", 14, 29,
7459 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7460 this->savres_define(symtab
,
7461 "_restgpr0_", 30, 31,
7462 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7463 this->savres_define(symtab
,
7464 "_savegpr1_", 14, 31,
7465 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7466 this->savres_define(symtab
,
7467 "_restgpr1_", 14, 31,
7468 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7469 this->savres_define(symtab
,
7470 "_savefpr_", 14, 31,
7471 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7472 this->savres_define(symtab
,
7473 "_restfpr_", 14, 29,
7474 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7475 this->savres_define(symtab
,
7476 "_restfpr_", 30, 31,
7477 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7478 this->savres_define(symtab
,
7480 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7481 this->savres_define(symtab
,
7483 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7484 this->savres_define(symtab
,
7486 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7487 this->savres_define(symtab
,
7489 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7492 template<int size
, bool big_endian
>
7494 Output_data_save_res
<size
, big_endian
>::savres_define(
7495 Symbol_table
* symtab
,
7497 unsigned int lo
, unsigned int hi
,
7498 unsigned char* write_ent(unsigned char*, int),
7499 unsigned char* write_tail(unsigned char*, int))
7501 size_t len
= strlen(name
);
7502 bool writing
= false;
7505 memcpy(sym
, name
, len
);
7508 for (unsigned int i
= lo
; i
<= hi
; i
++)
7510 sym
[len
+ 0] = i
/ 10 + '0';
7511 sym
[len
+ 1] = i
% 10 + '0';
7512 Symbol
* gsym
= symtab
->lookup(sym
);
7513 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7514 writing
= writing
|| refd
;
7517 if (this->contents_
== NULL
)
7518 this->contents_
= new unsigned char[this->savres_max
];
7520 section_size_type value
= this->current_data_size();
7521 unsigned char* p
= this->contents_
+ value
;
7523 p
= write_ent(p
, i
);
7525 p
= write_tail(p
, i
);
7526 section_size_type cur_size
= p
- this->contents_
;
7527 this->set_current_data_size(cur_size
);
7529 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7530 this, value
, cur_size
- value
,
7531 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7532 elfcpp::STV_HIDDEN
, 0, false, false);
7537 // Write out save/restore.
7539 template<int size
, bool big_endian
>
7541 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7543 const section_size_type off
= this->offset();
7544 const section_size_type oview_size
=
7545 convert_to_section_size_type(this->data_size());
7546 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7547 memcpy(oview
, this->contents_
, oview_size
);
7548 of
->write_output_view(off
, oview_size
, oview
);
7552 // Create the glink section.
7554 template<int size
, bool big_endian
>
7556 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7558 if (this->glink_
== NULL
)
7560 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7561 this->glink_
->add_eh_frame(layout
);
7562 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7563 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7564 this->glink_
, ORDER_TEXT
, false);
7568 // Create a PLT entry for a global symbol.
7570 template<int size
, bool big_endian
>
7572 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7576 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7577 && gsym
->can_use_relative_reloc(false))
7579 if (this->iplt_
== NULL
)
7580 this->make_iplt_section(symtab
, layout
);
7581 this->iplt_
->add_ifunc_entry(gsym
);
7585 if (this->plt_
== NULL
)
7586 this->make_plt_section(symtab
, layout
);
7587 this->plt_
->add_entry(gsym
);
7591 // Make a PLT entry for a local symbol.
7593 template<int size
, bool big_endian
>
7595 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7596 Symbol_table
* symtab
,
7598 Sized_relobj_file
<size
, big_endian
>* relobj
,
7601 if (this->lplt_
== NULL
)
7602 this->make_lplt_section(symtab
, layout
);
7603 this->lplt_
->add_local_entry(relobj
, r_sym
);
7606 template<int size
, bool big_endian
>
7608 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(Symbol_table
* symtab
,
7612 if (this->lplt_
== NULL
)
7613 this->make_lplt_section(symtab
, layout
);
7614 this->lplt_
->add_entry(gsym
, true);
7617 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7619 template<int size
, bool big_endian
>
7621 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7622 Symbol_table
* symtab
,
7624 Sized_relobj_file
<size
, big_endian
>* relobj
,
7627 if (this->iplt_
== NULL
)
7628 this->make_iplt_section(symtab
, layout
);
7629 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7632 // Return the number of entries in the PLT.
7634 template<int size
, bool big_endian
>
7636 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7638 if (this->plt_
== NULL
)
7640 return this->plt_
->entry_count();
7643 // Create a GOT entry for local dynamic __tls_get_addr calls.
7645 template<int size
, bool big_endian
>
7647 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7648 Symbol_table
* symtab
,
7650 Sized_relobj_file
<size
, big_endian
>* object
)
7652 if (this->tlsld_got_offset_
== -1U)
7654 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7655 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7656 Output_data_got_powerpc
<size
, big_endian
>* got
7657 = this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
7658 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7659 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7661 this->tlsld_got_offset_
= got_offset
;
7663 return this->tlsld_got_offset_
;
7666 // Get the Reference_flags for a particular relocation.
7668 template<int size
, bool big_endian
>
7670 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7671 unsigned int r_type
,
7672 const Target_powerpc
* target
)
7678 case elfcpp::R_PPC64_TOC
:
7682 case elfcpp::R_POWERPC_NONE
:
7683 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7684 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7685 // No symbol reference.
7688 case elfcpp::R_PPC64_ADDR64
:
7689 case elfcpp::R_PPC64_UADDR64
:
7690 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7691 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7692 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7693 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7694 case elfcpp::R_PPC64_D34
:
7695 case elfcpp::R_PPC64_D34_LO
:
7696 case elfcpp::R_PPC64_D34_HI30
:
7697 case elfcpp::R_PPC64_D34_HA30
:
7698 case elfcpp::R_PPC64_D28
:
7702 case elfcpp::R_POWERPC_ADDR32
:
7703 case elfcpp::R_POWERPC_UADDR32
:
7704 case elfcpp::R_POWERPC_ADDR16
:
7705 case elfcpp::R_POWERPC_UADDR16
:
7706 case elfcpp::R_POWERPC_ADDR16_LO
:
7707 case elfcpp::R_POWERPC_ADDR16_HI
:
7708 case elfcpp::R_POWERPC_ADDR16_HA
:
7709 ref
= Symbol::ABSOLUTE_REF
;
7712 case elfcpp::R_POWERPC_ADDR24
:
7713 case elfcpp::R_POWERPC_ADDR14
:
7714 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7715 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7716 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7719 case elfcpp::R_PPC_LOCAL24PC
:
7723 ref
= Symbol::RELATIVE_REF
;
7726 case elfcpp::R_PPC64_REL64
:
7727 case elfcpp::R_PPC64_REL16_HIGH
:
7728 case elfcpp::R_PPC64_REL16_HIGHA
:
7729 case elfcpp::R_PPC64_REL16_HIGHER
:
7730 case elfcpp::R_PPC64_REL16_HIGHERA
:
7731 case elfcpp::R_PPC64_REL16_HIGHEST
:
7732 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7733 case elfcpp::R_PPC64_PCREL34
:
7734 case elfcpp::R_PPC64_REL16_HIGHER34
:
7735 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7736 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7737 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7738 case elfcpp::R_PPC64_PCREL28
:
7742 case elfcpp::R_POWERPC_REL32
:
7743 case elfcpp::R_POWERPC_REL16
:
7744 case elfcpp::R_POWERPC_REL16_LO
:
7745 case elfcpp::R_POWERPC_REL16_HI
:
7746 case elfcpp::R_POWERPC_REL16_HA
:
7747 ref
= Symbol::RELATIVE_REF
;
7750 case elfcpp::R_PPC_PLTREL24
:
7753 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7756 case elfcpp::R_PPC64_REL24_NOTOC
:
7757 case elfcpp::R_PPC64_REL24_P9NOTOC
:
7758 case elfcpp::R_PPC64_PLT16_LO_DS
:
7759 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7760 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7761 case elfcpp::R_PPC64_PLT_PCREL34
:
7762 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7766 case elfcpp::R_POWERPC_REL24
:
7767 case elfcpp::R_POWERPC_REL14
:
7768 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7769 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7770 case elfcpp::R_POWERPC_PLT16_LO
:
7771 case elfcpp::R_POWERPC_PLT16_HI
:
7772 case elfcpp::R_POWERPC_PLT16_HA
:
7773 case elfcpp::R_POWERPC_PLTSEQ
:
7774 case elfcpp::R_POWERPC_PLTCALL
:
7775 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7778 case elfcpp::R_PPC64_GOT16_DS
:
7779 case elfcpp::R_PPC64_GOT16_LO_DS
:
7780 case elfcpp::R_PPC64_GOT_PCREL34
:
7781 case elfcpp::R_PPC64_TOC16
:
7782 case elfcpp::R_PPC64_TOC16_LO
:
7783 case elfcpp::R_PPC64_TOC16_HI
:
7784 case elfcpp::R_PPC64_TOC16_HA
:
7785 case elfcpp::R_PPC64_TOC16_DS
:
7786 case elfcpp::R_PPC64_TOC16_LO_DS
:
7790 case elfcpp::R_POWERPC_GOT16
:
7791 case elfcpp::R_POWERPC_GOT16_LO
:
7792 case elfcpp::R_POWERPC_GOT16_HI
:
7793 case elfcpp::R_POWERPC_GOT16_HA
:
7794 ref
= Symbol::RELATIVE_REF
;
7797 case elfcpp::R_PPC64_TLSGD
:
7798 case elfcpp::R_PPC64_TLSLD
:
7799 case elfcpp::R_PPC64_TPREL34
:
7800 case elfcpp::R_PPC64_DTPREL34
:
7801 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7802 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7803 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7804 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7808 case elfcpp::R_POWERPC_GOT_TPREL16
:
7809 case elfcpp::R_POWERPC_TLS
:
7810 ref
= Symbol::TLS_REF
;
7813 case elfcpp::R_POWERPC_COPY
:
7814 case elfcpp::R_POWERPC_GLOB_DAT
:
7815 case elfcpp::R_POWERPC_JMP_SLOT
:
7816 case elfcpp::R_POWERPC_RELATIVE
:
7817 case elfcpp::R_POWERPC_DTPMOD
:
7819 // Not expected. We will give an error later.
7823 if (size
== 64 && target
->abiversion() < 2)
7824 ref
|= Symbol::FUNC_DESC_ABI
;
7828 // Report an unsupported relocation against a local symbol.
7830 template<int size
, bool big_endian
>
7832 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7833 Sized_relobj_file
<size
, big_endian
>* object
,
7834 unsigned int r_type
)
7836 gold_error(_("%s: unsupported reloc %u against local symbol"),
7837 object
->name().c_str(), r_type
);
7840 // We are about to emit a dynamic relocation of type R_TYPE. If the
7841 // dynamic linker does not support it, issue an error.
7843 template<int size
, bool big_endian
>
7845 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7846 unsigned int r_type
)
7848 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7850 // These are the relocation types supported by glibc for both 32-bit
7851 // and 64-bit powerpc.
7854 case elfcpp::R_POWERPC_NONE
:
7855 case elfcpp::R_POWERPC_RELATIVE
:
7856 case elfcpp::R_POWERPC_GLOB_DAT
:
7857 case elfcpp::R_POWERPC_DTPMOD
:
7858 case elfcpp::R_POWERPC_DTPREL
:
7859 case elfcpp::R_POWERPC_TPREL
:
7860 case elfcpp::R_POWERPC_JMP_SLOT
:
7861 case elfcpp::R_POWERPC_COPY
:
7862 case elfcpp::R_POWERPC_IRELATIVE
:
7863 case elfcpp::R_POWERPC_ADDR32
:
7864 case elfcpp::R_POWERPC_UADDR32
:
7865 case elfcpp::R_POWERPC_ADDR24
:
7866 case elfcpp::R_POWERPC_ADDR16
:
7867 case elfcpp::R_POWERPC_UADDR16
:
7868 case elfcpp::R_POWERPC_ADDR16_LO
:
7869 case elfcpp::R_POWERPC_ADDR16_HI
:
7870 case elfcpp::R_POWERPC_ADDR16_HA
:
7871 case elfcpp::R_POWERPC_ADDR14
:
7872 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7873 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7874 case elfcpp::R_POWERPC_REL32
:
7875 case elfcpp::R_POWERPC_TPREL16
:
7876 case elfcpp::R_POWERPC_TPREL16_LO
:
7877 case elfcpp::R_POWERPC_TPREL16_HI
:
7878 case elfcpp::R_POWERPC_TPREL16_HA
:
7889 // These are the relocation types supported only on 64-bit.
7890 case elfcpp::R_PPC64_ADDR64
:
7891 case elfcpp::R_PPC64_UADDR64
:
7892 case elfcpp::R_PPC64_JMP_IREL
:
7893 case elfcpp::R_PPC64_ADDR16_DS
:
7894 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7895 case elfcpp::R_PPC64_ADDR16_HIGH
:
7896 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7897 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7898 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7899 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7900 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7901 case elfcpp::R_PPC64_REL64
:
7902 case elfcpp::R_POWERPC_ADDR30
:
7903 case elfcpp::R_PPC64_TPREL16_DS
:
7904 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7905 case elfcpp::R_PPC64_TPREL16_HIGH
:
7906 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7907 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7908 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7909 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7910 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7921 // These are the relocation types supported only on 32-bit.
7922 // ??? glibc ld.so doesn't need to support these.
7923 case elfcpp::R_POWERPC_REL24
:
7924 case elfcpp::R_POWERPC_DTPREL16
:
7925 case elfcpp::R_POWERPC_DTPREL16_LO
:
7926 case elfcpp::R_POWERPC_DTPREL16_HI
:
7927 case elfcpp::R_POWERPC_DTPREL16_HA
:
7935 // This prevents us from issuing more than one error per reloc
7936 // section. But we can still wind up issuing more than one
7937 // error per object file.
7938 if (this->issued_non_pic_error_
)
7940 gold_assert(parameters
->options().output_is_position_independent());
7941 object
->error(_("requires unsupported dynamic reloc; "
7942 "recompile with -fPIC"));
7943 this->issued_non_pic_error_
= true;
7947 // Return whether we need to make a PLT entry for a relocation of the
7948 // given type against a STT_GNU_IFUNC symbol.
7950 template<int size
, bool big_endian
>
7952 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7953 Target_powerpc
<size
, big_endian
>* target
,
7954 Sized_relobj_file
<size
, big_endian
>* object
,
7955 unsigned int r_type
,
7958 // In non-pic code any reference will resolve to the plt call stub
7959 // for the ifunc symbol.
7960 if ((size
== 32 || target
->abiversion() >= 2)
7961 && !parameters
->options().output_is_position_independent())
7966 // Word size refs from data sections are OK, but don't need a PLT entry.
7967 case elfcpp::R_POWERPC_ADDR32
:
7968 case elfcpp::R_POWERPC_UADDR32
:
7973 case elfcpp::R_PPC64_ADDR64
:
7974 case elfcpp::R_PPC64_UADDR64
:
7979 // GOT refs are good, but also don't need a PLT entry.
7980 case elfcpp::R_POWERPC_GOT16
:
7981 case elfcpp::R_POWERPC_GOT16_LO
:
7982 case elfcpp::R_POWERPC_GOT16_HI
:
7983 case elfcpp::R_POWERPC_GOT16_HA
:
7984 case elfcpp::R_PPC64_GOT16_DS
:
7985 case elfcpp::R_PPC64_GOT16_LO_DS
:
7986 case elfcpp::R_PPC64_GOT_PCREL34
:
7989 // PLT relocs are OK and need a PLT entry.
7990 case elfcpp::R_POWERPC_PLT16_LO
:
7991 case elfcpp::R_POWERPC_PLT16_HI
:
7992 case elfcpp::R_POWERPC_PLT16_HA
:
7993 case elfcpp::R_PPC64_PLT16_LO_DS
:
7994 case elfcpp::R_POWERPC_PLTSEQ
:
7995 case elfcpp::R_POWERPC_PLTCALL
:
7996 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7997 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7998 case elfcpp::R_PPC64_PLT_PCREL34
:
7999 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8003 // Function calls are good, and these do need a PLT entry.
8004 case elfcpp::R_PPC64_REL24_NOTOC
:
8008 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8009 case elfcpp::R_POWERPC_ADDR24
:
8010 case elfcpp::R_POWERPC_ADDR14
:
8011 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8012 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8013 case elfcpp::R_POWERPC_REL24
:
8014 case elfcpp::R_PPC_PLTREL24
:
8015 case elfcpp::R_POWERPC_REL14
:
8016 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8017 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8024 // Anything else is a problem.
8025 // If we are building a static executable, the libc startup function
8026 // responsible for applying indirect function relocations is going
8027 // to complain about the reloc type.
8028 // If we are building a dynamic executable, we will have a text
8029 // relocation. The dynamic loader will set the text segment
8030 // writable and non-executable to apply text relocations. So we'll
8031 // segfault when trying to run the indirection function to resolve
8034 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
8035 object
->name().c_str(), r_type
);
8039 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
8043 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
8045 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8046 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8047 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8048 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8049 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8050 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8051 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8052 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8053 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8054 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8055 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8056 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8057 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8058 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8059 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8060 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8061 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8062 /* Exclude lfqu by testing reloc. If relocs are ever
8063 defined for the reduced D field in psq_lu then those
8064 will need testing too. */
8065 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8066 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8067 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8069 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8070 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8071 /* Exclude stfqu. psq_stu as above for psq_lu. */
8072 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8073 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8074 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8075 && (insn
& 1) == 0));
8078 // Scan a relocation for a local symbol.
8080 template<int size
, bool big_endian
>
8082 Target_powerpc
<size
, big_endian
>::Scan::local(
8083 Symbol_table
* symtab
,
8085 Target_powerpc
<size
, big_endian
>* target
,
8086 Sized_relobj_file
<size
, big_endian
>* object
,
8087 unsigned int data_shndx
,
8088 Output_section
* output_section
,
8089 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8090 unsigned int r_type
,
8091 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8094 Powerpc_relobj
<size
, big_endian
>* ppc_object
8095 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8097 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
8099 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8100 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8102 this->expect_tls_get_addr_call();
8103 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8104 if (tls_type
!= tls::TLSOPT_NONE
)
8105 this->skip_next_tls_get_addr_call();
8107 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8108 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8110 this->expect_tls_get_addr_call();
8111 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8112 if (tls_type
!= tls::TLSOPT_NONE
)
8113 this->skip_next_tls_get_addr_call();
8119 && data_shndx
== ppc_object
->opd_shndx()
8120 && r_type
== elfcpp::R_PPC64_ADDR64
)
8121 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8125 // A local STT_GNU_IFUNC symbol may require a PLT entry.
8126 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
8127 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8129 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8130 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8131 r_type
, r_sym
, reloc
.get_r_addend());
8132 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
8137 case elfcpp::R_POWERPC_NONE
:
8138 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8139 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8140 case elfcpp::R_POWERPC_TLS
:
8141 case elfcpp::R_PPC64_ENTRY
:
8142 case elfcpp::R_POWERPC_PLTSEQ
:
8143 case elfcpp::R_POWERPC_PLTCALL
:
8144 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8145 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8146 case elfcpp::R_PPC64_PCREL_OPT
:
8147 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8148 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8149 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8150 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8151 case elfcpp::R_PPC64_REL16_HIGHER34
:
8152 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8153 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8154 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8155 case elfcpp::R_PPC64_D34
:
8156 case elfcpp::R_PPC64_D34_LO
:
8157 case elfcpp::R_PPC64_D34_HI30
:
8158 case elfcpp::R_PPC64_D34_HA30
:
8159 case elfcpp::R_PPC64_D28
:
8160 case elfcpp::R_PPC64_PCREL34
:
8161 case elfcpp::R_PPC64_PCREL28
:
8162 case elfcpp::R_PPC64_TPREL34
:
8163 case elfcpp::R_PPC64_DTPREL34
:
8166 case elfcpp::R_PPC64_TOC
:
8168 Output_data_got_powerpc
<size
, big_endian
>* got
8169 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8170 if (parameters
->options().output_is_position_independent())
8172 Address off
= reloc
.get_r_offset();
8174 && target
->abiversion() < 2
8175 && data_shndx
== ppc_object
->opd_shndx()
8176 && ppc_object
->get_opd_discard(off
- 8))
8179 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8180 Address got_off
= got
->g_o_t();
8181 rela_dyn
->add_output_section_relative(got
->output_section(),
8182 elfcpp::R_POWERPC_RELATIVE
,
8184 object
, data_shndx
, off
,
8190 case elfcpp::R_PPC64_ADDR64
:
8191 case elfcpp::R_PPC64_UADDR64
:
8192 case elfcpp::R_POWERPC_ADDR32
:
8193 case elfcpp::R_POWERPC_UADDR32
:
8194 case elfcpp::R_POWERPC_ADDR24
:
8195 case elfcpp::R_POWERPC_ADDR16
:
8196 case elfcpp::R_POWERPC_ADDR16_LO
:
8197 case elfcpp::R_POWERPC_ADDR16_HI
:
8198 case elfcpp::R_POWERPC_ADDR16_HA
:
8199 case elfcpp::R_POWERPC_UADDR16
:
8200 case elfcpp::R_PPC64_ADDR16_HIGH
:
8201 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8202 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8203 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8204 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8205 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8206 case elfcpp::R_PPC64_ADDR16_DS
:
8207 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8208 case elfcpp::R_POWERPC_ADDR14
:
8209 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8210 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8211 // If building a shared library (or a position-independent
8212 // executable), we need to create a dynamic relocation for
8214 if (parameters
->options().output_is_position_independent()
8215 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8217 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8219 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8220 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8221 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8223 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8224 : elfcpp::R_POWERPC_RELATIVE
);
8225 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8226 output_section
, data_shndx
,
8227 reloc
.get_r_offset(),
8228 reloc
.get_r_addend(), false);
8230 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8232 check_non_pic(object
, r_type
);
8233 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8234 data_shndx
, reloc
.get_r_offset(),
8235 reloc
.get_r_addend());
8239 gold_assert(lsym
.get_st_value() == 0);
8240 unsigned int shndx
= lsym
.get_st_shndx();
8242 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8245 object
->error(_("section symbol %u has bad shndx %u"),
8248 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8249 output_section
, data_shndx
,
8250 reloc
.get_r_offset());
8255 case elfcpp::R_PPC64_PLT_PCREL34
:
8256 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8257 case elfcpp::R_POWERPC_PLT16_LO
:
8258 case elfcpp::R_POWERPC_PLT16_HI
:
8259 case elfcpp::R_POWERPC_PLT16_HA
:
8260 case elfcpp::R_PPC64_PLT16_LO_DS
:
8263 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8264 target
->make_local_plt_entry(symtab
, layout
, object
, r_sym
);
8268 case elfcpp::R_PPC64_REL24_NOTOC
:
8272 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8273 case elfcpp::R_POWERPC_REL24
:
8274 case elfcpp::R_PPC_PLTREL24
:
8275 case elfcpp::R_PPC_LOCAL24PC
:
8276 case elfcpp::R_POWERPC_REL14
:
8277 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8278 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8281 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8282 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8283 r_type
, r_sym
, reloc
.get_r_addend());
8287 case elfcpp::R_PPC64_TOCSAVE
:
8288 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8289 // caller has already saved r2 and thus a plt call stub need not
8292 && target
->mark_pltcall(ppc_object
, data_shndx
,
8293 reloc
.get_r_offset() - 4, symtab
))
8295 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8296 unsigned int shndx
= lsym
.get_st_shndx();
8298 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8300 object
->error(_("tocsave symbol %u has bad shndx %u"),
8303 target
->add_tocsave(ppc_object
, shndx
,
8304 lsym
.get_st_value() + reloc
.get_r_addend());
8308 case elfcpp::R_PPC64_REL64
:
8309 case elfcpp::R_POWERPC_REL32
:
8310 case elfcpp::R_POWERPC_REL16
:
8311 case elfcpp::R_POWERPC_REL16_LO
:
8312 case elfcpp::R_POWERPC_REL16_HI
:
8313 case elfcpp::R_POWERPC_REL16_HA
:
8314 case elfcpp::R_POWERPC_REL16DX_HA
:
8315 case elfcpp::R_PPC64_REL16_HIGH
:
8316 case elfcpp::R_PPC64_REL16_HIGHA
:
8317 case elfcpp::R_PPC64_REL16_HIGHER
:
8318 case elfcpp::R_PPC64_REL16_HIGHERA
:
8319 case elfcpp::R_PPC64_REL16_HIGHEST
:
8320 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8321 case elfcpp::R_POWERPC_SECTOFF
:
8322 case elfcpp::R_POWERPC_SECTOFF_LO
:
8323 case elfcpp::R_POWERPC_SECTOFF_HI
:
8324 case elfcpp::R_POWERPC_SECTOFF_HA
:
8325 case elfcpp::R_PPC64_SECTOFF_DS
:
8326 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8327 case elfcpp::R_POWERPC_TPREL16
:
8328 case elfcpp::R_POWERPC_TPREL16_LO
:
8329 case elfcpp::R_POWERPC_TPREL16_HI
:
8330 case elfcpp::R_POWERPC_TPREL16_HA
:
8331 case elfcpp::R_PPC64_TPREL16_DS
:
8332 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8333 case elfcpp::R_PPC64_TPREL16_HIGH
:
8334 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8335 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8336 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8337 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8338 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8339 case elfcpp::R_POWERPC_DTPREL16
:
8340 case elfcpp::R_POWERPC_DTPREL16_LO
:
8341 case elfcpp::R_POWERPC_DTPREL16_HI
:
8342 case elfcpp::R_POWERPC_DTPREL16_HA
:
8343 case elfcpp::R_PPC64_DTPREL16_DS
:
8344 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8345 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8346 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8347 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8348 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8349 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8350 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8351 case elfcpp::R_PPC64_TLSGD
:
8352 case elfcpp::R_PPC64_TLSLD
:
8353 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8356 case elfcpp::R_PPC64_GOT_PCREL34
:
8357 case elfcpp::R_POWERPC_GOT16
:
8358 case elfcpp::R_POWERPC_GOT16_LO
:
8359 case elfcpp::R_POWERPC_GOT16_HI
:
8360 case elfcpp::R_POWERPC_GOT16_HA
:
8361 case elfcpp::R_PPC64_GOT16_DS
:
8362 case elfcpp::R_PPC64_GOT16_LO_DS
:
8364 // The symbol requires a GOT entry.
8365 Got_type got_type
= ((size
== 32
8366 || r_type
== elfcpp::R_POWERPC_GOT16
8367 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8368 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8369 Output_data_got_powerpc
<size
, big_endian
>* got
8370 = target
->got_section(symtab
, layout
, got_type
);
8371 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8372 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8374 if (!parameters
->options().output_is_position_independent())
8377 && (size
== 32 || target
->abiversion() >= 2))
8378 got
->add_local_plt(object
, r_sym
, got_type
, addend
);
8380 got
->add_local(object
, r_sym
, got_type
, addend
);
8382 else if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8384 // If we are generating a shared object or a pie, this
8385 // symbol's GOT entry will be set by a dynamic relocation.
8387 off
= got
->add_constant(0);
8388 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8390 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8392 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8393 : elfcpp::R_POWERPC_RELATIVE
);
8394 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8395 got
, off
, addend
, false);
8400 case elfcpp::R_PPC64_TOC16
:
8401 case elfcpp::R_PPC64_TOC16_LO
:
8402 case elfcpp::R_PPC64_TOC16_HI
:
8403 case elfcpp::R_PPC64_TOC16_HA
:
8404 case elfcpp::R_PPC64_TOC16_DS
:
8405 case elfcpp::R_PPC64_TOC16_LO_DS
:
8406 // We need a GOT section.
8407 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8410 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8411 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8412 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8413 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8414 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8416 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8417 if (tls_type
== tls::TLSOPT_NONE
)
8419 Got_type got_type
= ((size
== 32
8420 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8421 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8422 Output_data_got_powerpc
<size
, big_endian
>* got
8423 = target
->got_section(symtab
, layout
, got_type
);
8424 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8425 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8426 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8427 got
->add_local_tls_pair(object
, r_sym
, got_type
,
8428 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
,
8431 else if (tls_type
== tls::TLSOPT_TO_LE
)
8433 // no GOT relocs needed for Local Exec.
8440 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8441 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8442 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8443 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8444 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8446 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8447 if (tls_type
== tls::TLSOPT_NONE
)
8448 target
->tlsld_got_offset(symtab
, layout
, object
);
8449 else if (tls_type
== tls::TLSOPT_TO_LE
)
8451 // no GOT relocs needed for Local Exec.
8452 if (parameters
->options().emit_relocs())
8454 Output_section
* os
= layout
->tls_segment()->first_section();
8455 gold_assert(os
!= NULL
);
8456 os
->set_needs_symtab_index();
8464 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8465 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8466 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8467 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8468 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8470 Got_type got_type
= ((size
== 32
8471 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
8472 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
8473 Output_data_got_powerpc
<size
, big_endian
>* got
8474 = target
->got_section(symtab
, layout
, got_type
);
8475 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8476 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8477 got
->add_local_tls(object
, r_sym
, got_type
, addend
);
8481 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8482 case elfcpp::R_POWERPC_GOT_TPREL16
:
8483 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8484 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8485 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8487 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8488 if (tls_type
== tls::TLSOPT_NONE
)
8490 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8491 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8492 Got_type got_type
= ((size
== 32
8493 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
8494 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
8495 if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8497 Output_data_got_powerpc
<size
, big_endian
>* got
8498 = target
->got_section(symtab
, layout
, got_type
);
8499 unsigned int off
= got
->add_constant(0);
8500 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8502 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8503 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8504 elfcpp::R_POWERPC_TPREL
,
8508 else if (tls_type
== tls::TLSOPT_TO_LE
)
8510 // no GOT relocs needed for Local Exec.
8518 unsupported_reloc_local(object
, r_type
);
8523 && parameters
->options().toc_optimize())
8525 if (data_shndx
== ppc_object
->toc_shndx())
8528 if (r_type
!= elfcpp::R_PPC64_ADDR64
8529 || (is_ifunc
&& target
->abiversion() < 2))
8531 else if (parameters
->options().output_is_position_independent())
8537 unsigned int shndx
= lsym
.get_st_shndx();
8538 if (shndx
>= elfcpp::SHN_LORESERVE
8539 && shndx
!= elfcpp::SHN_XINDEX
)
8544 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8547 enum {no_check
, check_lo
, check_ha
} insn_check
;
8551 insn_check
= no_check
;
8554 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8555 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8556 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8557 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8558 case elfcpp::R_POWERPC_GOT16_HA
:
8559 case elfcpp::R_PPC64_TOC16_HA
:
8560 insn_check
= check_ha
;
8563 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8564 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8565 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8566 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8567 case elfcpp::R_POWERPC_GOT16_LO
:
8568 case elfcpp::R_PPC64_GOT16_LO_DS
:
8569 case elfcpp::R_PPC64_TOC16_LO
:
8570 case elfcpp::R_PPC64_TOC16_LO_DS
:
8571 insn_check
= check_lo
;
8575 section_size_type slen
;
8576 const unsigned char* view
= NULL
;
8577 if (insn_check
!= no_check
)
8579 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8580 section_size_type off
=
8581 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8584 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8585 if (insn_check
== check_lo
8586 ? !ok_lo_toc_insn(insn
, r_type
)
8587 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8588 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8590 ppc_object
->set_no_toc_opt();
8591 gold_warning(_("%s: toc optimization is not supported "
8592 "for %#08x instruction"),
8593 ppc_object
->name().c_str(), insn
);
8602 case elfcpp::R_PPC64_TOC16
:
8603 case elfcpp::R_PPC64_TOC16_LO
:
8604 case elfcpp::R_PPC64_TOC16_HI
:
8605 case elfcpp::R_PPC64_TOC16_HA
:
8606 case elfcpp::R_PPC64_TOC16_DS
:
8607 case elfcpp::R_PPC64_TOC16_LO_DS
:
8608 unsigned int shndx
= lsym
.get_st_shndx();
8609 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8611 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8612 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8614 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8615 if (dst_off
< ppc_object
->section_size(shndx
))
8618 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8620 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8622 // Need to check that the insn is a ld
8624 view
= ppc_object
->section_contents(data_shndx
,
8627 section_size_type off
=
8628 (convert_to_section_size_type(reloc
.get_r_offset())
8629 + (big_endian
? -2 : 3));
8631 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8635 ppc_object
->set_no_toc_opt(dst_off
);
8646 case elfcpp::R_POWERPC_REL32
:
8647 if (ppc_object
->got2_shndx() != 0
8648 && parameters
->options().output_is_position_independent())
8650 unsigned int shndx
= lsym
.get_st_shndx();
8651 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8653 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8654 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8655 && (ppc_object
->section_flags(data_shndx
)
8656 & elfcpp::SHF_EXECINSTR
) != 0)
8657 gold_error(_("%s: unsupported -mbss-plt code"),
8658 ppc_object
->name().c_str());
8668 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8669 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8670 case elfcpp::R_POWERPC_GOT_TPREL16
:
8671 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8672 case elfcpp::R_POWERPC_GOT16
:
8673 case elfcpp::R_PPC64_GOT16_DS
:
8674 case elfcpp::R_PPC64_TOC16
:
8675 case elfcpp::R_PPC64_TOC16_DS
:
8676 ppc_object
->set_has_small_toc_reloc();
8684 case elfcpp::R_PPC64_TPREL16_DS
:
8685 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8686 case elfcpp::R_PPC64_TPREL16_HIGH
:
8687 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8688 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8689 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8690 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8691 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8692 case elfcpp::R_PPC64_TPREL34
:
8696 case elfcpp::R_POWERPC_TPREL16
:
8697 case elfcpp::R_POWERPC_TPREL16_LO
:
8698 case elfcpp::R_POWERPC_TPREL16_HI
:
8699 case elfcpp::R_POWERPC_TPREL16_HA
:
8700 layout
->set_has_static_tls();
8708 case elfcpp::R_POWERPC_TPREL16_HA
:
8709 if (target
->tprel_opt())
8711 section_size_type slen
;
8712 const unsigned char* view
= NULL
;
8713 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8714 section_size_type off
8715 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8718 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8719 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8720 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8721 target
->set_no_tprel_opt();
8726 case elfcpp::R_PPC64_TPREL16_HIGH
:
8727 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8728 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8729 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8730 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8731 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8735 case elfcpp::R_POWERPC_TPREL16_HI
:
8736 target
->set_no_tprel_opt();
8744 case elfcpp::R_PPC64_D34
:
8745 case elfcpp::R_PPC64_D34_LO
:
8746 case elfcpp::R_PPC64_D34_HI30
:
8747 case elfcpp::R_PPC64_D34_HA30
:
8748 case elfcpp::R_PPC64_D28
:
8749 case elfcpp::R_PPC64_PCREL34
:
8750 case elfcpp::R_PPC64_PCREL28
:
8751 case elfcpp::R_PPC64_TPREL34
:
8752 case elfcpp::R_PPC64_DTPREL34
:
8753 case elfcpp::R_PPC64_PLT_PCREL34
:
8754 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8755 case elfcpp::R_PPC64_GOT_PCREL34
:
8756 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8757 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8758 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8759 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8760 target
->set_power10_relocs();
8767 // Report an unsupported relocation against a global symbol.
8769 template<int size
, bool big_endian
>
8771 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8772 Sized_relobj_file
<size
, big_endian
>* object
,
8773 unsigned int r_type
,
8776 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8777 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8780 // Scan a relocation for a global symbol.
8782 template<int size
, bool big_endian
>
8784 Target_powerpc
<size
, big_endian
>::Scan::global(
8785 Symbol_table
* symtab
,
8787 Target_powerpc
<size
, big_endian
>* target
,
8788 Sized_relobj_file
<size
, big_endian
>* object
,
8789 unsigned int data_shndx
,
8790 Output_section
* output_section
,
8791 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8792 unsigned int r_type
,
8795 Powerpc_relobj
<size
, big_endian
>* ppc_object
8796 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8798 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8800 case Track_tls::SKIP
:
8806 if (target
->replace_tls_get_addr(gsym
))
8807 // Change a __tls_get_addr reference to __tls_get_addr_opt
8808 // so dynamic relocs are emitted against the latter symbol.
8809 gsym
= target
->tls_get_addr_opt();
8811 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8812 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8814 this->expect_tls_get_addr_call();
8815 bool final
= gsym
->final_value_is_known();
8816 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8817 if (tls_type
!= tls::TLSOPT_NONE
)
8818 this->skip_next_tls_get_addr_call();
8820 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8821 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8823 this->expect_tls_get_addr_call();
8824 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8825 if (tls_type
!= tls::TLSOPT_NONE
)
8826 this->skip_next_tls_get_addr_call();
8829 // A STT_GNU_IFUNC symbol may require a PLT entry.
8830 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8831 bool pushed_ifunc
= false;
8832 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8834 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8835 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8836 r_type
, r_sym
, reloc
.get_r_addend());
8837 target
->make_plt_entry(symtab
, layout
, gsym
);
8838 pushed_ifunc
= true;
8843 case elfcpp::R_POWERPC_NONE
:
8844 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8845 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8846 case elfcpp::R_PPC_LOCAL24PC
:
8847 case elfcpp::R_POWERPC_TLS
:
8848 case elfcpp::R_PPC64_ENTRY
:
8849 case elfcpp::R_POWERPC_PLTSEQ
:
8850 case elfcpp::R_POWERPC_PLTCALL
:
8851 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8852 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8853 case elfcpp::R_PPC64_PCREL_OPT
:
8854 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8855 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8856 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8857 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8858 case elfcpp::R_PPC64_REL16_HIGHER34
:
8859 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8860 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8861 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8862 case elfcpp::R_PPC64_D34
:
8863 case elfcpp::R_PPC64_D34_LO
:
8864 case elfcpp::R_PPC64_D34_HI30
:
8865 case elfcpp::R_PPC64_D34_HA30
:
8866 case elfcpp::R_PPC64_D28
:
8867 case elfcpp::R_PPC64_PCREL34
:
8868 case elfcpp::R_PPC64_PCREL28
:
8869 case elfcpp::R_PPC64_TPREL34
:
8870 case elfcpp::R_PPC64_DTPREL34
:
8873 case elfcpp::R_PPC64_TOC
:
8875 Output_data_got_powerpc
<size
, big_endian
>* got
8876 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8877 if (parameters
->options().output_is_position_independent())
8879 Address off
= reloc
.get_r_offset();
8881 && data_shndx
== ppc_object
->opd_shndx()
8882 && ppc_object
->get_opd_discard(off
- 8))
8885 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8886 Address got_off
= got
->g_o_t();
8887 rela_dyn
->add_output_section_relative(got
->output_section(),
8888 elfcpp::R_POWERPC_RELATIVE
,
8890 object
, data_shndx
, off
,
8896 case elfcpp::R_PPC64_ADDR64
:
8898 && target
->abiversion() < 2
8899 && data_shndx
== ppc_object
->opd_shndx()
8900 && (gsym
->is_defined_in_discarded_section()
8901 || gsym
->object() != object
))
8903 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8907 case elfcpp::R_PPC64_UADDR64
:
8908 case elfcpp::R_POWERPC_ADDR32
:
8909 case elfcpp::R_POWERPC_UADDR32
:
8910 case elfcpp::R_POWERPC_ADDR24
:
8911 case elfcpp::R_POWERPC_ADDR16
:
8912 case elfcpp::R_POWERPC_ADDR16_LO
:
8913 case elfcpp::R_POWERPC_ADDR16_HI
:
8914 case elfcpp::R_POWERPC_ADDR16_HA
:
8915 case elfcpp::R_POWERPC_UADDR16
:
8916 case elfcpp::R_PPC64_ADDR16_HIGH
:
8917 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8918 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8919 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8920 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8921 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8922 case elfcpp::R_PPC64_ADDR16_DS
:
8923 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8924 case elfcpp::R_POWERPC_ADDR14
:
8925 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8926 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8928 // Make a PLT entry if necessary.
8929 if (gsym
->needs_plt_entry())
8931 // Since this is not a PC-relative relocation, we may be
8932 // taking the address of a function. In that case we need to
8933 // set the entry in the dynamic symbol table to the address of
8934 // the PLT call stub.
8935 bool need_ifunc_plt
= false;
8936 if ((size
== 32 || target
->abiversion() >= 2)
8937 && gsym
->is_from_dynobj()
8938 && !parameters
->options().output_is_position_independent())
8940 gsym
->set_needs_dynsym_value();
8941 need_ifunc_plt
= true;
8943 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8945 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8946 target
->push_branch(ppc_object
, data_shndx
,
8947 reloc
.get_r_offset(), r_type
, r_sym
,
8948 reloc
.get_r_addend());
8949 target
->make_plt_entry(symtab
, layout
, gsym
);
8952 // Make a dynamic relocation if necessary.
8953 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8954 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8956 if (!parameters
->options().output_is_position_independent()
8957 && gsym
->may_need_copy_reloc())
8959 target
->copy_reloc(symtab
, layout
, object
,
8960 data_shndx
, output_section
, gsym
, reloc
);
8962 else if ((((size
== 32
8963 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8965 && r_type
== elfcpp::R_PPC64_ADDR64
8966 && target
->abiversion() >= 2))
8967 && gsym
->can_use_relative_reloc(false)
8968 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8969 && parameters
->options().shared()))
8971 && r_type
== elfcpp::R_PPC64_ADDR64
8972 && target
->abiversion() < 2
8973 && (gsym
->can_use_relative_reloc(false)
8974 || data_shndx
== ppc_object
->opd_shndx())))
8976 Reloc_section
* rela_dyn
8977 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8978 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8979 : elfcpp::R_POWERPC_RELATIVE
);
8980 rela_dyn
->add_symbolless_global_addend(
8981 gsym
, dynrel
, output_section
, object
, data_shndx
,
8982 reloc
.get_r_offset(), reloc
.get_r_addend());
8986 Reloc_section
* rela_dyn
8987 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8988 check_non_pic(object
, r_type
);
8989 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8991 reloc
.get_r_offset(),
8992 reloc
.get_r_addend());
8995 && parameters
->options().toc_optimize()
8996 && data_shndx
== ppc_object
->toc_shndx())
8997 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9003 case elfcpp::R_PPC64_PLT_PCREL34
:
9004 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9005 case elfcpp::R_POWERPC_PLT16_LO
:
9006 case elfcpp::R_POWERPC_PLT16_HI
:
9007 case elfcpp::R_POWERPC_PLT16_HA
:
9008 case elfcpp::R_PPC64_PLT16_LO_DS
:
9011 if (!parameters
->doing_static_link())
9012 target
->make_plt_entry(symtab
, layout
, gsym
);
9014 target
->make_local_plt_entry(symtab
, layout
, gsym
);
9018 case elfcpp::R_PPC64_REL24_NOTOC
:
9022 case elfcpp::R_PPC64_REL24_P9NOTOC
:
9023 case elfcpp::R_PPC_PLTREL24
:
9024 case elfcpp::R_POWERPC_REL24
:
9027 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9028 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9029 r_type
, r_sym
, reloc
.get_r_addend());
9030 if (gsym
->needs_plt_entry()
9031 || (!gsym
->final_value_is_known()
9032 && (gsym
->is_undefined()
9033 || gsym
->is_from_dynobj()
9034 || gsym
->is_preemptible())))
9035 target
->make_plt_entry(symtab
, layout
, gsym
);
9039 case elfcpp::R_PPC64_REL64
:
9040 case elfcpp::R_POWERPC_REL32
:
9041 // Make a dynamic relocation if necessary.
9042 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
9044 if (!parameters
->options().output_is_position_independent()
9045 && gsym
->may_need_copy_reloc())
9047 target
->copy_reloc(symtab
, layout
, object
,
9048 data_shndx
, output_section
, gsym
,
9053 Reloc_section
* rela_dyn
9054 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9055 check_non_pic(object
, r_type
);
9056 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
9057 data_shndx
, reloc
.get_r_offset(),
9058 reloc
.get_r_addend());
9063 case elfcpp::R_POWERPC_REL14
:
9064 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9065 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9068 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9069 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9070 r_type
, r_sym
, reloc
.get_r_addend());
9074 case elfcpp::R_PPC64_TOCSAVE
:
9075 // R_PPC64_TOCSAVE follows a call instruction to indicate the
9076 // caller has already saved r2 and thus a plt call stub need not
9079 && target
->mark_pltcall(ppc_object
, data_shndx
,
9080 reloc
.get_r_offset() - 4, symtab
))
9082 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9084 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9086 object
->error(_("tocsave symbol %u has bad shndx %u"),
9090 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9091 target
->add_tocsave(ppc_object
, shndx
,
9092 sym
->value() + reloc
.get_r_addend());
9097 case elfcpp::R_POWERPC_REL16
:
9098 case elfcpp::R_POWERPC_REL16_LO
:
9099 case elfcpp::R_POWERPC_REL16_HI
:
9100 case elfcpp::R_POWERPC_REL16_HA
:
9101 case elfcpp::R_POWERPC_REL16DX_HA
:
9102 case elfcpp::R_PPC64_REL16_HIGH
:
9103 case elfcpp::R_PPC64_REL16_HIGHA
:
9104 case elfcpp::R_PPC64_REL16_HIGHER
:
9105 case elfcpp::R_PPC64_REL16_HIGHERA
:
9106 case elfcpp::R_PPC64_REL16_HIGHEST
:
9107 case elfcpp::R_PPC64_REL16_HIGHESTA
:
9108 case elfcpp::R_POWERPC_SECTOFF
:
9109 case elfcpp::R_POWERPC_SECTOFF_LO
:
9110 case elfcpp::R_POWERPC_SECTOFF_HI
:
9111 case elfcpp::R_POWERPC_SECTOFF_HA
:
9112 case elfcpp::R_PPC64_SECTOFF_DS
:
9113 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9114 case elfcpp::R_POWERPC_TPREL16
:
9115 case elfcpp::R_POWERPC_TPREL16_LO
:
9116 case elfcpp::R_POWERPC_TPREL16_HI
:
9117 case elfcpp::R_POWERPC_TPREL16_HA
:
9118 case elfcpp::R_PPC64_TPREL16_DS
:
9119 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9120 case elfcpp::R_PPC64_TPREL16_HIGH
:
9121 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9122 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9123 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9124 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9125 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9126 case elfcpp::R_POWERPC_DTPREL16
:
9127 case elfcpp::R_POWERPC_DTPREL16_LO
:
9128 case elfcpp::R_POWERPC_DTPREL16_HI
:
9129 case elfcpp::R_POWERPC_DTPREL16_HA
:
9130 case elfcpp::R_PPC64_DTPREL16_DS
:
9131 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
9132 case elfcpp::R_PPC64_DTPREL16_HIGH
:
9133 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
9134 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
9135 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
9136 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
9137 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
9138 case elfcpp::R_PPC64_TLSGD
:
9139 case elfcpp::R_PPC64_TLSLD
:
9140 case elfcpp::R_PPC64_ADDR64_LOCAL
:
9143 case elfcpp::R_PPC64_GOT_PCREL34
:
9144 case elfcpp::R_POWERPC_GOT16
:
9145 case elfcpp::R_POWERPC_GOT16_LO
:
9146 case elfcpp::R_POWERPC_GOT16_HI
:
9147 case elfcpp::R_POWERPC_GOT16_HA
:
9148 case elfcpp::R_PPC64_GOT16_DS
:
9149 case elfcpp::R_PPC64_GOT16_LO_DS
:
9151 // The symbol requires a GOT entry.
9152 Output_data_got_powerpc
<size
, big_endian
>* got
;
9153 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9154 Got_type got_type
= ((size
== 32
9155 || r_type
== elfcpp::R_POWERPC_GOT16
9156 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
9157 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
9159 got
= target
->got_section(symtab
, layout
, got_type
);
9160 if (gsym
->final_value_is_known())
9163 && (size
== 32 || target
->abiversion() >= 2))
9164 got
->add_global_plt(gsym
, got_type
, addend
);
9166 got
->add_global(gsym
, got_type
, addend
);
9168 else if (!gsym
->has_got_offset(got_type
, addend
))
9170 // If we are generating a shared object or a pie, this
9171 // symbol's GOT entry will be set by a dynamic relocation.
9172 unsigned int off
= got
->add_constant(0);
9173 gsym
->set_got_offset(got_type
, off
, addend
);
9175 Reloc_section
* rela_dyn
9176 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9178 if (gsym
->can_use_relative_reloc(false)
9180 || target
->abiversion() >= 2)
9181 && gsym
->visibility() == elfcpp::STV_PROTECTED
9182 && parameters
->options().shared()))
9184 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
9185 : elfcpp::R_POWERPC_RELATIVE
);
9186 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
,
9191 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
9192 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, addend
);
9198 case elfcpp::R_PPC64_TOC16
:
9199 case elfcpp::R_PPC64_TOC16_LO
:
9200 case elfcpp::R_PPC64_TOC16_HI
:
9201 case elfcpp::R_PPC64_TOC16_HA
:
9202 case elfcpp::R_PPC64_TOC16_DS
:
9203 case elfcpp::R_PPC64_TOC16_LO_DS
:
9204 // We need a GOT section.
9205 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
9208 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9209 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9210 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9211 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9212 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9214 bool final
= gsym
->final_value_is_known();
9215 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9216 if (tls_type
== tls::TLSOPT_NONE
)
9218 Got_type got_type
= ((size
== 32
9219 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9220 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
9221 Output_data_got_powerpc
<size
, big_endian
>* got
9222 = target
->got_section(symtab
, layout
, got_type
);
9223 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9224 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9225 got
->add_global_pair_with_rel(gsym
, got_type
, rela_dyn
,
9226 elfcpp::R_POWERPC_DTPMOD
,
9227 elfcpp::R_POWERPC_DTPREL
,
9230 else if (tls_type
== tls::TLSOPT_TO_IE
)
9232 Got_type got_type
= ((size
== 32
9233 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9234 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9235 if (!gsym
->has_got_offset(got_type
))
9237 Output_data_got_powerpc
<size
, big_endian
>* got
9238 = target
->got_section(symtab
, layout
, got_type
);
9239 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9240 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9241 if (gsym
->is_undefined()
9242 || gsym
->is_from_dynobj())
9244 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9245 elfcpp::R_POWERPC_TPREL
, addend
);
9249 unsigned int off
= got
->add_constant(0);
9250 gsym
->set_got_offset(got_type
, off
);
9251 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9252 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9257 else if (tls_type
== tls::TLSOPT_TO_LE
)
9259 // no GOT relocs needed for Local Exec.
9266 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9267 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9268 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9269 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9270 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9272 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9273 if (tls_type
== tls::TLSOPT_NONE
)
9274 target
->tlsld_got_offset(symtab
, layout
, object
);
9275 else if (tls_type
== tls::TLSOPT_TO_LE
)
9277 // no GOT relocs needed for Local Exec.
9278 if (parameters
->options().emit_relocs())
9280 Output_section
* os
= layout
->tls_segment()->first_section();
9281 gold_assert(os
!= NULL
);
9282 os
->set_needs_symtab_index();
9290 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9291 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9292 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9293 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9294 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9296 Got_type got_type
= ((size
== 32
9297 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
9298 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
9299 Output_data_got_powerpc
<size
, big_endian
>* got
9300 = target
->got_section(symtab
, layout
, got_type
);
9301 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9302 if (!gsym
->final_value_is_known()
9303 && (gsym
->is_from_dynobj()
9304 || gsym
->is_undefined()
9305 || gsym
->is_preemptible()))
9306 got
->add_global_with_rel(gsym
, got_type
,
9307 target
->rela_dyn_section(layout
),
9308 elfcpp::R_POWERPC_DTPREL
, addend
);
9310 got
->add_global_tls(gsym
, got_type
, addend
);
9314 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9315 case elfcpp::R_POWERPC_GOT_TPREL16
:
9316 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9317 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9318 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9320 bool final
= gsym
->final_value_is_known();
9321 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9322 if (tls_type
== tls::TLSOPT_NONE
)
9324 Got_type got_type
= ((size
== 32
9325 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
9326 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9327 if (!gsym
->has_got_offset(got_type
))
9329 Output_data_got_powerpc
<size
, big_endian
>* got
9330 = target
->got_section(symtab
, layout
, got_type
);
9331 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9332 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9333 if (gsym
->is_undefined()
9334 || gsym
->is_from_dynobj())
9336 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9337 elfcpp::R_POWERPC_TPREL
, addend
);
9341 unsigned int off
= got
->add_constant(0);
9342 gsym
->set_got_offset(got_type
, off
);
9343 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9344 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9349 else if (tls_type
== tls::TLSOPT_TO_LE
)
9351 // no GOT relocs needed for Local Exec.
9359 unsupported_reloc_global(object
, r_type
, gsym
);
9364 && parameters
->options().toc_optimize())
9366 if (data_shndx
== ppc_object
->toc_shndx())
9369 if (r_type
!= elfcpp::R_PPC64_ADDR64
9370 || (is_ifunc
&& target
->abiversion() < 2))
9372 else if (parameters
->options().output_is_position_independent()
9373 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9376 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9379 enum {no_check
, check_lo
, check_ha
} insn_check
;
9383 insn_check
= no_check
;
9386 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9387 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9388 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9389 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9390 case elfcpp::R_POWERPC_GOT16_HA
:
9391 case elfcpp::R_PPC64_TOC16_HA
:
9392 insn_check
= check_ha
;
9395 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9396 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9397 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9398 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9399 case elfcpp::R_POWERPC_GOT16_LO
:
9400 case elfcpp::R_PPC64_GOT16_LO_DS
:
9401 case elfcpp::R_PPC64_TOC16_LO
:
9402 case elfcpp::R_PPC64_TOC16_LO_DS
:
9403 insn_check
= check_lo
;
9407 section_size_type slen
;
9408 const unsigned char* view
= NULL
;
9409 if (insn_check
!= no_check
)
9411 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9412 section_size_type off
=
9413 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9416 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9417 if (insn_check
== check_lo
9418 ? !ok_lo_toc_insn(insn
, r_type
)
9419 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9420 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9422 ppc_object
->set_no_toc_opt();
9423 gold_warning(_("%s: toc optimization is not supported "
9424 "for %#08x instruction"),
9425 ppc_object
->name().c_str(), insn
);
9434 case elfcpp::R_PPC64_TOC16
:
9435 case elfcpp::R_PPC64_TOC16_LO
:
9436 case elfcpp::R_PPC64_TOC16_HI
:
9437 case elfcpp::R_PPC64_TOC16_HA
:
9438 case elfcpp::R_PPC64_TOC16_DS
:
9439 case elfcpp::R_PPC64_TOC16_LO_DS
:
9440 if (gsym
->source() == Symbol::FROM_OBJECT
9441 && !gsym
->object()->is_dynamic())
9443 Powerpc_relobj
<size
, big_endian
>* sym_object
9444 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9446 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9447 if (shndx
== sym_object
->toc_shndx())
9449 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9450 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9451 if (dst_off
< sym_object
->section_size(shndx
))
9454 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9456 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9458 // Need to check that the insn is a ld
9460 view
= ppc_object
->section_contents(data_shndx
,
9463 section_size_type off
=
9464 (convert_to_section_size_type(reloc
.get_r_offset())
9465 + (big_endian
? -2 : 3));
9467 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9471 sym_object
->set_no_toc_opt(dst_off
);
9483 case elfcpp::R_PPC_LOCAL24PC
:
9484 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9485 gold_error(_("%s: unsupported -mbss-plt code"),
9486 ppc_object
->name().c_str());
9495 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9496 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9497 case elfcpp::R_POWERPC_GOT_TPREL16
:
9498 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9499 case elfcpp::R_POWERPC_GOT16
:
9500 case elfcpp::R_PPC64_GOT16_DS
:
9501 case elfcpp::R_PPC64_TOC16
:
9502 case elfcpp::R_PPC64_TOC16_DS
:
9503 ppc_object
->set_has_small_toc_reloc();
9511 case elfcpp::R_PPC64_TPREL16_DS
:
9512 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9513 case elfcpp::R_PPC64_TPREL16_HIGH
:
9514 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9515 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9516 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9517 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9518 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9519 case elfcpp::R_PPC64_TPREL34
:
9523 case elfcpp::R_POWERPC_TPREL16
:
9524 case elfcpp::R_POWERPC_TPREL16_LO
:
9525 case elfcpp::R_POWERPC_TPREL16_HI
:
9526 case elfcpp::R_POWERPC_TPREL16_HA
:
9527 layout
->set_has_static_tls();
9535 case elfcpp::R_POWERPC_TPREL16_HA
:
9536 if (target
->tprel_opt())
9538 section_size_type slen
;
9539 const unsigned char* view
= NULL
;
9540 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9541 section_size_type off
9542 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9545 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9546 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9547 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9548 target
->set_no_tprel_opt();
9553 case elfcpp::R_PPC64_TPREL16_HIGH
:
9554 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9555 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9556 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9557 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9558 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9562 case elfcpp::R_POWERPC_TPREL16_HI
:
9563 target
->set_no_tprel_opt();
9571 case elfcpp::R_PPC64_D34
:
9572 case elfcpp::R_PPC64_D34_LO
:
9573 case elfcpp::R_PPC64_D34_HI30
:
9574 case elfcpp::R_PPC64_D34_HA30
:
9575 case elfcpp::R_PPC64_D28
:
9576 case elfcpp::R_PPC64_PCREL34
:
9577 case elfcpp::R_PPC64_PCREL28
:
9578 case elfcpp::R_PPC64_TPREL34
:
9579 case elfcpp::R_PPC64_DTPREL34
:
9580 case elfcpp::R_PPC64_PLT_PCREL34
:
9581 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9582 case elfcpp::R_PPC64_GOT_PCREL34
:
9583 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9584 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9585 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9586 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9587 target
->set_power10_relocs();
9594 // Process relocations for gc.
9596 template<int size
, bool big_endian
>
9598 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9599 Symbol_table
* symtab
,
9601 Sized_relobj_file
<size
, big_endian
>* object
,
9602 unsigned int data_shndx
,
9604 const unsigned char* prelocs
,
9606 Output_section
* output_section
,
9607 bool needs_special_offset_handling
,
9608 size_t local_symbol_count
,
9609 const unsigned char* plocal_symbols
)
9611 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9612 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9615 Powerpc_relobj
<size
, big_endian
>* ppc_object
9616 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9618 ppc_object
->set_opd_valid();
9619 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9621 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9622 for (p
= ppc_object
->access_from_map()->begin();
9623 p
!= ppc_object
->access_from_map()->end();
9626 Address dst_off
= p
->first
;
9627 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9628 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9629 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9631 Relobj
* src_obj
= s
->first
;
9632 unsigned int src_indx
= s
->second
;
9633 symtab
->gc()->add_reference(src_obj
, src_indx
,
9634 ppc_object
, dst_indx
);
9638 ppc_object
->access_from_map()->clear();
9639 ppc_object
->process_gc_mark(symtab
);
9640 // Don't look at .opd relocs as .opd will reference everything.
9644 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9653 needs_special_offset_handling
,
9658 // Handle target specific gc actions when adding a gc reference from
9659 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9660 // and DST_OFF. For powerpc64, this adds a referenc to the code
9661 // section of a function descriptor.
9663 template<int size
, bool big_endian
>
9665 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9666 Symbol_table
* symtab
,
9668 unsigned int src_shndx
,
9670 unsigned int dst_shndx
,
9671 Address dst_off
) const
9673 if (size
!= 64 || dst_obj
->is_dynamic())
9676 Powerpc_relobj
<size
, big_endian
>* ppc_object
9677 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9678 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9680 if (ppc_object
->opd_valid())
9682 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9683 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9687 // If we haven't run scan_opd_relocs, we must delay
9688 // processing this function descriptor reference.
9689 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9694 // Add any special sections for this symbol to the gc work list.
9695 // For powerpc64, this adds the code section of a function
9698 template<int size
, bool big_endian
>
9700 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9701 Symbol_table
* symtab
,
9704 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9706 Powerpc_relobj
<size
, big_endian
>* ppc_object
9707 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9709 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9710 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9712 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9713 Address dst_off
= gsym
->value();
9714 if (ppc_object
->opd_valid())
9716 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9717 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9721 ppc_object
->add_gc_mark(dst_off
);
9726 // For a symbol location in .opd, set LOC to the location of the
9729 template<int size
, bool big_endian
>
9731 Target_powerpc
<size
, big_endian
>::do_function_location(
9732 Symbol_location
* loc
) const
9734 if (size
== 64 && loc
->shndx
!= 0)
9736 if (loc
->object
->is_dynamic())
9738 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9739 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9740 if (loc
->shndx
== ppc_object
->opd_shndx())
9743 Address off
= loc
->offset
- ppc_object
->opd_address();
9744 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9745 loc
->offset
= dest_off
;
9750 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9751 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9752 if (loc
->shndx
== ppc_object
->opd_shndx())
9755 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9756 loc
->offset
= dest_off
;
9762 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9763 // compiled with -fsplit-stack. The function calls non-split-stack
9764 // code. Change the function to ensure it has enough stack space to
9765 // call some random function.
9767 template<int size
, bool big_endian
>
9769 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9772 section_offset_type fnoffset
,
9773 section_size_type fnsize
,
9774 const unsigned char* prelocs
,
9776 unsigned char* view
,
9777 section_size_type view_size
,
9779 std::string
* to
) const
9781 // 32-bit not supported.
9785 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9786 prelocs
, reloc_count
, view
, view_size
,
9791 // The function always starts with
9792 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9793 // addis %r12,%r1,-allocate@ha
9794 // addi %r12,%r12,-allocate@l
9796 // but note that the addis or addi may be replaced with a nop
9798 unsigned char *entry
= view
+ fnoffset
;
9799 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9801 if ((insn
& 0xffff0000) == addis_2_12
)
9803 /* Skip ELFv2 global entry code. */
9805 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9808 unsigned char *pinsn
= entry
;
9810 const uint32_t ld_private_ss
= 0xe80d8fc0;
9811 if (insn
== ld_private_ss
)
9813 int32_t allocate
= 0;
9817 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9818 if ((insn
& 0xffff0000) == addis_12_1
)
9819 allocate
+= (insn
& 0xffff) << 16;
9820 else if ((insn
& 0xffff0000) == addi_12_1
9821 || (insn
& 0xffff0000) == addi_12_12
)
9822 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9823 else if (insn
!= nop
)
9826 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9828 int extra
= parameters
->options().split_stack_adjust_size();
9830 if (allocate
>= 0 || extra
< 0)
9832 object
->error(_("split-stack stack size overflow at "
9833 "section %u offset %0zx"),
9834 shndx
, static_cast<size_t>(fnoffset
));
9838 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9839 if (insn
!= addis_12_1
)
9841 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9843 insn
= addi_12_12
| (allocate
& 0xffff);
9844 if (insn
!= addi_12_12
)
9846 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9852 insn
= addi_12_1
| (allocate
& 0xffff);
9853 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9856 if (pinsn
!= entry
+ 12)
9857 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9865 if (!object
->has_no_split_stack())
9866 object
->error(_("failed to match split-stack sequence at "
9867 "section %u offset %0zx"),
9868 shndx
, static_cast<size_t>(fnoffset
));
9872 // Scan relocations for a section.
9874 template<int size
, bool big_endian
>
9876 Target_powerpc
<size
, big_endian
>::scan_relocs(
9877 Symbol_table
* symtab
,
9879 Sized_relobj_file
<size
, big_endian
>* object
,
9880 unsigned int data_shndx
,
9881 unsigned int sh_type
,
9882 const unsigned char* prelocs
,
9884 Output_section
* output_section
,
9885 bool needs_special_offset_handling
,
9886 size_t local_symbol_count
,
9887 const unsigned char* plocal_symbols
)
9889 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9890 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9893 if (!this->plt_localentry0_init_
)
9895 bool plt_localentry0
= false;
9897 && this->abiversion() >= 2)
9899 if (parameters
->options().user_set_plt_localentry())
9900 plt_localentry0
= parameters
->options().plt_localentry();
9902 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9903 gold_warning(_("--plt-localentry is especially dangerous without "
9904 "ld.so support to detect ABI violations"));
9906 this->plt_localentry0_
= plt_localentry0
;
9907 this->plt_localentry0_init_
= true;
9910 if (sh_type
== elfcpp::SHT_REL
)
9912 gold_error(_("%s: unsupported REL reloc section"),
9913 object
->name().c_str());
9917 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9926 needs_special_offset_handling
,
9930 if (this->plt_localentry0_
&& this->power10_relocs_
)
9932 gold_warning(_("--plt-localentry is incompatible with "
9933 "power10 pc-relative code"));
9934 this->plt_localentry0_
= false;
9938 // Functor class for processing the global symbol table.
9939 // Removes symbols defined on discarded opd entries.
9941 template<bool big_endian
>
9942 class Global_symbol_visitor_opd
9945 Global_symbol_visitor_opd()
9949 operator()(Sized_symbol
<64>* sym
)
9951 if (sym
->has_symtab_index()
9952 || sym
->source() != Symbol::FROM_OBJECT
9953 || !sym
->in_real_elf())
9956 if (sym
->object()->is_dynamic())
9959 Powerpc_relobj
<64, big_endian
>* symobj
9960 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9961 if (symobj
->opd_shndx() == 0)
9965 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9966 if (shndx
== symobj
->opd_shndx()
9967 && symobj
->get_opd_discard(sym
->value()))
9969 sym
->set_undefined();
9970 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9971 sym
->set_is_defined_in_discarded_section();
9972 sym
->set_symtab_index(-1U);
9977 template<int size
, bool big_endian
>
9979 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9981 Symbol_table
* symtab
)
9985 Output_data_save_res
<size
, big_endian
>* savres
9986 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9987 this->savres_section_
= savres
;
9988 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9989 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9990 savres
, ORDER_TEXT
, false);
9994 // Sort linker created .got section first (for the header), then input
9995 // sections belonging to files using small model code.
9997 template<bool big_endian
>
9998 class Sort_toc_sections
10000 const Output_section_data
*
10001 small_got_section() const
10003 return (static_cast<Target_powerpc
<64, big_endian
>*>(
10004 parameters
->sized_target
<64, big_endian
>())
10005 ->got_section(GOT_TYPE_SMALL
));
10009 rank(const Output_section::Input_section
& isec
) const
10011 if (!isec
.is_input_section())
10013 if (isec
.output_section_data() == this->small_got_section())
10017 if (static_cast<const Powerpc_relobj
<64, big_endian
>*>(isec
.relobj())
10018 ->has_small_toc_reloc())
10025 operator()(const Output_section::Input_section
& is1
,
10026 const Output_section::Input_section
& is2
) const
10028 return rank(is1
) < rank(is2
);
10032 // Finalize the sections.
10034 template<int size
, bool big_endian
>
10036 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
10038 const Input_objects
* input_objects
,
10039 Symbol_table
* symtab
)
10041 if (parameters
->doing_static_link())
10043 // At least some versions of glibc elf-init.o have a strong
10044 // reference to __rela_iplt marker syms. A weak ref would be
10046 if (this->iplt_
!= NULL
)
10048 Reloc_section
* rel
= this->iplt_
->rel_plt();
10049 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
10050 Symbol_table::PREDEFINED
, rel
, 0, 0,
10051 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10052 elfcpp::STV_HIDDEN
, 0, false, true);
10053 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
10054 Symbol_table::PREDEFINED
, rel
, 0, 0,
10055 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10056 elfcpp::STV_HIDDEN
, 0, true, true);
10060 symtab
->define_as_constant("__rela_iplt_start", NULL
,
10061 Symbol_table::PREDEFINED
, 0, 0,
10062 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10063 elfcpp::STV_HIDDEN
, 0, true, false);
10064 symtab
->define_as_constant("__rela_iplt_end", NULL
,
10065 Symbol_table::PREDEFINED
, 0, 0,
10066 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10067 elfcpp::STV_HIDDEN
, 0, true, false);
10073 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
10074 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
10076 if (!parameters
->options().relocatable())
10078 this->define_save_restore_funcs(layout
, symtab
);
10080 // Annoyingly, we need to make these sections now whether or
10081 // not we need them. If we delay until do_relax then we
10082 // need to mess with the relaxation machinery checkpointing.
10083 this->got_section(symtab
, layout
, GOT_TYPE_STANDARD
);
10084 this->make_brlt_section(layout
);
10086 // FIXME, maybe. Here we could run through all the got
10087 // entries in the small got section, removing any duplicates
10088 // found in the big got section and renumbering offsets.
10090 if (parameters
->options().toc_sort())
10092 Output_section
* os
= this->got_
->output_section();
10093 if (os
!= NULL
&& os
->input_sections().size() > 1)
10094 std::stable_sort(os
->input_sections().begin(),
10095 os
->input_sections().end(),
10096 Sort_toc_sections
<big_endian
>());
10101 // Fill in some more dynamic tags.
10102 Output_data_dynamic
* odyn
= layout
->dynamic_data();
10105 const Reloc_section
* rel_plt
= (this->plt_
== NULL
10107 : this->plt_
->rel_plt());
10108 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
10109 this->rela_dyn_
, true, size
== 32);
10113 if (this->got_
!= NULL
)
10115 this->got_
->finalize_data_size();
10116 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
10117 this->got_
, this->got_
->g_o_t());
10119 if (this->has_tls_get_addr_opt_
)
10120 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
10124 if (this->glink_
!= NULL
)
10126 this->glink_
->finalize_data_size();
10127 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
10129 (this->glink_
->pltresolve_size()
10132 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
10133 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
10134 ((this->has_localentry0_
10135 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
10136 | (this->has_tls_get_addr_opt_
10137 ? elfcpp::PPC64_OPT_TLS
: 0)));
10141 // Emit any relocs we saved in an attempt to avoid generating COPY
10143 if (this->copy_relocs_
.any_saved_relocs())
10144 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
10146 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
10147 p
!= input_objects
->relobj_end();
10150 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
10151 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
10152 if (ppc_relobj
->attributes_section_data())
10153 this->merge_object_attributes(ppc_relobj
,
10154 ppc_relobj
->attributes_section_data());
10156 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
10157 p
!= input_objects
->dynobj_end();
10160 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
10161 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
10162 if (ppc_dynobj
->attributes_section_data())
10163 this->merge_object_attributes(ppc_dynobj
,
10164 ppc_dynobj
->attributes_section_data());
10167 // Create a .gnu.attributes section if we have merged any attributes
10169 if (this->attributes_section_data_
!= NULL
10170 && this->attributes_section_data_
->size() != 0)
10172 Output_attributes_section_data
* attributes_section
10173 = new Output_attributes_section_data(*this->attributes_section_data_
);
10174 layout
->add_output_section_data(".gnu.attributes",
10175 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
10176 attributes_section
, ORDER_INVALID
, false);
10180 // Merge object attributes from input file called NAME with those of the
10181 // output. The input object attributes are in the object pointed by PASD.
10183 template<int size
, bool big_endian
>
10185 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
10187 const Attributes_section_data
* pasd
)
10189 // Return if there is no attributes section data.
10193 // Create output object attributes.
10194 if (this->attributes_section_data_
== NULL
)
10195 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
10197 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
10198 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
10199 Object_attribute
* out_attr
10200 = this->attributes_section_data_
->known_attributes(vendor
);
10202 const char* name
= obj
->name().c_str();
10205 const char* second
;
10206 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
10207 int in_fp
= in_attr
[tag
].int_value() & 0xf;
10208 int out_fp
= out_attr
[tag
].int_value() & 0xf;
10209 bool warn_only
= obj
->is_dynamic();
10210 if (in_fp
!= out_fp
)
10213 if ((in_fp
& 3) == 0)
10215 else if ((out_fp
& 3) == 0)
10219 out_fp
|= in_fp
& 3;
10220 out_attr
[tag
].set_int_value(out_fp
);
10221 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10222 this->last_fp_
= name
;
10225 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
10227 err
= N_("%s uses hard float, %s uses soft float");
10228 first
= this->last_fp_
;
10231 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10233 err
= N_("%s uses hard float, %s uses soft float");
10235 second
= this->last_fp_
;
10237 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10239 err
= N_("%s uses double-precision hard float, "
10240 "%s uses single-precision hard float");
10241 first
= this->last_fp_
;
10244 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10246 err
= N_("%s uses double-precision hard float, "
10247 "%s uses single-precision hard float");
10249 second
= this->last_fp_
;
10252 if (err
|| (in_fp
& 0xc) == 0)
10254 else if ((out_fp
& 0xc) == 0)
10258 out_fp
|= in_fp
& 0xc;
10259 out_attr
[tag
].set_int_value(out_fp
);
10260 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10261 this->last_ld_
= name
;
10264 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10266 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10268 second
= this->last_ld_
;
10270 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10272 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10273 first
= this->last_ld_
;
10276 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10278 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10279 first
= this->last_ld_
;
10282 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10284 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10286 second
= this->last_ld_
;
10291 if (parameters
->options().warn_mismatch())
10294 gold_warning(_(err
), first
, second
);
10296 gold_error(_(err
), first
, second
);
10298 // Arrange for this attribute to be deleted. It's better to
10299 // say "don't know" about a file than to wrongly claim compliance.
10301 out_attr
[tag
].set_type(0);
10307 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10308 int in_vec
= in_attr
[tag
].int_value() & 3;
10309 int out_vec
= out_attr
[tag
].int_value() & 3;
10310 if (in_vec
!= out_vec
)
10315 else if (out_vec
== 0)
10318 out_attr
[tag
].set_int_value(out_vec
);
10319 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10320 this->last_vec_
= name
;
10322 // For now, allow generic to transition to AltiVec or SPE
10323 // without a warning. If GCC marked files with their stack
10324 // alignment and used don't-care markings for files which are
10325 // not affected by the vector ABI, we could warn about this
10327 else if (in_vec
== 1)
10329 else if (out_vec
== 1)
10332 out_attr
[tag
].set_int_value(out_vec
);
10333 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10334 this->last_vec_
= name
;
10336 else if (out_vec
< in_vec
)
10338 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10339 first
= this->last_vec_
;
10342 else if (out_vec
> in_vec
)
10344 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10346 second
= this->last_vec_
;
10350 if (parameters
->options().warn_mismatch())
10351 gold_error(_(err
), first
, second
);
10352 out_attr
[tag
].set_type(0);
10356 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10357 int in_struct
= in_attr
[tag
].int_value() & 3;
10358 int out_struct
= out_attr
[tag
].int_value() & 3;
10359 if (in_struct
!= out_struct
)
10362 if (in_struct
== 0 || in_struct
== 3)
10364 else if (out_struct
== 0)
10366 out_struct
= in_struct
;
10367 out_attr
[tag
].set_int_value(out_struct
);
10368 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10369 this->last_struct_
= name
;
10371 else if (out_struct
< in_struct
)
10373 err
= N_("%s uses r3/r4 for small structure returns, "
10375 first
= this->last_struct_
;
10378 else if (out_struct
> in_struct
)
10380 err
= N_("%s uses r3/r4 for small structure returns, "
10383 second
= this->last_struct_
;
10387 if (parameters
->options().warn_mismatch())
10388 gold_error(_(err
), first
, second
);
10389 out_attr
[tag
].set_type(0);
10394 // Merge Tag_compatibility attributes and any common GNU ones.
10395 this->attributes_section_data_
->merge(name
, pasd
);
10398 // Emit any saved relocs, and mark toc entries using any of these
10399 // relocs as not optimizable.
10401 template<int sh_type
, int size
, bool big_endian
>
10403 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10404 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10407 && parameters
->options().toc_optimize())
10409 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10410 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10411 p
!= this->entries_
.end();
10414 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10417 // If the symbol is no longer defined in a dynamic object,
10418 // then we emitted a COPY relocation. If it is still
10419 // dynamic then we'll need dynamic relocations and thus
10420 // can't optimize toc entries.
10421 if (entry
.sym_
->is_from_dynobj())
10423 Powerpc_relobj
<size
, big_endian
>* ppc_object
10424 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10425 if (entry
.shndx_
== ppc_object
->toc_shndx())
10426 ppc_object
->set_no_toc_opt(entry
.address_
);
10431 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10434 // Return the value to use for a branch relocation.
10436 template<int size
, bool big_endian
>
10438 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10439 const Symbol_table
* symtab
,
10440 const Sized_symbol
<size
>* gsym
,
10441 Powerpc_relobj
<size
, big_endian
>* object
,
10443 unsigned int *dest_shndx
)
10445 if (size
== 32 || this->abiversion() >= 2)
10446 gold_unreachable();
10449 // If the symbol is defined in an opd section, ie. is a function
10450 // descriptor, use the function descriptor code entry address
10451 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10453 && (gsym
->source() != Symbol::FROM_OBJECT
10454 || gsym
->object()->is_dynamic()))
10457 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10458 unsigned int shndx
= symobj
->opd_shndx();
10461 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10462 if (opd_addr
== invalid_address
)
10464 opd_addr
+= symobj
->output_section_address(shndx
);
10465 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10468 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10469 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10472 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10473 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10474 *dest_shndx
= folded
.second
;
10476 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10477 if (sec_addr
== invalid_address
)
10480 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10481 *value
= sec_addr
+ sec_off
;
10488 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10490 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10493 if (gsym
->is_from_dynobj()
10494 || gsym
->is_undefined()
10495 || gsym
->is_preemptible())
10498 if (gsym
->is_absolute())
10499 return !parameters
->options().output_is_position_independent();
10506 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10508 if (psymval
->is_ifunc_symbol())
10512 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10514 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10517 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10518 // pld ra,symbol@got@pcrel
10519 // load/store rt,0(ra)
10521 // pla ra,symbol@pcrel
10522 // load/store rt,0(ra)
10523 // may be translated to
10524 // pload/pstore rt,symbol@pcrel
10526 // This function returns true if the optimization is possible, placing
10527 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10529 // On entry to this function, the linker has already determined that
10530 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10531 // while *PINSN2 is the second instruction.
10534 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10536 uint32_t insn2
= *pinsn2
>> 32;
10539 // Check that regs match.
10540 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10543 switch ((insn2
>> 26) & 63)
10559 // These are the PMLS cases, where we just need to tack a prefix
10560 // on the insn. Check that the D field is zero.
10561 if ((insn2
& 0xffff) != 0)
10563 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10564 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10567 case 58: // lwa, ld
10568 if ((insn2
& 0xfffd) != 0)
10570 i1new
= ((1ULL << 58) | (1ULL << 52)
10571 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10572 | (insn2
& (31ULL << 21)));
10575 case 57: // lxsd, lxssp
10576 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10578 i1new
= ((1ULL << 58) | (1ULL << 52)
10579 | ((40ULL | (insn2
& 3)) << 26)
10580 | (insn2
& (31ULL << 21)));
10583 case 61: // stxsd, stxssp, lxv, stxv
10584 if ((insn2
& 3) == 0)
10586 else if ((insn2
& 3) >= 2)
10588 if ((insn2
& 0xfffc) != 0)
10590 i1new
= ((1ULL << 58) | (1ULL << 52)
10591 | ((44ULL | (insn2
& 3)) << 26)
10592 | (insn2
& (31ULL << 21)));
10596 if ((insn2
& 0xfff0) != 0)
10598 i1new
= ((1ULL << 58) | (1ULL << 52)
10599 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10600 | (insn2
& (31ULL << 21)));
10605 if ((insn2
& 0xffff) != 0)
10607 i1new
= ((1ULL << 58) | (1ULL << 52)
10608 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10611 case 62: // std, stq
10612 if ((insn2
& 0xfffd) != 0)
10614 i1new
= ((1ULL << 58) | (1ULL << 52)
10615 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10616 | (insn2
& (31ULL << 21)));
10621 *pinsn2
= (uint64_t) nop
<< 32;
10625 // Perform a relocation.
10627 template<int size
, bool big_endian
>
10629 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10630 const Relocate_info
<size
, big_endian
>* relinfo
,
10632 Target_powerpc
* target
,
10633 Output_section
* os
,
10635 const unsigned char* preloc
,
10636 const Sized_symbol
<size
>* gsym
,
10637 const Symbol_value
<size
>* psymval
,
10638 unsigned char* view
,
10640 section_size_type view_size
)
10642 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10643 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10644 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10649 if (target
->replace_tls_get_addr(gsym
))
10650 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10652 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10653 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10654 Powerpc_relobj
<size
, big_endian
>* const object
10655 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10656 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10658 case Track_tls::NOT_EXPECTED
:
10659 // No warning. This will result in really old code without tls
10660 // marker relocs being mis-optimised, but there shouldn't be too
10661 // much of that code around. The problem with warning is that
10662 // glibc and libphobos both construct direct calls to
10663 // __tls_get_addr in a way that is harmless.
10665 case Track_tls::EXPECTED
:
10666 // We have already complained.
10668 case Track_tls::SKIP
:
10669 if (is_plt16_reloc
<size
>(r_type
)
10670 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10671 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10673 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10674 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10676 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10678 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10679 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10681 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10682 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10684 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10685 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10686 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10689 case Track_tls::NORMAL
:
10693 // Offset from start of insn to d-field reloc.
10694 const int d_offset
= big_endian
? 2 : 0;
10697 bool has_stub_value
= false;
10698 bool localentry0
= false;
10699 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10700 bool pltcall_to_direct
= false;
10702 if (is_plt16_reloc
<size
>(r_type
)
10703 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10704 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10705 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10706 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
10707 || r_type
== elfcpp::R_POWERPC_PLTCALL
10708 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10710 // It would be possible to replace inline plt calls with direct
10711 // calls if the PLTCALL is in range. The only difficulty is
10712 // that the decision depends on the PLTCALL reloc, and we don't
10713 // know the address of that instruction when processing others
10714 // in the sequence. So the decision needs to be made in
10716 pltcall_to_direct
= !(gsym
!= NULL
10717 ? gsym
->has_plt_offset()
10718 : object
->local_has_plt_offset(r_sym
));
10720 else if ((gsym
!= NULL
10721 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10722 : psymval
->is_ifunc_symbol() && object
->local_has_plt_offset(r_sym
))
10723 && !is_got_reloc(r_type
)
10724 && (!psymval
->is_ifunc_symbol()
10725 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
,
10730 && target
->abiversion() >= 2
10731 && !parameters
->options().output_is_position_independent()
10732 && !is_branch_reloc
<size
>(r_type
))
10734 Address off
= target
->glink_section()->find_global_entry(gsym
);
10735 if (off
!= invalid_address
)
10737 value
= target
->glink_section()->global_entry_address() + off
;
10738 has_stub_value
= true;
10743 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10744 if (target
->stub_tables().size() == 1)
10745 stub_table
= target
->stub_tables()[0];
10746 if (stub_table
== NULL
10749 && !parameters
->options().output_is_position_independent()
10750 && !is_branch_reloc
<size
>(r_type
)))
10751 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10752 if (stub_table
== NULL
)
10754 // This is a ref from a data section to an ifunc symbol,
10755 // or a non-branch reloc for which we always want to use
10756 // one set of stubs for resolving function addresses.
10757 if (target
->stub_tables().size() != 0)
10758 stub_table
= target
->stub_tables()[0];
10760 if (stub_table
!= NULL
)
10762 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10764 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10765 rela
.get_r_addend());
10767 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10768 rela
.get_r_addend());
10771 value
= stub_table
->stub_address() + ent
->off_
;
10772 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10773 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10774 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10777 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10780 value
+= ent
->p9off_
;
10782 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10783 value
+= ent
->p9off_
;
10785 value
+= ent
->tocoff_
;
10790 && target
->is_tls_get_addr_opt(gsym
)))
10792 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
10793 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10795 if (!(target
->power10_stubs()
10796 && target
->power10_stubs_auto()))
10799 else if (relnum
< reloc_count
- 1)
10801 Reltype
next_rela(preloc
+ reloc_size
);
10802 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10803 == elfcpp::R_PPC64_TOCSAVE
10804 && (next_rela
.get_r_offset()
10805 == rela
.get_r_offset() + 4))
10809 localentry0
= ent
->localentry0_
;
10810 has_stub_value
= true;
10814 // We don't care too much about bogus debug references to
10815 // non-local functions, but otherwise there had better be a plt
10816 // call stub or global entry stub as appropriate.
10817 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10820 if (!pltcall_to_direct
&& (is_plt16_reloc
<size
>(r_type
)
10821 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10822 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10824 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10826 value
= target
->plt_off(gsym
, &plt
);
10828 value
= target
->plt_off(object
, r_sym
, &plt
);
10829 value
+= plt
->address();
10833 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10834 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10835 value
-= target
->toc_pointer();
10837 else if (parameters
->options().output_is_position_independent())
10839 if (rela
.get_r_addend() >= 32768)
10841 unsigned int got2
= object
->got2_shndx();
10842 value
-= (object
->get_output_section_offset(got2
)
10843 + object
->output_section(got2
)->address()
10844 + rela
.get_r_addend());
10847 value
-= target
->toc_pointer();
10850 else if (pltcall_to_direct
10851 && (is_plt16_reloc
<size
>(r_type
)
10852 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10853 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10855 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10856 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10857 r_type
= elfcpp::R_POWERPC_NONE
;
10859 else if (pltcall_to_direct
10860 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10861 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10863 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10864 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10865 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10866 r_type
= elfcpp::R_POWERPC_NONE
;
10868 else if (is_got_reloc(r_type
))
10870 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10871 Got_type got_type
= ((size
== 32
10872 || r_type
== elfcpp::R_POWERPC_GOT16
10873 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
10874 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10876 value
= gsym
->got_offset(got_type
, addend
);
10878 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10879 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10880 value
+= target
->got_section(got_type
)->address();
10882 value
-= target
->got_base_offset(got_type
);
10884 else if (r_type
== elfcpp::R_PPC64_TOC
)
10886 value
= target
->toc_pointer();
10888 else if (gsym
!= NULL
10889 && (r_type
== elfcpp::R_POWERPC_REL24
10890 || r_type
== elfcpp::R_PPC_PLTREL24
)
10895 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10896 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10897 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10898 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10900 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10901 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10902 if ((insn
& 1) != 0
10904 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10906 elfcpp::Swap
<32, big_endian
>::
10907 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10908 can_plt_call
= true;
10913 // If we don't have a branch and link followed by a nop,
10914 // we can't go via the plt because there is no place to
10915 // put a toc restoring instruction.
10916 // Unless we know we won't be returning.
10917 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10918 can_plt_call
= true;
10922 // g++ as of 20130507 emits self-calls without a
10923 // following nop. This is arguably wrong since we have
10924 // conflicting information. On the one hand a global
10925 // symbol and on the other a local call sequence, but
10926 // don't error for this special case.
10927 // It isn't possible to cheaply verify we have exactly
10928 // such a call. Allow all calls to the same section.
10930 Address code
= value
;
10931 if (gsym
->source() == Symbol::FROM_OBJECT
10932 && gsym
->object() == object
)
10934 unsigned int dest_shndx
= 0;
10935 if (target
->abiversion() < 2)
10937 Address addend
= rela
.get_r_addend();
10938 code
= psymval
->value(object
, addend
);
10939 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10940 &code
, &dest_shndx
);
10943 if (dest_shndx
== 0)
10944 dest_shndx
= gsym
->shndx(&is_ordinary
);
10945 ok
= dest_shndx
== relinfo
->data_shndx
;
10949 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10950 _("call lacks nop, can't restore toc; "
10951 "recompile with -fPIC"));
10957 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10958 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10959 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10960 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10961 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10963 // First instruction of a global dynamic sequence, arg setup insn.
10964 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10965 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10966 Got_type got_type
= ((size
== 32
10967 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
10968 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10969 if (tls_type
== tls::TLSOPT_NONE
)
10970 got_type
= Got_type(got_type
| GOT_TYPE_TLSGD
);
10971 else if (tls_type
== tls::TLSOPT_TO_IE
)
10972 got_type
= Got_type(got_type
| GOT_TYPE_TPREL
);
10973 if ((got_type
& ~GOT_TYPE_SMALL
) != GOT_TYPE_STANDARD
)
10975 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10977 value
= gsym
->got_offset(got_type
, addend
);
10979 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10980 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10981 value
+= target
->got_section(got_type
)->address();
10983 value
-= target
->got_base_offset(got_type
);
10985 if (tls_type
== tls::TLSOPT_TO_IE
)
10987 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10989 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10990 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10992 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10994 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10995 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10996 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10997 pinsn
& 0xffffffff);
10998 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
11002 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11003 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11005 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11006 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11007 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
11009 insn
|= 32 << 26; // lwz
11011 insn
|= 58 << 26; // ld
11012 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11014 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11015 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11018 else if (tls_type
== tls::TLSOPT_TO_LE
)
11020 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11022 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11023 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11025 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11026 // pla pcrel -> paddi r13
11027 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11028 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11029 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11030 pinsn
& 0xffffffff);
11031 r_type
= elfcpp::R_PPC64_TPREL34
;
11032 value
= psymval
->value(object
, rela
.get_r_addend());
11036 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11037 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11039 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11040 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11041 insn
&= (1 << 26) - (1 << 21); // extract rt
11045 insn
|= addis_0_13
;
11046 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11047 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11048 value
= psymval
->value(object
, rela
.get_r_addend());
11052 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11054 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11055 r_type
= elfcpp::R_POWERPC_NONE
;
11060 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11061 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11062 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11063 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
11064 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11066 // First instruction of a local dynamic sequence, arg setup insn.
11067 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11068 if (tls_type
== tls::TLSOPT_NONE
)
11070 value
= target
->tlsld_got_offset();
11071 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11072 value
+= target
->got_section(GOT_TYPE_SMALL
)->address();
11074 value
-= target
->got_base_offset(GOT_TYPE_SMALL
);
11078 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11079 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11081 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11082 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11084 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11085 // pla pcrel -> paddi r13
11086 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11087 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11088 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11089 pinsn
& 0xffffffff);
11090 r_type
= elfcpp::R_PPC64_TPREL34
;
11091 value
= dtp_offset
;
11093 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11094 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11096 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11097 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11098 insn
&= (1 << 26) - (1 << 21); // extract rt
11102 insn
|= addis_0_13
;
11103 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11104 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11105 value
= dtp_offset
;
11109 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11111 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11112 r_type
= elfcpp::R_POWERPC_NONE
;
11116 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
11117 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
11118 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
11119 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
11120 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11122 // Accesses relative to a local dynamic sequence address,
11123 // no optimisation here.
11124 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11125 Got_type got_type
= ((size
== 32
11126 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
11127 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
11129 value
= gsym
->got_offset(got_type
, addend
);
11131 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11132 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11133 value
+= target
->got_section(got_type
)->address();
11135 value
-= target
->got_base_offset(got_type
);
11137 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11138 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11139 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11140 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
11141 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11143 // First instruction of initial exec sequence.
11144 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11145 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11146 if (tls_type
== tls::TLSOPT_NONE
)
11148 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11149 Got_type got_type
= ((size
== 32
11150 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
11151 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
11153 value
= gsym
->got_offset(got_type
, addend
);
11155 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11156 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11157 value
+= target
->got_section(got_type
)->address();
11159 value
-= target
->got_base_offset(got_type
);
11163 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11164 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11166 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11167 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11169 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11170 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
11171 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
11172 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
11173 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11174 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11175 pinsn
& 0xffffffff);
11176 r_type
= elfcpp::R_PPC64_TPREL34
;
11177 value
= psymval
->value(object
, rela
.get_r_addend());
11179 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11180 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11182 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11183 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11184 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
11188 insn
|= addis_0_13
;
11189 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11190 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11191 value
= psymval
->value(object
, rela
.get_r_addend());
11195 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11197 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11198 r_type
= elfcpp::R_POWERPC_NONE
;
11202 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11203 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11205 // Second instruction of a global dynamic sequence,
11206 // the __tls_get_addr call
11207 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11208 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11209 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
11210 if (tls_type
!= tls::TLSOPT_NONE
)
11212 if (tls_type
== tls::TLSOPT_TO_IE
)
11214 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11215 Insn insn
= add_3_3_13
;
11218 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11219 r_type
= elfcpp::R_POWERPC_NONE
;
11223 bool is_pcrel
= false;
11224 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11225 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11226 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11227 if (relnum
< reloc_count
- 1)
11229 Reltype
next_rela(preloc
+ reloc_size
);
11230 unsigned int r_type2
11231 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11232 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11233 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11234 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11235 && next_rela
.get_r_offset() == rela
.get_r_offset())
11238 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11241 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11242 r_type
= elfcpp::R_POWERPC_NONE
;
11246 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11247 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11249 value
= psymval
->value(object
, rela
.get_r_addend());
11252 this->skip_next_tls_get_addr_call();
11255 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11256 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11258 // Second instruction of a local dynamic sequence,
11259 // the __tls_get_addr call
11260 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11261 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11262 if (tls_type
== tls::TLSOPT_TO_LE
)
11264 bool is_pcrel
= false;
11265 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11266 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11267 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11268 if (relnum
< reloc_count
- 1)
11270 Reltype
next_rela(preloc
+ reloc_size
);
11271 unsigned int r_type2
11272 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11273 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11274 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11275 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11276 && next_rela
.get_r_offset() == rela
.get_r_offset())
11279 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11282 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11283 r_type
= elfcpp::R_POWERPC_NONE
;
11287 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11288 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11290 value
= dtp_offset
;
11292 this->skip_next_tls_get_addr_call();
11295 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11297 // Second instruction of an initial exec sequence
11298 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11299 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11300 if (tls_type
== tls::TLSOPT_TO_LE
)
11302 Address roff
= rela
.get_r_offset() & 3;
11303 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11304 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11305 unsigned int reg
= size
== 32 ? 2 : 13;
11306 insn
= at_tls_transform(insn
, reg
);
11307 gold_assert(insn
!= 0);
11310 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11311 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11313 value
= psymval
->value(object
, rela
.get_r_addend());
11315 else if (roff
== 1)
11317 // For pcrel IE to LE we already have the full offset
11318 // and thus don't need an addi here. A nop or mr will do.
11319 if ((insn
& (0x3f << 26)) == 14 << 26)
11321 // Extract regs from addi rt,ra,si.
11322 unsigned int rt
= (insn
>> 21) & 0x1f;
11323 unsigned int ra
= (insn
>> 16) & 0x1f;
11328 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11329 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11330 insn
|= (31u << 26) | (444u << 1);
11333 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11334 r_type
= elfcpp::R_POWERPC_NONE
;
11338 else if (!has_stub_value
)
11340 if (pltcall_to_direct
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11341 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11343 // PLTCALL without plt entry => convert to direct call
11344 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11345 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11346 insn
= (insn
& 1) | b
;
11347 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11349 r_type
= elfcpp::R_PPC_PLTREL24
;
11350 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11351 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11353 r_type
= elfcpp::R_POWERPC_REL24
;
11355 Address addend
= 0;
11357 && (r_type
== elfcpp::R_PPC_PLTREL24
11358 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11359 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11360 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11361 addend
= rela
.get_r_addend();
11362 value
= psymval
->value(object
, addend
);
11363 unsigned int local_ent
= 0;
11364 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11366 if (target
->abiversion() >= 2)
11369 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11371 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11375 unsigned int dest_shndx
;
11376 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11377 &value
, &dest_shndx
);
11380 Address max_branch
= max_branch_delta
<size
>(r_type
);
11381 if (max_branch
!= 0
11382 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11384 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
11385 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11387 ? object
->ppc64_needs_toc(gsym
)
11388 : object
->ppc64_needs_toc(r_sym
)))))
11390 Stub_table
<size
, big_endian
>* stub_table
11391 = object
->stub_table(relinfo
->data_shndx
);
11392 if (stub_table
!= NULL
)
11394 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11395 = stub_table
->find_long_branch_entry(value
);
11398 if (ent
->save_res_
)
11399 value
= (value
- target
->savres_section()->address()
11400 + stub_table
->stub_address()
11401 + stub_table
->plt_size()
11402 + stub_table
->branch_size());
11405 value
= (stub_table
->stub_address()
11406 + stub_table
->plt_size()
11410 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11413 value
+= ent
->p9off_
;
11415 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
11416 value
+= ent
->p9off_
;
11418 value
+= ent
->tocoff_
;
11421 has_stub_value
= true;
11425 if (!has_stub_value
)
11426 value
+= local_ent
;
11431 case elfcpp::R_PPC64_REL24_NOTOC
:
11435 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11436 case elfcpp::R_PPC64_REL64
:
11437 case elfcpp::R_POWERPC_REL32
:
11438 case elfcpp::R_POWERPC_REL24
:
11439 case elfcpp::R_PPC_PLTREL24
:
11440 case elfcpp::R_PPC_LOCAL24PC
:
11441 case elfcpp::R_POWERPC_REL16
:
11442 case elfcpp::R_POWERPC_REL16_LO
:
11443 case elfcpp::R_POWERPC_REL16_HI
:
11444 case elfcpp::R_POWERPC_REL16_HA
:
11445 case elfcpp::R_POWERPC_REL16DX_HA
:
11446 case elfcpp::R_PPC64_REL16_HIGH
:
11447 case elfcpp::R_PPC64_REL16_HIGHA
:
11448 case elfcpp::R_PPC64_REL16_HIGHER
:
11449 case elfcpp::R_PPC64_REL16_HIGHERA
:
11450 case elfcpp::R_PPC64_REL16_HIGHEST
:
11451 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11452 case elfcpp::R_POWERPC_REL14
:
11453 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11454 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11455 case elfcpp::R_PPC64_PCREL34
:
11456 case elfcpp::R_PPC64_GOT_PCREL34
:
11457 case elfcpp::R_PPC64_PLT_PCREL34
:
11458 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11459 case elfcpp::R_PPC64_PCREL28
:
11460 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11461 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11462 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11463 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11464 case elfcpp::R_PPC64_REL16_HIGHER34
:
11465 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11466 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11467 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11471 case elfcpp::R_PPC64_TOC16
:
11472 case elfcpp::R_PPC64_TOC16_LO
:
11473 case elfcpp::R_PPC64_TOC16_HI
:
11474 case elfcpp::R_PPC64_TOC16_HA
:
11475 case elfcpp::R_PPC64_TOC16_DS
:
11476 case elfcpp::R_PPC64_TOC16_LO_DS
:
11477 // Subtract the TOC base address.
11478 value
-= target
->toc_pointer();
11481 case elfcpp::R_POWERPC_SECTOFF
:
11482 case elfcpp::R_POWERPC_SECTOFF_LO
:
11483 case elfcpp::R_POWERPC_SECTOFF_HI
:
11484 case elfcpp::R_POWERPC_SECTOFF_HA
:
11485 case elfcpp::R_PPC64_SECTOFF_DS
:
11486 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11488 value
-= os
->address();
11491 case elfcpp::R_PPC64_TPREL16_DS
:
11492 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11493 case elfcpp::R_PPC64_TPREL16_HIGH
:
11494 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11496 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11499 case elfcpp::R_POWERPC_TPREL16
:
11500 case elfcpp::R_POWERPC_TPREL16_LO
:
11501 case elfcpp::R_POWERPC_TPREL16_HI
:
11502 case elfcpp::R_POWERPC_TPREL16_HA
:
11503 case elfcpp::R_POWERPC_TPREL
:
11504 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11505 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11506 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11507 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11508 case elfcpp::R_PPC64_TPREL34
:
11509 // tls symbol values are relative to tls_segment()->vaddr()
11510 value
-= tp_offset
;
11513 case elfcpp::R_PPC64_DTPREL16_DS
:
11514 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11515 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11516 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11517 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11518 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11520 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11521 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11524 case elfcpp::R_POWERPC_DTPREL16
:
11525 case elfcpp::R_POWERPC_DTPREL16_LO
:
11526 case elfcpp::R_POWERPC_DTPREL16_HI
:
11527 case elfcpp::R_POWERPC_DTPREL16_HA
:
11528 case elfcpp::R_POWERPC_DTPREL
:
11529 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11530 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11531 case elfcpp::R_PPC64_DTPREL34
:
11532 // tls symbol values are relative to tls_segment()->vaddr()
11533 value
-= dtp_offset
;
11536 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11538 value
+= object
->ppc64_local_entry_offset(gsym
);
11540 value
+= object
->ppc64_local_entry_offset(r_sym
);
11547 Insn branch_bit
= 0;
11550 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11551 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11552 branch_bit
= 1 << 21;
11554 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11555 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11557 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11558 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11559 insn
&= ~(1 << 21);
11560 insn
|= branch_bit
;
11561 if (this->is_isa_v2
)
11563 // Set 'a' bit. This is 0b00010 in BO field for branch
11564 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11565 // for branch on CTR insns (BO == 1a00t or 1a01t).
11566 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11567 insn
|= 0x02 << 21;
11568 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11569 insn
|= 0x08 << 21;
11575 // Invert 'y' bit if not the default.
11576 if (static_cast<Signed_address
>(value
) < 0)
11579 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11583 case elfcpp::R_POWERPC_PLT16_HA
:
11585 && !parameters
->options().output_is_position_independent())
11587 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11588 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11590 // Convert addis to lis.
11591 if ((insn
& (0x3f << 26)) == 15u << 26
11592 && (insn
& (0x1f << 16)) != 0)
11594 insn
&= ~(0x1f << 16);
11595 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11605 ? relative_value_is_known(gsym
)
11606 : relative_value_is_known(psymval
))
11611 uint64_t pinsn
, pinsn2
;
11618 // Multi-instruction sequences that access the GOT/TOC can
11619 // be optimized, eg.
11620 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11621 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11623 // addis ra,r2,0; addi rb,ra,x@toc@l;
11624 // to nop; addi rb,r2,x@toc;
11625 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11626 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11627 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11628 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11629 case elfcpp::R_POWERPC_GOT16_HA
:
11630 case elfcpp::R_PPC64_TOC16_HA
:
11631 if (size
== 64 && parameters
->options().toc_optimize())
11633 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11634 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11635 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11636 && object
->make_toc_relative(target
, &value
))
11637 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11638 && object
->make_got_relative(target
, psymval
,
11639 rela
.get_r_addend(),
11642 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11643 == ((15u << 26) | (2 << 16)));
11645 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11646 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11647 && value
+ 0x8000 < 0x10000)
11649 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11655 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11656 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11657 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11658 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11659 case elfcpp::R_POWERPC_GOT16_LO
:
11660 case elfcpp::R_PPC64_GOT16_LO_DS
:
11661 case elfcpp::R_PPC64_TOC16_LO
:
11662 case elfcpp::R_PPC64_TOC16_LO_DS
:
11663 if (size
== 64 && parameters
->options().toc_optimize())
11665 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11666 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11667 bool changed
= false;
11668 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11669 && object
->make_toc_relative(target
, &value
))
11670 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11671 && object
->make_got_relative(target
, psymval
,
11672 rela
.get_r_addend(),
11675 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11676 insn
^= (14u << 26) ^ (58u << 26);
11677 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11680 if (ok_lo_toc_insn(insn
, r_type
)
11681 && value
+ 0x8000 < 0x10000)
11683 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11685 // Transform addic to addi when we change reg.
11686 insn
&= ~((0x3f << 26) | (0x1f << 16));
11687 insn
|= (14u << 26) | (2 << 16);
11691 insn
&= ~(0x1f << 16);
11697 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11701 case elfcpp::R_PPC64_GOT_PCREL34
:
11702 if (size
== 64 && parameters
->options().toc_optimize())
11704 iview
= reinterpret_cast<Insn
*>(view
);
11705 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11707 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11708 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11709 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11712 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11714 if (relval
+ (1ULL << 33) < 1ULL << 34)
11717 // Replace with paddi
11718 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11719 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11720 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11721 pinsn
& 0xffffffff);
11727 case elfcpp::R_PPC64_PCREL34
:
11730 iview
= reinterpret_cast<Insn
*>(view
);
11731 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11733 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11734 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11735 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11736 | (14ULL << 26) /* paddi */))
11740 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11741 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11742 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11743 if (relnum
>= reloc_count
- 1)
11746 Reltype
next_rela(preloc
+ reloc_size
);
11747 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11748 != elfcpp::R_PPC64_PCREL_OPT
)
11749 || next_rela
.get_r_offset() != rela
.get_r_offset())
11752 Address off
= next_rela
.get_r_addend();
11754 off
= 8; // zero means next insn.
11755 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11758 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11759 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11761 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11763 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11765 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11766 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11767 pinsn
& 0xffffffff);
11768 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11773 case elfcpp::R_POWERPC_TPREL16_HA
:
11774 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11776 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11777 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11782 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11784 // R_PPC_TLSGD, R_PPC_TLSLD
11787 case elfcpp::R_POWERPC_TPREL16_LO
:
11788 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11790 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11791 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11792 insn
&= ~(0x1f << 16);
11793 insn
|= (size
== 32 ? 2 : 13) << 16;
11794 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11798 case elfcpp::R_PPC64_ENTRY
:
11801 value
= target
->toc_pointer();
11802 if (value
+ 0x80008000 <= 0xffffffff
11803 && !parameters
->options().output_is_position_independent())
11805 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11806 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11807 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11809 if ((insn1
& ~0xfffc) == ld_2_12
11810 && insn2
== add_2_2_12
)
11812 insn1
= lis_2
+ ha(value
);
11813 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11814 insn2
= addi_2_2
+ l(value
);
11815 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11822 if (value
+ 0x80008000 <= 0xffffffff)
11824 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11825 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11826 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11828 if ((insn1
& ~0xfffc) == ld_2_12
11829 && insn2
== add_2_2_12
)
11831 insn1
= addis_2_12
+ ha(value
);
11832 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11833 insn2
= addi_2_2
+ l(value
);
11834 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11842 case elfcpp::R_POWERPC_REL16_LO
:
11843 // If we are generating a non-PIC executable, edit
11844 // 0: addis 2,12,.TOC.-0b@ha
11845 // addi 2,2,.TOC.-0b@l
11846 // used by ELFv2 global entry points to set up r2, to
11848 // addi 2,2,.TOC.@l
11849 // if .TOC. is in range. */
11851 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11854 && target
->abiversion() >= 2
11855 && !parameters
->options().output_is_position_independent()
11856 && rela
.get_r_addend() == d_offset
+ 4
11858 && strcmp(gsym
->name(), ".TOC.") == 0)
11860 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11861 Reltype
prev_rela(preloc
- reloc_size
);
11862 if ((prev_rela
.get_r_info()
11863 == elfcpp::elf_r_info
<size
>(r_sym
,
11864 elfcpp::R_POWERPC_REL16_HA
))
11865 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11866 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11868 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11869 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11870 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11872 if ((insn1
& 0xffff0000) == addis_2_12
11873 && (insn2
& 0xffff0000) == addi_2_2
)
11875 insn1
= lis_2
+ ha(value
+ address
- 4);
11876 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11877 insn2
= addi_2_2
+ l(value
+ address
- 4);
11878 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11881 relinfo
->rr
->set_strategy(relnum
- 1,
11882 Relocatable_relocs::RELOC_SPECIAL
);
11883 relinfo
->rr
->set_strategy(relnum
,
11884 Relocatable_relocs::RELOC_SPECIAL
);
11894 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11895 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11898 case elfcpp::R_POWERPC_ADDR32
:
11899 case elfcpp::R_POWERPC_UADDR32
:
11901 overflow
= Reloc::CHECK_BITFIELD
;
11904 case elfcpp::R_POWERPC_REL32
:
11905 case elfcpp::R_POWERPC_REL16DX_HA
:
11907 overflow
= Reloc::CHECK_SIGNED
;
11910 case elfcpp::R_POWERPC_UADDR16
:
11911 overflow
= Reloc::CHECK_BITFIELD
;
11914 case elfcpp::R_POWERPC_ADDR16
:
11915 // We really should have three separate relocations,
11916 // one for 16-bit data, one for insns with 16-bit signed fields,
11917 // and one for insns with 16-bit unsigned fields.
11918 overflow
= Reloc::CHECK_BITFIELD
;
11919 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11920 overflow
= Reloc::CHECK_LOW_INSN
;
11923 case elfcpp::R_POWERPC_ADDR16_HI
:
11924 case elfcpp::R_POWERPC_ADDR16_HA
:
11925 case elfcpp::R_POWERPC_GOT16_HI
:
11926 case elfcpp::R_POWERPC_GOT16_HA
:
11927 case elfcpp::R_POWERPC_PLT16_HI
:
11928 case elfcpp::R_POWERPC_PLT16_HA
:
11929 case elfcpp::R_POWERPC_SECTOFF_HI
:
11930 case elfcpp::R_POWERPC_SECTOFF_HA
:
11931 case elfcpp::R_PPC64_TOC16_HI
:
11932 case elfcpp::R_PPC64_TOC16_HA
:
11933 case elfcpp::R_PPC64_PLTGOT16_HI
:
11934 case elfcpp::R_PPC64_PLTGOT16_HA
:
11935 case elfcpp::R_POWERPC_TPREL16_HI
:
11936 case elfcpp::R_POWERPC_TPREL16_HA
:
11937 case elfcpp::R_POWERPC_DTPREL16_HI
:
11938 case elfcpp::R_POWERPC_DTPREL16_HA
:
11939 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11940 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11941 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11942 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11943 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11944 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11945 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11946 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11947 case elfcpp::R_POWERPC_REL16_HI
:
11948 case elfcpp::R_POWERPC_REL16_HA
:
11950 overflow
= Reloc::CHECK_HIGH_INSN
;
11953 case elfcpp::R_POWERPC_REL16
:
11954 case elfcpp::R_PPC64_TOC16
:
11955 case elfcpp::R_POWERPC_GOT16
:
11956 case elfcpp::R_POWERPC_SECTOFF
:
11957 case elfcpp::R_POWERPC_TPREL16
:
11958 case elfcpp::R_POWERPC_DTPREL16
:
11959 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11960 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11961 case elfcpp::R_POWERPC_GOT_TPREL16
:
11962 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11963 overflow
= Reloc::CHECK_LOW_INSN
;
11966 case elfcpp::R_PPC64_REL24_NOTOC
:
11970 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11971 case elfcpp::R_POWERPC_ADDR24
:
11972 case elfcpp::R_POWERPC_ADDR14
:
11973 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11974 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11975 case elfcpp::R_PPC64_ADDR16_DS
:
11976 case elfcpp::R_POWERPC_REL24
:
11977 case elfcpp::R_PPC_PLTREL24
:
11978 case elfcpp::R_PPC_LOCAL24PC
:
11979 case elfcpp::R_PPC64_TPREL16_DS
:
11980 case elfcpp::R_PPC64_DTPREL16_DS
:
11981 case elfcpp::R_PPC64_TOC16_DS
:
11982 case elfcpp::R_PPC64_GOT16_DS
:
11983 case elfcpp::R_PPC64_SECTOFF_DS
:
11984 case elfcpp::R_POWERPC_REL14
:
11985 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11986 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11987 case elfcpp::R_PPC64_D34
:
11988 case elfcpp::R_PPC64_PCREL34
:
11989 case elfcpp::R_PPC64_GOT_PCREL34
:
11990 case elfcpp::R_PPC64_PLT_PCREL34
:
11991 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11992 case elfcpp::R_PPC64_D28
:
11993 case elfcpp::R_PPC64_PCREL28
:
11994 case elfcpp::R_PPC64_TPREL34
:
11995 case elfcpp::R_PPC64_DTPREL34
:
11996 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11997 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11998 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11999 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12000 overflow
= Reloc::CHECK_SIGNED
;
12004 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
12007 if (overflow
== Reloc::CHECK_LOW_INSN
12008 || overflow
== Reloc::CHECK_HIGH_INSN
)
12010 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12012 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
12013 overflow
= Reloc::CHECK_BITFIELD
;
12014 else if (overflow
== Reloc::CHECK_LOW_INSN
12015 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
12016 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
12017 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
12018 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
12019 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
12020 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
12021 overflow
= Reloc::CHECK_UNSIGNED
;
12023 overflow
= Reloc::CHECK_SIGNED
;
12026 bool maybe_dq_reloc
= false;
12027 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
12028 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
12031 case elfcpp::R_POWERPC_NONE
:
12032 case elfcpp::R_POWERPC_TLS
:
12033 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
12034 case elfcpp::R_POWERPC_GNU_VTENTRY
:
12035 case elfcpp::R_POWERPC_PLTSEQ
:
12036 case elfcpp::R_POWERPC_PLTCALL
:
12037 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
12038 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
12039 case elfcpp::R_PPC64_PCREL_OPT
:
12042 case elfcpp::R_PPC64_ADDR64
:
12043 case elfcpp::R_PPC64_REL64
:
12044 case elfcpp::R_PPC64_TOC
:
12045 case elfcpp::R_PPC64_ADDR64_LOCAL
:
12046 Reloc::addr64(view
, value
);
12049 case elfcpp::R_POWERPC_TPREL
:
12050 case elfcpp::R_POWERPC_DTPREL
:
12052 Reloc::addr64(view
, value
);
12054 status
= Reloc::addr32(view
, value
, overflow
);
12057 case elfcpp::R_PPC64_UADDR64
:
12058 Reloc::addr64_u(view
, value
);
12061 case elfcpp::R_POWERPC_ADDR32
:
12062 status
= Reloc::addr32(view
, value
, overflow
);
12065 case elfcpp::R_POWERPC_REL32
:
12066 case elfcpp::R_POWERPC_UADDR32
:
12067 status
= Reloc::addr32_u(view
, value
, overflow
);
12070 case elfcpp::R_PPC64_REL24_NOTOC
:
12072 goto unsupp
; // R_PPC_EMB_RELSDA
12074 case elfcpp::R_PPC64_REL24_P9NOTOC
:
12075 case elfcpp::R_POWERPC_ADDR24
:
12076 case elfcpp::R_POWERPC_REL24
:
12077 case elfcpp::R_PPC_PLTREL24
:
12078 case elfcpp::R_PPC_LOCAL24PC
:
12079 status
= Reloc::addr24(view
, value
, overflow
);
12082 case elfcpp::R_POWERPC_GOT_DTPREL16
:
12083 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
12084 case elfcpp::R_POWERPC_GOT_TPREL16
:
12085 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
12088 // On ppc64 these are all ds form
12089 maybe_dq_reloc
= true;
12093 case elfcpp::R_POWERPC_ADDR16
:
12094 case elfcpp::R_POWERPC_REL16
:
12095 case elfcpp::R_PPC64_TOC16
:
12096 case elfcpp::R_POWERPC_GOT16
:
12097 case elfcpp::R_POWERPC_SECTOFF
:
12098 case elfcpp::R_POWERPC_TPREL16
:
12099 case elfcpp::R_POWERPC_DTPREL16
:
12100 case elfcpp::R_POWERPC_GOT_TLSGD16
:
12101 case elfcpp::R_POWERPC_GOT_TLSLD16
:
12102 case elfcpp::R_POWERPC_ADDR16_LO
:
12103 case elfcpp::R_POWERPC_REL16_LO
:
12104 case elfcpp::R_PPC64_TOC16_LO
:
12105 case elfcpp::R_POWERPC_GOT16_LO
:
12106 case elfcpp::R_POWERPC_PLT16_LO
:
12107 case elfcpp::R_POWERPC_SECTOFF_LO
:
12108 case elfcpp::R_POWERPC_TPREL16_LO
:
12109 case elfcpp::R_POWERPC_DTPREL16_LO
:
12110 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
12111 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
12113 status
= Reloc::addr16(view
, value
, overflow
);
12115 maybe_dq_reloc
= true;
12118 case elfcpp::R_POWERPC_UADDR16
:
12119 status
= Reloc::addr16_u(view
, value
, overflow
);
12122 case elfcpp::R_PPC64_ADDR16_HIGH
:
12123 case elfcpp::R_PPC64_TPREL16_HIGH
:
12124 case elfcpp::R_PPC64_DTPREL16_HIGH
:
12126 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
12129 case elfcpp::R_POWERPC_ADDR16_HI
:
12130 case elfcpp::R_POWERPC_REL16_HI
:
12131 case elfcpp::R_PPC64_REL16_HIGH
:
12132 case elfcpp::R_PPC64_TOC16_HI
:
12133 case elfcpp::R_POWERPC_GOT16_HI
:
12134 case elfcpp::R_POWERPC_PLT16_HI
:
12135 case elfcpp::R_POWERPC_SECTOFF_HI
:
12136 case elfcpp::R_POWERPC_TPREL16_HI
:
12137 case elfcpp::R_POWERPC_DTPREL16_HI
:
12138 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
12139 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
12140 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
12141 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
12142 Reloc::addr16_hi(view
, value
);
12145 case elfcpp::R_PPC64_ADDR16_HIGHA
:
12146 case elfcpp::R_PPC64_TPREL16_HIGHA
:
12147 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
12149 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
12152 case elfcpp::R_POWERPC_ADDR16_HA
:
12153 case elfcpp::R_POWERPC_REL16_HA
:
12154 case elfcpp::R_PPC64_REL16_HIGHA
:
12155 case elfcpp::R_PPC64_TOC16_HA
:
12156 case elfcpp::R_POWERPC_GOT16_HA
:
12157 case elfcpp::R_POWERPC_PLT16_HA
:
12158 case elfcpp::R_POWERPC_SECTOFF_HA
:
12159 case elfcpp::R_POWERPC_TPREL16_HA
:
12160 case elfcpp::R_POWERPC_DTPREL16_HA
:
12161 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
12162 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
12163 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
12164 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
12165 Reloc::addr16_ha(view
, value
);
12168 case elfcpp::R_POWERPC_REL16DX_HA
:
12169 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
12172 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
12174 // R_PPC_EMB_NADDR16_LO
12177 case elfcpp::R_PPC64_ADDR16_HIGHER
:
12178 case elfcpp::R_PPC64_REL16_HIGHER
:
12179 case elfcpp::R_PPC64_TPREL16_HIGHER
:
12180 Reloc::addr16_hi2(view
, value
);
12183 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
12185 // R_PPC_EMB_NADDR16_HI
12188 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
12189 case elfcpp::R_PPC64_REL16_HIGHERA
:
12190 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
12191 Reloc::addr16_ha2(view
, value
);
12194 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
12196 // R_PPC_EMB_NADDR16_HA
12199 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
12200 case elfcpp::R_PPC64_REL16_HIGHEST
:
12201 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
12202 Reloc::addr16_hi3(view
, value
);
12205 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
12207 // R_PPC_EMB_SDAI16
12210 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
12211 case elfcpp::R_PPC64_REL16_HIGHESTA
:
12212 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
12213 Reloc::addr16_ha3(view
, value
);
12216 case elfcpp::R_PPC64_DTPREL16_DS
:
12217 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
12219 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
12222 case elfcpp::R_PPC64_TPREL16_DS
:
12223 case elfcpp::R_PPC64_TPREL16_LO_DS
:
12225 // R_PPC_TLSGD, R_PPC_TLSLD
12228 case elfcpp::R_PPC64_ADDR16_DS
:
12229 case elfcpp::R_PPC64_ADDR16_LO_DS
:
12230 case elfcpp::R_PPC64_TOC16_DS
:
12231 case elfcpp::R_PPC64_TOC16_LO_DS
:
12232 case elfcpp::R_PPC64_GOT16_DS
:
12233 case elfcpp::R_PPC64_GOT16_LO_DS
:
12234 case elfcpp::R_PPC64_PLT16_LO_DS
:
12235 case elfcpp::R_PPC64_SECTOFF_DS
:
12236 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
12237 maybe_dq_reloc
= true;
12240 case elfcpp::R_POWERPC_ADDR14
:
12241 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
12242 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12243 case elfcpp::R_POWERPC_REL14
:
12244 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12245 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12246 status
= Reloc::addr14(view
, value
, overflow
);
12249 case elfcpp::R_POWERPC_COPY
:
12250 case elfcpp::R_POWERPC_GLOB_DAT
:
12251 case elfcpp::R_POWERPC_JMP_SLOT
:
12252 case elfcpp::R_POWERPC_RELATIVE
:
12253 case elfcpp::R_POWERPC_DTPMOD
:
12254 case elfcpp::R_PPC64_JMP_IREL
:
12255 case elfcpp::R_POWERPC_IRELATIVE
:
12256 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12257 _("unexpected reloc %u in object file"),
12261 case elfcpp::R_PPC64_TOCSAVE
:
12267 Symbol_location loc
;
12268 loc
.object
= relinfo
->object
;
12269 loc
.shndx
= relinfo
->data_shndx
;
12270 loc
.offset
= rela
.get_r_offset();
12271 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12272 if (tocsave
->find(loc
) != tocsave
->end())
12274 // If we've generated plt calls using this tocsave, then
12275 // the nop needs to be changed to save r2.
12276 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12277 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12278 elfcpp::Swap
<32, big_endian
>::
12279 writeval(iview
, std_2_1
+ target
->stk_toc());
12284 case elfcpp::R_PPC_EMB_SDA2I16
:
12285 case elfcpp::R_PPC_EMB_SDA2REL
:
12288 // R_PPC64_TLSGD, R_PPC64_TLSLD
12291 case elfcpp::R_PPC64_D34
:
12292 case elfcpp::R_PPC64_D34_LO
:
12293 case elfcpp::R_PPC64_PCREL34
:
12294 case elfcpp::R_PPC64_GOT_PCREL34
:
12295 case elfcpp::R_PPC64_PLT_PCREL34
:
12296 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12297 case elfcpp::R_PPC64_TPREL34
:
12298 case elfcpp::R_PPC64_DTPREL34
:
12299 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12300 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12301 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12302 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12305 status
= Reloc::addr34(view
, value
, overflow
);
12308 case elfcpp::R_PPC64_D34_HI30
:
12311 Reloc::addr34_hi(view
, value
);
12314 case elfcpp::R_PPC64_D34_HA30
:
12317 Reloc::addr34_ha(view
, value
);
12320 case elfcpp::R_PPC64_D28
:
12321 case elfcpp::R_PPC64_PCREL28
:
12324 status
= Reloc::addr28(view
, value
, overflow
);
12327 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12328 case elfcpp::R_PPC64_REL16_HIGHER34
:
12331 Reloc::addr16_higher34(view
, value
);
12334 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12335 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12338 Reloc::addr16_highera34(view
, value
);
12341 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12342 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12345 Reloc::addr16_highest34(view
, value
);
12348 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12349 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12352 Reloc::addr16_highesta34(view
, value
);
12355 case elfcpp::R_POWERPC_PLT32
:
12356 case elfcpp::R_POWERPC_PLTREL32
:
12357 case elfcpp::R_PPC_SDAREL16
:
12358 case elfcpp::R_POWERPC_ADDR30
:
12359 case elfcpp::R_PPC64_PLT64
:
12360 case elfcpp::R_PPC64_PLTREL64
:
12361 case elfcpp::R_PPC64_PLTGOT16
:
12362 case elfcpp::R_PPC64_PLTGOT16_LO
:
12363 case elfcpp::R_PPC64_PLTGOT16_HI
:
12364 case elfcpp::R_PPC64_PLTGOT16_HA
:
12365 case elfcpp::R_PPC64_PLTGOT16_DS
:
12366 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12367 case elfcpp::R_PPC_TOC16
:
12370 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12371 _("unsupported reloc %u"),
12376 if (maybe_dq_reloc
)
12379 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12381 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12382 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12383 && (insn
& 3) == 1))
12384 status
= Reloc::addr16_dq(view
, value
, overflow
);
12385 else if (size
== 64
12386 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12387 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12388 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12389 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12390 status
= Reloc::addr16_ds(view
, value
, overflow
);
12392 status
= Reloc::addr16(view
, value
, overflow
);
12395 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12398 && gsym
->is_undefined()
12399 && is_branch_reloc
<size
>(r_type
))))
12401 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12402 _("relocation overflow"));
12403 if (has_stub_value
)
12404 gold_info(_("try relinking with a smaller --stub-group-size"));
12410 // Relocate section data.
12412 template<int size
, bool big_endian
>
12414 Target_powerpc
<size
, big_endian
>::relocate_section(
12415 const Relocate_info
<size
, big_endian
>* relinfo
,
12416 unsigned int sh_type
,
12417 const unsigned char* prelocs
,
12418 size_t reloc_count
,
12419 Output_section
* output_section
,
12420 bool needs_special_offset_handling
,
12421 unsigned char* view
,
12423 section_size_type view_size
,
12424 const Reloc_symbol_changes
* reloc_symbol_changes
)
12426 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12427 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12428 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12429 Powerpc_comdat_behavior
;
12430 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12433 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12435 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12436 Powerpc_comdat_behavior
, Classify_reloc
>(
12442 needs_special_offset_handling
,
12446 reloc_symbol_changes
);
12449 template<int size
, bool big_endian
>
12450 class Powerpc_scan_relocatable_reloc
12453 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12454 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12455 static const int sh_type
= elfcpp::SHT_RELA
;
12457 // Return the symbol referred to by the relocation.
12458 static inline unsigned int
12459 get_r_sym(const Reltype
* reloc
)
12460 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12462 // Return the type of the relocation.
12463 static inline unsigned int
12464 get_r_type(const Reltype
* reloc
)
12465 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12467 // Return the strategy to use for a local symbol which is not a
12468 // section symbol, given the relocation type.
12469 inline Relocatable_relocs::Reloc_strategy
12470 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12472 if (r_type
== 0 && r_sym
== 0)
12473 return Relocatable_relocs::RELOC_DISCARD
;
12474 return Relocatable_relocs::RELOC_COPY
;
12477 // Return the strategy to use for a local symbol which is a section
12478 // symbol, given the relocation type.
12479 inline Relocatable_relocs::Reloc_strategy
12480 local_section_strategy(unsigned int, Relobj
*)
12482 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12485 // Return the strategy to use for a global symbol, given the
12486 // relocation type, the object, and the symbol index.
12487 inline Relocatable_relocs::Reloc_strategy
12488 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12491 && (r_type
== elfcpp::R_PPC_PLTREL24
12492 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12493 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12494 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12495 return Relocatable_relocs::RELOC_SPECIAL
;
12496 return Relocatable_relocs::RELOC_COPY
;
12500 // Scan the relocs during a relocatable link.
12502 template<int size
, bool big_endian
>
12504 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12505 Symbol_table
* symtab
,
12507 Sized_relobj_file
<size
, big_endian
>* object
,
12508 unsigned int data_shndx
,
12509 unsigned int sh_type
,
12510 const unsigned char* prelocs
,
12511 size_t reloc_count
,
12512 Output_section
* output_section
,
12513 bool needs_special_offset_handling
,
12514 size_t local_symbol_count
,
12515 const unsigned char* plocal_symbols
,
12516 Relocatable_relocs
* rr
)
12518 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12520 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12522 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12530 needs_special_offset_handling
,
12531 local_symbol_count
,
12536 // Scan the relocs for --emit-relocs.
12538 template<int size
, bool big_endian
>
12540 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12541 Symbol_table
* symtab
,
12543 Sized_relobj_file
<size
, big_endian
>* object
,
12544 unsigned int data_shndx
,
12545 unsigned int sh_type
,
12546 const unsigned char* prelocs
,
12547 size_t reloc_count
,
12548 Output_section
* output_section
,
12549 bool needs_special_offset_handling
,
12550 size_t local_symbol_count
,
12551 const unsigned char* plocal_syms
,
12552 Relocatable_relocs
* rr
)
12554 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12556 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12557 Emit_relocs_strategy
;
12559 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12561 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12569 needs_special_offset_handling
,
12570 local_symbol_count
,
12575 // Emit relocations for a section.
12576 // This is a modified version of the function by the same name in
12577 // target-reloc.h. Using relocate_special_relocatable for
12578 // R_PPC_PLTREL24 would require duplication of the entire body of the
12579 // loop, so we may as well duplicate the whole thing.
12581 template<int size
, bool big_endian
>
12583 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12584 const Relocate_info
<size
, big_endian
>* relinfo
,
12585 unsigned int sh_type
,
12586 const unsigned char* prelocs
,
12587 size_t reloc_count
,
12588 Output_section
* output_section
,
12589 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12591 Address view_address
,
12593 unsigned char* reloc_view
,
12594 section_size_type reloc_view_size
)
12596 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12598 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12599 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12600 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12601 // Offset from start of insn to d-field reloc.
12602 const int d_offset
= big_endian
? 2 : 0;
12604 Powerpc_relobj
<size
, big_endian
>* const object
12605 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12606 const unsigned int local_count
= object
->local_symbol_count();
12607 unsigned int got2_shndx
= object
->got2_shndx();
12608 Address got2_addend
= 0;
12609 if (got2_shndx
!= 0)
12611 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12612 gold_assert(got2_addend
!= invalid_address
);
12615 const bool relocatable
= parameters
->options().relocatable();
12617 unsigned char* pwrite
= reloc_view
;
12618 bool zap_next
= false;
12619 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12621 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12622 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12625 Reltype
reloc(prelocs
);
12626 Reltype_write
reloc_write(pwrite
);
12628 Address offset
= reloc
.get_r_offset();
12629 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12630 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12631 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12632 const unsigned int orig_r_sym
= r_sym
;
12633 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12634 = reloc
.get_r_addend();
12635 const Symbol
* gsym
= NULL
;
12639 // We could arrange to discard these and other relocs for
12640 // tls optimised sequences in the strategy methods, but for
12641 // now do as BFD ld does.
12642 r_type
= elfcpp::R_POWERPC_NONE
;
12646 // Get the new symbol index.
12647 Output_section
* os
= NULL
;
12648 if (r_sym
< local_count
)
12652 case Relocatable_relocs::RELOC_COPY
:
12653 case Relocatable_relocs::RELOC_SPECIAL
:
12656 r_sym
= object
->symtab_index(r_sym
);
12657 gold_assert(r_sym
!= -1U);
12661 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12663 // We are adjusting a section symbol. We need to find
12664 // the symbol table index of the section symbol for
12665 // the output section corresponding to input section
12666 // in which this symbol is defined.
12667 gold_assert(r_sym
< local_count
);
12669 unsigned int shndx
=
12670 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12671 gold_assert(is_ordinary
);
12672 os
= object
->output_section(shndx
);
12673 gold_assert(os
!= NULL
);
12674 gold_assert(os
->needs_symtab_index());
12675 r_sym
= os
->symtab_index();
12680 gold_unreachable();
12685 gsym
= object
->global_symbol(r_sym
);
12686 gold_assert(gsym
!= NULL
);
12687 if (gsym
->is_forwarder())
12688 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12690 gold_assert(gsym
->has_symtab_index());
12691 r_sym
= gsym
->symtab_index();
12694 // Get the new offset--the location in the output section where
12695 // this relocation should be applied.
12696 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12697 offset
+= offset_in_output_section
;
12700 section_offset_type sot_offset
=
12701 convert_types
<section_offset_type
, Address
>(offset
);
12702 section_offset_type new_sot_offset
=
12703 output_section
->output_offset(object
, relinfo
->data_shndx
,
12705 gold_assert(new_sot_offset
!= -1);
12706 offset
= new_sot_offset
;
12709 // In an object file, r_offset is an offset within the section.
12710 // In an executable or dynamic object, generated by
12711 // --emit-relocs, r_offset is an absolute address.
12714 offset
+= view_address
;
12715 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12716 offset
-= offset_in_output_section
;
12719 // Handle the reloc addend based on the strategy.
12720 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12722 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12724 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12725 addend
= psymval
->value(object
, addend
);
12726 // In a relocatable link, the symbol value is relative to
12727 // the start of the output section. For a non-relocatable
12728 // link, we need to adjust the addend.
12731 gold_assert(os
!= NULL
);
12732 addend
-= os
->address();
12735 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12739 if (addend
>= 32768)
12740 addend
+= got2_addend
;
12742 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12744 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12745 addend
-= d_offset
;
12747 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12749 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12750 addend
-= d_offset
+ 4;
12754 gold_unreachable();
12758 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12759 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12760 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12761 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12763 // First instruction of a global dynamic sequence,
12765 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12766 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12769 case tls::TLSOPT_TO_IE
:
12770 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12771 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12773 case tls::TLSOPT_TO_LE
:
12774 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12775 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12776 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12779 r_type
= elfcpp::R_POWERPC_NONE
;
12780 offset
-= d_offset
;
12787 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12788 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12789 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12790 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12792 // First instruction of a local dynamic sequence,
12794 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12795 if (tls_type
== tls::TLSOPT_TO_LE
)
12797 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12798 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12800 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12801 const Output_section
* os
= relinfo
->layout
->tls_segment()
12803 gold_assert(os
!= NULL
);
12804 gold_assert(os
->needs_symtab_index());
12805 r_sym
= os
->symtab_index();
12806 addend
= dtp_offset
;
12810 r_type
= elfcpp::R_POWERPC_NONE
;
12811 offset
-= d_offset
;
12815 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12816 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12817 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12818 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12820 // First instruction of initial exec sequence.
12821 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12822 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12824 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12825 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12826 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12829 r_type
= elfcpp::R_POWERPC_NONE
;
12830 offset
-= d_offset
;
12834 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12835 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12837 // Second instruction of a global dynamic sequence,
12838 // the __tls_get_addr call
12839 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12840 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12843 case tls::TLSOPT_TO_IE
:
12844 r_type
= elfcpp::R_POWERPC_NONE
;
12847 case tls::TLSOPT_TO_LE
:
12848 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12849 offset
+= d_offset
;
12856 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12857 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12859 // Second instruction of a local dynamic sequence,
12860 // the __tls_get_addr call
12861 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12862 if (tls_type
== tls::TLSOPT_TO_LE
)
12864 const Output_section
* os
= relinfo
->layout
->tls_segment()
12866 gold_assert(os
!= NULL
);
12867 gold_assert(os
->needs_symtab_index());
12868 r_sym
= os
->symtab_index();
12869 addend
= dtp_offset
;
12870 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12871 offset
+= d_offset
;
12875 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12877 // Second instruction of an initial exec sequence
12878 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12879 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12881 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12882 offset
+= d_offset
;
12887 reloc_write
.put_r_offset(offset
);
12888 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12889 reloc_write
.put_r_addend(addend
);
12891 pwrite
+= reloc_size
;
12894 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12895 == reloc_view_size
);
12898 // Return the value to use for a dynamic symbol which requires special
12899 // treatment. This is how we support equality comparisons of function
12900 // pointers across shared library boundaries, as described in the
12901 // processor specific ABI supplement.
12903 template<int size
, bool big_endian
>
12905 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12909 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12910 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12911 p
!= this->stub_tables_
.end();
12914 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12915 = (*p
)->find_plt_call_entry(gsym
);
12917 return (*p
)->stub_address() + ent
->off_
;
12920 else if (this->abiversion() >= 2)
12922 Address off
= this->glink_section()->find_global_entry(gsym
);
12923 if (off
!= invalid_address
)
12924 return this->glink_section()->global_entry_address() + off
;
12926 gold_unreachable();
12929 // Return the PLT address to use for a local symbol.
12930 template<int size
, bool big_endian
>
12932 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12933 const Relobj
* object
,
12934 unsigned int symndx
) const
12938 const Sized_relobj
<size
, big_endian
>* relobj
12939 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12940 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12941 p
!= this->stub_tables_
.end();
12944 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12945 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12947 return (*p
)->stub_address() + ent
->off_
;
12950 gold_unreachable();
12953 // Return the PLT address to use for a global symbol.
12954 template<int size
, bool big_endian
>
12956 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12957 const Symbol
* gsym
) const
12961 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12962 p
!= this->stub_tables_
.end();
12965 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12966 = (*p
)->find_plt_call_entry(gsym
);
12968 return (*p
)->stub_address() + ent
->off_
;
12971 else if (this->abiversion() >= 2)
12973 Address off
= this->glink_section()->find_global_entry(gsym
);
12974 if (off
!= invalid_address
)
12975 return this->glink_section()->global_entry_address() + off
;
12977 gold_unreachable();
12980 // Return the offset to use for the GOT_INDX'th got entry which is
12981 // for a local tls symbol specified by OBJECT, SYMNDX.
12982 template<int size
, bool big_endian
>
12984 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12985 const Relobj
* object
,
12986 unsigned int symndx
,
12987 Output_data_got_base
* got
,
12988 unsigned int got_indx
,
12989 uint64_t addend
) const
12991 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12992 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12993 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12995 for (Got_type got_type
= (size
== 32
12996 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
12997 got_type
<= GOT_TYPE_SMALL_TPREL
;
12998 got_type
= Got_type(got_type
+ 1))
12999 if (got_type
!= GOT_TYPE_SMALL
13000 && ppc_object
->local_has_got_offset(symndx
, got_type
, addend
))
13003 = ppc_object
->local_got_offset(symndx
, got_type
, addend
);
13004 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13006 if (off
== got_indx
* (size
/ 8)
13007 && (size
== 32 || got
== this->got_section(got_type
)))
13009 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13012 return -dtp_offset
;
13016 gold_unreachable();
13019 // Return the offset to use for the GOT_INDX'th got entry which is
13020 // for global tls symbol GSYM.
13021 template<int size
, bool big_endian
>
13023 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
13025 Output_data_got_base
* got
,
13026 unsigned int got_indx
,
13027 uint64_t addend
) const
13029 if (gsym
->type() == elfcpp::STT_TLS
)
13031 for (Got_type got_type
= (size
== 32
13032 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13033 got_type
<= GOT_TYPE_SMALL_TPREL
;
13034 got_type
= Got_type(got_type
+ 1))
13035 if (got_type
!= GOT_TYPE_SMALL
13036 && gsym
->has_got_offset(got_type
, addend
))
13038 unsigned int off
= gsym
->got_offset(got_type
, addend
);
13039 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13041 if (off
== got_indx
* (size
/ 8)
13042 && (size
== 32 || got
== this->got_section(got_type
)))
13044 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13047 return -dtp_offset
;
13051 gold_unreachable();
13054 // The selector for powerpc object files.
13056 template<int size
, bool big_endian
>
13057 class Target_selector_powerpc
: public Target_selector
13060 Target_selector_powerpc()
13061 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
13064 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
13065 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
13067 ? (big_endian
? "elf64ppc" : "elf64lppc")
13068 : (big_endian
? "elf32ppc" : "elf32lppc")))
13072 do_instantiate_target()
13073 { return new Target_powerpc
<size
, big_endian
>(); }
13076 Target_selector_powerpc
<32, true> target_selector_ppc32
;
13077 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
13078 Target_selector_powerpc
<64, true> target_selector_ppc64
;
13079 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
13081 // Instantiate these constants for -O0
13082 template<int size
, bool big_endian
>
13083 const typename Output_data_glink
<size
, big_endian
>::Address
13084 Output_data_glink
<size
, big_endian
>::invalid_address
;
13085 template<int size
, bool big_endian
>
13086 const typename Stub_table
<size
, big_endian
>::Address
13087 Stub_table
<size
, big_endian
>::invalid_address
;
13088 template<int size
, bool big_endian
>
13089 const typename Target_powerpc
<size
, big_endian
>::Address
13090 Target_powerpc
<size
, big_endian
>::invalid_address
;
13092 } // End anonymous namespace.