1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2021 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
44 #include "attributes.h"
51 template<int size
, bool big_endian
>
52 class Output_data_plt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_brlt_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_got_powerpc
;
60 template<int size
, bool big_endian
>
61 class Output_data_glink
;
63 template<int size
, bool big_endian
>
66 template<int size
, bool big_endian
>
67 class Output_data_save_res
;
69 template<int size
, bool big_endian
>
72 struct Stub_table_owner
75 : output_section(NULL
), owner(NULL
)
78 Output_section
* output_section
;
79 const Output_section::Input_section
* owner
;
83 inline bool is_branch_reloc(unsigned int);
86 inline bool is_plt16_reloc(unsigned int);
88 // Counter incremented on every Powerpc_relobj constructed.
89 static uint32_t object_id
= 0;
91 template<int size
, bool big_endian
>
92 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
95 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
96 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
97 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
99 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
100 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
101 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
102 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
103 has_small_toc_reloc_(false), opd_valid_(false),
104 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
105 access_from_map_(), has14_(), stub_table_index_(), st_other_(),
106 attributes_section_data_(NULL
)
108 this->set_abiversion(0);
112 { delete this->attributes_section_data_
; }
114 // Read the symbols then set up st_other vector.
116 do_read_symbols(Read_symbols_data
*);
118 // Arrange to always relocate .toc first.
120 do_relocate_sections(
121 const Symbol_table
* symtab
, const Layout
* layout
,
122 const unsigned char* pshdrs
, Output_file
* of
,
123 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
125 // The .toc section index.
132 // Mark .toc entry at OFF as not optimizable.
134 set_no_toc_opt(Address off
)
136 if (this->no_toc_opt_
.empty())
137 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
140 if (off
< this->no_toc_opt_
.size())
141 this->no_toc_opt_
[off
] = true;
144 // Mark the entire .toc as not optimizable.
148 this->no_toc_opt_
.resize(1);
149 this->no_toc_opt_
[0] = true;
152 // Return true if code using the .toc entry at OFF should not be edited.
154 no_toc_opt(Address off
) const
156 if (this->no_toc_opt_
.empty())
159 if (off
>= this->no_toc_opt_
.size())
161 return this->no_toc_opt_
[off
];
164 // The .got2 section shndx.
169 return this->special_
;
174 // The .opd section shndx.
181 return this->special_
;
184 // Init OPD entry arrays.
186 init_opd(size_t opd_size
)
188 size_t count
= this->opd_ent_ndx(opd_size
);
189 this->opd_ent_
.resize(count
);
192 // Return section and offset of function entry for .opd + R_OFF.
194 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
196 size_t ndx
= this->opd_ent_ndx(r_off
);
197 gold_assert(ndx
< this->opd_ent_
.size());
198 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
200 *value
= this->opd_ent_
[ndx
].off
;
201 return this->opd_ent_
[ndx
].shndx
;
204 // Set section and offset of function entry for .opd + R_OFF.
206 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
208 size_t ndx
= this->opd_ent_ndx(r_off
);
209 gold_assert(ndx
< this->opd_ent_
.size());
210 this->opd_ent_
[ndx
].shndx
= shndx
;
211 this->opd_ent_
[ndx
].off
= value
;
214 // Return discard flag for .opd + R_OFF.
216 get_opd_discard(Address r_off
) const
218 size_t ndx
= this->opd_ent_ndx(r_off
);
219 gold_assert(ndx
< this->opd_ent_
.size());
220 return this->opd_ent_
[ndx
].discard
;
223 // Set discard flag for .opd + R_OFF.
225 set_opd_discard(Address r_off
)
227 size_t ndx
= this->opd_ent_ndx(r_off
);
228 gold_assert(ndx
< this->opd_ent_
.size());
229 this->opd_ent_
[ndx
].discard
= true;
234 { return this->opd_valid_
; }
238 { this->opd_valid_
= true; }
240 // Examine .rela.opd to build info about function entry points.
242 scan_opd_relocs(size_t reloc_count
,
243 const unsigned char* prelocs
,
244 const unsigned char* plocal_syms
);
246 // Returns true if a code sequence loading a TOC entry can be
247 // converted into code calculating a TOC pointer relative offset.
249 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
253 make_got_relative(Target_powerpc
<size
, big_endian
>* target
,
254 const Symbol_value
<size
>* psymval
,
258 // Perform the Sized_relobj_file method, then set up opd info from
261 do_read_relocs(Read_relocs_data
*);
264 do_find_special_sections(Read_symbols_data
* sd
);
266 // Adjust this local symbol value. Return false if the symbol
267 // should be discarded from the output file.
269 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
271 if (size
== 64 && this->opd_shndx() != 0)
274 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
276 if (this->get_opd_discard(lv
->input_value()))
284 { return &this->access_from_map_
; }
286 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
287 // section at DST_OFF.
289 add_reference(Relobj
* src_obj
,
290 unsigned int src_indx
,
291 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
293 Section_id
src_id(src_obj
, src_indx
);
294 this->access_from_map_
[dst_off
].insert(src_id
);
297 // Add a reference to the code section specified by the .opd entry
300 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
302 size_t ndx
= this->opd_ent_ndx(dst_off
);
303 if (ndx
>= this->opd_ent_
.size())
304 this->opd_ent_
.resize(ndx
+ 1);
305 this->opd_ent_
[ndx
].gc_mark
= true;
309 process_gc_mark(Symbol_table
* symtab
)
311 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
312 if (this->opd_ent_
[i
].gc_mark
)
314 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
315 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
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_POWERPC_NONE
:
7679 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7680 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7681 case elfcpp::R_PPC64_TOC
:
7682 // No symbol reference.
7685 case elfcpp::R_PPC64_ADDR64
:
7686 case elfcpp::R_PPC64_UADDR64
:
7687 case elfcpp::R_POWERPC_ADDR32
:
7688 case elfcpp::R_POWERPC_UADDR32
:
7689 case elfcpp::R_POWERPC_ADDR16
:
7690 case elfcpp::R_POWERPC_UADDR16
:
7691 case elfcpp::R_POWERPC_ADDR16_LO
:
7692 case elfcpp::R_POWERPC_ADDR16_HI
:
7693 case elfcpp::R_POWERPC_ADDR16_HA
:
7694 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7695 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7696 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7697 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7698 case elfcpp::R_PPC64_D34
:
7699 case elfcpp::R_PPC64_D34_LO
:
7700 case elfcpp::R_PPC64_D34_HI30
:
7701 case elfcpp::R_PPC64_D34_HA30
:
7702 case elfcpp::R_PPC64_D28
:
7703 ref
= Symbol::ABSOLUTE_REF
;
7706 case elfcpp::R_POWERPC_ADDR24
:
7707 case elfcpp::R_POWERPC_ADDR14
:
7708 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7709 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7710 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7713 case elfcpp::R_PPC64_REL64
:
7714 case elfcpp::R_POWERPC_REL32
:
7715 case elfcpp::R_PPC_LOCAL24PC
:
7716 case elfcpp::R_POWERPC_REL16
:
7717 case elfcpp::R_POWERPC_REL16_LO
:
7718 case elfcpp::R_POWERPC_REL16_HI
:
7719 case elfcpp::R_POWERPC_REL16_HA
:
7720 case elfcpp::R_PPC64_REL16_HIGH
:
7721 case elfcpp::R_PPC64_REL16_HIGHA
:
7722 case elfcpp::R_PPC64_REL16_HIGHER
:
7723 case elfcpp::R_PPC64_REL16_HIGHERA
:
7724 case elfcpp::R_PPC64_REL16_HIGHEST
:
7725 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7726 case elfcpp::R_PPC64_PCREL34
:
7727 case elfcpp::R_PPC64_REL16_HIGHER34
:
7728 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7729 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7730 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7731 case elfcpp::R_PPC64_PCREL28
:
7732 ref
= Symbol::RELATIVE_REF
;
7735 case elfcpp::R_PPC64_REL24_NOTOC
:
7739 case elfcpp::R_PPC64_REL24_P9NOTOC
:
7740 case elfcpp::R_POWERPC_REL24
:
7741 case elfcpp::R_PPC_PLTREL24
:
7742 case elfcpp::R_POWERPC_REL14
:
7743 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7744 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7745 case elfcpp::R_POWERPC_PLT16_LO
:
7746 case elfcpp::R_POWERPC_PLT16_HI
:
7747 case elfcpp::R_POWERPC_PLT16_HA
:
7748 case elfcpp::R_PPC64_PLT16_LO_DS
:
7749 case elfcpp::R_POWERPC_PLTSEQ
:
7750 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7751 case elfcpp::R_POWERPC_PLTCALL
:
7752 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7753 case elfcpp::R_PPC64_PLT_PCREL34
:
7754 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7755 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7758 case elfcpp::R_POWERPC_GOT16
:
7759 case elfcpp::R_POWERPC_GOT16_LO
:
7760 case elfcpp::R_POWERPC_GOT16_HI
:
7761 case elfcpp::R_POWERPC_GOT16_HA
:
7762 case elfcpp::R_PPC64_GOT16_DS
:
7763 case elfcpp::R_PPC64_GOT16_LO_DS
:
7764 case elfcpp::R_PPC64_GOT_PCREL34
:
7765 case elfcpp::R_PPC64_TOC16
:
7766 case elfcpp::R_PPC64_TOC16_LO
:
7767 case elfcpp::R_PPC64_TOC16_HI
:
7768 case elfcpp::R_PPC64_TOC16_HA
:
7769 case elfcpp::R_PPC64_TOC16_DS
:
7770 case elfcpp::R_PPC64_TOC16_LO_DS
:
7771 ref
= Symbol::RELATIVE_REF
;
7774 case elfcpp::R_POWERPC_GOT_TPREL16
:
7775 case elfcpp::R_POWERPC_TLS
:
7776 case elfcpp::R_PPC64_TLSGD
:
7777 case elfcpp::R_PPC64_TLSLD
:
7778 case elfcpp::R_PPC64_TPREL34
:
7779 case elfcpp::R_PPC64_DTPREL34
:
7780 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7781 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7782 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7783 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7784 ref
= Symbol::TLS_REF
;
7787 case elfcpp::R_POWERPC_COPY
:
7788 case elfcpp::R_POWERPC_GLOB_DAT
:
7789 case elfcpp::R_POWERPC_JMP_SLOT
:
7790 case elfcpp::R_POWERPC_RELATIVE
:
7791 case elfcpp::R_POWERPC_DTPMOD
:
7793 // Not expected. We will give an error later.
7797 if (size
== 64 && target
->abiversion() < 2)
7798 ref
|= Symbol::FUNC_DESC_ABI
;
7802 // Report an unsupported relocation against a local symbol.
7804 template<int size
, bool big_endian
>
7806 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7807 Sized_relobj_file
<size
, big_endian
>* object
,
7808 unsigned int r_type
)
7810 gold_error(_("%s: unsupported reloc %u against local symbol"),
7811 object
->name().c_str(), r_type
);
7814 // We are about to emit a dynamic relocation of type R_TYPE. If the
7815 // dynamic linker does not support it, issue an error.
7817 template<int size
, bool big_endian
>
7819 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7820 unsigned int r_type
)
7822 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7824 // These are the relocation types supported by glibc for both 32-bit
7825 // and 64-bit powerpc.
7828 case elfcpp::R_POWERPC_NONE
:
7829 case elfcpp::R_POWERPC_RELATIVE
:
7830 case elfcpp::R_POWERPC_GLOB_DAT
:
7831 case elfcpp::R_POWERPC_DTPMOD
:
7832 case elfcpp::R_POWERPC_DTPREL
:
7833 case elfcpp::R_POWERPC_TPREL
:
7834 case elfcpp::R_POWERPC_JMP_SLOT
:
7835 case elfcpp::R_POWERPC_COPY
:
7836 case elfcpp::R_POWERPC_IRELATIVE
:
7837 case elfcpp::R_POWERPC_ADDR32
:
7838 case elfcpp::R_POWERPC_UADDR32
:
7839 case elfcpp::R_POWERPC_ADDR24
:
7840 case elfcpp::R_POWERPC_ADDR16
:
7841 case elfcpp::R_POWERPC_UADDR16
:
7842 case elfcpp::R_POWERPC_ADDR16_LO
:
7843 case elfcpp::R_POWERPC_ADDR16_HI
:
7844 case elfcpp::R_POWERPC_ADDR16_HA
:
7845 case elfcpp::R_POWERPC_ADDR14
:
7846 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7847 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7848 case elfcpp::R_POWERPC_REL32
:
7849 case elfcpp::R_POWERPC_TPREL16
:
7850 case elfcpp::R_POWERPC_TPREL16_LO
:
7851 case elfcpp::R_POWERPC_TPREL16_HI
:
7852 case elfcpp::R_POWERPC_TPREL16_HA
:
7863 // These are the relocation types supported only on 64-bit.
7864 case elfcpp::R_PPC64_ADDR64
:
7865 case elfcpp::R_PPC64_UADDR64
:
7866 case elfcpp::R_PPC64_JMP_IREL
:
7867 case elfcpp::R_PPC64_ADDR16_DS
:
7868 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7869 case elfcpp::R_PPC64_ADDR16_HIGH
:
7870 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7871 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7872 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7873 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7874 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7875 case elfcpp::R_PPC64_REL64
:
7876 case elfcpp::R_POWERPC_ADDR30
:
7877 case elfcpp::R_PPC64_TPREL16_DS
:
7878 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7879 case elfcpp::R_PPC64_TPREL16_HIGH
:
7880 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7881 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7882 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7883 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7884 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7895 // These are the relocation types supported only on 32-bit.
7896 // ??? glibc ld.so doesn't need to support these.
7897 case elfcpp::R_POWERPC_REL24
:
7898 case elfcpp::R_POWERPC_DTPREL16
:
7899 case elfcpp::R_POWERPC_DTPREL16_LO
:
7900 case elfcpp::R_POWERPC_DTPREL16_HI
:
7901 case elfcpp::R_POWERPC_DTPREL16_HA
:
7909 // This prevents us from issuing more than one error per reloc
7910 // section. But we can still wind up issuing more than one
7911 // error per object file.
7912 if (this->issued_non_pic_error_
)
7914 gold_assert(parameters
->options().output_is_position_independent());
7915 object
->error(_("requires unsupported dynamic reloc; "
7916 "recompile with -fPIC"));
7917 this->issued_non_pic_error_
= true;
7921 // Return whether we need to make a PLT entry for a relocation of the
7922 // given type against a STT_GNU_IFUNC symbol.
7924 template<int size
, bool big_endian
>
7926 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7927 Target_powerpc
<size
, big_endian
>* target
,
7928 Sized_relobj_file
<size
, big_endian
>* object
,
7929 unsigned int r_type
,
7932 // In non-pic code any reference will resolve to the plt call stub
7933 // for the ifunc symbol.
7934 if ((size
== 32 || target
->abiversion() >= 2)
7935 && !parameters
->options().output_is_position_independent())
7940 // Word size refs from data sections are OK, but don't need a PLT entry.
7941 case elfcpp::R_POWERPC_ADDR32
:
7942 case elfcpp::R_POWERPC_UADDR32
:
7947 case elfcpp::R_PPC64_ADDR64
:
7948 case elfcpp::R_PPC64_UADDR64
:
7953 // GOT refs are good, but also don't need a PLT entry.
7954 case elfcpp::R_POWERPC_GOT16
:
7955 case elfcpp::R_POWERPC_GOT16_LO
:
7956 case elfcpp::R_POWERPC_GOT16_HI
:
7957 case elfcpp::R_POWERPC_GOT16_HA
:
7958 case elfcpp::R_PPC64_GOT16_DS
:
7959 case elfcpp::R_PPC64_GOT16_LO_DS
:
7960 case elfcpp::R_PPC64_GOT_PCREL34
:
7963 // PLT relocs are OK and need a PLT entry.
7964 case elfcpp::R_POWERPC_PLT16_LO
:
7965 case elfcpp::R_POWERPC_PLT16_HI
:
7966 case elfcpp::R_POWERPC_PLT16_HA
:
7967 case elfcpp::R_PPC64_PLT16_LO_DS
:
7968 case elfcpp::R_POWERPC_PLTSEQ
:
7969 case elfcpp::R_POWERPC_PLTCALL
:
7970 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7971 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7972 case elfcpp::R_PPC64_PLT_PCREL34
:
7973 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7977 // Function calls are good, and these do need a PLT entry.
7978 case elfcpp::R_PPC64_REL24_NOTOC
:
7982 case elfcpp::R_PPC64_REL24_P9NOTOC
:
7983 case elfcpp::R_POWERPC_ADDR24
:
7984 case elfcpp::R_POWERPC_ADDR14
:
7985 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7986 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7987 case elfcpp::R_POWERPC_REL24
:
7988 case elfcpp::R_PPC_PLTREL24
:
7989 case elfcpp::R_POWERPC_REL14
:
7990 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7991 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7998 // Anything else is a problem.
7999 // If we are building a static executable, the libc startup function
8000 // responsible for applying indirect function relocations is going
8001 // to complain about the reloc type.
8002 // If we are building a dynamic executable, we will have a text
8003 // relocation. The dynamic loader will set the text segment
8004 // writable and non-executable to apply text relocations. So we'll
8005 // segfault when trying to run the indirection function to resolve
8008 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
8009 object
->name().c_str(), r_type
);
8013 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
8017 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
8019 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8020 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8021 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8022 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8023 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8024 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8025 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8026 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8027 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8028 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8029 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8030 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8031 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8032 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8033 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8034 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8035 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8036 /* Exclude lfqu by testing reloc. If relocs are ever
8037 defined for the reduced D field in psq_lu then those
8038 will need testing too. */
8039 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8040 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8041 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8043 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8044 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8045 /* Exclude stfqu. psq_stu as above for psq_lu. */
8046 && r_type
!= elfcpp::R_PPC64_TOC16_LO
8047 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
8048 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8049 && (insn
& 1) == 0));
8052 // Scan a relocation for a local symbol.
8054 template<int size
, bool big_endian
>
8056 Target_powerpc
<size
, big_endian
>::Scan::local(
8057 Symbol_table
* symtab
,
8059 Target_powerpc
<size
, big_endian
>* target
,
8060 Sized_relobj_file
<size
, big_endian
>* object
,
8061 unsigned int data_shndx
,
8062 Output_section
* output_section
,
8063 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8064 unsigned int r_type
,
8065 const elfcpp::Sym
<size
, big_endian
>& lsym
,
8068 Powerpc_relobj
<size
, big_endian
>* ppc_object
8069 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8071 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
8073 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8074 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8076 this->expect_tls_get_addr_call();
8077 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8078 if (tls_type
!= tls::TLSOPT_NONE
)
8079 this->skip_next_tls_get_addr_call();
8081 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8082 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8084 this->expect_tls_get_addr_call();
8085 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8086 if (tls_type
!= tls::TLSOPT_NONE
)
8087 this->skip_next_tls_get_addr_call();
8093 && data_shndx
== ppc_object
->opd_shndx()
8094 && r_type
== elfcpp::R_PPC64_ADDR64
)
8095 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8099 // A local STT_GNU_IFUNC symbol may require a PLT entry.
8100 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
8101 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8103 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8104 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8105 r_type
, r_sym
, reloc
.get_r_addend());
8106 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
8111 case elfcpp::R_POWERPC_NONE
:
8112 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8113 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8114 case elfcpp::R_POWERPC_TLS
:
8115 case elfcpp::R_PPC64_ENTRY
:
8116 case elfcpp::R_POWERPC_PLTSEQ
:
8117 case elfcpp::R_POWERPC_PLTCALL
:
8118 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8119 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8120 case elfcpp::R_PPC64_PCREL_OPT
:
8121 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8122 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8123 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8124 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8125 case elfcpp::R_PPC64_REL16_HIGHER34
:
8126 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8127 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8128 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8129 case elfcpp::R_PPC64_D34
:
8130 case elfcpp::R_PPC64_D34_LO
:
8131 case elfcpp::R_PPC64_D34_HI30
:
8132 case elfcpp::R_PPC64_D34_HA30
:
8133 case elfcpp::R_PPC64_D28
:
8134 case elfcpp::R_PPC64_PCREL34
:
8135 case elfcpp::R_PPC64_PCREL28
:
8136 case elfcpp::R_PPC64_TPREL34
:
8137 case elfcpp::R_PPC64_DTPREL34
:
8140 case elfcpp::R_PPC64_TOC
:
8142 Output_data_got_powerpc
<size
, big_endian
>* got
8143 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8144 if (parameters
->options().output_is_position_independent())
8146 Address off
= reloc
.get_r_offset();
8148 && target
->abiversion() < 2
8149 && data_shndx
== ppc_object
->opd_shndx()
8150 && ppc_object
->get_opd_discard(off
- 8))
8153 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8154 Address got_off
= got
->g_o_t();
8155 rela_dyn
->add_output_section_relative(got
->output_section(),
8156 elfcpp::R_POWERPC_RELATIVE
,
8158 object
, data_shndx
, off
,
8164 case elfcpp::R_PPC64_ADDR64
:
8165 case elfcpp::R_PPC64_UADDR64
:
8166 case elfcpp::R_POWERPC_ADDR32
:
8167 case elfcpp::R_POWERPC_UADDR32
:
8168 case elfcpp::R_POWERPC_ADDR24
:
8169 case elfcpp::R_POWERPC_ADDR16
:
8170 case elfcpp::R_POWERPC_ADDR16_LO
:
8171 case elfcpp::R_POWERPC_ADDR16_HI
:
8172 case elfcpp::R_POWERPC_ADDR16_HA
:
8173 case elfcpp::R_POWERPC_UADDR16
:
8174 case elfcpp::R_PPC64_ADDR16_HIGH
:
8175 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8176 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8177 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8178 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8179 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8180 case elfcpp::R_PPC64_ADDR16_DS
:
8181 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8182 case elfcpp::R_POWERPC_ADDR14
:
8183 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8184 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8185 // If building a shared library (or a position-independent
8186 // executable), we need to create a dynamic relocation for
8188 if (parameters
->options().output_is_position_independent()
8189 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8191 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8193 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8194 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8195 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8197 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8198 : elfcpp::R_POWERPC_RELATIVE
);
8199 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8200 output_section
, data_shndx
,
8201 reloc
.get_r_offset(),
8202 reloc
.get_r_addend(), false);
8204 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8206 check_non_pic(object
, r_type
);
8207 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8208 data_shndx
, reloc
.get_r_offset(),
8209 reloc
.get_r_addend());
8213 gold_assert(lsym
.get_st_value() == 0);
8214 unsigned int shndx
= lsym
.get_st_shndx();
8216 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8219 object
->error(_("section symbol %u has bad shndx %u"),
8222 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8223 output_section
, data_shndx
,
8224 reloc
.get_r_offset());
8229 case elfcpp::R_PPC64_PLT_PCREL34
:
8230 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8231 case elfcpp::R_POWERPC_PLT16_LO
:
8232 case elfcpp::R_POWERPC_PLT16_HI
:
8233 case elfcpp::R_POWERPC_PLT16_HA
:
8234 case elfcpp::R_PPC64_PLT16_LO_DS
:
8237 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8238 target
->make_local_plt_entry(symtab
, layout
, object
, r_sym
);
8242 case elfcpp::R_PPC64_REL24_NOTOC
:
8246 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8247 case elfcpp::R_POWERPC_REL24
:
8248 case elfcpp::R_PPC_PLTREL24
:
8249 case elfcpp::R_PPC_LOCAL24PC
:
8250 case elfcpp::R_POWERPC_REL14
:
8251 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8252 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8255 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8256 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8257 r_type
, r_sym
, reloc
.get_r_addend());
8261 case elfcpp::R_PPC64_TOCSAVE
:
8262 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8263 // caller has already saved r2 and thus a plt call stub need not
8266 && target
->mark_pltcall(ppc_object
, data_shndx
,
8267 reloc
.get_r_offset() - 4, symtab
))
8269 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8270 unsigned int shndx
= lsym
.get_st_shndx();
8272 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8274 object
->error(_("tocsave symbol %u has bad shndx %u"),
8277 target
->add_tocsave(ppc_object
, shndx
,
8278 lsym
.get_st_value() + reloc
.get_r_addend());
8282 case elfcpp::R_PPC64_REL64
:
8283 case elfcpp::R_POWERPC_REL32
:
8284 case elfcpp::R_POWERPC_REL16
:
8285 case elfcpp::R_POWERPC_REL16_LO
:
8286 case elfcpp::R_POWERPC_REL16_HI
:
8287 case elfcpp::R_POWERPC_REL16_HA
:
8288 case elfcpp::R_POWERPC_REL16DX_HA
:
8289 case elfcpp::R_PPC64_REL16_HIGH
:
8290 case elfcpp::R_PPC64_REL16_HIGHA
:
8291 case elfcpp::R_PPC64_REL16_HIGHER
:
8292 case elfcpp::R_PPC64_REL16_HIGHERA
:
8293 case elfcpp::R_PPC64_REL16_HIGHEST
:
8294 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8295 case elfcpp::R_POWERPC_SECTOFF
:
8296 case elfcpp::R_POWERPC_SECTOFF_LO
:
8297 case elfcpp::R_POWERPC_SECTOFF_HI
:
8298 case elfcpp::R_POWERPC_SECTOFF_HA
:
8299 case elfcpp::R_PPC64_SECTOFF_DS
:
8300 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8301 case elfcpp::R_POWERPC_TPREL16
:
8302 case elfcpp::R_POWERPC_TPREL16_LO
:
8303 case elfcpp::R_POWERPC_TPREL16_HI
:
8304 case elfcpp::R_POWERPC_TPREL16_HA
:
8305 case elfcpp::R_PPC64_TPREL16_DS
:
8306 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8307 case elfcpp::R_PPC64_TPREL16_HIGH
:
8308 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8309 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8310 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8311 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8312 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8313 case elfcpp::R_POWERPC_DTPREL16
:
8314 case elfcpp::R_POWERPC_DTPREL16_LO
:
8315 case elfcpp::R_POWERPC_DTPREL16_HI
:
8316 case elfcpp::R_POWERPC_DTPREL16_HA
:
8317 case elfcpp::R_PPC64_DTPREL16_DS
:
8318 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8319 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8320 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8321 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8322 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8323 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8324 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8325 case elfcpp::R_PPC64_TLSGD
:
8326 case elfcpp::R_PPC64_TLSLD
:
8327 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8330 case elfcpp::R_PPC64_GOT_PCREL34
:
8331 case elfcpp::R_POWERPC_GOT16
:
8332 case elfcpp::R_POWERPC_GOT16_LO
:
8333 case elfcpp::R_POWERPC_GOT16_HI
:
8334 case elfcpp::R_POWERPC_GOT16_HA
:
8335 case elfcpp::R_PPC64_GOT16_DS
:
8336 case elfcpp::R_PPC64_GOT16_LO_DS
:
8338 // The symbol requires a GOT entry.
8339 Got_type got_type
= ((size
== 32
8340 || r_type
== elfcpp::R_POWERPC_GOT16
8341 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8342 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8343 Output_data_got_powerpc
<size
, big_endian
>* got
8344 = target
->got_section(symtab
, layout
, got_type
);
8345 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8346 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8348 if (!parameters
->options().output_is_position_independent())
8351 && (size
== 32 || target
->abiversion() >= 2))
8352 got
->add_local_plt(object
, r_sym
, got_type
, addend
);
8354 got
->add_local(object
, r_sym
, got_type
, addend
);
8356 else if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8358 // If we are generating a shared object or a pie, this
8359 // symbol's GOT entry will be set by a dynamic relocation.
8361 off
= got
->add_constant(0);
8362 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8364 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8366 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8367 : elfcpp::R_POWERPC_RELATIVE
);
8368 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8369 got
, off
, addend
, false);
8374 case elfcpp::R_PPC64_TOC16
:
8375 case elfcpp::R_PPC64_TOC16_LO
:
8376 case elfcpp::R_PPC64_TOC16_HI
:
8377 case elfcpp::R_PPC64_TOC16_HA
:
8378 case elfcpp::R_PPC64_TOC16_DS
:
8379 case elfcpp::R_PPC64_TOC16_LO_DS
:
8380 // We need a GOT section.
8381 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8384 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8385 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8386 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8387 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8388 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8390 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8391 if (tls_type
== tls::TLSOPT_NONE
)
8393 Got_type got_type
= ((size
== 32
8394 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8395 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8396 Output_data_got_powerpc
<size
, big_endian
>* got
8397 = target
->got_section(symtab
, layout
, got_type
);
8398 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8399 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8400 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8401 got
->add_local_tls_pair(object
, r_sym
, got_type
,
8402 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
,
8405 else if (tls_type
== tls::TLSOPT_TO_LE
)
8407 // no GOT relocs needed for Local Exec.
8414 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8415 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8416 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8417 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8418 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8420 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8421 if (tls_type
== tls::TLSOPT_NONE
)
8422 target
->tlsld_got_offset(symtab
, layout
, object
);
8423 else if (tls_type
== tls::TLSOPT_TO_LE
)
8425 // no GOT relocs needed for Local Exec.
8426 if (parameters
->options().emit_relocs())
8428 Output_section
* os
= layout
->tls_segment()->first_section();
8429 gold_assert(os
!= NULL
);
8430 os
->set_needs_symtab_index();
8438 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8439 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8440 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8441 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8442 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8444 Got_type got_type
= ((size
== 32
8445 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
8446 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
8447 Output_data_got_powerpc
<size
, big_endian
>* got
8448 = target
->got_section(symtab
, layout
, got_type
);
8449 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8450 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8451 got
->add_local_tls(object
, r_sym
, got_type
, addend
);
8455 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8456 case elfcpp::R_POWERPC_GOT_TPREL16
:
8457 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8458 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8459 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8461 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8462 if (tls_type
== tls::TLSOPT_NONE
)
8464 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8465 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8466 Got_type got_type
= ((size
== 32
8467 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
8468 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
8469 if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8471 Output_data_got_powerpc
<size
, big_endian
>* got
8472 = target
->got_section(symtab
, layout
, got_type
);
8473 unsigned int off
= got
->add_constant(0);
8474 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8476 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8477 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8478 elfcpp::R_POWERPC_TPREL
,
8482 else if (tls_type
== tls::TLSOPT_TO_LE
)
8484 // no GOT relocs needed for Local Exec.
8492 unsupported_reloc_local(object
, r_type
);
8497 && parameters
->options().toc_optimize())
8499 if (data_shndx
== ppc_object
->toc_shndx())
8502 if (r_type
!= elfcpp::R_PPC64_ADDR64
8503 || (is_ifunc
&& target
->abiversion() < 2))
8505 else if (parameters
->options().output_is_position_independent())
8511 unsigned int shndx
= lsym
.get_st_shndx();
8512 if (shndx
>= elfcpp::SHN_LORESERVE
8513 && shndx
!= elfcpp::SHN_XINDEX
)
8518 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8521 enum {no_check
, check_lo
, check_ha
} insn_check
;
8525 insn_check
= no_check
;
8528 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8529 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8530 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8531 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8532 case elfcpp::R_POWERPC_GOT16_HA
:
8533 case elfcpp::R_PPC64_TOC16_HA
:
8534 insn_check
= check_ha
;
8537 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8538 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8539 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8540 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8541 case elfcpp::R_POWERPC_GOT16_LO
:
8542 case elfcpp::R_PPC64_GOT16_LO_DS
:
8543 case elfcpp::R_PPC64_TOC16_LO
:
8544 case elfcpp::R_PPC64_TOC16_LO_DS
:
8545 insn_check
= check_lo
;
8549 section_size_type slen
;
8550 const unsigned char* view
= NULL
;
8551 if (insn_check
!= no_check
)
8553 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8554 section_size_type off
=
8555 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8558 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8559 if (insn_check
== check_lo
8560 ? !ok_lo_toc_insn(insn
, r_type
)
8561 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8562 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8564 ppc_object
->set_no_toc_opt();
8565 gold_warning(_("%s: toc optimization is not supported "
8566 "for %#08x instruction"),
8567 ppc_object
->name().c_str(), insn
);
8576 case elfcpp::R_PPC64_TOC16
:
8577 case elfcpp::R_PPC64_TOC16_LO
:
8578 case elfcpp::R_PPC64_TOC16_HI
:
8579 case elfcpp::R_PPC64_TOC16_HA
:
8580 case elfcpp::R_PPC64_TOC16_DS
:
8581 case elfcpp::R_PPC64_TOC16_LO_DS
:
8582 unsigned int shndx
= lsym
.get_st_shndx();
8583 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8585 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8586 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8588 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8589 if (dst_off
< ppc_object
->section_size(shndx
))
8592 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8594 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8596 // Need to check that the insn is a ld
8598 view
= ppc_object
->section_contents(data_shndx
,
8601 section_size_type off
=
8602 (convert_to_section_size_type(reloc
.get_r_offset())
8603 + (big_endian
? -2 : 3));
8605 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8609 ppc_object
->set_no_toc_opt(dst_off
);
8620 case elfcpp::R_POWERPC_REL32
:
8621 if (ppc_object
->got2_shndx() != 0
8622 && parameters
->options().output_is_position_independent())
8624 unsigned int shndx
= lsym
.get_st_shndx();
8625 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8627 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8628 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8629 && (ppc_object
->section_flags(data_shndx
)
8630 & elfcpp::SHF_EXECINSTR
) != 0)
8631 gold_error(_("%s: unsupported -mbss-plt code"),
8632 ppc_object
->name().c_str());
8642 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8643 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8644 case elfcpp::R_POWERPC_GOT_TPREL16
:
8645 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8646 case elfcpp::R_POWERPC_GOT16
:
8647 case elfcpp::R_PPC64_GOT16_DS
:
8648 case elfcpp::R_PPC64_TOC16
:
8649 case elfcpp::R_PPC64_TOC16_DS
:
8650 ppc_object
->set_has_small_toc_reloc();
8658 case elfcpp::R_PPC64_TPREL16_DS
:
8659 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8660 case elfcpp::R_PPC64_TPREL16_HIGH
:
8661 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8662 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8663 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8664 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8665 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8666 case elfcpp::R_PPC64_TPREL34
:
8670 case elfcpp::R_POWERPC_TPREL16
:
8671 case elfcpp::R_POWERPC_TPREL16_LO
:
8672 case elfcpp::R_POWERPC_TPREL16_HI
:
8673 case elfcpp::R_POWERPC_TPREL16_HA
:
8674 layout
->set_has_static_tls();
8682 case elfcpp::R_POWERPC_TPREL16_HA
:
8683 if (target
->tprel_opt())
8685 section_size_type slen
;
8686 const unsigned char* view
= NULL
;
8687 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8688 section_size_type off
8689 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8692 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8693 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8694 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8695 target
->set_no_tprel_opt();
8700 case elfcpp::R_PPC64_TPREL16_HIGH
:
8701 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8702 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8703 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8704 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8705 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8709 case elfcpp::R_POWERPC_TPREL16_HI
:
8710 target
->set_no_tprel_opt();
8718 case elfcpp::R_PPC64_D34
:
8719 case elfcpp::R_PPC64_D34_LO
:
8720 case elfcpp::R_PPC64_D34_HI30
:
8721 case elfcpp::R_PPC64_D34_HA30
:
8722 case elfcpp::R_PPC64_D28
:
8723 case elfcpp::R_PPC64_PCREL34
:
8724 case elfcpp::R_PPC64_PCREL28
:
8725 case elfcpp::R_PPC64_TPREL34
:
8726 case elfcpp::R_PPC64_DTPREL34
:
8727 case elfcpp::R_PPC64_PLT_PCREL34
:
8728 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8729 case elfcpp::R_PPC64_GOT_PCREL34
:
8730 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8731 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8732 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8733 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8734 target
->set_power10_relocs();
8741 // Report an unsupported relocation against a global symbol.
8743 template<int size
, bool big_endian
>
8745 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8746 Sized_relobj_file
<size
, big_endian
>* object
,
8747 unsigned int r_type
,
8750 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8751 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8754 // Scan a relocation for a global symbol.
8756 template<int size
, bool big_endian
>
8758 Target_powerpc
<size
, big_endian
>::Scan::global(
8759 Symbol_table
* symtab
,
8761 Target_powerpc
<size
, big_endian
>* target
,
8762 Sized_relobj_file
<size
, big_endian
>* object
,
8763 unsigned int data_shndx
,
8764 Output_section
* output_section
,
8765 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8766 unsigned int r_type
,
8769 Powerpc_relobj
<size
, big_endian
>* ppc_object
8770 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8772 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8774 case Track_tls::SKIP
:
8780 if (target
->replace_tls_get_addr(gsym
))
8781 // Change a __tls_get_addr reference to __tls_get_addr_opt
8782 // so dynamic relocs are emitted against the latter symbol.
8783 gsym
= target
->tls_get_addr_opt();
8785 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8786 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8788 this->expect_tls_get_addr_call();
8789 bool final
= gsym
->final_value_is_known();
8790 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8791 if (tls_type
!= tls::TLSOPT_NONE
)
8792 this->skip_next_tls_get_addr_call();
8794 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8795 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8797 this->expect_tls_get_addr_call();
8798 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8799 if (tls_type
!= tls::TLSOPT_NONE
)
8800 this->skip_next_tls_get_addr_call();
8803 // A STT_GNU_IFUNC symbol may require a PLT entry.
8804 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8805 bool pushed_ifunc
= false;
8806 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8808 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8809 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8810 r_type
, r_sym
, reloc
.get_r_addend());
8811 target
->make_plt_entry(symtab
, layout
, gsym
);
8812 pushed_ifunc
= true;
8817 case elfcpp::R_POWERPC_NONE
:
8818 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8819 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8820 case elfcpp::R_PPC_LOCAL24PC
:
8821 case elfcpp::R_POWERPC_TLS
:
8822 case elfcpp::R_PPC64_ENTRY
:
8823 case elfcpp::R_POWERPC_PLTSEQ
:
8824 case elfcpp::R_POWERPC_PLTCALL
:
8825 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8826 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8827 case elfcpp::R_PPC64_PCREL_OPT
:
8828 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8829 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8830 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8831 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8832 case elfcpp::R_PPC64_REL16_HIGHER34
:
8833 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8834 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8835 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8836 case elfcpp::R_PPC64_D34
:
8837 case elfcpp::R_PPC64_D34_LO
:
8838 case elfcpp::R_PPC64_D34_HI30
:
8839 case elfcpp::R_PPC64_D34_HA30
:
8840 case elfcpp::R_PPC64_D28
:
8841 case elfcpp::R_PPC64_PCREL34
:
8842 case elfcpp::R_PPC64_PCREL28
:
8843 case elfcpp::R_PPC64_TPREL34
:
8844 case elfcpp::R_PPC64_DTPREL34
:
8847 case elfcpp::R_PPC64_TOC
:
8849 Output_data_got_powerpc
<size
, big_endian
>* got
8850 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8851 if (parameters
->options().output_is_position_independent())
8853 Address off
= reloc
.get_r_offset();
8855 && data_shndx
== ppc_object
->opd_shndx()
8856 && ppc_object
->get_opd_discard(off
- 8))
8859 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8860 Address got_off
= got
->g_o_t();
8861 rela_dyn
->add_output_section_relative(got
->output_section(),
8862 elfcpp::R_POWERPC_RELATIVE
,
8864 object
, data_shndx
, off
,
8870 case elfcpp::R_PPC64_ADDR64
:
8872 && target
->abiversion() < 2
8873 && data_shndx
== ppc_object
->opd_shndx()
8874 && (gsym
->is_defined_in_discarded_section()
8875 || gsym
->object() != object
))
8877 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8881 case elfcpp::R_PPC64_UADDR64
:
8882 case elfcpp::R_POWERPC_ADDR32
:
8883 case elfcpp::R_POWERPC_UADDR32
:
8884 case elfcpp::R_POWERPC_ADDR24
:
8885 case elfcpp::R_POWERPC_ADDR16
:
8886 case elfcpp::R_POWERPC_ADDR16_LO
:
8887 case elfcpp::R_POWERPC_ADDR16_HI
:
8888 case elfcpp::R_POWERPC_ADDR16_HA
:
8889 case elfcpp::R_POWERPC_UADDR16
:
8890 case elfcpp::R_PPC64_ADDR16_HIGH
:
8891 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8892 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8893 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8894 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8895 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8896 case elfcpp::R_PPC64_ADDR16_DS
:
8897 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8898 case elfcpp::R_POWERPC_ADDR14
:
8899 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8900 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8902 // Make a PLT entry if necessary.
8903 if (gsym
->needs_plt_entry())
8905 // Since this is not a PC-relative relocation, we may be
8906 // taking the address of a function. In that case we need to
8907 // set the entry in the dynamic symbol table to the address of
8908 // the PLT call stub.
8909 bool need_ifunc_plt
= false;
8910 if ((size
== 32 || target
->abiversion() >= 2)
8911 && gsym
->is_from_dynobj()
8912 && !parameters
->options().output_is_position_independent())
8914 gsym
->set_needs_dynsym_value();
8915 need_ifunc_plt
= true;
8917 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8919 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8920 target
->push_branch(ppc_object
, data_shndx
,
8921 reloc
.get_r_offset(), r_type
, r_sym
,
8922 reloc
.get_r_addend());
8923 target
->make_plt_entry(symtab
, layout
, gsym
);
8926 // Make a dynamic relocation if necessary.
8927 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8928 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8930 if (!parameters
->options().output_is_position_independent()
8931 && gsym
->may_need_copy_reloc())
8933 target
->copy_reloc(symtab
, layout
, object
,
8934 data_shndx
, output_section
, gsym
, reloc
);
8936 else if ((((size
== 32
8937 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8939 && r_type
== elfcpp::R_PPC64_ADDR64
8940 && target
->abiversion() >= 2))
8941 && gsym
->can_use_relative_reloc(false)
8942 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8943 && parameters
->options().shared()))
8945 && r_type
== elfcpp::R_PPC64_ADDR64
8946 && target
->abiversion() < 2
8947 && (gsym
->can_use_relative_reloc(false)
8948 || data_shndx
== ppc_object
->opd_shndx())))
8950 Reloc_section
* rela_dyn
8951 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8952 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8953 : elfcpp::R_POWERPC_RELATIVE
);
8954 rela_dyn
->add_symbolless_global_addend(
8955 gsym
, dynrel
, output_section
, object
, data_shndx
,
8956 reloc
.get_r_offset(), reloc
.get_r_addend());
8960 Reloc_section
* rela_dyn
8961 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8962 check_non_pic(object
, r_type
);
8963 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8965 reloc
.get_r_offset(),
8966 reloc
.get_r_addend());
8969 && parameters
->options().toc_optimize()
8970 && data_shndx
== ppc_object
->toc_shndx())
8971 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8977 case elfcpp::R_PPC64_PLT_PCREL34
:
8978 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8979 case elfcpp::R_POWERPC_PLT16_LO
:
8980 case elfcpp::R_POWERPC_PLT16_HI
:
8981 case elfcpp::R_POWERPC_PLT16_HA
:
8982 case elfcpp::R_PPC64_PLT16_LO_DS
:
8985 if (!parameters
->doing_static_link())
8986 target
->make_plt_entry(symtab
, layout
, gsym
);
8988 target
->make_local_plt_entry(symtab
, layout
, gsym
);
8992 case elfcpp::R_PPC64_REL24_NOTOC
:
8996 case elfcpp::R_PPC64_REL24_P9NOTOC
:
8997 case elfcpp::R_PPC_PLTREL24
:
8998 case elfcpp::R_POWERPC_REL24
:
9001 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9002 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9003 r_type
, r_sym
, reloc
.get_r_addend());
9004 if (gsym
->needs_plt_entry()
9005 || (!gsym
->final_value_is_known()
9006 && (gsym
->is_undefined()
9007 || gsym
->is_from_dynobj()
9008 || gsym
->is_preemptible())))
9009 target
->make_plt_entry(symtab
, layout
, gsym
);
9013 case elfcpp::R_PPC64_REL64
:
9014 case elfcpp::R_POWERPC_REL32
:
9015 // Make a dynamic relocation if necessary.
9016 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
9018 if (!parameters
->options().output_is_position_independent()
9019 && gsym
->may_need_copy_reloc())
9021 target
->copy_reloc(symtab
, layout
, object
,
9022 data_shndx
, output_section
, gsym
,
9027 Reloc_section
* rela_dyn
9028 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9029 check_non_pic(object
, r_type
);
9030 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
9031 data_shndx
, reloc
.get_r_offset(),
9032 reloc
.get_r_addend());
9037 case elfcpp::R_POWERPC_REL14
:
9038 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9039 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9042 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9043 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
9044 r_type
, r_sym
, reloc
.get_r_addend());
9048 case elfcpp::R_PPC64_TOCSAVE
:
9049 // R_PPC64_TOCSAVE follows a call instruction to indicate the
9050 // caller has already saved r2 and thus a plt call stub need not
9053 && target
->mark_pltcall(ppc_object
, data_shndx
,
9054 reloc
.get_r_offset() - 4, symtab
))
9056 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
9058 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9060 object
->error(_("tocsave symbol %u has bad shndx %u"),
9064 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9065 target
->add_tocsave(ppc_object
, shndx
,
9066 sym
->value() + reloc
.get_r_addend());
9071 case elfcpp::R_POWERPC_REL16
:
9072 case elfcpp::R_POWERPC_REL16_LO
:
9073 case elfcpp::R_POWERPC_REL16_HI
:
9074 case elfcpp::R_POWERPC_REL16_HA
:
9075 case elfcpp::R_POWERPC_REL16DX_HA
:
9076 case elfcpp::R_PPC64_REL16_HIGH
:
9077 case elfcpp::R_PPC64_REL16_HIGHA
:
9078 case elfcpp::R_PPC64_REL16_HIGHER
:
9079 case elfcpp::R_PPC64_REL16_HIGHERA
:
9080 case elfcpp::R_PPC64_REL16_HIGHEST
:
9081 case elfcpp::R_PPC64_REL16_HIGHESTA
:
9082 case elfcpp::R_POWERPC_SECTOFF
:
9083 case elfcpp::R_POWERPC_SECTOFF_LO
:
9084 case elfcpp::R_POWERPC_SECTOFF_HI
:
9085 case elfcpp::R_POWERPC_SECTOFF_HA
:
9086 case elfcpp::R_PPC64_SECTOFF_DS
:
9087 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9088 case elfcpp::R_POWERPC_TPREL16
:
9089 case elfcpp::R_POWERPC_TPREL16_LO
:
9090 case elfcpp::R_POWERPC_TPREL16_HI
:
9091 case elfcpp::R_POWERPC_TPREL16_HA
:
9092 case elfcpp::R_PPC64_TPREL16_DS
:
9093 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9094 case elfcpp::R_PPC64_TPREL16_HIGH
:
9095 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9096 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9097 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9098 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9099 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9100 case elfcpp::R_POWERPC_DTPREL16
:
9101 case elfcpp::R_POWERPC_DTPREL16_LO
:
9102 case elfcpp::R_POWERPC_DTPREL16_HI
:
9103 case elfcpp::R_POWERPC_DTPREL16_HA
:
9104 case elfcpp::R_PPC64_DTPREL16_DS
:
9105 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
9106 case elfcpp::R_PPC64_DTPREL16_HIGH
:
9107 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
9108 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
9109 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
9110 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
9111 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
9112 case elfcpp::R_PPC64_TLSGD
:
9113 case elfcpp::R_PPC64_TLSLD
:
9114 case elfcpp::R_PPC64_ADDR64_LOCAL
:
9117 case elfcpp::R_PPC64_GOT_PCREL34
:
9118 case elfcpp::R_POWERPC_GOT16
:
9119 case elfcpp::R_POWERPC_GOT16_LO
:
9120 case elfcpp::R_POWERPC_GOT16_HI
:
9121 case elfcpp::R_POWERPC_GOT16_HA
:
9122 case elfcpp::R_PPC64_GOT16_DS
:
9123 case elfcpp::R_PPC64_GOT16_LO_DS
:
9125 // The symbol requires a GOT entry.
9126 Output_data_got_powerpc
<size
, big_endian
>* got
;
9127 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9128 Got_type got_type
= ((size
== 32
9129 || r_type
== elfcpp::R_POWERPC_GOT16
9130 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
9131 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
9133 got
= target
->got_section(symtab
, layout
, got_type
);
9134 if (gsym
->final_value_is_known())
9137 && (size
== 32 || target
->abiversion() >= 2))
9138 got
->add_global_plt(gsym
, got_type
, addend
);
9140 got
->add_global(gsym
, got_type
, addend
);
9142 else if (!gsym
->has_got_offset(got_type
, addend
))
9144 // If we are generating a shared object or a pie, this
9145 // symbol's GOT entry will be set by a dynamic relocation.
9146 unsigned int off
= got
->add_constant(0);
9147 gsym
->set_got_offset(got_type
, off
, addend
);
9149 Reloc_section
* rela_dyn
9150 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9152 if (gsym
->can_use_relative_reloc(false)
9154 || target
->abiversion() >= 2)
9155 && gsym
->visibility() == elfcpp::STV_PROTECTED
9156 && parameters
->options().shared()))
9158 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
9159 : elfcpp::R_POWERPC_RELATIVE
);
9160 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
,
9165 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
9166 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, addend
);
9172 case elfcpp::R_PPC64_TOC16
:
9173 case elfcpp::R_PPC64_TOC16_LO
:
9174 case elfcpp::R_PPC64_TOC16_HI
:
9175 case elfcpp::R_PPC64_TOC16_HA
:
9176 case elfcpp::R_PPC64_TOC16_DS
:
9177 case elfcpp::R_PPC64_TOC16_LO_DS
:
9178 // We need a GOT section.
9179 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
9182 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9183 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9184 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9185 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9186 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9188 bool final
= gsym
->final_value_is_known();
9189 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9190 if (tls_type
== tls::TLSOPT_NONE
)
9192 Got_type got_type
= ((size
== 32
9193 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9194 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
9195 Output_data_got_powerpc
<size
, big_endian
>* got
9196 = target
->got_section(symtab
, layout
, got_type
);
9197 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9198 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9199 got
->add_global_pair_with_rel(gsym
, got_type
, rela_dyn
,
9200 elfcpp::R_POWERPC_DTPMOD
,
9201 elfcpp::R_POWERPC_DTPREL
,
9204 else if (tls_type
== tls::TLSOPT_TO_IE
)
9206 Got_type got_type
= ((size
== 32
9207 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9208 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9209 if (!gsym
->has_got_offset(got_type
))
9211 Output_data_got_powerpc
<size
, big_endian
>* got
9212 = target
->got_section(symtab
, layout
, got_type
);
9213 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9214 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9215 if (gsym
->is_undefined()
9216 || gsym
->is_from_dynobj())
9218 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9219 elfcpp::R_POWERPC_TPREL
, addend
);
9223 unsigned int off
= got
->add_constant(0);
9224 gsym
->set_got_offset(got_type
, off
);
9225 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9226 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9231 else if (tls_type
== tls::TLSOPT_TO_LE
)
9233 // no GOT relocs needed for Local Exec.
9240 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9241 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9242 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9243 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9244 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9246 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9247 if (tls_type
== tls::TLSOPT_NONE
)
9248 target
->tlsld_got_offset(symtab
, layout
, object
);
9249 else if (tls_type
== tls::TLSOPT_TO_LE
)
9251 // no GOT relocs needed for Local Exec.
9252 if (parameters
->options().emit_relocs())
9254 Output_section
* os
= layout
->tls_segment()->first_section();
9255 gold_assert(os
!= NULL
);
9256 os
->set_needs_symtab_index();
9264 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9265 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9266 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9267 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9268 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9270 Got_type got_type
= ((size
== 32
9271 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
9272 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
9273 Output_data_got_powerpc
<size
, big_endian
>* got
9274 = target
->got_section(symtab
, layout
, got_type
);
9275 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9276 if (!gsym
->final_value_is_known()
9277 && (gsym
->is_from_dynobj()
9278 || gsym
->is_undefined()
9279 || gsym
->is_preemptible()))
9280 got
->add_global_with_rel(gsym
, got_type
,
9281 target
->rela_dyn_section(layout
),
9282 elfcpp::R_POWERPC_DTPREL
, addend
);
9284 got
->add_global_tls(gsym
, got_type
, addend
);
9288 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9289 case elfcpp::R_POWERPC_GOT_TPREL16
:
9290 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9291 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9292 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9294 bool final
= gsym
->final_value_is_known();
9295 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9296 if (tls_type
== tls::TLSOPT_NONE
)
9298 Got_type got_type
= ((size
== 32
9299 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
9300 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9301 if (!gsym
->has_got_offset(got_type
))
9303 Output_data_got_powerpc
<size
, big_endian
>* got
9304 = target
->got_section(symtab
, layout
, got_type
);
9305 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9306 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9307 if (gsym
->is_undefined()
9308 || gsym
->is_from_dynobj())
9310 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9311 elfcpp::R_POWERPC_TPREL
, addend
);
9315 unsigned int off
= got
->add_constant(0);
9316 gsym
->set_got_offset(got_type
, off
);
9317 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9318 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9323 else if (tls_type
== tls::TLSOPT_TO_LE
)
9325 // no GOT relocs needed for Local Exec.
9333 unsupported_reloc_global(object
, r_type
, gsym
);
9338 && parameters
->options().toc_optimize())
9340 if (data_shndx
== ppc_object
->toc_shndx())
9343 if (r_type
!= elfcpp::R_PPC64_ADDR64
9344 || (is_ifunc
&& target
->abiversion() < 2))
9346 else if (parameters
->options().output_is_position_independent()
9347 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9350 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9353 enum {no_check
, check_lo
, check_ha
} insn_check
;
9357 insn_check
= no_check
;
9360 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9361 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9362 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9363 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9364 case elfcpp::R_POWERPC_GOT16_HA
:
9365 case elfcpp::R_PPC64_TOC16_HA
:
9366 insn_check
= check_ha
;
9369 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9370 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9371 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9372 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9373 case elfcpp::R_POWERPC_GOT16_LO
:
9374 case elfcpp::R_PPC64_GOT16_LO_DS
:
9375 case elfcpp::R_PPC64_TOC16_LO
:
9376 case elfcpp::R_PPC64_TOC16_LO_DS
:
9377 insn_check
= check_lo
;
9381 section_size_type slen
;
9382 const unsigned char* view
= NULL
;
9383 if (insn_check
!= no_check
)
9385 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9386 section_size_type off
=
9387 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9390 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9391 if (insn_check
== check_lo
9392 ? !ok_lo_toc_insn(insn
, r_type
)
9393 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9394 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9396 ppc_object
->set_no_toc_opt();
9397 gold_warning(_("%s: toc optimization is not supported "
9398 "for %#08x instruction"),
9399 ppc_object
->name().c_str(), insn
);
9408 case elfcpp::R_PPC64_TOC16
:
9409 case elfcpp::R_PPC64_TOC16_LO
:
9410 case elfcpp::R_PPC64_TOC16_HI
:
9411 case elfcpp::R_PPC64_TOC16_HA
:
9412 case elfcpp::R_PPC64_TOC16_DS
:
9413 case elfcpp::R_PPC64_TOC16_LO_DS
:
9414 if (gsym
->source() == Symbol::FROM_OBJECT
9415 && !gsym
->object()->is_dynamic())
9417 Powerpc_relobj
<size
, big_endian
>* sym_object
9418 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9420 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9421 if (shndx
== sym_object
->toc_shndx())
9423 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9424 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9425 if (dst_off
< sym_object
->section_size(shndx
))
9428 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9430 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9432 // Need to check that the insn is a ld
9434 view
= ppc_object
->section_contents(data_shndx
,
9437 section_size_type off
=
9438 (convert_to_section_size_type(reloc
.get_r_offset())
9439 + (big_endian
? -2 : 3));
9441 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9445 sym_object
->set_no_toc_opt(dst_off
);
9457 case elfcpp::R_PPC_LOCAL24PC
:
9458 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9459 gold_error(_("%s: unsupported -mbss-plt code"),
9460 ppc_object
->name().c_str());
9469 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9470 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9471 case elfcpp::R_POWERPC_GOT_TPREL16
:
9472 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9473 case elfcpp::R_POWERPC_GOT16
:
9474 case elfcpp::R_PPC64_GOT16_DS
:
9475 case elfcpp::R_PPC64_TOC16
:
9476 case elfcpp::R_PPC64_TOC16_DS
:
9477 ppc_object
->set_has_small_toc_reloc();
9485 case elfcpp::R_PPC64_TPREL16_DS
:
9486 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9487 case elfcpp::R_PPC64_TPREL16_HIGH
:
9488 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9489 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9490 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9491 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9492 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9493 case elfcpp::R_PPC64_TPREL34
:
9497 case elfcpp::R_POWERPC_TPREL16
:
9498 case elfcpp::R_POWERPC_TPREL16_LO
:
9499 case elfcpp::R_POWERPC_TPREL16_HI
:
9500 case elfcpp::R_POWERPC_TPREL16_HA
:
9501 layout
->set_has_static_tls();
9509 case elfcpp::R_POWERPC_TPREL16_HA
:
9510 if (target
->tprel_opt())
9512 section_size_type slen
;
9513 const unsigned char* view
= NULL
;
9514 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9515 section_size_type off
9516 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9519 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9520 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9521 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9522 target
->set_no_tprel_opt();
9527 case elfcpp::R_PPC64_TPREL16_HIGH
:
9528 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9529 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9530 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9531 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9532 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9536 case elfcpp::R_POWERPC_TPREL16_HI
:
9537 target
->set_no_tprel_opt();
9545 case elfcpp::R_PPC64_D34
:
9546 case elfcpp::R_PPC64_D34_LO
:
9547 case elfcpp::R_PPC64_D34_HI30
:
9548 case elfcpp::R_PPC64_D34_HA30
:
9549 case elfcpp::R_PPC64_D28
:
9550 case elfcpp::R_PPC64_PCREL34
:
9551 case elfcpp::R_PPC64_PCREL28
:
9552 case elfcpp::R_PPC64_TPREL34
:
9553 case elfcpp::R_PPC64_DTPREL34
:
9554 case elfcpp::R_PPC64_PLT_PCREL34
:
9555 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9556 case elfcpp::R_PPC64_GOT_PCREL34
:
9557 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9558 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9559 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9560 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9561 target
->set_power10_relocs();
9568 // Process relocations for gc.
9570 template<int size
, bool big_endian
>
9572 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9573 Symbol_table
* symtab
,
9575 Sized_relobj_file
<size
, big_endian
>* object
,
9576 unsigned int data_shndx
,
9578 const unsigned char* prelocs
,
9580 Output_section
* output_section
,
9581 bool needs_special_offset_handling
,
9582 size_t local_symbol_count
,
9583 const unsigned char* plocal_symbols
)
9585 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9586 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9589 Powerpc_relobj
<size
, big_endian
>* ppc_object
9590 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9592 ppc_object
->set_opd_valid();
9593 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9595 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9596 for (p
= ppc_object
->access_from_map()->begin();
9597 p
!= ppc_object
->access_from_map()->end();
9600 Address dst_off
= p
->first
;
9601 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9602 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9603 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9605 Relobj
* src_obj
= s
->first
;
9606 unsigned int src_indx
= s
->second
;
9607 symtab
->gc()->add_reference(src_obj
, src_indx
,
9608 ppc_object
, dst_indx
);
9612 ppc_object
->access_from_map()->clear();
9613 ppc_object
->process_gc_mark(symtab
);
9614 // Don't look at .opd relocs as .opd will reference everything.
9618 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9627 needs_special_offset_handling
,
9632 // Handle target specific gc actions when adding a gc reference from
9633 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9634 // and DST_OFF. For powerpc64, this adds a referenc to the code
9635 // section of a function descriptor.
9637 template<int size
, bool big_endian
>
9639 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9640 Symbol_table
* symtab
,
9642 unsigned int src_shndx
,
9644 unsigned int dst_shndx
,
9645 Address dst_off
) const
9647 if (size
!= 64 || dst_obj
->is_dynamic())
9650 Powerpc_relobj
<size
, big_endian
>* ppc_object
9651 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9652 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9654 if (ppc_object
->opd_valid())
9656 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9657 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9661 // If we haven't run scan_opd_relocs, we must delay
9662 // processing this function descriptor reference.
9663 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9668 // Add any special sections for this symbol to the gc work list.
9669 // For powerpc64, this adds the code section of a function
9672 template<int size
, bool big_endian
>
9674 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9675 Symbol_table
* symtab
,
9678 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9680 Powerpc_relobj
<size
, big_endian
>* ppc_object
9681 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9683 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9684 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9686 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9687 Address dst_off
= gsym
->value();
9688 if (ppc_object
->opd_valid())
9690 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9691 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9695 ppc_object
->add_gc_mark(dst_off
);
9700 // For a symbol location in .opd, set LOC to the location of the
9703 template<int size
, bool big_endian
>
9705 Target_powerpc
<size
, big_endian
>::do_function_location(
9706 Symbol_location
* loc
) const
9708 if (size
== 64 && loc
->shndx
!= 0)
9710 if (loc
->object
->is_dynamic())
9712 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9713 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9714 if (loc
->shndx
== ppc_object
->opd_shndx())
9717 Address off
= loc
->offset
- ppc_object
->opd_address();
9718 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9719 loc
->offset
= dest_off
;
9724 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9725 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9726 if (loc
->shndx
== ppc_object
->opd_shndx())
9729 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9730 loc
->offset
= dest_off
;
9736 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9737 // compiled with -fsplit-stack. The function calls non-split-stack
9738 // code. Change the function to ensure it has enough stack space to
9739 // call some random function.
9741 template<int size
, bool big_endian
>
9743 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9746 section_offset_type fnoffset
,
9747 section_size_type fnsize
,
9748 const unsigned char* prelocs
,
9750 unsigned char* view
,
9751 section_size_type view_size
,
9753 std::string
* to
) const
9755 // 32-bit not supported.
9759 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9760 prelocs
, reloc_count
, view
, view_size
,
9765 // The function always starts with
9766 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9767 // addis %r12,%r1,-allocate@ha
9768 // addi %r12,%r12,-allocate@l
9770 // but note that the addis or addi may be replaced with a nop
9772 unsigned char *entry
= view
+ fnoffset
;
9773 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9775 if ((insn
& 0xffff0000) == addis_2_12
)
9777 /* Skip ELFv2 global entry code. */
9779 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9782 unsigned char *pinsn
= entry
;
9784 const uint32_t ld_private_ss
= 0xe80d8fc0;
9785 if (insn
== ld_private_ss
)
9787 int32_t allocate
= 0;
9791 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9792 if ((insn
& 0xffff0000) == addis_12_1
)
9793 allocate
+= (insn
& 0xffff) << 16;
9794 else if ((insn
& 0xffff0000) == addi_12_1
9795 || (insn
& 0xffff0000) == addi_12_12
)
9796 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9797 else if (insn
!= nop
)
9800 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9802 int extra
= parameters
->options().split_stack_adjust_size();
9804 if (allocate
>= 0 || extra
< 0)
9806 object
->error(_("split-stack stack size overflow at "
9807 "section %u offset %0zx"),
9808 shndx
, static_cast<size_t>(fnoffset
));
9812 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9813 if (insn
!= addis_12_1
)
9815 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9817 insn
= addi_12_12
| (allocate
& 0xffff);
9818 if (insn
!= addi_12_12
)
9820 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9826 insn
= addi_12_1
| (allocate
& 0xffff);
9827 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9830 if (pinsn
!= entry
+ 12)
9831 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9839 if (!object
->has_no_split_stack())
9840 object
->error(_("failed to match split-stack sequence at "
9841 "section %u offset %0zx"),
9842 shndx
, static_cast<size_t>(fnoffset
));
9846 // Scan relocations for a section.
9848 template<int size
, bool big_endian
>
9850 Target_powerpc
<size
, big_endian
>::scan_relocs(
9851 Symbol_table
* symtab
,
9853 Sized_relobj_file
<size
, big_endian
>* object
,
9854 unsigned int data_shndx
,
9855 unsigned int sh_type
,
9856 const unsigned char* prelocs
,
9858 Output_section
* output_section
,
9859 bool needs_special_offset_handling
,
9860 size_t local_symbol_count
,
9861 const unsigned char* plocal_symbols
)
9863 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9864 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9867 if (!this->plt_localentry0_init_
)
9869 bool plt_localentry0
= false;
9871 && this->abiversion() >= 2)
9873 if (parameters
->options().user_set_plt_localentry())
9874 plt_localentry0
= parameters
->options().plt_localentry();
9876 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9877 gold_warning(_("--plt-localentry is especially dangerous without "
9878 "ld.so support to detect ABI violations"));
9880 this->plt_localentry0_
= plt_localentry0
;
9881 this->plt_localentry0_init_
= true;
9884 if (sh_type
== elfcpp::SHT_REL
)
9886 gold_error(_("%s: unsupported REL reloc section"),
9887 object
->name().c_str());
9891 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9900 needs_special_offset_handling
,
9904 if (this->plt_localentry0_
&& this->power10_relocs_
)
9906 gold_warning(_("--plt-localentry is incompatible with "
9907 "power10 pc-relative code"));
9908 this->plt_localentry0_
= false;
9912 // Functor class for processing the global symbol table.
9913 // Removes symbols defined on discarded opd entries.
9915 template<bool big_endian
>
9916 class Global_symbol_visitor_opd
9919 Global_symbol_visitor_opd()
9923 operator()(Sized_symbol
<64>* sym
)
9925 if (sym
->has_symtab_index()
9926 || sym
->source() != Symbol::FROM_OBJECT
9927 || !sym
->in_real_elf())
9930 if (sym
->object()->is_dynamic())
9933 Powerpc_relobj
<64, big_endian
>* symobj
9934 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9935 if (symobj
->opd_shndx() == 0)
9939 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9940 if (shndx
== symobj
->opd_shndx()
9941 && symobj
->get_opd_discard(sym
->value()))
9943 sym
->set_undefined();
9944 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9945 sym
->set_is_defined_in_discarded_section();
9946 sym
->set_symtab_index(-1U);
9951 template<int size
, bool big_endian
>
9953 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9955 Symbol_table
* symtab
)
9959 Output_data_save_res
<size
, big_endian
>* savres
9960 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9961 this->savres_section_
= savres
;
9962 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9963 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9964 savres
, ORDER_TEXT
, false);
9968 // Sort linker created .got section first (for the header), then input
9969 // sections belonging to files using small model code.
9971 template<bool big_endian
>
9972 class Sort_toc_sections
9974 const Output_section_data
*
9975 small_got_section() const
9977 return (static_cast<Target_powerpc
<64, big_endian
>*>(
9978 parameters
->sized_target
<64, big_endian
>())
9979 ->got_section(GOT_TYPE_SMALL
));
9983 rank(const Output_section::Input_section
& isec
) const
9985 if (!isec
.is_input_section())
9987 if (isec
.output_section_data() == this->small_got_section())
9991 if (static_cast<const Powerpc_relobj
<64, big_endian
>*>(isec
.relobj())
9992 ->has_small_toc_reloc())
9999 operator()(const Output_section::Input_section
& is1
,
10000 const Output_section::Input_section
& is2
) const
10002 return rank(is1
) < rank(is2
);
10006 // Finalize the sections.
10008 template<int size
, bool big_endian
>
10010 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
10012 const Input_objects
* input_objects
,
10013 Symbol_table
* symtab
)
10015 if (parameters
->doing_static_link())
10017 // At least some versions of glibc elf-init.o have a strong
10018 // reference to __rela_iplt marker syms. A weak ref would be
10020 if (this->iplt_
!= NULL
)
10022 Reloc_section
* rel
= this->iplt_
->rel_plt();
10023 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
10024 Symbol_table::PREDEFINED
, rel
, 0, 0,
10025 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10026 elfcpp::STV_HIDDEN
, 0, false, true);
10027 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
10028 Symbol_table::PREDEFINED
, rel
, 0, 0,
10029 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10030 elfcpp::STV_HIDDEN
, 0, true, true);
10034 symtab
->define_as_constant("__rela_iplt_start", NULL
,
10035 Symbol_table::PREDEFINED
, 0, 0,
10036 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10037 elfcpp::STV_HIDDEN
, 0, true, false);
10038 symtab
->define_as_constant("__rela_iplt_end", NULL
,
10039 Symbol_table::PREDEFINED
, 0, 0,
10040 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
10041 elfcpp::STV_HIDDEN
, 0, true, false);
10047 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
10048 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
10050 if (!parameters
->options().relocatable())
10052 this->define_save_restore_funcs(layout
, symtab
);
10054 // Annoyingly, we need to make these sections now whether or
10055 // not we need them. If we delay until do_relax then we
10056 // need to mess with the relaxation machinery checkpointing.
10057 this->got_section(symtab
, layout
, GOT_TYPE_STANDARD
);
10058 this->make_brlt_section(layout
);
10060 // FIXME, maybe. Here we could run through all the got
10061 // entries in the small got section, removing any duplicates
10062 // found in the big got section and renumbering offsets.
10064 if (parameters
->options().toc_sort())
10066 Output_section
* os
= this->got_
->output_section();
10067 if (os
!= NULL
&& os
->input_sections().size() > 1)
10068 std::stable_sort(os
->input_sections().begin(),
10069 os
->input_sections().end(),
10070 Sort_toc_sections
<big_endian
>());
10075 // Fill in some more dynamic tags.
10076 Output_data_dynamic
* odyn
= layout
->dynamic_data();
10079 const Reloc_section
* rel_plt
= (this->plt_
== NULL
10081 : this->plt_
->rel_plt());
10082 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
10083 this->rela_dyn_
, true, size
== 32);
10087 if (this->got_
!= NULL
)
10089 this->got_
->finalize_data_size();
10090 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
10091 this->got_
, this->got_
->g_o_t());
10093 if (this->has_tls_get_addr_opt_
)
10094 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
10098 if (this->glink_
!= NULL
)
10100 this->glink_
->finalize_data_size();
10101 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
10103 (this->glink_
->pltresolve_size()
10106 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
10107 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
10108 ((this->has_localentry0_
10109 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
10110 | (this->has_tls_get_addr_opt_
10111 ? elfcpp::PPC64_OPT_TLS
: 0)));
10115 // Emit any relocs we saved in an attempt to avoid generating COPY
10117 if (this->copy_relocs_
.any_saved_relocs())
10118 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
10120 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
10121 p
!= input_objects
->relobj_end();
10124 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
10125 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
10126 if (ppc_relobj
->attributes_section_data())
10127 this->merge_object_attributes(ppc_relobj
,
10128 ppc_relobj
->attributes_section_data());
10130 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
10131 p
!= input_objects
->dynobj_end();
10134 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
10135 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
10136 if (ppc_dynobj
->attributes_section_data())
10137 this->merge_object_attributes(ppc_dynobj
,
10138 ppc_dynobj
->attributes_section_data());
10141 // Create a .gnu.attributes section if we have merged any attributes
10143 if (this->attributes_section_data_
!= NULL
10144 && this->attributes_section_data_
->size() != 0)
10146 Output_attributes_section_data
* attributes_section
10147 = new Output_attributes_section_data(*this->attributes_section_data_
);
10148 layout
->add_output_section_data(".gnu.attributes",
10149 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
10150 attributes_section
, ORDER_INVALID
, false);
10154 // Merge object attributes from input file called NAME with those of the
10155 // output. The input object attributes are in the object pointed by PASD.
10157 template<int size
, bool big_endian
>
10159 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
10161 const Attributes_section_data
* pasd
)
10163 // Return if there is no attributes section data.
10167 // Create output object attributes.
10168 if (this->attributes_section_data_
== NULL
)
10169 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
10171 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
10172 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
10173 Object_attribute
* out_attr
10174 = this->attributes_section_data_
->known_attributes(vendor
);
10176 const char* name
= obj
->name().c_str();
10179 const char* second
;
10180 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
10181 int in_fp
= in_attr
[tag
].int_value() & 0xf;
10182 int out_fp
= out_attr
[tag
].int_value() & 0xf;
10183 bool warn_only
= obj
->is_dynamic();
10184 if (in_fp
!= out_fp
)
10187 if ((in_fp
& 3) == 0)
10189 else if ((out_fp
& 3) == 0)
10193 out_fp
|= in_fp
& 3;
10194 out_attr
[tag
].set_int_value(out_fp
);
10195 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10196 this->last_fp_
= name
;
10199 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
10201 err
= N_("%s uses hard float, %s uses soft float");
10202 first
= this->last_fp_
;
10205 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10207 err
= N_("%s uses hard float, %s uses soft float");
10209 second
= this->last_fp_
;
10211 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10213 err
= N_("%s uses double-precision hard float, "
10214 "%s uses single-precision hard float");
10215 first
= this->last_fp_
;
10218 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10220 err
= N_("%s uses double-precision hard float, "
10221 "%s uses single-precision hard float");
10223 second
= this->last_fp_
;
10226 if (err
|| (in_fp
& 0xc) == 0)
10228 else if ((out_fp
& 0xc) == 0)
10232 out_fp
|= in_fp
& 0xc;
10233 out_attr
[tag
].set_int_value(out_fp
);
10234 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10235 this->last_ld_
= name
;
10238 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10240 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10242 second
= this->last_ld_
;
10244 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10246 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10247 first
= this->last_ld_
;
10250 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10252 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10253 first
= this->last_ld_
;
10256 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10258 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10260 second
= this->last_ld_
;
10265 if (parameters
->options().warn_mismatch())
10268 gold_warning(_(err
), first
, second
);
10270 gold_error(_(err
), first
, second
);
10272 // Arrange for this attribute to be deleted. It's better to
10273 // say "don't know" about a file than to wrongly claim compliance.
10275 out_attr
[tag
].set_type(0);
10281 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10282 int in_vec
= in_attr
[tag
].int_value() & 3;
10283 int out_vec
= out_attr
[tag
].int_value() & 3;
10284 if (in_vec
!= out_vec
)
10289 else if (out_vec
== 0)
10292 out_attr
[tag
].set_int_value(out_vec
);
10293 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10294 this->last_vec_
= name
;
10296 // For now, allow generic to transition to AltiVec or SPE
10297 // without a warning. If GCC marked files with their stack
10298 // alignment and used don't-care markings for files which are
10299 // not affected by the vector ABI, we could warn about this
10301 else if (in_vec
== 1)
10303 else if (out_vec
== 1)
10306 out_attr
[tag
].set_int_value(out_vec
);
10307 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10308 this->last_vec_
= name
;
10310 else if (out_vec
< in_vec
)
10312 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10313 first
= this->last_vec_
;
10316 else if (out_vec
> in_vec
)
10318 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10320 second
= this->last_vec_
;
10324 if (parameters
->options().warn_mismatch())
10325 gold_error(_(err
), first
, second
);
10326 out_attr
[tag
].set_type(0);
10330 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10331 int in_struct
= in_attr
[tag
].int_value() & 3;
10332 int out_struct
= out_attr
[tag
].int_value() & 3;
10333 if (in_struct
!= out_struct
)
10336 if (in_struct
== 0 || in_struct
== 3)
10338 else if (out_struct
== 0)
10340 out_struct
= in_struct
;
10341 out_attr
[tag
].set_int_value(out_struct
);
10342 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10343 this->last_struct_
= name
;
10345 else if (out_struct
< in_struct
)
10347 err
= N_("%s uses r3/r4 for small structure returns, "
10349 first
= this->last_struct_
;
10352 else if (out_struct
> in_struct
)
10354 err
= N_("%s uses r3/r4 for small structure returns, "
10357 second
= this->last_struct_
;
10361 if (parameters
->options().warn_mismatch())
10362 gold_error(_(err
), first
, second
);
10363 out_attr
[tag
].set_type(0);
10368 // Merge Tag_compatibility attributes and any common GNU ones.
10369 this->attributes_section_data_
->merge(name
, pasd
);
10372 // Emit any saved relocs, and mark toc entries using any of these
10373 // relocs as not optimizable.
10375 template<int sh_type
, int size
, bool big_endian
>
10377 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10378 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10381 && parameters
->options().toc_optimize())
10383 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10384 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10385 p
!= this->entries_
.end();
10388 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10391 // If the symbol is no longer defined in a dynamic object,
10392 // then we emitted a COPY relocation. If it is still
10393 // dynamic then we'll need dynamic relocations and thus
10394 // can't optimize toc entries.
10395 if (entry
.sym_
->is_from_dynobj())
10397 Powerpc_relobj
<size
, big_endian
>* ppc_object
10398 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10399 if (entry
.shndx_
== ppc_object
->toc_shndx())
10400 ppc_object
->set_no_toc_opt(entry
.address_
);
10405 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10408 // Return the value to use for a branch relocation.
10410 template<int size
, bool big_endian
>
10412 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10413 const Symbol_table
* symtab
,
10414 const Sized_symbol
<size
>* gsym
,
10415 Powerpc_relobj
<size
, big_endian
>* object
,
10417 unsigned int *dest_shndx
)
10419 if (size
== 32 || this->abiversion() >= 2)
10420 gold_unreachable();
10423 // If the symbol is defined in an opd section, ie. is a function
10424 // descriptor, use the function descriptor code entry address
10425 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10427 && (gsym
->source() != Symbol::FROM_OBJECT
10428 || gsym
->object()->is_dynamic()))
10431 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10432 unsigned int shndx
= symobj
->opd_shndx();
10435 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10436 if (opd_addr
== invalid_address
)
10438 opd_addr
+= symobj
->output_section_address(shndx
);
10439 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10442 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10443 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10446 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10447 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10448 *dest_shndx
= folded
.second
;
10450 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10451 if (sec_addr
== invalid_address
)
10454 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10455 *value
= sec_addr
+ sec_off
;
10462 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10464 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10467 if (gsym
->is_from_dynobj()
10468 || gsym
->is_undefined()
10469 || gsym
->is_preemptible())
10472 if (gsym
->is_absolute())
10473 return !parameters
->options().output_is_position_independent();
10480 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10482 if (psymval
->is_ifunc_symbol())
10486 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10488 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10491 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10492 // pld ra,symbol@got@pcrel
10493 // load/store rt,0(ra)
10495 // pla ra,symbol@pcrel
10496 // load/store rt,0(ra)
10497 // may be translated to
10498 // pload/pstore rt,symbol@pcrel
10500 // This function returns true if the optimization is possible, placing
10501 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10503 // On entry to this function, the linker has already determined that
10504 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10505 // while *PINSN2 is the second instruction.
10508 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10510 uint32_t insn2
= *pinsn2
>> 32;
10513 // Check that regs match.
10514 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10517 switch ((insn2
>> 26) & 63)
10533 // These are the PMLS cases, where we just need to tack a prefix
10534 // on the insn. Check that the D field is zero.
10535 if ((insn2
& 0xffff) != 0)
10537 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10538 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10541 case 58: // lwa, ld
10542 if ((insn2
& 0xfffd) != 0)
10544 i1new
= ((1ULL << 58) | (1ULL << 52)
10545 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10546 | (insn2
& (31ULL << 21)));
10549 case 57: // lxsd, lxssp
10550 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10552 i1new
= ((1ULL << 58) | (1ULL << 52)
10553 | ((40ULL | (insn2
& 3)) << 26)
10554 | (insn2
& (31ULL << 21)));
10557 case 61: // stxsd, stxssp, lxv, stxv
10558 if ((insn2
& 3) == 0)
10560 else if ((insn2
& 3) >= 2)
10562 if ((insn2
& 0xfffc) != 0)
10564 i1new
= ((1ULL << 58) | (1ULL << 52)
10565 | ((44ULL | (insn2
& 3)) << 26)
10566 | (insn2
& (31ULL << 21)));
10570 if ((insn2
& 0xfff0) != 0)
10572 i1new
= ((1ULL << 58) | (1ULL << 52)
10573 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10574 | (insn2
& (31ULL << 21)));
10579 if ((insn2
& 0xffff) != 0)
10581 i1new
= ((1ULL << 58) | (1ULL << 52)
10582 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10585 case 62: // std, stq
10586 if ((insn2
& 0xfffd) != 0)
10588 i1new
= ((1ULL << 58) | (1ULL << 52)
10589 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10590 | (insn2
& (31ULL << 21)));
10595 *pinsn2
= (uint64_t) nop
<< 32;
10599 // Perform a relocation.
10601 template<int size
, bool big_endian
>
10603 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10604 const Relocate_info
<size
, big_endian
>* relinfo
,
10606 Target_powerpc
* target
,
10607 Output_section
* os
,
10609 const unsigned char* preloc
,
10610 const Sized_symbol
<size
>* gsym
,
10611 const Symbol_value
<size
>* psymval
,
10612 unsigned char* view
,
10614 section_size_type view_size
)
10616 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10617 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10618 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10623 if (target
->replace_tls_get_addr(gsym
))
10624 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10626 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10627 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10628 Powerpc_relobj
<size
, big_endian
>* const object
10629 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10630 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10632 case Track_tls::NOT_EXPECTED
:
10633 // No warning. This will result in really old code without tls
10634 // marker relocs being mis-optimised, but there shouldn't be too
10635 // much of that code around. The problem with warning is that
10636 // glibc and libphobos both construct direct calls to
10637 // __tls_get_addr in a way that is harmless.
10639 case Track_tls::EXPECTED
:
10640 // We have already complained.
10642 case Track_tls::SKIP
:
10643 if (is_plt16_reloc
<size
>(r_type
)
10644 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10645 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10647 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10648 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10650 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10652 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10653 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10655 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10656 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10658 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10659 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10660 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10663 case Track_tls::NORMAL
:
10667 // Offset from start of insn to d-field reloc.
10668 const int d_offset
= big_endian
? 2 : 0;
10671 bool has_stub_value
= false;
10672 bool localentry0
= false;
10673 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10674 bool use_plt_offset
10676 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10677 : object
->local_has_plt_offset(r_sym
));
10678 if (is_plt16_reloc
<size
>(r_type
)
10679 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10680 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10681 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10682 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
10683 || r_type
== elfcpp::R_POWERPC_PLTCALL
10684 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10686 // It would be possible to replace inline plt calls with direct
10687 // calls if the PLTCALL is in range. The only difficulty is
10688 // that the decision depends on the PLTCALL reloc, and we don't
10689 // know the address of that instruction when processing others
10690 // in the sequence. So the decision needs to be made in
10691 // do_relax(). For now, don't optimise inline plt calls.
10693 use_plt_offset
= gsym
->has_plt_offset();
10696 && !is_got_reloc(r_type
)
10697 && !is_plt16_reloc
<size
>(r_type
)
10698 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10699 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10700 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10701 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10702 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10703 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10704 && (!psymval
->is_ifunc_symbol()
10705 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10709 && target
->abiversion() >= 2
10710 && !parameters
->options().output_is_position_independent()
10711 && !is_branch_reloc
<size
>(r_type
))
10713 Address off
= target
->glink_section()->find_global_entry(gsym
);
10714 if (off
!= invalid_address
)
10716 value
= target
->glink_section()->global_entry_address() + off
;
10717 has_stub_value
= true;
10722 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10723 if (target
->stub_tables().size() == 1)
10724 stub_table
= target
->stub_tables()[0];
10725 if (stub_table
== NULL
10728 && !parameters
->options().output_is_position_independent()
10729 && !is_branch_reloc
<size
>(r_type
)))
10730 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10731 if (stub_table
== NULL
)
10733 // This is a ref from a data section to an ifunc symbol,
10734 // or a non-branch reloc for which we always want to use
10735 // one set of stubs for resolving function addresses.
10736 if (target
->stub_tables().size() != 0)
10737 stub_table
= target
->stub_tables()[0];
10739 if (stub_table
!= NULL
)
10741 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10743 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10744 rela
.get_r_addend());
10746 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10747 rela
.get_r_addend());
10750 value
= stub_table
->stub_address() + ent
->off_
;
10751 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10752 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10753 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10756 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10759 value
+= ent
->p9off_
;
10761 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10762 value
+= ent
->p9off_
;
10764 value
+= ent
->tocoff_
;
10769 && target
->is_tls_get_addr_opt(gsym
)))
10771 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
10772 || r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
10774 if (!(target
->power10_stubs()
10775 && target
->power10_stubs_auto()))
10778 else if (relnum
< reloc_count
- 1)
10780 Reltype
next_rela(preloc
+ reloc_size
);
10781 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10782 == elfcpp::R_PPC64_TOCSAVE
10783 && (next_rela
.get_r_offset()
10784 == rela
.get_r_offset() + 4))
10788 localentry0
= ent
->localentry0_
;
10789 has_stub_value
= true;
10793 // We don't care too much about bogus debug references to
10794 // non-local functions, but otherwise there had better be a plt
10795 // call stub or global entry stub as appropriate.
10796 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10799 if (use_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10800 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10801 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10803 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10805 value
= target
->plt_off(gsym
, &plt
);
10807 value
= target
->plt_off(object
, r_sym
, &plt
);
10808 value
+= plt
->address();
10812 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10813 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10814 value
-= target
->toc_pointer();
10816 else if (parameters
->options().output_is_position_independent())
10818 if (rela
.get_r_addend() >= 32768)
10820 unsigned int got2
= object
->got2_shndx();
10821 value
-= (object
->get_output_section_offset(got2
)
10822 + object
->output_section(got2
)->address()
10823 + rela
.get_r_addend());
10826 value
-= target
->toc_pointer();
10829 else if (!use_plt_offset
10830 && (is_plt16_reloc
<size
>(r_type
)
10831 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10832 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10834 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10835 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10836 r_type
= elfcpp::R_POWERPC_NONE
;
10838 else if (!use_plt_offset
10839 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10840 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10842 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10843 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10844 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10845 r_type
= elfcpp::R_POWERPC_NONE
;
10847 else if (is_got_reloc(r_type
))
10849 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10850 Got_type got_type
= ((size
== 32
10851 || r_type
== elfcpp::R_POWERPC_GOT16
10852 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
10853 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10855 value
= gsym
->got_offset(got_type
, addend
);
10857 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10858 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10859 value
+= target
->got_section(got_type
)->address();
10861 value
-= target
->got_base_offset(got_type
);
10863 else if (r_type
== elfcpp::R_PPC64_TOC
)
10865 value
= target
->toc_pointer();
10867 else if (gsym
!= NULL
10868 && (r_type
== elfcpp::R_POWERPC_REL24
10869 || r_type
== elfcpp::R_PPC_PLTREL24
)
10874 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10875 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10876 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10877 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10879 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10880 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10881 if ((insn
& 1) != 0
10883 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10885 elfcpp::Swap
<32, big_endian
>::
10886 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10887 can_plt_call
= true;
10892 // If we don't have a branch and link followed by a nop,
10893 // we can't go via the plt because there is no place to
10894 // put a toc restoring instruction.
10895 // Unless we know we won't be returning.
10896 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10897 can_plt_call
= true;
10901 // g++ as of 20130507 emits self-calls without a
10902 // following nop. This is arguably wrong since we have
10903 // conflicting information. On the one hand a global
10904 // symbol and on the other a local call sequence, but
10905 // don't error for this special case.
10906 // It isn't possible to cheaply verify we have exactly
10907 // such a call. Allow all calls to the same section.
10909 Address code
= value
;
10910 if (gsym
->source() == Symbol::FROM_OBJECT
10911 && gsym
->object() == object
)
10913 unsigned int dest_shndx
= 0;
10914 if (target
->abiversion() < 2)
10916 Address addend
= rela
.get_r_addend();
10917 code
= psymval
->value(object
, addend
);
10918 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10919 &code
, &dest_shndx
);
10922 if (dest_shndx
== 0)
10923 dest_shndx
= gsym
->shndx(&is_ordinary
);
10924 ok
= dest_shndx
== relinfo
->data_shndx
;
10928 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10929 _("call lacks nop, can't restore toc; "
10930 "recompile with -fPIC"));
10936 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10937 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10938 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10939 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10940 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10942 // First instruction of a global dynamic sequence, arg setup insn.
10943 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10944 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10945 Got_type got_type
= ((size
== 32
10946 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
10947 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10948 if (tls_type
== tls::TLSOPT_NONE
)
10949 got_type
= Got_type(got_type
| GOT_TYPE_TLSGD
);
10950 else if (tls_type
== tls::TLSOPT_TO_IE
)
10951 got_type
= Got_type(got_type
| GOT_TYPE_TPREL
);
10952 if ((got_type
& ~GOT_TYPE_SMALL
) != GOT_TYPE_STANDARD
)
10954 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10956 value
= gsym
->got_offset(got_type
, addend
);
10958 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10959 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10960 value
+= target
->got_section(got_type
)->address();
10962 value
-= target
->got_base_offset(got_type
);
10964 if (tls_type
== tls::TLSOPT_TO_IE
)
10966 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10968 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10969 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10971 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10973 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10974 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10975 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10976 pinsn
& 0xffffffff);
10977 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10981 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10982 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10984 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10985 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10986 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10988 insn
|= 32 << 26; // lwz
10990 insn
|= 58 << 26; // ld
10991 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10993 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10994 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10997 else if (tls_type
== tls::TLSOPT_TO_LE
)
10999 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
11001 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11002 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11004 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11005 // pla pcrel -> paddi r13
11006 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11007 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11008 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11009 pinsn
& 0xffffffff);
11010 r_type
= elfcpp::R_PPC64_TPREL34
;
11011 value
= psymval
->value(object
, rela
.get_r_addend());
11015 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11016 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11018 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11019 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11020 insn
&= (1 << 26) - (1 << 21); // extract rt
11024 insn
|= addis_0_13
;
11025 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11026 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11027 value
= psymval
->value(object
, rela
.get_r_addend());
11031 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11033 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11034 r_type
= elfcpp::R_POWERPC_NONE
;
11039 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11040 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11041 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11042 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
11043 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11045 // First instruction of a local dynamic sequence, arg setup insn.
11046 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11047 if (tls_type
== tls::TLSOPT_NONE
)
11049 value
= target
->tlsld_got_offset();
11050 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11051 value
+= target
->got_section(GOT_TYPE_SMALL
)->address();
11053 value
-= target
->got_base_offset(GOT_TYPE_SMALL
);
11057 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11058 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
11060 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11061 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11063 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11064 // pla pcrel -> paddi r13
11065 pinsn
+= (-1ULL << 52) + (13ULL << 16);
11066 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11067 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11068 pinsn
& 0xffffffff);
11069 r_type
= elfcpp::R_PPC64_TPREL34
;
11070 value
= dtp_offset
;
11072 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11073 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11075 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11076 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11077 insn
&= (1 << 26) - (1 << 21); // extract rt
11081 insn
|= addis_0_13
;
11082 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11083 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11084 value
= dtp_offset
;
11088 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11090 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11091 r_type
= elfcpp::R_POWERPC_NONE
;
11095 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
11096 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
11097 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
11098 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
11099 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11101 // Accesses relative to a local dynamic sequence address,
11102 // no optimisation here.
11103 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11104 Got_type got_type
= ((size
== 32
11105 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
11106 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
11108 value
= gsym
->got_offset(got_type
, addend
);
11110 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11111 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
11112 value
+= target
->got_section(got_type
)->address();
11114 value
-= target
->got_base_offset(got_type
);
11116 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11117 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11118 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11119 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
11120 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11122 // First instruction of initial exec sequence.
11123 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11124 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11125 if (tls_type
== tls::TLSOPT_NONE
)
11127 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
11128 Got_type got_type
= ((size
== 32
11129 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
11130 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
11132 value
= gsym
->got_offset(got_type
, addend
);
11134 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
11135 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11136 value
+= target
->got_section(got_type
)->address();
11138 value
-= target
->got_base_offset(got_type
);
11142 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
11143 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
11145 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11146 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11148 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11149 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
11150 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
11151 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
11152 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11153 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11154 pinsn
& 0xffffffff);
11155 r_type
= elfcpp::R_PPC64_TPREL34
;
11156 value
= psymval
->value(object
, rela
.get_r_addend());
11158 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11159 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11161 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11162 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11163 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
11167 insn
|= addis_0_13
;
11168 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11169 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11170 value
= psymval
->value(object
, rela
.get_r_addend());
11174 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11176 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11177 r_type
= elfcpp::R_POWERPC_NONE
;
11181 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11182 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11184 // Second instruction of a global dynamic sequence,
11185 // the __tls_get_addr call
11186 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11187 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11188 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
11189 if (tls_type
!= tls::TLSOPT_NONE
)
11191 if (tls_type
== tls::TLSOPT_TO_IE
)
11193 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11194 Insn insn
= add_3_3_13
;
11197 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11198 r_type
= elfcpp::R_POWERPC_NONE
;
11202 bool is_pcrel
= false;
11203 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11204 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11205 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11206 if (relnum
< reloc_count
- 1)
11208 Reltype
next_rela(preloc
+ reloc_size
);
11209 unsigned int r_type2
11210 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11211 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11212 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11213 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11214 && next_rela
.get_r_offset() == rela
.get_r_offset())
11217 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11220 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11221 r_type
= elfcpp::R_POWERPC_NONE
;
11225 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11226 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11228 value
= psymval
->value(object
, rela
.get_r_addend());
11231 this->skip_next_tls_get_addr_call();
11234 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11235 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11237 // Second instruction of a local dynamic sequence,
11238 // the __tls_get_addr call
11239 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11240 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11241 if (tls_type
== tls::TLSOPT_TO_LE
)
11243 bool is_pcrel
= false;
11244 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11245 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11246 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11247 if (relnum
< reloc_count
- 1)
11249 Reltype
next_rela(preloc
+ reloc_size
);
11250 unsigned int r_type2
11251 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11252 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11253 || r_type2
== elfcpp::R_PPC64_REL24_P9NOTOC
11254 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11255 && next_rela
.get_r_offset() == rela
.get_r_offset())
11258 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11261 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11262 r_type
= elfcpp::R_POWERPC_NONE
;
11266 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11267 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11269 value
= dtp_offset
;
11271 this->skip_next_tls_get_addr_call();
11274 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11276 // Second instruction of an initial exec sequence
11277 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11278 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11279 if (tls_type
== tls::TLSOPT_TO_LE
)
11281 Address roff
= rela
.get_r_offset() & 3;
11282 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11283 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11284 unsigned int reg
= size
== 32 ? 2 : 13;
11285 insn
= at_tls_transform(insn
, reg
);
11286 gold_assert(insn
!= 0);
11289 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11290 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11292 value
= psymval
->value(object
, rela
.get_r_addend());
11294 else if (roff
== 1)
11296 // For pcrel IE to LE we already have the full offset
11297 // and thus don't need an addi here. A nop or mr will do.
11298 if ((insn
& (0x3f << 26)) == 14 << 26)
11300 // Extract regs from addi rt,ra,si.
11301 unsigned int rt
= (insn
>> 21) & 0x1f;
11302 unsigned int ra
= (insn
>> 16) & 0x1f;
11307 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11308 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11309 insn
|= (31u << 26) | (444u << 1);
11312 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11313 r_type
= elfcpp::R_POWERPC_NONE
;
11317 else if (!has_stub_value
)
11319 if (!use_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11320 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11322 // PLTCALL without plt entry => convert to direct call
11323 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11324 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11325 insn
= (insn
& 1) | b
;
11326 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11328 r_type
= elfcpp::R_PPC_PLTREL24
;
11329 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11330 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11332 r_type
= elfcpp::R_POWERPC_REL24
;
11334 Address addend
= 0;
11336 && (r_type
== elfcpp::R_PPC_PLTREL24
11337 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11338 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11339 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11340 addend
= rela
.get_r_addend();
11341 value
= psymval
->value(object
, addend
);
11342 unsigned int local_ent
= 0;
11343 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11345 if (target
->abiversion() >= 2)
11348 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11350 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11354 unsigned int dest_shndx
;
11355 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11356 &value
, &dest_shndx
);
11359 Address max_branch
= max_branch_delta
<size
>(r_type
);
11360 if (max_branch
!= 0
11361 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11363 && (r_type
== elfcpp::R_PPC64_REL24_NOTOC
11364 || r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11366 ? object
->ppc64_needs_toc(gsym
)
11367 : object
->ppc64_needs_toc(r_sym
)))))
11369 Stub_table
<size
, big_endian
>* stub_table
11370 = object
->stub_table(relinfo
->data_shndx
);
11371 if (stub_table
!= NULL
)
11373 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11374 = stub_table
->find_long_branch_entry(value
);
11377 if (ent
->save_res_
)
11378 value
= (value
- target
->savres_section()->address()
11379 + stub_table
->stub_address()
11380 + stub_table
->plt_size()
11381 + stub_table
->branch_size());
11384 value
= (stub_table
->stub_address()
11385 + stub_table
->plt_size()
11389 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
11392 value
+= ent
->p9off_
;
11394 else if (r_type
== elfcpp::R_PPC64_REL24_P9NOTOC
)
11395 value
+= ent
->p9off_
;
11397 value
+= ent
->tocoff_
;
11400 has_stub_value
= true;
11404 if (!has_stub_value
)
11405 value
+= local_ent
;
11410 case elfcpp::R_PPC64_REL24_NOTOC
:
11414 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11415 case elfcpp::R_PPC64_REL64
:
11416 case elfcpp::R_POWERPC_REL32
:
11417 case elfcpp::R_POWERPC_REL24
:
11418 case elfcpp::R_PPC_PLTREL24
:
11419 case elfcpp::R_PPC_LOCAL24PC
:
11420 case elfcpp::R_POWERPC_REL16
:
11421 case elfcpp::R_POWERPC_REL16_LO
:
11422 case elfcpp::R_POWERPC_REL16_HI
:
11423 case elfcpp::R_POWERPC_REL16_HA
:
11424 case elfcpp::R_POWERPC_REL16DX_HA
:
11425 case elfcpp::R_PPC64_REL16_HIGH
:
11426 case elfcpp::R_PPC64_REL16_HIGHA
:
11427 case elfcpp::R_PPC64_REL16_HIGHER
:
11428 case elfcpp::R_PPC64_REL16_HIGHERA
:
11429 case elfcpp::R_PPC64_REL16_HIGHEST
:
11430 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11431 case elfcpp::R_POWERPC_REL14
:
11432 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11433 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11434 case elfcpp::R_PPC64_PCREL34
:
11435 case elfcpp::R_PPC64_GOT_PCREL34
:
11436 case elfcpp::R_PPC64_PLT_PCREL34
:
11437 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11438 case elfcpp::R_PPC64_PCREL28
:
11439 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11440 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11441 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11442 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11443 case elfcpp::R_PPC64_REL16_HIGHER34
:
11444 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11445 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11446 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11450 case elfcpp::R_PPC64_TOC16
:
11451 case elfcpp::R_PPC64_TOC16_LO
:
11452 case elfcpp::R_PPC64_TOC16_HI
:
11453 case elfcpp::R_PPC64_TOC16_HA
:
11454 case elfcpp::R_PPC64_TOC16_DS
:
11455 case elfcpp::R_PPC64_TOC16_LO_DS
:
11456 // Subtract the TOC base address.
11457 value
-= target
->toc_pointer();
11460 case elfcpp::R_POWERPC_SECTOFF
:
11461 case elfcpp::R_POWERPC_SECTOFF_LO
:
11462 case elfcpp::R_POWERPC_SECTOFF_HI
:
11463 case elfcpp::R_POWERPC_SECTOFF_HA
:
11464 case elfcpp::R_PPC64_SECTOFF_DS
:
11465 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11467 value
-= os
->address();
11470 case elfcpp::R_PPC64_TPREL16_DS
:
11471 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11472 case elfcpp::R_PPC64_TPREL16_HIGH
:
11473 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11475 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11478 case elfcpp::R_POWERPC_TPREL16
:
11479 case elfcpp::R_POWERPC_TPREL16_LO
:
11480 case elfcpp::R_POWERPC_TPREL16_HI
:
11481 case elfcpp::R_POWERPC_TPREL16_HA
:
11482 case elfcpp::R_POWERPC_TPREL
:
11483 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11484 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11485 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11486 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11487 case elfcpp::R_PPC64_TPREL34
:
11488 // tls symbol values are relative to tls_segment()->vaddr()
11489 value
-= tp_offset
;
11492 case elfcpp::R_PPC64_DTPREL16_DS
:
11493 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11494 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11495 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11496 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11497 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11499 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11500 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11503 case elfcpp::R_POWERPC_DTPREL16
:
11504 case elfcpp::R_POWERPC_DTPREL16_LO
:
11505 case elfcpp::R_POWERPC_DTPREL16_HI
:
11506 case elfcpp::R_POWERPC_DTPREL16_HA
:
11507 case elfcpp::R_POWERPC_DTPREL
:
11508 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11509 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11510 case elfcpp::R_PPC64_DTPREL34
:
11511 // tls symbol values are relative to tls_segment()->vaddr()
11512 value
-= dtp_offset
;
11515 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11517 value
+= object
->ppc64_local_entry_offset(gsym
);
11519 value
+= object
->ppc64_local_entry_offset(r_sym
);
11526 Insn branch_bit
= 0;
11529 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11530 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11531 branch_bit
= 1 << 21;
11533 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11534 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11536 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11537 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11538 insn
&= ~(1 << 21);
11539 insn
|= branch_bit
;
11540 if (this->is_isa_v2
)
11542 // Set 'a' bit. This is 0b00010 in BO field for branch
11543 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11544 // for branch on CTR insns (BO == 1a00t or 1a01t).
11545 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11546 insn
|= 0x02 << 21;
11547 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11548 insn
|= 0x08 << 21;
11554 // Invert 'y' bit if not the default.
11555 if (static_cast<Signed_address
>(value
) < 0)
11558 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11562 case elfcpp::R_POWERPC_PLT16_HA
:
11564 && !parameters
->options().output_is_position_independent())
11566 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11567 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11569 // Convert addis to lis.
11570 if ((insn
& (0x3f << 26)) == 15u << 26
11571 && (insn
& (0x1f << 16)) != 0)
11573 insn
&= ~(0x1f << 16);
11574 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11584 ? relative_value_is_known(gsym
)
11585 : relative_value_is_known(psymval
))
11590 uint64_t pinsn
, pinsn2
;
11597 // Multi-instruction sequences that access the GOT/TOC can
11598 // be optimized, eg.
11599 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11600 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11602 // addis ra,r2,0; addi rb,ra,x@toc@l;
11603 // to nop; addi rb,r2,x@toc;
11604 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11605 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11606 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11607 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11608 case elfcpp::R_POWERPC_GOT16_HA
:
11609 case elfcpp::R_PPC64_TOC16_HA
:
11610 if (size
== 64 && parameters
->options().toc_optimize())
11612 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11613 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11614 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11615 && object
->make_toc_relative(target
, &value
))
11616 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11617 && object
->make_got_relative(target
, psymval
,
11618 rela
.get_r_addend(),
11621 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11622 == ((15u << 26) | (2 << 16)));
11624 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11625 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11626 && value
+ 0x8000 < 0x10000)
11628 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11634 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11635 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11636 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11637 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11638 case elfcpp::R_POWERPC_GOT16_LO
:
11639 case elfcpp::R_PPC64_GOT16_LO_DS
:
11640 case elfcpp::R_PPC64_TOC16_LO
:
11641 case elfcpp::R_PPC64_TOC16_LO_DS
:
11642 if (size
== 64 && parameters
->options().toc_optimize())
11644 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11645 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11646 bool changed
= false;
11647 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11648 && object
->make_toc_relative(target
, &value
))
11649 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11650 && object
->make_got_relative(target
, psymval
,
11651 rela
.get_r_addend(),
11654 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11655 insn
^= (14u << 26) ^ (58u << 26);
11656 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11659 if (ok_lo_toc_insn(insn
, r_type
)
11660 && value
+ 0x8000 < 0x10000)
11662 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11664 // Transform addic to addi when we change reg.
11665 insn
&= ~((0x3f << 26) | (0x1f << 16));
11666 insn
|= (14u << 26) | (2 << 16);
11670 insn
&= ~(0x1f << 16);
11676 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11680 case elfcpp::R_PPC64_GOT_PCREL34
:
11681 if (size
== 64 && parameters
->options().toc_optimize())
11683 iview
= reinterpret_cast<Insn
*>(view
);
11684 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11686 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11687 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11688 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11691 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11693 if (relval
+ (1ULL << 33) < 1ULL << 34)
11696 // Replace with paddi
11697 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11698 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11699 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11700 pinsn
& 0xffffffff);
11706 case elfcpp::R_PPC64_PCREL34
:
11709 iview
= reinterpret_cast<Insn
*>(view
);
11710 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11712 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11713 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11714 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11715 | (14ULL << 26) /* paddi */))
11719 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11720 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11721 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11722 if (relnum
>= reloc_count
- 1)
11725 Reltype
next_rela(preloc
+ reloc_size
);
11726 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11727 != elfcpp::R_PPC64_PCREL_OPT
)
11728 || next_rela
.get_r_offset() != rela
.get_r_offset())
11731 Address off
= next_rela
.get_r_addend();
11733 off
= 8; // zero means next insn.
11734 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11737 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11738 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11740 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11742 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11744 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11745 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11746 pinsn
& 0xffffffff);
11747 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11752 case elfcpp::R_POWERPC_TPREL16_HA
:
11753 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11755 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11756 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11761 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11763 // R_PPC_TLSGD, R_PPC_TLSLD
11766 case elfcpp::R_POWERPC_TPREL16_LO
:
11767 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11769 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11770 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11771 insn
&= ~(0x1f << 16);
11772 insn
|= (size
== 32 ? 2 : 13) << 16;
11773 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11777 case elfcpp::R_PPC64_ENTRY
:
11780 value
= target
->toc_pointer();
11781 if (value
+ 0x80008000 <= 0xffffffff
11782 && !parameters
->options().output_is_position_independent())
11784 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11785 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11786 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11788 if ((insn1
& ~0xfffc) == ld_2_12
11789 && insn2
== add_2_2_12
)
11791 insn1
= lis_2
+ ha(value
);
11792 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11793 insn2
= addi_2_2
+ l(value
);
11794 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11801 if (value
+ 0x80008000 <= 0xffffffff)
11803 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11804 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11805 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11807 if ((insn1
& ~0xfffc) == ld_2_12
11808 && insn2
== add_2_2_12
)
11810 insn1
= addis_2_12
+ ha(value
);
11811 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11812 insn2
= addi_2_2
+ l(value
);
11813 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11821 case elfcpp::R_POWERPC_REL16_LO
:
11822 // If we are generating a non-PIC executable, edit
11823 // 0: addis 2,12,.TOC.-0b@ha
11824 // addi 2,2,.TOC.-0b@l
11825 // used by ELFv2 global entry points to set up r2, to
11827 // addi 2,2,.TOC.@l
11828 // if .TOC. is in range. */
11830 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11833 && target
->abiversion() >= 2
11834 && !parameters
->options().output_is_position_independent()
11835 && rela
.get_r_addend() == d_offset
+ 4
11837 && strcmp(gsym
->name(), ".TOC.") == 0)
11839 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11840 Reltype
prev_rela(preloc
- reloc_size
);
11841 if ((prev_rela
.get_r_info()
11842 == elfcpp::elf_r_info
<size
>(r_sym
,
11843 elfcpp::R_POWERPC_REL16_HA
))
11844 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11845 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11847 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11848 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11849 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11851 if ((insn1
& 0xffff0000) == addis_2_12
11852 && (insn2
& 0xffff0000) == addi_2_2
)
11854 insn1
= lis_2
+ ha(value
+ address
- 4);
11855 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11856 insn2
= addi_2_2
+ l(value
+ address
- 4);
11857 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11860 relinfo
->rr
->set_strategy(relnum
- 1,
11861 Relocatable_relocs::RELOC_SPECIAL
);
11862 relinfo
->rr
->set_strategy(relnum
,
11863 Relocatable_relocs::RELOC_SPECIAL
);
11873 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11874 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11877 case elfcpp::R_POWERPC_ADDR32
:
11878 case elfcpp::R_POWERPC_UADDR32
:
11880 overflow
= Reloc::CHECK_BITFIELD
;
11883 case elfcpp::R_POWERPC_REL32
:
11884 case elfcpp::R_POWERPC_REL16DX_HA
:
11886 overflow
= Reloc::CHECK_SIGNED
;
11889 case elfcpp::R_POWERPC_UADDR16
:
11890 overflow
= Reloc::CHECK_BITFIELD
;
11893 case elfcpp::R_POWERPC_ADDR16
:
11894 // We really should have three separate relocations,
11895 // one for 16-bit data, one for insns with 16-bit signed fields,
11896 // and one for insns with 16-bit unsigned fields.
11897 overflow
= Reloc::CHECK_BITFIELD
;
11898 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11899 overflow
= Reloc::CHECK_LOW_INSN
;
11902 case elfcpp::R_POWERPC_ADDR16_HI
:
11903 case elfcpp::R_POWERPC_ADDR16_HA
:
11904 case elfcpp::R_POWERPC_GOT16_HI
:
11905 case elfcpp::R_POWERPC_GOT16_HA
:
11906 case elfcpp::R_POWERPC_PLT16_HI
:
11907 case elfcpp::R_POWERPC_PLT16_HA
:
11908 case elfcpp::R_POWERPC_SECTOFF_HI
:
11909 case elfcpp::R_POWERPC_SECTOFF_HA
:
11910 case elfcpp::R_PPC64_TOC16_HI
:
11911 case elfcpp::R_PPC64_TOC16_HA
:
11912 case elfcpp::R_PPC64_PLTGOT16_HI
:
11913 case elfcpp::R_PPC64_PLTGOT16_HA
:
11914 case elfcpp::R_POWERPC_TPREL16_HI
:
11915 case elfcpp::R_POWERPC_TPREL16_HA
:
11916 case elfcpp::R_POWERPC_DTPREL16_HI
:
11917 case elfcpp::R_POWERPC_DTPREL16_HA
:
11918 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11919 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11920 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11921 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11922 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11923 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11924 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11925 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11926 case elfcpp::R_POWERPC_REL16_HI
:
11927 case elfcpp::R_POWERPC_REL16_HA
:
11929 overflow
= Reloc::CHECK_HIGH_INSN
;
11932 case elfcpp::R_POWERPC_REL16
:
11933 case elfcpp::R_PPC64_TOC16
:
11934 case elfcpp::R_POWERPC_GOT16
:
11935 case elfcpp::R_POWERPC_SECTOFF
:
11936 case elfcpp::R_POWERPC_TPREL16
:
11937 case elfcpp::R_POWERPC_DTPREL16
:
11938 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11939 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11940 case elfcpp::R_POWERPC_GOT_TPREL16
:
11941 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11942 overflow
= Reloc::CHECK_LOW_INSN
;
11945 case elfcpp::R_PPC64_REL24_NOTOC
:
11949 case elfcpp::R_PPC64_REL24_P9NOTOC
:
11950 case elfcpp::R_POWERPC_ADDR24
:
11951 case elfcpp::R_POWERPC_ADDR14
:
11952 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11953 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11954 case elfcpp::R_PPC64_ADDR16_DS
:
11955 case elfcpp::R_POWERPC_REL24
:
11956 case elfcpp::R_PPC_PLTREL24
:
11957 case elfcpp::R_PPC_LOCAL24PC
:
11958 case elfcpp::R_PPC64_TPREL16_DS
:
11959 case elfcpp::R_PPC64_DTPREL16_DS
:
11960 case elfcpp::R_PPC64_TOC16_DS
:
11961 case elfcpp::R_PPC64_GOT16_DS
:
11962 case elfcpp::R_PPC64_SECTOFF_DS
:
11963 case elfcpp::R_POWERPC_REL14
:
11964 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11965 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11966 case elfcpp::R_PPC64_D34
:
11967 case elfcpp::R_PPC64_PCREL34
:
11968 case elfcpp::R_PPC64_GOT_PCREL34
:
11969 case elfcpp::R_PPC64_PLT_PCREL34
:
11970 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11971 case elfcpp::R_PPC64_D28
:
11972 case elfcpp::R_PPC64_PCREL28
:
11973 case elfcpp::R_PPC64_TPREL34
:
11974 case elfcpp::R_PPC64_DTPREL34
:
11975 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11976 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11977 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11978 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11979 overflow
= Reloc::CHECK_SIGNED
;
11983 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11986 if (overflow
== Reloc::CHECK_LOW_INSN
11987 || overflow
== Reloc::CHECK_HIGH_INSN
)
11989 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11991 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11992 overflow
= Reloc::CHECK_BITFIELD
;
11993 else if (overflow
== Reloc::CHECK_LOW_INSN
11994 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11995 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11996 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11997 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11998 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11999 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
12000 overflow
= Reloc::CHECK_UNSIGNED
;
12002 overflow
= Reloc::CHECK_SIGNED
;
12005 bool maybe_dq_reloc
= false;
12006 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
12007 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
12010 case elfcpp::R_POWERPC_NONE
:
12011 case elfcpp::R_POWERPC_TLS
:
12012 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
12013 case elfcpp::R_POWERPC_GNU_VTENTRY
:
12014 case elfcpp::R_POWERPC_PLTSEQ
:
12015 case elfcpp::R_POWERPC_PLTCALL
:
12016 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
12017 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
12018 case elfcpp::R_PPC64_PCREL_OPT
:
12021 case elfcpp::R_PPC64_ADDR64
:
12022 case elfcpp::R_PPC64_REL64
:
12023 case elfcpp::R_PPC64_TOC
:
12024 case elfcpp::R_PPC64_ADDR64_LOCAL
:
12025 Reloc::addr64(view
, value
);
12028 case elfcpp::R_POWERPC_TPREL
:
12029 case elfcpp::R_POWERPC_DTPREL
:
12031 Reloc::addr64(view
, value
);
12033 status
= Reloc::addr32(view
, value
, overflow
);
12036 case elfcpp::R_PPC64_UADDR64
:
12037 Reloc::addr64_u(view
, value
);
12040 case elfcpp::R_POWERPC_ADDR32
:
12041 status
= Reloc::addr32(view
, value
, overflow
);
12044 case elfcpp::R_POWERPC_REL32
:
12045 case elfcpp::R_POWERPC_UADDR32
:
12046 status
= Reloc::addr32_u(view
, value
, overflow
);
12049 case elfcpp::R_PPC64_REL24_NOTOC
:
12051 goto unsupp
; // R_PPC_EMB_RELSDA
12053 case elfcpp::R_PPC64_REL24_P9NOTOC
:
12054 case elfcpp::R_POWERPC_ADDR24
:
12055 case elfcpp::R_POWERPC_REL24
:
12056 case elfcpp::R_PPC_PLTREL24
:
12057 case elfcpp::R_PPC_LOCAL24PC
:
12058 status
= Reloc::addr24(view
, value
, overflow
);
12061 case elfcpp::R_POWERPC_GOT_DTPREL16
:
12062 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
12063 case elfcpp::R_POWERPC_GOT_TPREL16
:
12064 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
12067 // On ppc64 these are all ds form
12068 maybe_dq_reloc
= true;
12072 case elfcpp::R_POWERPC_ADDR16
:
12073 case elfcpp::R_POWERPC_REL16
:
12074 case elfcpp::R_PPC64_TOC16
:
12075 case elfcpp::R_POWERPC_GOT16
:
12076 case elfcpp::R_POWERPC_SECTOFF
:
12077 case elfcpp::R_POWERPC_TPREL16
:
12078 case elfcpp::R_POWERPC_DTPREL16
:
12079 case elfcpp::R_POWERPC_GOT_TLSGD16
:
12080 case elfcpp::R_POWERPC_GOT_TLSLD16
:
12081 case elfcpp::R_POWERPC_ADDR16_LO
:
12082 case elfcpp::R_POWERPC_REL16_LO
:
12083 case elfcpp::R_PPC64_TOC16_LO
:
12084 case elfcpp::R_POWERPC_GOT16_LO
:
12085 case elfcpp::R_POWERPC_PLT16_LO
:
12086 case elfcpp::R_POWERPC_SECTOFF_LO
:
12087 case elfcpp::R_POWERPC_TPREL16_LO
:
12088 case elfcpp::R_POWERPC_DTPREL16_LO
:
12089 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
12090 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
12092 status
= Reloc::addr16(view
, value
, overflow
);
12094 maybe_dq_reloc
= true;
12097 case elfcpp::R_POWERPC_UADDR16
:
12098 status
= Reloc::addr16_u(view
, value
, overflow
);
12101 case elfcpp::R_PPC64_ADDR16_HIGH
:
12102 case elfcpp::R_PPC64_TPREL16_HIGH
:
12103 case elfcpp::R_PPC64_DTPREL16_HIGH
:
12105 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
12108 case elfcpp::R_POWERPC_ADDR16_HI
:
12109 case elfcpp::R_POWERPC_REL16_HI
:
12110 case elfcpp::R_PPC64_REL16_HIGH
:
12111 case elfcpp::R_PPC64_TOC16_HI
:
12112 case elfcpp::R_POWERPC_GOT16_HI
:
12113 case elfcpp::R_POWERPC_PLT16_HI
:
12114 case elfcpp::R_POWERPC_SECTOFF_HI
:
12115 case elfcpp::R_POWERPC_TPREL16_HI
:
12116 case elfcpp::R_POWERPC_DTPREL16_HI
:
12117 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
12118 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
12119 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
12120 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
12121 Reloc::addr16_hi(view
, value
);
12124 case elfcpp::R_PPC64_ADDR16_HIGHA
:
12125 case elfcpp::R_PPC64_TPREL16_HIGHA
:
12126 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
12128 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
12131 case elfcpp::R_POWERPC_ADDR16_HA
:
12132 case elfcpp::R_POWERPC_REL16_HA
:
12133 case elfcpp::R_PPC64_REL16_HIGHA
:
12134 case elfcpp::R_PPC64_TOC16_HA
:
12135 case elfcpp::R_POWERPC_GOT16_HA
:
12136 case elfcpp::R_POWERPC_PLT16_HA
:
12137 case elfcpp::R_POWERPC_SECTOFF_HA
:
12138 case elfcpp::R_POWERPC_TPREL16_HA
:
12139 case elfcpp::R_POWERPC_DTPREL16_HA
:
12140 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
12141 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
12142 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
12143 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
12144 Reloc::addr16_ha(view
, value
);
12147 case elfcpp::R_POWERPC_REL16DX_HA
:
12148 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
12151 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
12153 // R_PPC_EMB_NADDR16_LO
12156 case elfcpp::R_PPC64_ADDR16_HIGHER
:
12157 case elfcpp::R_PPC64_REL16_HIGHER
:
12158 case elfcpp::R_PPC64_TPREL16_HIGHER
:
12159 Reloc::addr16_hi2(view
, value
);
12162 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
12164 // R_PPC_EMB_NADDR16_HI
12167 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
12168 case elfcpp::R_PPC64_REL16_HIGHERA
:
12169 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
12170 Reloc::addr16_ha2(view
, value
);
12173 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
12175 // R_PPC_EMB_NADDR16_HA
12178 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
12179 case elfcpp::R_PPC64_REL16_HIGHEST
:
12180 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
12181 Reloc::addr16_hi3(view
, value
);
12184 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
12186 // R_PPC_EMB_SDAI16
12189 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
12190 case elfcpp::R_PPC64_REL16_HIGHESTA
:
12191 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
12192 Reloc::addr16_ha3(view
, value
);
12195 case elfcpp::R_PPC64_DTPREL16_DS
:
12196 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
12198 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
12201 case elfcpp::R_PPC64_TPREL16_DS
:
12202 case elfcpp::R_PPC64_TPREL16_LO_DS
:
12204 // R_PPC_TLSGD, R_PPC_TLSLD
12207 case elfcpp::R_PPC64_ADDR16_DS
:
12208 case elfcpp::R_PPC64_ADDR16_LO_DS
:
12209 case elfcpp::R_PPC64_TOC16_DS
:
12210 case elfcpp::R_PPC64_TOC16_LO_DS
:
12211 case elfcpp::R_PPC64_GOT16_DS
:
12212 case elfcpp::R_PPC64_GOT16_LO_DS
:
12213 case elfcpp::R_PPC64_PLT16_LO_DS
:
12214 case elfcpp::R_PPC64_SECTOFF_DS
:
12215 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
12216 maybe_dq_reloc
= true;
12219 case elfcpp::R_POWERPC_ADDR14
:
12220 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
12221 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12222 case elfcpp::R_POWERPC_REL14
:
12223 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12224 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12225 status
= Reloc::addr14(view
, value
, overflow
);
12228 case elfcpp::R_POWERPC_COPY
:
12229 case elfcpp::R_POWERPC_GLOB_DAT
:
12230 case elfcpp::R_POWERPC_JMP_SLOT
:
12231 case elfcpp::R_POWERPC_RELATIVE
:
12232 case elfcpp::R_POWERPC_DTPMOD
:
12233 case elfcpp::R_PPC64_JMP_IREL
:
12234 case elfcpp::R_POWERPC_IRELATIVE
:
12235 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12236 _("unexpected reloc %u in object file"),
12240 case elfcpp::R_PPC64_TOCSAVE
:
12246 Symbol_location loc
;
12247 loc
.object
= relinfo
->object
;
12248 loc
.shndx
= relinfo
->data_shndx
;
12249 loc
.offset
= rela
.get_r_offset();
12250 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12251 if (tocsave
->find(loc
) != tocsave
->end())
12253 // If we've generated plt calls using this tocsave, then
12254 // the nop needs to be changed to save r2.
12255 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12256 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12257 elfcpp::Swap
<32, big_endian
>::
12258 writeval(iview
, std_2_1
+ target
->stk_toc());
12263 case elfcpp::R_PPC_EMB_SDA2I16
:
12264 case elfcpp::R_PPC_EMB_SDA2REL
:
12267 // R_PPC64_TLSGD, R_PPC64_TLSLD
12270 case elfcpp::R_PPC64_D34
:
12271 case elfcpp::R_PPC64_D34_LO
:
12272 case elfcpp::R_PPC64_PCREL34
:
12273 case elfcpp::R_PPC64_GOT_PCREL34
:
12274 case elfcpp::R_PPC64_PLT_PCREL34
:
12275 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12276 case elfcpp::R_PPC64_TPREL34
:
12277 case elfcpp::R_PPC64_DTPREL34
:
12278 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12279 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12280 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12281 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12284 status
= Reloc::addr34(view
, value
, overflow
);
12287 case elfcpp::R_PPC64_D34_HI30
:
12290 Reloc::addr34_hi(view
, value
);
12293 case elfcpp::R_PPC64_D34_HA30
:
12296 Reloc::addr34_ha(view
, value
);
12299 case elfcpp::R_PPC64_D28
:
12300 case elfcpp::R_PPC64_PCREL28
:
12303 status
= Reloc::addr28(view
, value
, overflow
);
12306 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12307 case elfcpp::R_PPC64_REL16_HIGHER34
:
12310 Reloc::addr16_higher34(view
, value
);
12313 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12314 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12317 Reloc::addr16_highera34(view
, value
);
12320 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12321 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12324 Reloc::addr16_highest34(view
, value
);
12327 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12328 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12331 Reloc::addr16_highesta34(view
, value
);
12334 case elfcpp::R_POWERPC_PLT32
:
12335 case elfcpp::R_POWERPC_PLTREL32
:
12336 case elfcpp::R_PPC_SDAREL16
:
12337 case elfcpp::R_POWERPC_ADDR30
:
12338 case elfcpp::R_PPC64_PLT64
:
12339 case elfcpp::R_PPC64_PLTREL64
:
12340 case elfcpp::R_PPC64_PLTGOT16
:
12341 case elfcpp::R_PPC64_PLTGOT16_LO
:
12342 case elfcpp::R_PPC64_PLTGOT16_HI
:
12343 case elfcpp::R_PPC64_PLTGOT16_HA
:
12344 case elfcpp::R_PPC64_PLTGOT16_DS
:
12345 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12346 case elfcpp::R_PPC_TOC16
:
12349 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12350 _("unsupported reloc %u"),
12355 if (maybe_dq_reloc
)
12358 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12360 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12361 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12362 && (insn
& 3) == 1))
12363 status
= Reloc::addr16_dq(view
, value
, overflow
);
12364 else if (size
== 64
12365 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12366 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12367 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12368 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12369 status
= Reloc::addr16_ds(view
, value
, overflow
);
12371 status
= Reloc::addr16(view
, value
, overflow
);
12374 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12377 && gsym
->is_undefined()
12378 && is_branch_reloc
<size
>(r_type
))))
12380 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12381 _("relocation overflow"));
12382 if (has_stub_value
)
12383 gold_info(_("try relinking with a smaller --stub-group-size"));
12389 // Relocate section data.
12391 template<int size
, bool big_endian
>
12393 Target_powerpc
<size
, big_endian
>::relocate_section(
12394 const Relocate_info
<size
, big_endian
>* relinfo
,
12395 unsigned int sh_type
,
12396 const unsigned char* prelocs
,
12397 size_t reloc_count
,
12398 Output_section
* output_section
,
12399 bool needs_special_offset_handling
,
12400 unsigned char* view
,
12402 section_size_type view_size
,
12403 const Reloc_symbol_changes
* reloc_symbol_changes
)
12405 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12406 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12407 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12408 Powerpc_comdat_behavior
;
12409 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12412 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12414 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12415 Powerpc_comdat_behavior
, Classify_reloc
>(
12421 needs_special_offset_handling
,
12425 reloc_symbol_changes
);
12428 template<int size
, bool big_endian
>
12429 class Powerpc_scan_relocatable_reloc
12432 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12433 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12434 static const int sh_type
= elfcpp::SHT_RELA
;
12436 // Return the symbol referred to by the relocation.
12437 static inline unsigned int
12438 get_r_sym(const Reltype
* reloc
)
12439 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12441 // Return the type of the relocation.
12442 static inline unsigned int
12443 get_r_type(const Reltype
* reloc
)
12444 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12446 // Return the strategy to use for a local symbol which is not a
12447 // section symbol, given the relocation type.
12448 inline Relocatable_relocs::Reloc_strategy
12449 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12451 if (r_type
== 0 && r_sym
== 0)
12452 return Relocatable_relocs::RELOC_DISCARD
;
12453 return Relocatable_relocs::RELOC_COPY
;
12456 // Return the strategy to use for a local symbol which is a section
12457 // symbol, given the relocation type.
12458 inline Relocatable_relocs::Reloc_strategy
12459 local_section_strategy(unsigned int, Relobj
*)
12461 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12464 // Return the strategy to use for a global symbol, given the
12465 // relocation type, the object, and the symbol index.
12466 inline Relocatable_relocs::Reloc_strategy
12467 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12470 && (r_type
== elfcpp::R_PPC_PLTREL24
12471 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12472 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12473 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12474 return Relocatable_relocs::RELOC_SPECIAL
;
12475 return Relocatable_relocs::RELOC_COPY
;
12479 // Scan the relocs during a relocatable link.
12481 template<int size
, bool big_endian
>
12483 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12484 Symbol_table
* symtab
,
12486 Sized_relobj_file
<size
, big_endian
>* object
,
12487 unsigned int data_shndx
,
12488 unsigned int sh_type
,
12489 const unsigned char* prelocs
,
12490 size_t reloc_count
,
12491 Output_section
* output_section
,
12492 bool needs_special_offset_handling
,
12493 size_t local_symbol_count
,
12494 const unsigned char* plocal_symbols
,
12495 Relocatable_relocs
* rr
)
12497 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12499 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12501 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12509 needs_special_offset_handling
,
12510 local_symbol_count
,
12515 // Scan the relocs for --emit-relocs.
12517 template<int size
, bool big_endian
>
12519 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12520 Symbol_table
* symtab
,
12522 Sized_relobj_file
<size
, big_endian
>* object
,
12523 unsigned int data_shndx
,
12524 unsigned int sh_type
,
12525 const unsigned char* prelocs
,
12526 size_t reloc_count
,
12527 Output_section
* output_section
,
12528 bool needs_special_offset_handling
,
12529 size_t local_symbol_count
,
12530 const unsigned char* plocal_syms
,
12531 Relocatable_relocs
* rr
)
12533 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12535 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12536 Emit_relocs_strategy
;
12538 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12540 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12548 needs_special_offset_handling
,
12549 local_symbol_count
,
12554 // Emit relocations for a section.
12555 // This is a modified version of the function by the same name in
12556 // target-reloc.h. Using relocate_special_relocatable for
12557 // R_PPC_PLTREL24 would require duplication of the entire body of the
12558 // loop, so we may as well duplicate the whole thing.
12560 template<int size
, bool big_endian
>
12562 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12563 const Relocate_info
<size
, big_endian
>* relinfo
,
12564 unsigned int sh_type
,
12565 const unsigned char* prelocs
,
12566 size_t reloc_count
,
12567 Output_section
* output_section
,
12568 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12570 Address view_address
,
12572 unsigned char* reloc_view
,
12573 section_size_type reloc_view_size
)
12575 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12577 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12578 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12579 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12580 // Offset from start of insn to d-field reloc.
12581 const int d_offset
= big_endian
? 2 : 0;
12583 Powerpc_relobj
<size
, big_endian
>* const object
12584 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12585 const unsigned int local_count
= object
->local_symbol_count();
12586 unsigned int got2_shndx
= object
->got2_shndx();
12587 Address got2_addend
= 0;
12588 if (got2_shndx
!= 0)
12590 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12591 gold_assert(got2_addend
!= invalid_address
);
12594 const bool relocatable
= parameters
->options().relocatable();
12596 unsigned char* pwrite
= reloc_view
;
12597 bool zap_next
= false;
12598 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12600 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12601 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12604 Reltype
reloc(prelocs
);
12605 Reltype_write
reloc_write(pwrite
);
12607 Address offset
= reloc
.get_r_offset();
12608 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12609 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12610 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12611 const unsigned int orig_r_sym
= r_sym
;
12612 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12613 = reloc
.get_r_addend();
12614 const Symbol
* gsym
= NULL
;
12618 // We could arrange to discard these and other relocs for
12619 // tls optimised sequences in the strategy methods, but for
12620 // now do as BFD ld does.
12621 r_type
= elfcpp::R_POWERPC_NONE
;
12625 // Get the new symbol index.
12626 Output_section
* os
= NULL
;
12627 if (r_sym
< local_count
)
12631 case Relocatable_relocs::RELOC_COPY
:
12632 case Relocatable_relocs::RELOC_SPECIAL
:
12635 r_sym
= object
->symtab_index(r_sym
);
12636 gold_assert(r_sym
!= -1U);
12640 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12642 // We are adjusting a section symbol. We need to find
12643 // the symbol table index of the section symbol for
12644 // the output section corresponding to input section
12645 // in which this symbol is defined.
12646 gold_assert(r_sym
< local_count
);
12648 unsigned int shndx
=
12649 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12650 gold_assert(is_ordinary
);
12651 os
= object
->output_section(shndx
);
12652 gold_assert(os
!= NULL
);
12653 gold_assert(os
->needs_symtab_index());
12654 r_sym
= os
->symtab_index();
12659 gold_unreachable();
12664 gsym
= object
->global_symbol(r_sym
);
12665 gold_assert(gsym
!= NULL
);
12666 if (gsym
->is_forwarder())
12667 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12669 gold_assert(gsym
->has_symtab_index());
12670 r_sym
= gsym
->symtab_index();
12673 // Get the new offset--the location in the output section where
12674 // this relocation should be applied.
12675 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12676 offset
+= offset_in_output_section
;
12679 section_offset_type sot_offset
=
12680 convert_types
<section_offset_type
, Address
>(offset
);
12681 section_offset_type new_sot_offset
=
12682 output_section
->output_offset(object
, relinfo
->data_shndx
,
12684 gold_assert(new_sot_offset
!= -1);
12685 offset
= new_sot_offset
;
12688 // In an object file, r_offset is an offset within the section.
12689 // In an executable or dynamic object, generated by
12690 // --emit-relocs, r_offset is an absolute address.
12693 offset
+= view_address
;
12694 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12695 offset
-= offset_in_output_section
;
12698 // Handle the reloc addend based on the strategy.
12699 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12701 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12703 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12704 addend
= psymval
->value(object
, addend
);
12705 // In a relocatable link, the symbol value is relative to
12706 // the start of the output section. For a non-relocatable
12707 // link, we need to adjust the addend.
12710 gold_assert(os
!= NULL
);
12711 addend
-= os
->address();
12714 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12718 if (addend
>= 32768)
12719 addend
+= got2_addend
;
12721 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12723 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12724 addend
-= d_offset
;
12726 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12728 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12729 addend
-= d_offset
+ 4;
12733 gold_unreachable();
12737 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12738 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12739 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12740 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12742 // First instruction of a global dynamic sequence,
12744 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12745 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12748 case tls::TLSOPT_TO_IE
:
12749 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12750 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12752 case tls::TLSOPT_TO_LE
:
12753 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12754 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12755 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12758 r_type
= elfcpp::R_POWERPC_NONE
;
12759 offset
-= d_offset
;
12766 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12767 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12768 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12769 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12771 // First instruction of a local dynamic sequence,
12773 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12774 if (tls_type
== tls::TLSOPT_TO_LE
)
12776 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12777 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12779 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12780 const Output_section
* os
= relinfo
->layout
->tls_segment()
12782 gold_assert(os
!= NULL
);
12783 gold_assert(os
->needs_symtab_index());
12784 r_sym
= os
->symtab_index();
12785 addend
= dtp_offset
;
12789 r_type
= elfcpp::R_POWERPC_NONE
;
12790 offset
-= d_offset
;
12794 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12795 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12796 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12797 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12799 // First instruction of initial exec sequence.
12800 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12801 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12803 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12804 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12805 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12808 r_type
= elfcpp::R_POWERPC_NONE
;
12809 offset
-= d_offset
;
12813 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12814 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12816 // Second instruction of a global dynamic sequence,
12817 // the __tls_get_addr call
12818 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12819 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12822 case tls::TLSOPT_TO_IE
:
12823 r_type
= elfcpp::R_POWERPC_NONE
;
12826 case tls::TLSOPT_TO_LE
:
12827 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12828 offset
+= d_offset
;
12835 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12836 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12838 // Second instruction of a local dynamic sequence,
12839 // the __tls_get_addr call
12840 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12841 if (tls_type
== tls::TLSOPT_TO_LE
)
12843 const Output_section
* os
= relinfo
->layout
->tls_segment()
12845 gold_assert(os
!= NULL
);
12846 gold_assert(os
->needs_symtab_index());
12847 r_sym
= os
->symtab_index();
12848 addend
= dtp_offset
;
12849 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12850 offset
+= d_offset
;
12854 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12856 // Second instruction of an initial exec sequence
12857 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12858 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12860 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12861 offset
+= d_offset
;
12866 reloc_write
.put_r_offset(offset
);
12867 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12868 reloc_write
.put_r_addend(addend
);
12870 pwrite
+= reloc_size
;
12873 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12874 == reloc_view_size
);
12877 // Return the value to use for a dynamic symbol which requires special
12878 // treatment. This is how we support equality comparisons of function
12879 // pointers across shared library boundaries, as described in the
12880 // processor specific ABI supplement.
12882 template<int size
, bool big_endian
>
12884 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12888 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12889 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12890 p
!= this->stub_tables_
.end();
12893 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12894 = (*p
)->find_plt_call_entry(gsym
);
12896 return (*p
)->stub_address() + ent
->off_
;
12899 else if (this->abiversion() >= 2)
12901 Address off
= this->glink_section()->find_global_entry(gsym
);
12902 if (off
!= invalid_address
)
12903 return this->glink_section()->global_entry_address() + off
;
12905 gold_unreachable();
12908 // Return the PLT address to use for a local symbol.
12909 template<int size
, bool big_endian
>
12911 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12912 const Relobj
* object
,
12913 unsigned int symndx
) const
12917 const Sized_relobj
<size
, big_endian
>* relobj
12918 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12919 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12920 p
!= this->stub_tables_
.end();
12923 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12924 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12926 return (*p
)->stub_address() + ent
->off_
;
12929 gold_unreachable();
12932 // Return the PLT address to use for a global symbol.
12933 template<int size
, bool big_endian
>
12935 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12936 const Symbol
* gsym
) const
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(gsym
);
12947 return (*p
)->stub_address() + ent
->off_
;
12950 else if (this->abiversion() >= 2)
12952 Address off
= this->glink_section()->find_global_entry(gsym
);
12953 if (off
!= invalid_address
)
12954 return this->glink_section()->global_entry_address() + off
;
12956 gold_unreachable();
12959 // Return the offset to use for the GOT_INDX'th got entry which is
12960 // for a local tls symbol specified by OBJECT, SYMNDX.
12961 template<int size
, bool big_endian
>
12963 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12964 const Relobj
* object
,
12965 unsigned int symndx
,
12966 Output_data_got_base
* got
,
12967 unsigned int got_indx
,
12968 uint64_t addend
) const
12970 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12971 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12972 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12974 for (Got_type got_type
= (size
== 32
12975 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
12976 got_type
<= GOT_TYPE_SMALL_TPREL
;
12977 got_type
= Got_type(got_type
+ 1))
12978 if (got_type
!= GOT_TYPE_SMALL
12979 && ppc_object
->local_has_got_offset(symndx
, got_type
, addend
))
12982 = ppc_object
->local_got_offset(symndx
, got_type
, addend
);
12983 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
12985 if (off
== got_indx
* (size
/ 8)
12986 && (size
== 32 || got
== this->got_section(got_type
)))
12988 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
12991 return -dtp_offset
;
12995 gold_unreachable();
12998 // Return the offset to use for the GOT_INDX'th got entry which is
12999 // for global tls symbol GSYM.
13000 template<int size
, bool big_endian
>
13002 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
13004 Output_data_got_base
* got
,
13005 unsigned int got_indx
,
13006 uint64_t addend
) const
13008 if (gsym
->type() == elfcpp::STT_TLS
)
13010 for (Got_type got_type
= (size
== 32
13011 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
13012 got_type
<= GOT_TYPE_SMALL_TPREL
;
13013 got_type
= Got_type(got_type
+ 1))
13014 if (got_type
!= GOT_TYPE_SMALL
13015 && gsym
->has_got_offset(got_type
, addend
))
13017 unsigned int off
= gsym
->got_offset(got_type
, addend
);
13018 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
13020 if (off
== got_indx
* (size
/ 8)
13021 && (size
== 32 || got
== this->got_section(got_type
)))
13023 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
13026 return -dtp_offset
;
13030 gold_unreachable();
13033 // The selector for powerpc object files.
13035 template<int size
, bool big_endian
>
13036 class Target_selector_powerpc
: public Target_selector
13039 Target_selector_powerpc()
13040 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
13043 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
13044 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
13046 ? (big_endian
? "elf64ppc" : "elf64lppc")
13047 : (big_endian
? "elf32ppc" : "elf32lppc")))
13051 do_instantiate_target()
13052 { return new Target_powerpc
<size
, big_endian
>(); }
13055 Target_selector_powerpc
<32, true> target_selector_ppc32
;
13056 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
13057 Target_selector_powerpc
<64, true> target_selector_ppc64
;
13058 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
13060 // Instantiate these constants for -O0
13061 template<int size
, bool big_endian
>
13062 const typename Output_data_glink
<size
, big_endian
>::Address
13063 Output_data_glink
<size
, big_endian
>::invalid_address
;
13064 template<int size
, bool big_endian
>
13065 const typename Stub_table
<size
, big_endian
>::Address
13066 Stub_table
<size
, big_endian
>::invalid_address
;
13067 template<int size
, bool big_endian
>
13068 const typename Target_powerpc
<size
, big_endian
>::Address
13069 Target_powerpc
<size
, big_endian
>::invalid_address
;
13071 } // End anonymous namespace.