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();
931 *sec
= this->plt_section();
932 return gsym
->plt_offset();
935 // Return the plt offset and section for the given local sym.
937 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
938 unsigned int local_sym_index
,
939 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
941 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
942 if (lsym
->is_ifunc_symbol())
943 *sec
= this->iplt_section();
945 *sec
= this->lplt_section();
946 return relobj
->local_plt_offset(local_sym_index
);
949 // Get the .glink section.
950 const Output_data_glink
<size
, big_endian
>*
951 glink_section() const
953 gold_assert(this->glink_
!= NULL
);
957 Output_data_glink
<size
, big_endian
>*
960 gold_assert(this->glink_
!= NULL
);
964 bool has_glink() const
965 { return this->glink_
!= NULL
; }
967 // Get the GOT section.
968 const Output_data_got_powerpc
<size
, big_endian
>*
969 got_section(Got_type got_type
) const
971 gold_assert(this->got_
!= NULL
);
972 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
974 gold_assert(this->biggot_
!= NULL
);
975 return this->biggot_
;
978 // Get the GOT section, creating it if necessary.
979 Output_data_got_powerpc
<size
, big_endian
>*
980 got_section(Symbol_table
*, Layout
*, Got_type
);
982 // The toc/got pointer reg will be set to this value.
986 return this->got_
->address() + this->got_
->g_o_t();
989 // Offset of base used to access the GOT/TOC relative to the GOT section.
991 got_base_offset(Got_type got_type
) const
993 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
994 return this->got_
->g_o_t();
995 return this->toc_pointer() - this->biggot_
->address();
999 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1000 const elfcpp::Ehdr
<size
, big_endian
>&);
1002 // Return the number of entries in the GOT.
1004 got_entry_count() const
1006 if (this->got_
== NULL
)
1008 return this->got_size() / (size
/ 8);
1011 // Return the number of entries in the PLT.
1013 plt_entry_count() const;
1015 // Return the offset of the first non-reserved PLT entry.
1017 first_plt_entry_offset() const
1021 if (this->abiversion() >= 2)
1026 // Return the size of each PLT entry.
1028 plt_entry_size() const
1032 if (this->abiversion() >= 2)
1037 Output_data_save_res
<size
, big_endian
>*
1038 savres_section() const
1040 return this->savres_section_
;
1043 // Add any special sections for this symbol to the gc work list.
1044 // For powerpc64, this adds the code section of a function
1047 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1049 // Handle target specific gc actions when adding a gc reference from
1050 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1051 // and DST_OFF. For powerpc64, this adds a referenc to the code
1052 // section of a function descriptor.
1054 do_gc_add_reference(Symbol_table
* symtab
,
1056 unsigned int src_shndx
,
1058 unsigned int dst_shndx
,
1059 Address dst_off
) const;
1061 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1064 { return this->stub_tables_
; }
1066 const Output_data_brlt_powerpc
<size
, big_endian
>*
1067 brlt_section() const
1068 { return this->brlt_section_
; }
1071 add_branch_lookup_table(Address to
)
1073 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1074 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1078 find_branch_lookup_table(Address to
)
1080 typename
Branch_lookup_table::const_iterator p
1081 = this->branch_lookup_table_
.find(to
);
1082 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1086 write_branch_lookup_table(unsigned char *oview
)
1088 for (typename
Branch_lookup_table::const_iterator p
1089 = this->branch_lookup_table_
.begin();
1090 p
!= this->branch_lookup_table_
.end();
1093 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1097 // Wrapper used after relax to define a local symbol in output data,
1098 // from the end if value < 0.
1100 define_local(Symbol_table
* symtab
, const char* name
,
1101 Output_data
* od
, Address value
, unsigned int symsize
)
1104 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1105 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1106 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1107 static_cast<Signed_address
>(value
) < 0,
1109 // We are creating this symbol late, so need to fix up things
1110 // done early in Layout::finalize.
1111 sym
->set_dynsym_index(-1U);
1115 set_power10_relocs()
1117 this->power10_relocs_
= true;
1121 power10_stubs() const
1123 return (this->power10_relocs_
1124 && (parameters
->options().power10_stubs_enum()
1125 != General_options::POWER10_STUBS_NO
));
1129 power10_stubs_auto() const
1131 return (parameters
->options().power10_stubs_enum()
1132 == General_options::POWER10_STUBS_AUTO
);
1136 plt_thread_safe() const
1137 { return this->plt_thread_safe_
; }
1140 plt_localentry0() const
1141 { return this->plt_localentry0_
; }
1144 has_localentry0() const
1145 { return this->has_localentry0_
; }
1148 set_has_localentry0()
1150 this->has_localentry0_
= true;
1154 is_elfv2_localentry0(const Symbol
* gsym
) const
1157 && this->abiversion() >= 2
1158 && this->plt_localentry0()
1159 && gsym
->type() == elfcpp::STT_FUNC
1160 && gsym
->is_defined()
1161 && gsym
->nonvis() >> 3 == 0
1162 && !gsym
->non_zero_localentry());
1166 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1167 unsigned int r_sym
) const
1169 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1170 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1173 && this->abiversion() >= 2
1174 && this->plt_localentry0()
1175 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1177 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1179 if (!psymval
->is_ifunc_symbol()
1180 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1189 { return !this->no_tprel_opt_
&& parameters
->options().tls_optimize(); }
1193 { this->no_tprel_opt_
= true; }
1195 // Remember any symbols seen with non-zero localentry, even those
1196 // not providing a definition
1198 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1203 unsigned char st_other
= sym
.get_st_other();
1204 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1205 to
->set_non_zero_localentry();
1207 // We haven't resolved anything, continue normal processing.
1213 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1216 set_abiversion(int ver
)
1218 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1219 flags
&= ~elfcpp::EF_PPC64_ABI
;
1220 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1221 this->set_processor_specific_flags(flags
);
1225 tls_get_addr_opt() const
1226 { return this->tls_get_addr_opt_
; }
1229 tls_get_addr() const
1230 { return this->tls_get_addr_
; }
1232 // If optimizing __tls_get_addr calls, whether this is the
1233 // "__tls_get_addr" symbol.
1235 is_tls_get_addr_opt(const Symbol
* gsym
) const
1237 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1238 || gsym
== this->tls_get_addr_opt_
);
1242 replace_tls_get_addr(const Symbol
* gsym
) const
1243 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1246 set_has_tls_get_addr_opt()
1247 { this->has_tls_get_addr_opt_
= true; }
1249 // Offset to toc save stack slot
1252 { return this->abiversion() < 2 ? 40 : 24; }
1254 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1255 // so use the CR save slot. Used only by __tls_get_addr call stub,
1256 // relying on __tls_get_addr not saving CR itself.
1259 { return this->abiversion() < 2 ? 32 : 8; }
1261 // Merge object attributes from input object with those in the output.
1263 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1279 : tls_get_addr_state_(NOT_EXPECTED
),
1280 relinfo_(NULL
), relnum_(0), r_offset_(0)
1285 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1292 if (this->relinfo_
!= NULL
)
1293 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1294 _("missing expected __tls_get_addr call"));
1298 expect_tls_get_addr_call(
1299 const Relocate_info
<size
, big_endian
>* relinfo
,
1303 this->tls_get_addr_state_
= EXPECTED
;
1304 this->relinfo_
= relinfo
;
1305 this->relnum_
= relnum
;
1306 this->r_offset_
= r_offset
;
1310 expect_tls_get_addr_call()
1311 { this->tls_get_addr_state_
= EXPECTED
; }
1314 skip_next_tls_get_addr_call()
1315 {this->tls_get_addr_state_
= SKIP
; }
1318 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1319 unsigned int r_type
, const Symbol
* gsym
)
1322 = ((r_type
== elfcpp::R_POWERPC_REL24
1323 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1324 || r_type
== elfcpp::R_PPC_PLTREL24
1325 || is_plt16_reloc
<size
>(r_type
)
1326 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1327 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1328 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1329 || r_type
== elfcpp::R_POWERPC_PLTCALL
1330 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1331 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1333 && (gsym
== target
->tls_get_addr()
1334 || gsym
== target
->tls_get_addr_opt()));
1335 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1336 this->tls_get_addr_state_
= NOT_EXPECTED
;
1337 if (is_tls_call
&& last_tls
!= EXPECTED
)
1339 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1348 // What we're up to regarding calls to __tls_get_addr.
1349 // On powerpc, the branch and link insn making a call to
1350 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1351 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1352 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1353 // The marker relocation always comes first, and has the same
1354 // symbol as the reloc on the insn setting up the __tls_get_addr
1355 // argument. This ties the arg setup insn with the call insn,
1356 // allowing ld to safely optimize away the call. We check that
1357 // every call to __tls_get_addr has a marker relocation, and that
1358 // every marker relocation is on a call to __tls_get_addr.
1359 Tls_get_addr tls_get_addr_state_
;
1360 // Info about the last reloc for error message.
1361 const Relocate_info
<size
, big_endian
>* relinfo_
;
1366 // The class which scans relocations.
1367 class Scan
: protected Track_tls
1370 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1373 : Track_tls(), issued_non_pic_error_(false)
1377 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1380 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1381 Sized_relobj_file
<size
, big_endian
>* object
,
1382 unsigned int data_shndx
,
1383 Output_section
* output_section
,
1384 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1385 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1389 global(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
,
1397 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1399 Sized_relobj_file
<size
, big_endian
>* relobj
,
1402 const elfcpp::Rela
<size
, big_endian
>& ,
1403 unsigned int r_type
,
1404 const elfcpp::Sym
<size
, big_endian
>&)
1406 // PowerPC64 .opd is not folded, so any identical function text
1407 // may be folded and we'll still keep function addresses distinct.
1408 // That means no reloc is of concern here.
1411 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1412 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1413 if (ppcobj
->abiversion() == 1)
1416 // For 32-bit and ELFv2, conservatively assume anything but calls to
1417 // function code might be taking the address of the function.
1418 return !is_branch_reloc
<size
>(r_type
);
1422 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1424 Sized_relobj_file
<size
, big_endian
>* relobj
,
1427 const elfcpp::Rela
<size
, big_endian
>& ,
1428 unsigned int r_type
,
1434 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1435 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1436 if (ppcobj
->abiversion() == 1)
1439 return !is_branch_reloc
<size
>(r_type
);
1443 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1444 Sized_relobj_file
<size
, big_endian
>* object
,
1445 unsigned int r_type
, bool report_err
);
1449 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1450 unsigned int r_type
);
1453 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1454 unsigned int r_type
, Symbol
*);
1457 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1458 Target_powerpc
* target
);
1461 check_non_pic(Relobj
*, unsigned int r_type
);
1463 // Whether we have issued an error about a non-PIC compilation.
1464 bool issued_non_pic_error_
;
1468 symval_for_branch(const Symbol_table
* symtab
,
1469 const Sized_symbol
<size
>* gsym
,
1470 Powerpc_relobj
<size
, big_endian
>* object
,
1471 Address
*value
, unsigned int *dest_shndx
);
1473 // The class which implements relocation.
1474 class Relocate
: protected Track_tls
1477 // Use 'at' branch hints when true, 'y' when false.
1478 // FIXME maybe: set this with an option.
1479 static const bool is_isa_v2
= true;
1485 // Do a relocation. Return false if the caller should not issue
1486 // any warnings about this relocation.
1488 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1489 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1490 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1491 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1495 class Relocate_comdat_behavior
1498 // Decide what the linker should do for relocations that refer to
1499 // discarded comdat sections.
1500 inline Comdat_behavior
1501 get(const char* name
)
1503 gold::Default_comdat_behavior default_behavior
;
1504 Comdat_behavior ret
= default_behavior
.get(name
);
1505 if (ret
== CB_ERROR
)
1508 && (strcmp(name
, ".fixup") == 0
1509 || strcmp(name
, ".got2") == 0))
1512 && (strcmp(name
, ".opd") == 0
1513 || strcmp(name
, ".toc") == 0
1514 || strcmp(name
, ".toc1") == 0))
1521 // Optimize the TLS relocation type based on what we know about the
1522 // symbol. IS_FINAL is true if the final address of this symbol is
1523 // known at link time.
1525 tls::Tls_optimization
1526 optimize_tls_gd(bool is_final
)
1528 // If we are generating a shared library, then we can't do anything
1530 if (parameters
->options().shared()
1531 || !parameters
->options().tls_optimize())
1532 return tls::TLSOPT_NONE
;
1535 return tls::TLSOPT_TO_IE
;
1536 return tls::TLSOPT_TO_LE
;
1539 tls::Tls_optimization
1542 if (parameters
->options().shared()
1543 || !parameters
->options().tls_optimize())
1544 return tls::TLSOPT_NONE
;
1546 return tls::TLSOPT_TO_LE
;
1549 tls::Tls_optimization
1550 optimize_tls_ie(bool is_final
)
1553 || parameters
->options().shared()
1554 || !parameters
->options().tls_optimize())
1555 return tls::TLSOPT_NONE
;
1557 return tls::TLSOPT_TO_LE
;
1562 make_glink_section(Layout
*);
1564 // Create the PLT section.
1566 make_plt_section(Symbol_table
*, Layout
*);
1569 make_iplt_section(Symbol_table
*, Layout
*);
1572 make_lplt_section(Layout
*);
1575 make_brlt_section(Layout
*);
1577 // Create a PLT entry for a global symbol.
1579 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1581 // Create a PLT entry for a local IFUNC symbol.
1583 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1584 Sized_relobj_file
<size
, big_endian
>*,
1587 // Create a PLT entry for a local non-IFUNC symbol.
1589 make_local_plt_entry(Layout
*,
1590 Sized_relobj_file
<size
, big_endian
>*,
1594 // Create a GOT entry for local dynamic __tls_get_addr.
1596 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1597 Sized_relobj_file
<size
, big_endian
>* object
);
1600 tlsld_got_offset() const
1602 return this->tlsld_got_offset_
;
1605 // Get the dynamic reloc section, creating it if necessary.
1607 rela_dyn_section(Layout
*);
1609 // Similarly, but for ifunc symbols get the one for ifunc.
1611 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1613 // Copy a relocation against a global symbol.
1615 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1616 Sized_relobj_file
<size
, big_endian
>* object
,
1617 unsigned int shndx
, Output_section
* output_section
,
1618 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1620 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1621 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1622 symtab
->get_sized_symbol
<size
>(sym
),
1623 object
, shndx
, output_section
,
1624 r_type
, reloc
.get_r_offset(),
1625 reloc
.get_r_addend(),
1626 this->rela_dyn_section(layout
));
1629 // Look over all the input sections, deciding where to place stubs.
1631 group_sections(Layout
*, const Task
*, bool);
1633 // Sort output sections by address.
1634 struct Sort_sections
1637 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1638 { return sec1
->address() < sec2
->address(); }
1644 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1645 unsigned int data_shndx
,
1647 unsigned int r_type
,
1650 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1651 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1657 // Return whether this branch is going via a plt call stub, and if
1658 // so, mark it as having an R_PPC64_TOCSAVE.
1660 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1661 unsigned int shndx
, Address offset
,
1662 Target_powerpc
* target
, Symbol_table
* symtab
);
1664 // If this branch needs a plt call stub, or a long branch stub, make one.
1666 make_stub(Stub_table
<size
, big_endian
>*,
1667 Stub_table
<size
, big_endian
>*,
1668 Symbol_table
*) const;
1671 // The branch location..
1672 Powerpc_relobj
<size
, big_endian
>* object_
;
1673 unsigned int shndx_
;
1675 // ..and the branch type and destination.
1676 unsigned int r_type_
: 31;
1677 unsigned int tocsave_
: 1;
1678 unsigned int r_sym_
;
1682 // Information about this specific target which we pass to the
1683 // general Target structure.
1684 static Target::Target_info powerpc_info
;
1686 // The small GOT section used by ppc32, and by ppc64 for entries that
1687 // must be addresseed +/-32k from the got pointer.
1688 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1689 // Another GOT section used for entries that can be addressed +/- 2G
1690 // from the got pointer.
1691 Output_data_got_powerpc
<size
, big_endian
>* biggot_
;
1693 // The PLT section. This is a container for a table of addresses,
1694 // and their relocations. Each address in the PLT has a dynamic
1695 // relocation (R_*_JMP_SLOT) and each address will have a
1696 // corresponding entry in .glink for lazy resolution of the PLT.
1697 // ppc32 initialises the PLT to point at the .glink entry, while
1698 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1699 // linker adds a stub that loads the PLT entry into ctr then
1700 // branches to ctr. There may be more than one stub for each PLT
1701 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1702 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1703 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1704 // The IPLT section. Like plt_, this is a container for a table of
1705 // addresses and their relocations, specifically for STT_GNU_IFUNC
1706 // functions that resolve locally (STT_GNU_IFUNC functions that
1707 // don't resolve locally go in PLT). Unlike plt_, these have no
1708 // entry in .glink for lazy resolution, and the relocation section
1709 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1710 // the relocation section may contain relocations against
1711 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1712 // relocation section will appear at the end of other dynamic
1713 // relocations, so that ld.so applies these relocations after other
1714 // dynamic relocations. In a static executable, the relocation
1715 // section is emitted and marked with __rela_iplt_start and
1716 // __rela_iplt_end symbols.
1717 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1718 // A PLT style section for local, non-ifunc symbols
1719 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1720 // Section holding long branch destinations.
1721 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1722 // The .glink section.
1723 Output_data_glink
<size
, big_endian
>* glink_
;
1724 // The dynamic reloc section.
1725 Reloc_section
* rela_dyn_
;
1726 // Relocs saved to avoid a COPY reloc.
1727 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1728 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1729 unsigned int tlsld_got_offset_
;
1731 Stub_tables stub_tables_
;
1732 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1733 Branch_lookup_table branch_lookup_table_
;
1735 typedef std::vector
<Branch_info
> Branches
;
1736 Branches branch_info_
;
1737 Tocsave_loc tocsave_loc_
;
1739 bool power10_relocs_
;
1740 bool plt_thread_safe_
;
1741 bool plt_localentry0_
;
1742 bool plt_localentry0_init_
;
1743 bool has_localentry0_
;
1744 bool has_tls_get_addr_opt_
;
1748 int relax_fail_count_
;
1749 int32_t stub_group_size_
;
1751 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1753 // The "__tls_get_addr" symbol, if present
1754 Symbol
* tls_get_addr_
;
1755 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1756 Symbol
* tls_get_addr_opt_
;
1758 // Attributes in output.
1759 Attributes_section_data
* attributes_section_data_
;
1761 // Last input file to change various attribute tags
1762 const char* last_fp_
;
1763 const char* last_ld_
;
1764 const char* last_vec_
;
1765 const char* last_struct_
;
1769 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1772 true, // is_big_endian
1773 elfcpp::EM_PPC
, // machine_code
1774 false, // has_make_symbol
1775 false, // has_resolve
1776 false, // has_code_fill
1777 true, // is_default_stack_executable
1778 false, // can_icf_inline_merge_sections
1780 "/usr/lib/ld.so.1", // dynamic_linker
1781 0x10000000, // default_text_segment_address
1782 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1783 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1784 false, // isolate_execinstr
1786 elfcpp::SHN_UNDEF
, // small_common_shndx
1787 elfcpp::SHN_UNDEF
, // large_common_shndx
1788 0, // small_common_section_flags
1789 0, // large_common_section_flags
1790 NULL
, // attributes_section
1791 NULL
, // attributes_vendor
1792 "_start", // entry_symbol_name
1793 32, // hash_entry_size
1794 elfcpp::SHT_PROGBITS
, // unwind_section_type
1798 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1801 false, // is_big_endian
1802 elfcpp::EM_PPC
, // machine_code
1803 false, // has_make_symbol
1804 false, // has_resolve
1805 false, // has_code_fill
1806 true, // is_default_stack_executable
1807 false, // can_icf_inline_merge_sections
1809 "/usr/lib/ld.so.1", // dynamic_linker
1810 0x10000000, // default_text_segment_address
1811 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1812 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1813 false, // isolate_execinstr
1815 elfcpp::SHN_UNDEF
, // small_common_shndx
1816 elfcpp::SHN_UNDEF
, // large_common_shndx
1817 0, // small_common_section_flags
1818 0, // large_common_section_flags
1819 NULL
, // attributes_section
1820 NULL
, // attributes_vendor
1821 "_start", // entry_symbol_name
1822 32, // hash_entry_size
1823 elfcpp::SHT_PROGBITS
, // unwind_section_type
1827 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1830 true, // is_big_endian
1831 elfcpp::EM_PPC64
, // machine_code
1832 false, // has_make_symbol
1833 true, // has_resolve
1834 false, // has_code_fill
1835 false, // is_default_stack_executable
1836 false, // can_icf_inline_merge_sections
1838 "/usr/lib/ld.so.1", // dynamic_linker
1839 0x10000000, // default_text_segment_address
1840 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1841 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1842 false, // isolate_execinstr
1844 elfcpp::SHN_UNDEF
, // small_common_shndx
1845 elfcpp::SHN_UNDEF
, // large_common_shndx
1846 0, // small_common_section_flags
1847 0, // large_common_section_flags
1848 NULL
, // attributes_section
1849 NULL
, // attributes_vendor
1850 "_start", // entry_symbol_name
1851 32, // hash_entry_size
1852 elfcpp::SHT_PROGBITS
, // unwind_section_type
1856 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1859 false, // is_big_endian
1860 elfcpp::EM_PPC64
, // machine_code
1861 false, // has_make_symbol
1862 true, // has_resolve
1863 false, // has_code_fill
1864 false, // is_default_stack_executable
1865 false, // can_icf_inline_merge_sections
1867 "/usr/lib/ld.so.1", // dynamic_linker
1868 0x10000000, // default_text_segment_address
1869 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1870 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1871 false, // isolate_execinstr
1873 elfcpp::SHN_UNDEF
, // small_common_shndx
1874 elfcpp::SHN_UNDEF
, // large_common_shndx
1875 0, // small_common_section_flags
1876 0, // large_common_section_flags
1877 NULL
, // attributes_section
1878 NULL
, // attributes_vendor
1879 "_start", // entry_symbol_name
1880 32, // hash_entry_size
1881 elfcpp::SHT_PROGBITS
, // unwind_section_type
1886 is_branch_reloc(unsigned int r_type
)
1888 return (r_type
== elfcpp::R_POWERPC_REL24
1889 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1890 || r_type
== elfcpp::R_PPC_PLTREL24
1891 || r_type
== elfcpp::R_PPC_LOCAL24PC
1892 || r_type
== elfcpp::R_POWERPC_REL14
1893 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1894 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1895 || r_type
== elfcpp::R_POWERPC_ADDR24
1896 || r_type
== elfcpp::R_POWERPC_ADDR14
1897 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1898 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1901 // Reloc resolves to plt entry.
1904 is_plt16_reloc(unsigned int r_type
)
1906 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1907 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1908 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1909 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1912 // GOT_TYPE_STANDARD or GOT_TYPE_SMALL (ie. not TLS) GOT relocs
1914 is_got_reloc(unsigned int r_type
)
1916 return (r_type
== elfcpp::R_POWERPC_GOT16
1917 || r_type
== elfcpp::R_POWERPC_GOT16_LO
1918 || r_type
== elfcpp::R_POWERPC_GOT16_HI
1919 || r_type
== elfcpp::R_POWERPC_GOT16_HA
1920 || r_type
== elfcpp::R_PPC64_GOT16_DS
1921 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
1922 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
);
1925 // If INSN is an opcode that may be used with an @tls operand, return
1926 // the transformed insn for TLS optimisation, otherwise return 0. If
1927 // REG is non-zero only match an insn with RB or RA equal to REG.
1929 at_tls_transform(uint32_t insn
, unsigned int reg
)
1931 if ((insn
& (0x3f << 26)) != 31 << 26)
1935 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1936 rtra
= insn
& ((1 << 26) - (1 << 16));
1937 else if (((insn
>> 16) & 0x1f) == reg
)
1938 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1942 if ((insn
& (0x3ff << 1)) == 266 << 1)
1945 else if ((insn
& (0x1f << 1)) == 23 << 1
1946 && ((insn
& (0x1f << 6)) < 14 << 6
1947 || ((insn
& (0x1f << 6)) >= 16 << 6
1948 && (insn
& (0x1f << 6)) < 24 << 6)))
1949 // load and store indexed -> dform
1950 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1951 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1952 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1953 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1954 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1956 insn
= (58 << 26) | 2;
1964 template<int size
, bool big_endian
>
1965 class Powerpc_relocate_functions
1985 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1986 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1987 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1989 template<int valsize
>
1991 has_overflow_signed(Address value
)
1993 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1994 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1995 limit
<<= ((valsize
- 1) >> 1);
1996 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1997 return value
+ limit
> (limit
<< 1) - 1;
2000 template<int valsize
>
2002 has_overflow_unsigned(Address value
)
2004 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2005 limit
<<= ((valsize
- 1) >> 1);
2006 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2007 return value
> (limit
<< 1) - 1;
2010 template<int valsize
>
2012 has_overflow_bitfield(Address value
)
2014 return (has_overflow_unsigned
<valsize
>(value
)
2015 && has_overflow_signed
<valsize
>(value
));
2018 template<int valsize
>
2019 static inline Status
2020 overflowed(Address value
, Overflow_check overflow
)
2022 if (overflow
== CHECK_SIGNED
)
2024 if (has_overflow_signed
<valsize
>(value
))
2025 return STATUS_OVERFLOW
;
2027 else if (overflow
== CHECK_UNSIGNED
)
2029 if (has_overflow_unsigned
<valsize
>(value
))
2030 return STATUS_OVERFLOW
;
2032 else if (overflow
== CHECK_BITFIELD
)
2034 if (has_overflow_bitfield
<valsize
>(value
))
2035 return STATUS_OVERFLOW
;
2040 // Do a simple RELA relocation
2041 template<int fieldsize
, int valsize
>
2042 static inline Status
2043 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2045 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2046 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2047 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2048 return overflowed
<valsize
>(value
, overflow
);
2051 template<int fieldsize
, int valsize
>
2052 static inline Status
2053 rela(unsigned char* view
,
2054 unsigned int right_shift
,
2055 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2057 Overflow_check overflow
)
2059 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2060 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2061 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2062 if (overflow
== CHECK_SIGNED
)
2063 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2065 value
= value
>> right_shift
;
2066 Valtype reloc
= value
;
2069 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2070 return overflowed
<valsize
>(value
, overflow
);
2073 // Do a simple RELA relocation, unaligned.
2074 template<int fieldsize
, int valsize
>
2075 static inline Status
2076 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2078 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2079 return overflowed
<valsize
>(value
, overflow
);
2082 template<int fieldsize
, int valsize
>
2083 static inline Status
2084 rela_ua(unsigned char* view
,
2085 unsigned int right_shift
,
2086 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2088 Overflow_check overflow
)
2090 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2092 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2093 if (overflow
== CHECK_SIGNED
)
2094 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2096 value
= value
>> right_shift
;
2097 Valtype reloc
= value
;
2100 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2101 return overflowed
<valsize
>(value
, overflow
);
2105 // R_PPC64_ADDR64: (Symbol + Addend)
2107 addr64(unsigned char* view
, Address value
)
2108 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2110 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2112 addr64_u(unsigned char* view
, Address value
)
2113 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2115 // R_POWERPC_ADDR32: (Symbol + Addend)
2116 static inline Status
2117 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2118 { return This::template rela
<32,32>(view
, value
, overflow
); }
2120 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2121 static inline Status
2122 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2123 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2125 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2126 static inline Status
2127 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2129 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2131 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2132 stat
= STATUS_OVERFLOW
;
2136 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2137 static inline Status
2138 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2139 { return This::template rela
<16,16>(view
, value
, overflow
); }
2141 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2142 static inline Status
2143 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2144 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2146 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2147 static inline Status
2148 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2150 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2151 if ((value
& 3) != 0)
2152 stat
= STATUS_OVERFLOW
;
2156 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2157 static inline Status
2158 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2160 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2161 if ((value
& 15) != 0)
2162 stat
= STATUS_OVERFLOW
;
2166 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2168 addr16_hi(unsigned char* view
, Address value
)
2169 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2171 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2173 addr16_ha(unsigned char* view
, Address value
)
2174 { This::addr16_hi(view
, value
+ 0x8000); }
2176 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2178 addr16_hi2(unsigned char* view
, Address value
)
2179 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2181 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2183 addr16_ha2(unsigned char* view
, Address value
)
2184 { This::addr16_hi2(view
, value
+ 0x8000); }
2186 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2188 addr16_hi3(unsigned char* view
, Address value
)
2189 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2191 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2193 addr16_ha3(unsigned char* view
, Address value
)
2194 { This::addr16_hi3(view
, value
+ 0x8000); }
2196 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2197 static inline Status
2198 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2200 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2201 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2202 stat
= STATUS_OVERFLOW
;
2206 // R_POWERPC_REL16DX_HA
2207 static inline Status
2208 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2210 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2211 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2212 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2214 value
= static_cast<SignedAddress
>(value
) >> 16;
2215 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2216 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2217 return overflowed
<16>(value
, overflow
);
2221 static inline Status
2222 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2224 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2226 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2232 addr34_hi(unsigned char *view
, uint64_t value
)
2233 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2237 addr34_ha(unsigned char *view
, uint64_t value
)
2238 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2241 static inline Status
2242 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2244 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2246 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2250 // R_PPC64_ADDR16_HIGHER34
2252 addr16_higher34(unsigned char* view
, uint64_t value
)
2253 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2255 // R_PPC64_ADDR16_HIGHERA34
2257 addr16_highera34(unsigned char* view
, uint64_t value
)
2258 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2260 // R_PPC64_ADDR16_HIGHEST34
2262 addr16_highest34(unsigned char* view
, uint64_t value
)
2263 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2265 // R_PPC64_ADDR16_HIGHESTA34
2267 addr16_highesta34(unsigned char* view
, uint64_t value
)
2268 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2271 // Set ABI version for input and output.
2273 template<int size
, bool big_endian
>
2275 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2277 this->e_flags_
|= ver
;
2278 if (this->abiversion() != 0)
2280 Target_powerpc
<size
, big_endian
>* target
=
2281 static_cast<Target_powerpc
<size
, big_endian
>*>(
2282 parameters
->sized_target
<size
, big_endian
>());
2283 if (target
->abiversion() == 0)
2284 target
->set_abiversion(this->abiversion());
2285 else if (target
->abiversion() != this->abiversion())
2286 gold_error(_("%s: ABI version %d is not compatible "
2287 "with ABI version %d output"),
2288 this->name().c_str(),
2289 this->abiversion(), target
->abiversion());
2294 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2295 // relocatable object, if such sections exists.
2297 template<int size
, bool big_endian
>
2299 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2300 Read_symbols_data
* sd
)
2302 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2303 const unsigned char* namesu
= sd
->section_names
->data();
2304 const char* names
= reinterpret_cast<const char*>(namesu
);
2305 section_size_type names_size
= sd
->section_names_size
;
2306 const unsigned char* s
;
2308 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2309 size
== 32 ? ".got2" : ".opd",
2310 names
, names_size
, NULL
);
2313 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2314 this->special_
= ndx
;
2317 if (this->abiversion() == 0)
2318 this->set_abiversion(1);
2319 else if (this->abiversion() > 1)
2320 gold_error(_("%s: .opd invalid in abiv%d"),
2321 this->name().c_str(), this->abiversion());
2326 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2327 names
, names_size
, NULL
);
2330 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2331 this->relatoc_
= ndx
;
2332 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2333 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2336 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2339 // Examine .rela.opd to build info about function entry points.
2341 template<int size
, bool big_endian
>
2343 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2345 const unsigned char* prelocs
,
2346 const unsigned char* plocal_syms
)
2350 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2351 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2352 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2353 Address expected_off
= 0;
2354 bool regular
= true;
2355 unsigned int opd_ent_size
= 0;
2357 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2359 Reltype
reloc(prelocs
);
2360 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2361 = reloc
.get_r_info();
2362 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2363 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2365 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2366 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2369 if (r_sym
< this->local_symbol_count())
2371 typename
elfcpp::Sym
<size
, big_endian
>
2372 lsym(plocal_syms
+ r_sym
* sym_size
);
2373 shndx
= lsym
.get_st_shndx();
2374 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2375 value
= lsym
.get_st_value();
2378 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2380 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2381 value
+ reloc
.get_r_addend());
2384 expected_off
= reloc
.get_r_offset();
2385 opd_ent_size
= expected_off
;
2387 else if (expected_off
!= reloc
.get_r_offset())
2389 expected_off
+= opd_ent_size
;
2391 else if (r_type
== elfcpp::R_PPC64_TOC
)
2393 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2398 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2399 this->name().c_str(), r_type
);
2403 if (reloc_count
<= 2)
2404 opd_ent_size
= this->section_size(this->opd_shndx());
2405 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2409 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2410 this->name().c_str());
2416 // Returns true if a code sequence loading the TOC entry at VALUE
2417 // relative to the TOC pointer can be converted into code calculating
2418 // a TOC pointer relative offset.
2419 // If so, the TOC pointer relative offset is stored to VALUE.
2421 template<int size
, bool big_endian
>
2423 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2424 Target_powerpc
<size
, big_endian
>* target
,
2430 // With -mcmodel=medium code it is quite possible to have
2431 // toc-relative relocs referring to objects outside the TOC.
2432 // Don't try to look at a non-existent TOC.
2433 if (this->toc_shndx() == 0
2434 || this->output_section(this->toc_shndx()) == 0)
2437 // Convert VALUE back to an address by adding got_base (see below),
2438 // then to an offset in the TOC by subtracting the TOC output
2439 // section address and the TOC output offset.
2440 Address off
= (*value
+ target
->toc_pointer()
2441 - this->output_section(this->toc_shndx())->address()
2442 - this->output_section_offset(this->toc_shndx()));
2443 // Is this offset in the TOC? -mcmodel=medium code may be using
2444 // TOC relative access to variables outside the TOC. Those of
2445 // course can't be optimized. We also don't try to optimize code
2446 // that is using a different object's TOC.
2447 if (off
>= this->section_size(this->toc_shndx()))
2450 if (this->no_toc_opt(off
))
2453 section_size_type vlen
;
2454 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2455 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2457 Address got_base
= target
->toc_pointer();
2459 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2466 template<int size
, bool big_endian
>
2468 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2469 Target_powerpc
<size
, big_endian
>* target
,
2470 const Symbol_value
<size
>* psymval
,
2474 Address addr
= psymval
->value(this, addend
);
2475 Address got_base
= target
->toc_pointer();
2477 if (addr
+ 0x80008000 > 0xffffffff)
2484 // Perform the Sized_relobj_file method, then set up opd info from
2487 template<int size
, bool big_endian
>
2489 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2491 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2494 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2495 p
!= rd
->relocs
.end();
2498 if (p
->data_shndx
== this->opd_shndx())
2500 uint64_t opd_size
= this->section_size(this->opd_shndx());
2501 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2504 this->init_opd(opd_size
);
2505 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2506 rd
->local_symbols
->data());
2514 // Read the symbols then set up st_other vector.
2516 template<int size
, bool big_endian
>
2518 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2520 this->base_read_symbols(sd
);
2521 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2525 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2526 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2527 const unsigned int loccount
= this->do_local_symbol_count();
2530 this->st_other_
.resize(loccount
);
2531 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2532 off_t locsize
= loccount
* sym_size
;
2533 const unsigned int symtab_shndx
= this->symtab_shndx();
2534 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2535 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2536 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2537 locsize
, true, false);
2539 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2541 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2542 unsigned char st_other
= sym
.get_st_other();
2543 this->st_other_
[i
] = st_other
;
2544 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2546 if (this->abiversion() == 0)
2547 this->set_abiversion(2);
2548 else if (this->abiversion() < 2)
2549 gold_error(_("%s: local symbol %d has invalid st_other"
2550 " for ABI version 1"),
2551 this->name().c_str(), i
);
2557 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2558 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2559 bool merge_attributes
= false;
2560 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2562 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2563 switch (shdr
.get_sh_type())
2565 case elfcpp::SHT_GNU_ATTRIBUTES
:
2567 gold_assert(this->attributes_section_data_
== NULL
);
2568 section_offset_type section_offset
= shdr
.get_sh_offset();
2569 section_size_type section_size
=
2570 convert_to_section_size_type(shdr
.get_sh_size());
2571 const unsigned char* view
=
2572 this->get_view(section_offset
, section_size
, true, false);
2573 this->attributes_section_data_
=
2574 new Attributes_section_data(view
, section_size
);
2578 case elfcpp::SHT_SYMTAB
:
2580 // Sometimes an object has no contents except the section
2581 // name string table and an empty symbol table with the
2582 // undefined symbol. We don't want to merge
2583 // processor-specific flags from such an object.
2584 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2585 elfcpp::Elf_sizes
<size
>::sym_size
;
2586 if (shdr
.get_sh_size() > sym_size
)
2587 merge_attributes
= true;
2591 case elfcpp::SHT_STRTAB
:
2595 merge_attributes
= true;
2600 if (!merge_attributes
)
2602 // Should rarely happen.
2603 delete this->attributes_section_data_
;
2604 this->attributes_section_data_
= NULL
;
2608 template<int size
, bool big_endian
>
2610 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2612 this->e_flags_
|= ver
;
2613 if (this->abiversion() != 0)
2615 Target_powerpc
<size
, big_endian
>* target
=
2616 static_cast<Target_powerpc
<size
, big_endian
>*>(
2617 parameters
->sized_target
<size
, big_endian
>());
2618 if (target
->abiversion() == 0)
2619 target
->set_abiversion(this->abiversion());
2620 else if (target
->abiversion() != this->abiversion())
2621 gold_error(_("%s: ABI version %d is not compatible "
2622 "with ABI version %d output"),
2623 this->name().c_str(),
2624 this->abiversion(), target
->abiversion());
2629 // Call Sized_dynobj::base_read_symbols to read the symbols then
2630 // read .opd from a dynamic object, filling in opd_ent_ vector,
2632 template<int size
, bool big_endian
>
2634 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2636 this->base_read_symbols(sd
);
2637 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2638 const unsigned char* ps
=
2639 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2640 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2642 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2643 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2645 section_offset_type section_offset
= shdr
.get_sh_offset();
2646 section_size_type section_size
=
2647 convert_to_section_size_type(shdr
.get_sh_size());
2648 const unsigned char* view
=
2649 this->get_view(section_offset
, section_size
, true, false);
2650 this->attributes_section_data_
=
2651 new Attributes_section_data(view
, section_size
);
2657 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2658 const unsigned char* namesu
= sd
->section_names
->data();
2659 const char* names
= reinterpret_cast<const char*>(namesu
);
2660 const unsigned char* s
= NULL
;
2661 const unsigned char* opd
;
2662 section_size_type opd_size
;
2664 // Find and read .opd section.
2667 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2668 sd
->section_names_size
,
2673 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2674 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2675 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2677 if (this->abiversion() == 0)
2678 this->set_abiversion(1);
2679 else if (this->abiversion() > 1)
2680 gold_error(_("%s: .opd invalid in abiv%d"),
2681 this->name().c_str(), this->abiversion());
2683 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2684 this->opd_address_
= shdr
.get_sh_addr();
2685 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2686 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2692 // Build set of executable sections.
2693 // Using a set is probably overkill. There is likely to be only
2694 // a few executable sections, typically .init, .text and .fini,
2695 // and they are generally grouped together.
2696 typedef std::set
<Sec_info
> Exec_sections
;
2697 Exec_sections exec_sections
;
2699 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2701 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2702 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2703 && ((shdr
.get_sh_flags()
2704 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2705 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2706 && shdr
.get_sh_size() != 0)
2708 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2709 shdr
.get_sh_size(), i
));
2712 if (exec_sections
.empty())
2715 // Look over the OPD entries. This is complicated by the fact
2716 // that some binaries will use two-word entries while others
2717 // will use the standard three-word entries. In most cases
2718 // the third word (the environment pointer for languages like
2719 // Pascal) is unused and will be zero. If the third word is
2720 // used it should not be pointing into executable sections,
2722 this->init_opd(opd_size
);
2723 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2725 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2726 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2727 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2729 // Chances are that this is the third word of an OPD entry.
2731 typename
Exec_sections::const_iterator e
2732 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2733 if (e
!= exec_sections
.begin())
2736 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2738 // We have an address in an executable section.
2739 // VAL ought to be the function entry, set it up.
2740 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2741 // Skip second word of OPD entry, the TOC pointer.
2745 // If we didn't match any executable sections, we likely
2746 // have a non-zero third word in the OPD entry.
2751 // Relocate sections.
2753 template<int size
, bool big_endian
>
2755 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2756 const Symbol_table
* symtab
, const Layout
* layout
,
2757 const unsigned char* pshdrs
, Output_file
* of
,
2758 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2760 unsigned int start
= 1;
2762 && this->relatoc_
!= 0
2763 && !parameters
->options().relocatable())
2765 // Relocate .toc first.
2766 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2767 this->relatoc_
, this->relatoc_
);
2768 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2769 1, this->relatoc_
- 1);
2770 start
= this->relatoc_
+ 1;
2772 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2773 start
, this->shnum() - 1);
2775 if (!parameters
->options().output_is_position_independent())
2777 Target_powerpc
<size
, big_endian
>* target
2778 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2779 parameters
->sized_target
<size
, big_endian
>());
2780 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2782 const section_size_type offset
= target
->lplt_section()->offset();
2783 const section_size_type oview_size
2784 = convert_to_section_size_type(target
->lplt_section()->data_size());
2785 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2787 bool modified
= false;
2788 unsigned int nsyms
= this->local_symbol_count();
2789 for (unsigned int i
= 0; i
< nsyms
; i
++)
2790 if (this->local_has_plt_offset(i
))
2792 Address value
= this->local_symbol_value(i
, 0);
2793 size_t off
= this->local_plt_offset(i
);
2794 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2798 of
->write_output_view(offset
, oview_size
, oview
);
2803 // Set up some symbols.
2805 template<int size
, bool big_endian
>
2807 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2808 Symbol_table
* symtab
,
2813 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2814 // undefined when scanning relocs (and thus requires
2815 // non-relative dynamic relocs). The proper value will be
2817 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2818 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2820 Target_powerpc
<size
, big_endian
>* target
=
2821 static_cast<Target_powerpc
<size
, big_endian
>*>(
2822 parameters
->sized_target
<size
, big_endian
>());
2823 Output_data_got_powerpc
<size
, big_endian
>* got
2824 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
2825 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2826 Symbol_table::PREDEFINED
,
2830 elfcpp::STV_HIDDEN
, 0,
2834 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2835 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2836 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2838 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2840 = layout
->add_output_section_data(".sdata", 0,
2842 | elfcpp::SHF_WRITE
,
2843 sdata
, ORDER_SMALL_DATA
, false);
2844 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2845 Symbol_table::PREDEFINED
,
2846 os
, 32768, 0, elfcpp::STT_OBJECT
,
2847 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2853 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2854 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2855 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2857 Target_powerpc
<size
, big_endian
>* target
=
2858 static_cast<Target_powerpc
<size
, big_endian
>*>(
2859 parameters
->sized_target
<size
, big_endian
>());
2860 Output_data_got_powerpc
<size
, big_endian
>* got
2861 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
2862 symtab
->define_in_output_data(".TOC.", NULL
,
2863 Symbol_table::PREDEFINED
,
2867 elfcpp::STV_HIDDEN
, 0,
2872 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2873 if (parameters
->options().tls_get_addr_optimize()
2874 && this->tls_get_addr_
!= NULL
2875 && this->tls_get_addr_
->in_reg())
2876 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2877 if (this->tls_get_addr_opt_
!= NULL
)
2879 if (this->tls_get_addr_
->is_undefined()
2880 || this->tls_get_addr_
->is_from_dynobj())
2882 // Make it seem as if references to __tls_get_addr are
2883 // really to __tls_get_addr_opt, so the latter symbol is
2884 // made dynamic, not the former.
2885 this->tls_get_addr_
->clear_in_reg();
2886 this->tls_get_addr_opt_
->set_in_reg();
2888 // We have a non-dynamic definition for __tls_get_addr.
2889 // Make __tls_get_addr_opt the same, if it does not already have
2890 // a non-dynamic definition.
2891 else if (this->tls_get_addr_opt_
->is_undefined()
2892 || this->tls_get_addr_opt_
->is_from_dynobj())
2894 Sized_symbol
<size
>* from
2895 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2896 Sized_symbol
<size
>* to
2897 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2898 symtab
->clone
<size
>(to
, from
);
2903 // Set up PowerPC target specific relobj.
2905 template<int size
, bool big_endian
>
2907 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2908 const std::string
& name
,
2909 Input_file
* input_file
,
2910 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2912 int et
= ehdr
.get_e_type();
2913 // ET_EXEC files are valid input for --just-symbols/-R,
2914 // and we treat them as relocatable objects.
2915 if (et
== elfcpp::ET_REL
2916 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2918 Powerpc_relobj
<size
, big_endian
>* obj
=
2919 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2923 else if (et
== elfcpp::ET_DYN
)
2925 Powerpc_dynobj
<size
, big_endian
>* obj
=
2926 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2932 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2937 template<int size
, bool big_endian
>
2938 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2941 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2942 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2944 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
,
2946 : Output_data_got
<size
, big_endian
>(),
2947 symtab_(symtab
), layout_(layout
),
2948 header_ent_cnt_(size
== 32 ? 3 : 1),
2949 header_index_(size
== 32 ? 0x2000 : -1u)
2952 this->set_addralign(256);
2953 if (size
== 64 && (got_type
& GOT_TYPE_SMALL
))
2954 this->make_header();
2957 // Override all the Output_data_got methods we use so as to first call
2960 add_global(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2962 this->reserve_ent();
2963 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
,
2968 add_global_plt(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2970 this->reserve_ent();
2971 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
,
2976 add_global_tls(Symbol
* gsym
, unsigned int got_type
, uint64_t addend
)
2977 { return this->add_global_plt(gsym
, got_type
, addend
); }
2980 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2981 Output_data_reloc_generic
* rel_dyn
,
2982 unsigned int r_type
, uint64_t addend
)
2984 this->reserve_ent();
2985 Output_data_got
<size
, big_endian
>::
2986 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
, addend
);
2990 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2991 Output_data_reloc_generic
* rel_dyn
,
2992 unsigned int r_type_1
, unsigned int r_type_2
,
2995 if (gsym
->has_got_offset(got_type
))
2998 this->reserve_ent(2);
2999 Output_data_got
<size
, big_endian
>::
3000 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
,
3005 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
,
3008 this->reserve_ent();
3009 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
3014 add_local_plt(Relobj
* object
, unsigned int sym_index
,
3015 unsigned int got_type
, uint64_t addend
)
3017 this->reserve_ent();
3018 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
3023 add_local_tls(Relobj
* object
, unsigned int sym_index
,
3024 unsigned int got_type
, uint64_t addend
)
3025 { return this->add_local_plt(object
, sym_index
, got_type
, addend
); }
3028 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
3029 unsigned int got_type
,
3030 Output_data_reloc_generic
* rel_dyn
,
3031 unsigned int r_type
, uint64_t addend
)
3033 if (object
->local_has_got_offset(sym_index
, got_type
, addend
))
3036 this->reserve_ent(2);
3037 Output_data_got
<size
, big_endian
>::
3038 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
, addend
);
3042 add_constant(Valtype constant
)
3044 this->reserve_ent();
3045 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
3049 add_constant_pair(Valtype c1
, Valtype c2
)
3051 this->reserve_ent(2);
3052 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3055 // Offset of _GLOBAL_OFFSET_TABLE_ and .TOC. in this section.
3060 return this->got_offset(this->header_index_
);
3061 else if (this->header_index_
!= -1u)
3062 return this->got_offset(this->header_index_
) + 0x8000;
3067 // Ensure our GOT has a header.
3069 set_final_data_size()
3071 if (size
== 32 && this->header_ent_cnt_
!= 0)
3072 this->make_header();
3073 Output_data_got
<size
, big_endian
>::set_final_data_size();
3076 // First word of GOT header needs some values that are not
3077 // handled by Output_data_got so poke them in here.
3078 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3080 do_write(Output_file
* of
)
3082 if (this->header_index_
!= -1u)
3085 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3086 val
= this->layout_
->dynamic_section()->address();
3088 val
= this->address() + this->g_o_t();
3089 this->replace_constant(this->header_index_
, val
);
3091 Output_data_got
<size
, big_endian
>::do_write(of
);
3096 reserve_ent(unsigned int cnt
= 1)
3098 if (size
!= 32 || this->header_ent_cnt_
== 0)
3100 if (this->num_entries() + cnt
> this->header_index_
)
3101 this->make_header();
3107 this->header_ent_cnt_
= 0;
3108 this->header_index_
= this->num_entries();
3111 Output_data_got
<size
, big_endian
>::add_constant(0);
3112 Output_data_got
<size
, big_endian
>::add_constant(0);
3113 Output_data_got
<size
, big_endian
>::add_constant(0);
3115 // Define _GLOBAL_OFFSET_TABLE_ at the header
3116 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3119 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3120 sym
->set_value(this->g_o_t());
3123 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3124 Symbol_table::PREDEFINED
,
3125 this, this->g_o_t(), 0,
3128 elfcpp::STV_HIDDEN
, 0,
3132 Output_data_got
<size
, big_endian
>::add_constant(0);
3135 // Stashed pointers.
3136 Symbol_table
* symtab_
;
3140 unsigned int header_ent_cnt_
;
3141 // GOT header index.
3142 unsigned int header_index_
;
3145 // Get the GOT section, creating it if necessary.
3147 template<int size
, bool big_endian
>
3148 Output_data_got_powerpc
<size
, big_endian
>*
3149 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3153 if (this->got_
== NULL
)
3155 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3158 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
,
3161 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3162 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3163 this->got_
, ORDER_DATA
, false);
3166 if (size
== 32 || (got_type
& GOT_TYPE_SMALL
))
3169 if (this->biggot_
== NULL
)
3172 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
,
3175 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3176 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3177 this->biggot_
, ORDER_DATA
, false);
3180 return this->biggot_
;
3183 // Get the dynamic reloc section, creating it if necessary.
3185 template<int size
, bool big_endian
>
3186 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3187 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3189 if (this->rela_dyn_
== NULL
)
3191 gold_assert(layout
!= NULL
);
3192 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3193 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3194 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3195 ORDER_DYNAMIC_RELOCS
, false);
3197 return this->rela_dyn_
;
3200 // Similarly, but for ifunc symbols get the one for ifunc.
3202 template<int size
, bool big_endian
>
3203 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3204 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3209 return this->rela_dyn_section(layout
);
3211 if (this->iplt_
== NULL
)
3212 this->make_iplt_section(symtab
, layout
);
3213 return this->iplt_
->rel_plt();
3219 // Determine the stub group size. The group size is the absolute
3220 // value of the parameter --stub-group-size. If --stub-group-size
3221 // is passed a negative value, we restrict stubs to be always after
3222 // the stubbed branches.
3223 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3224 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3225 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3226 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3227 owner_(NULL
), output_section_(NULL
)
3231 // Return true iff input section can be handled by current stub
3234 can_add_to_stub_group(Output_section
* o
,
3235 const Output_section::Input_section
* i
,
3238 const Output_section::Input_section
*
3244 { return output_section_
; }
3247 set_output_and_owner(Output_section
* o
,
3248 const Output_section::Input_section
* i
)
3250 this->output_section_
= o
;
3259 // Adding group sections before the stubs.
3260 FINDING_STUB_SECTION
,
3261 // Adding group sections after the stubs.
3265 uint32_t stub_group_size_
;
3266 bool stubs_always_after_branch_
;
3267 bool suppress_size_errors_
;
3268 // True if a stub group can serve multiple output sections.
3271 // Current max size of group. Starts at stub_group_size_ but is
3272 // reduced to stub_group_size_/1024 on seeing a section with
3273 // external conditional branches.
3274 uint32_t group_size_
;
3275 uint64_t group_start_addr_
;
3276 // owner_ and output_section_ specify the section to which stubs are
3277 // attached. The stubs are placed at the end of this section.
3278 const Output_section::Input_section
* owner_
;
3279 Output_section
* output_section_
;
3282 // Return true iff input section can be handled by current stub
3283 // group. Sections are presented to this function in order,
3284 // so the first section is the head of the group.
3287 Stub_control::can_add_to_stub_group(Output_section
* o
,
3288 const Output_section::Input_section
* i
,
3291 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3293 uint64_t start_addr
= o
->address();
3296 // .init and .fini sections are pasted together to form a single
3297 // function. We can't be adding stubs in the middle of the function.
3298 this_size
= o
->data_size();
3301 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3302 this_size
= i
->data_size();
3305 uint64_t end_addr
= start_addr
+ this_size
;
3306 uint32_t group_size
= this->stub_group_size_
;
3308 this->group_size_
= group_size
= group_size
>> 10;
3310 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3311 gold_warning(_("%s:%s exceeds group size"),
3312 i
->relobj()->name().c_str(),
3313 i
->relobj()->section_name(i
->shndx()).c_str());
3315 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3316 has14
? " 14bit" : "",
3317 i
->relobj()->name().c_str(),
3318 i
->relobj()->section_name(i
->shndx()).c_str(),
3319 (long long) this_size
,
3320 (this->state_
== NO_GROUP
3322 : (long long) end_addr
- this->group_start_addr_
));
3324 if (this->state_
== NO_GROUP
)
3326 // Only here on very first use of Stub_control
3328 this->output_section_
= o
;
3329 this->state_
= FINDING_STUB_SECTION
;
3330 this->group_size_
= group_size
;
3331 this->group_start_addr_
= start_addr
;
3334 else if (!this->multi_os_
&& this->output_section_
!= o
)
3336 else if (this->state_
== HAS_STUB_SECTION
)
3338 // Can we add this section, which is after the stubs, to the
3340 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3343 else if (this->state_
== FINDING_STUB_SECTION
)
3345 if ((whole_sec
&& this->output_section_
== o
)
3346 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3348 // Stubs are added at the end of "owner_".
3350 this->output_section_
= o
;
3353 // The group before the stubs has reached maximum size.
3354 // Now see about adding sections after the stubs to the
3355 // group. If the current section has a 14-bit branch and
3356 // the group before the stubs exceeds group_size_ (because
3357 // they didn't have 14-bit branches), don't add sections
3358 // after the stubs: The size of stubs for such a large
3359 // group may exceed the reach of a 14-bit branch.
3360 if (!this->stubs_always_after_branch_
3361 && this_size
<= this->group_size_
3362 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3364 gold_debug(DEBUG_TARGET
, "adding after stubs");
3365 this->state_
= HAS_STUB_SECTION
;
3366 this->group_start_addr_
= start_addr
;
3373 gold_debug(DEBUG_TARGET
,
3374 !this->multi_os_
&& this->output_section_
!= o
3375 ? "nope, new output section\n"
3376 : "nope, didn't fit\n");
3378 // The section fails to fit in the current group. Set up a few
3379 // things for the next group. owner_ and output_section_ will be
3380 // set later after we've retrieved those values for the current
3382 this->state_
= FINDING_STUB_SECTION
;
3383 this->group_size_
= group_size
;
3384 this->group_start_addr_
= start_addr
;
3388 // Look over all the input sections, deciding where to place stubs.
3390 template<int size
, bool big_endian
>
3392 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3394 bool no_size_errors
)
3396 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3397 parameters
->options().stub_group_multi());
3399 // Group input sections and insert stub table
3400 Stub_table_owner
* table_owner
= NULL
;
3401 std::vector
<Stub_table_owner
*> tables
;
3402 Layout::Section_list section_list
;
3403 layout
->get_executable_sections(§ion_list
);
3404 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3405 for (Layout::Section_list::iterator o
= section_list
.begin();
3406 o
!= section_list
.end();
3409 typedef Output_section::Input_section_list Input_section_list
;
3410 for (Input_section_list::const_iterator i
3411 = (*o
)->input_sections().begin();
3412 i
!= (*o
)->input_sections().end();
3415 if (i
->is_input_section()
3416 || i
->is_relaxed_input_section())
3418 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3419 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3420 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3421 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3423 table_owner
->output_section
= stub_control
.output_section();
3424 table_owner
->owner
= stub_control
.owner();
3425 stub_control
.set_output_and_owner(*o
, &*i
);
3428 if (table_owner
== NULL
)
3430 table_owner
= new Stub_table_owner
;
3431 tables
.push_back(table_owner
);
3433 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3437 if (table_owner
!= NULL
)
3439 table_owner
->output_section
= stub_control
.output_section();
3440 table_owner
->owner
= stub_control
.owner();;
3442 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3446 Stub_table
<size
, big_endian
>* stub_table
;
3448 if ((*t
)->owner
->is_input_section())
3449 stub_table
= new Stub_table
<size
, big_endian
>(this,
3450 (*t
)->output_section
,
3452 this->stub_tables_
.size());
3453 else if ((*t
)->owner
->is_relaxed_input_section())
3454 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3455 (*t
)->owner
->relaxed_input_section());
3458 this->stub_tables_
.push_back(stub_table
);
3464 static unsigned long
3465 max_branch_delta (unsigned int r_type
)
3467 if (r_type
== elfcpp::R_POWERPC_REL14
3468 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3469 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3471 if (r_type
== elfcpp::R_POWERPC_REL24
3472 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3473 || r_type
== elfcpp::R_PPC_PLTREL24
3474 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3479 // Return whether this branch is going via a plt call stub.
3481 template<int size
, bool big_endian
>
3483 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3484 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3487 Target_powerpc
* target
,
3488 Symbol_table
* symtab
)
3490 if (this->object_
!= ppc_object
3491 || this->shndx_
!= shndx
3492 || this->offset_
!= offset
)
3495 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3496 if (sym
!= NULL
&& sym
->is_forwarder())
3497 sym
= symtab
->resolve_forwards(sym
);
3498 if (target
->replace_tls_get_addr(sym
))
3499 sym
= target
->tls_get_addr_opt();
3500 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3502 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3503 && !target
->is_elfv2_localentry0(gsym
))
3504 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3505 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3513 // If this branch needs a plt call stub, or a long branch stub, make one.
3515 template<int size
, bool big_endian
>
3517 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3518 Stub_table
<size
, big_endian
>* stub_table
,
3519 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3520 Symbol_table
* symtab
) const
3522 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3523 Target_powerpc
<size
, big_endian
>* target
=
3524 static_cast<Target_powerpc
<size
, big_endian
>*>(
3525 parameters
->sized_target
<size
, big_endian
>());
3526 if (sym
!= NULL
&& sym
->is_forwarder())
3527 sym
= symtab
->resolve_forwards(sym
);
3528 if (target
->replace_tls_get_addr(sym
))
3529 sym
= target
->tls_get_addr_opt();
3530 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3534 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3535 : this->object_
->local_has_plt_offset(this->r_sym_
))
3539 && target
->abiversion() >= 2
3540 && !parameters
->options().output_is_position_independent()
3541 && !is_branch_reloc
<size
>(this->r_type_
))
3542 target
->glink_section()->add_global_entry(gsym
);
3545 if (stub_table
== NULL
3548 && !parameters
->options().output_is_position_independent()
3549 && !is_branch_reloc
<size
>(this->r_type_
)))
3550 stub_table
= this->object_
->stub_table(this->shndx_
);
3551 if (stub_table
== NULL
)
3553 // This is a ref from a data section to an ifunc symbol,
3554 // or a non-branch reloc for which we always want to use
3555 // one set of stubs for resolving function addresses.
3556 stub_table
= ifunc_stub_table
;
3558 gold_assert(stub_table
!= NULL
);
3559 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3560 if (from
!= invalid_address
)
3561 from
+= (this->object_
->output_section(this->shndx_
)->address()
3564 ok
= stub_table
->add_plt_call_entry(from
,
3565 this->object_
, gsym
,
3566 this->r_type_
, this->addend_
,
3569 ok
= stub_table
->add_plt_call_entry(from
,
3570 this->object_
, this->r_sym_
,
3571 this->r_type_
, this->addend_
,
3577 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3578 if (max_branch_offset
== 0)
3580 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3581 gold_assert(from
!= invalid_address
);
3582 from
+= (this->object_
->output_section(this->shndx_
)->address()
3585 unsigned int other
= 0;
3588 switch (gsym
->source())
3590 case Symbol::FROM_OBJECT
:
3592 Object
* symobj
= gsym
->object();
3593 if (symobj
->is_dynamic()
3594 || symobj
->pluginobj() != NULL
)
3597 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3598 if (shndx
== elfcpp::SHN_UNDEF
)
3603 case Symbol::IS_UNDEFINED
:
3609 Symbol_table::Compute_final_value_status status
;
3610 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3611 if (status
!= Symbol_table::CFVS_OK
)
3614 other
= gsym
->nonvis() >> 3;
3618 const Symbol_value
<size
>* psymval
3619 = this->object_
->local_symbol(this->r_sym_
);
3620 Symbol_value
<size
> symval
;
3621 if (psymval
->is_section_symbol())
3622 symval
.set_is_section_symbol();
3623 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3624 typename
ObjType::Compute_final_local_value_status status
3625 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3627 if (status
!= ObjType::CFLV_OK
3628 || !symval
.has_output_value())
3630 to
= symval
.value(this->object_
, 0);
3632 other
= this->object_
->st_other(this->r_sym_
) >> 5;
3634 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3635 to
+= this->addend_
;
3636 if (stub_table
== NULL
)
3637 stub_table
= this->object_
->stub_table(this->shndx_
);
3638 if (size
== 64 && target
->abiversion() < 2)
3640 unsigned int dest_shndx
;
3641 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3645 unsigned int local_ent
= 0;
3647 && this->r_type_
!= elfcpp::R_PPC64_REL24_NOTOC
)
3648 local_ent
= elfcpp::ppc64_decode_local_entry(other
);
3649 Address delta
= to
+ local_ent
- from
;
3650 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3652 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3654 ? this->object_
->ppc64_needs_toc(gsym
)
3655 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3657 if (stub_table
== NULL
)
3659 gold_warning(_("%s:%s: branch in non-executable section,"
3660 " no long branch stub for you"),
3661 this->object_
->name().c_str(),
3662 this->object_
->section_name(this->shndx_
).c_str());
3665 bool save_res
= (size
== 64
3667 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3668 && gsym
->output_data() == target
->savres_section());
3669 ok
= stub_table
->add_long_branch_entry(this->r_type_
,
3670 from
, to
, other
, save_res
);
3674 gold_debug(DEBUG_TARGET
,
3675 "branch at %s:%s+%#lx\n"
3676 "can't reach stub attached to %s:%s",
3677 this->object_
->name().c_str(),
3678 this->object_
->section_name(this->shndx_
).c_str(),
3679 (unsigned long) this->offset_
,
3680 stub_table
->relobj()->name().c_str(),
3681 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3686 // Relaxation hook. This is where we do stub generation.
3688 template<int size
, bool big_endian
>
3690 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3691 const Input_objects
*,
3692 Symbol_table
* symtab
,
3696 unsigned int prev_brlt_size
= 0;
3700 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3702 && this->abiversion() < 2
3704 && !parameters
->options().user_set_plt_thread_safe())
3706 static const char* const thread_starter
[] =
3710 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3712 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3713 "mq_notify", "create_timer",
3718 "GOMP_parallel_start",
3719 "GOMP_parallel_loop_static",
3720 "GOMP_parallel_loop_static_start",
3721 "GOMP_parallel_loop_dynamic",
3722 "GOMP_parallel_loop_dynamic_start",
3723 "GOMP_parallel_loop_guided",
3724 "GOMP_parallel_loop_guided_start",
3725 "GOMP_parallel_loop_runtime",
3726 "GOMP_parallel_loop_runtime_start",
3727 "GOMP_parallel_sections",
3728 "GOMP_parallel_sections_start",
3733 if (parameters
->options().shared())
3737 for (unsigned int i
= 0;
3738 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3741 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3742 thread_safe
= (sym
!= NULL
3744 && sym
->in_real_elf());
3750 this->plt_thread_safe_
= thread_safe
;
3755 this->stub_group_size_
= parameters
->options().stub_group_size();
3756 bool no_size_errors
= true;
3757 if (this->stub_group_size_
== 1)
3758 this->stub_group_size_
= 0x1c00000;
3759 else if (this->stub_group_size_
== -1)
3760 this->stub_group_size_
= -0x1e00000;
3762 no_size_errors
= false;
3763 this->group_sections(layout
, task
, no_size_errors
);
3765 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3767 this->branch_lookup_table_
.clear();
3768 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3769 p
!= this->stub_tables_
.end();
3772 (*p
)->clear_stubs(true);
3774 this->stub_tables_
.clear();
3775 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3776 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3777 program_name
, this->stub_group_size_
);
3778 this->group_sections(layout
, task
, true);
3781 // We need address of stub tables valid for make_stub.
3782 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3783 p
!= this->stub_tables_
.end();
3786 const Powerpc_relobj
<size
, big_endian
>* object
3787 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3788 Address off
= object
->get_output_section_offset((*p
)->shndx());
3789 gold_assert(off
!= invalid_address
);
3790 Output_section
* os
= (*p
)->output_section();
3791 (*p
)->set_address_and_size(os
, off
);
3796 // Clear plt call stubs, long branch stubs and branch lookup table.
3797 prev_brlt_size
= this->branch_lookup_table_
.size();
3798 this->branch_lookup_table_
.clear();
3799 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3800 p
!= this->stub_tables_
.end();
3803 (*p
)->clear_stubs(false);
3807 // Build all the stubs.
3808 this->relax_failed_
= false;
3809 Stub_table
<size
, big_endian
>* ifunc_stub_table
3810 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3811 Stub_table
<size
, big_endian
>* one_stub_table
3812 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3813 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3814 b
!= this->branch_info_
.end();
3817 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3818 && !this->relax_failed_
)
3820 this->relax_failed_
= true;
3821 this->relax_fail_count_
++;
3822 if (this->relax_fail_count_
< 3)
3826 bool do_resize
= false;
3827 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3828 p
!= this->stub_tables_
.end();
3830 if ((*p
)->need_resize())
3837 this->branch_lookup_table_
.clear();
3838 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3839 p
!= this->stub_tables_
.end();
3841 (*p
)->set_resizing(true);
3842 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3843 b
!= this->branch_info_
.end();
3846 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3847 && !this->relax_failed_
)
3849 this->relax_failed_
= true;
3850 this->relax_fail_count_
++;
3851 if (this->relax_fail_count_
< 3)
3855 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3856 p
!= this->stub_tables_
.end();
3858 (*p
)->set_resizing(false);
3861 // Did anything change size?
3862 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3863 bool again
= num_huge_branches
!= prev_brlt_size
;
3864 if (size
== 64 && num_huge_branches
!= 0)
3865 this->make_brlt_section(layout
);
3866 if (size
== 64 && again
)
3867 this->brlt_section_
->set_current_size(num_huge_branches
);
3869 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3870 p
!= this->stub_tables_
.rend();
3872 (*p
)->remove_eh_frame(layout
);
3874 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3875 p
!= this->stub_tables_
.end();
3877 (*p
)->add_eh_frame(layout
);
3879 typedef Unordered_set
<Output_section
*> Output_sections
;
3880 Output_sections os_need_update
;
3881 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3882 p
!= this->stub_tables_
.end();
3885 if ((*p
)->size_update())
3888 os_need_update
.insert((*p
)->output_section());
3892 // Set output section offsets for all input sections in an output
3893 // section that just changed size. Anything past the stubs will
3895 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3896 p
!= os_need_update
.end();
3899 Output_section
* os
= *p
;
3901 typedef Output_section::Input_section_list Input_section_list
;
3902 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3903 i
!= os
->input_sections().end();
3906 off
= align_address(off
, i
->addralign());
3907 if (i
->is_input_section() || i
->is_relaxed_input_section())
3908 i
->relobj()->set_section_offset(i
->shndx(), off
);
3909 if (i
->is_relaxed_input_section())
3911 Stub_table
<size
, big_endian
>* stub_table
3912 = static_cast<Stub_table
<size
, big_endian
>*>(
3913 i
->relaxed_input_section());
3914 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3915 off
+= stub_table_size
;
3916 // After a few iterations, set current stub table size
3917 // as min size threshold, so later stub tables can only
3920 stub_table
->set_min_size_threshold(stub_table_size
);
3923 off
+= i
->data_size();
3925 // If .branch_lt is part of this output section, then we have
3926 // just done the offset adjustment.
3927 os
->clear_section_offsets_need_adjustment();
3932 && num_huge_branches
!= 0
3933 && parameters
->options().output_is_position_independent())
3935 // Fill in the BRLT relocs.
3936 this->brlt_section_
->reset_brlt_sizes();
3937 for (typename
Branch_lookup_table::const_iterator p
3938 = this->branch_lookup_table_
.begin();
3939 p
!= this->branch_lookup_table_
.end();
3942 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3944 this->brlt_section_
->finalize_brlt_sizes();
3948 && (parameters
->options().user_set_emit_stub_syms()
3949 ? parameters
->options().emit_stub_syms()
3951 || parameters
->options().output_is_position_independent()
3952 || parameters
->options().emit_relocs())))
3954 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3955 p
!= this->stub_tables_
.end();
3957 (*p
)->define_stub_syms(symtab
);
3959 if (this->glink_
!= NULL
)
3961 int stub_size
= this->glink_
->pltresolve_size();
3962 Address value
= -stub_size
;
3968 this->define_local(symtab
, "__glink_PLTresolve",
3969 this->glink_
, value
, stub_size
);
3972 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3979 template<int size
, bool big_endian
>
3981 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3982 unsigned char* oview
,
3986 uint64_t address
= plt
->address();
3987 off_t len
= plt
->data_size();
3989 if (plt
== this->glink_
)
3991 // See Output_data_glink::do_write() for glink contents.
3994 // Static linking may need stubs, to support ifunc and long
3995 // branches. We need to create an output section for
3996 // .eh_frame early in the link process, to have a place to
3997 // attach stub .eh_frame info. We also need to have
3998 // registered a CIE that matches the stub CIE. Both of
3999 // these requirements are satisfied by creating an FDE and
4000 // CIE for .glink, even though static linking will leave
4001 // .glink zero length.
4002 // ??? Hopefully generating an FDE with a zero address range
4003 // won't confuse anything that consumes .eh_frame info.
4005 else if (size
== 64)
4007 // There is one word before __glink_PLTresolve
4011 else if (parameters
->options().output_is_position_independent())
4013 // There are two FDEs for a position independent glink.
4014 // The first covers the branch table, the second
4015 // __glink_PLTresolve at the end of glink.
4016 off_t resolve_size
= this->glink_
->pltresolve_size();
4017 if (oview
[9] == elfcpp::DW_CFA_nop
)
4018 len
-= resolve_size
;
4021 address
+= len
- resolve_size
;
4028 // Must be a stub table.
4029 const Stub_table
<size
, big_endian
>* stub_table
4030 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
4031 uint64_t stub_address
= stub_table
->stub_address();
4032 len
-= stub_address
- address
;
4033 address
= stub_address
;
4036 *paddress
= address
;
4040 // A class to handle the PLT data.
4042 template<int size
, bool big_endian
>
4043 class Output_data_plt_powerpc
: public Output_section_data_build
4046 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4047 size
, big_endian
> Reloc_section
;
4049 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4050 Reloc_section
* plt_rel
,
4052 : Output_section_data_build(size
== 32 ? 4 : 8),
4058 // Add an entry to the PLT.
4063 add_ifunc_entry(Symbol
*);
4066 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4069 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4071 // Return the .rela.plt section data.
4078 // Return the number of PLT entries.
4082 if (this->current_data_size() == 0)
4084 return ((this->current_data_size() - this->first_plt_entry_offset())
4085 / this->plt_entry_size());
4090 do_adjust_output_section(Output_section
* os
)
4095 // Write to a map file.
4097 do_print_to_mapfile(Mapfile
* mapfile
) const
4098 { mapfile
->print_output_data(this, this->name_
); }
4101 // Return the offset of the first non-reserved PLT entry.
4103 first_plt_entry_offset() const
4105 // IPLT and LPLT have no reserved entry.
4106 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4108 return this->targ_
->first_plt_entry_offset();
4111 // Return the size of each PLT entry.
4113 plt_entry_size() const
4115 return this->targ_
->plt_entry_size();
4118 // Write out the PLT data.
4120 do_write(Output_file
*);
4122 // The reloc section.
4123 Reloc_section
* rel_
;
4124 // Allows access to .glink for do_write.
4125 Target_powerpc
<size
, big_endian
>* targ_
;
4126 // What to report in map file.
4130 // Add an entry to the PLT.
4132 template<int size
, bool big_endian
>
4134 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4136 if (!gsym
->has_plt_offset())
4138 section_size_type off
= this->current_data_size();
4140 off
+= this->first_plt_entry_offset();
4141 gsym
->set_plt_offset(off
);
4142 gsym
->set_needs_dynsym_entry();
4143 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4144 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4145 off
+= this->plt_entry_size();
4146 this->set_current_data_size(off
);
4150 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4152 template<int size
, bool big_endian
>
4154 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4156 if (!gsym
->has_plt_offset())
4158 section_size_type off
= this->current_data_size();
4159 gsym
->set_plt_offset(off
);
4160 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4161 if (size
== 64 && this->targ_
->abiversion() < 2)
4162 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4163 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4164 off
+= this->plt_entry_size();
4165 this->set_current_data_size(off
);
4169 // Add an entry for a local symbol to the PLT.
4171 template<int size
, bool big_endian
>
4173 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4174 Sized_relobj_file
<size
, big_endian
>* relobj
,
4175 unsigned int local_sym_index
)
4177 if (!relobj
->local_has_plt_offset(local_sym_index
))
4179 section_size_type off
= this->current_data_size();
4180 relobj
->set_local_plt_offset(local_sym_index
, off
);
4183 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4184 if (size
== 64 && this->targ_
->abiversion() < 2)
4185 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4186 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4187 dynrel
, this, off
, 0);
4189 off
+= this->plt_entry_size();
4190 this->set_current_data_size(off
);
4194 // Add an entry for a local ifunc symbol to the IPLT.
4196 template<int size
, bool big_endian
>
4198 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4199 Sized_relobj_file
<size
, big_endian
>* relobj
,
4200 unsigned int local_sym_index
)
4202 if (!relobj
->local_has_plt_offset(local_sym_index
))
4204 section_size_type off
= this->current_data_size();
4205 relobj
->set_local_plt_offset(local_sym_index
, off
);
4206 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4207 if (size
== 64 && this->targ_
->abiversion() < 2)
4208 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4209 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4211 off
+= this->plt_entry_size();
4212 this->set_current_data_size(off
);
4216 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4217 static const uint32_t add_2_2_11
= 0x7c425a14;
4218 static const uint32_t add_2_2_12
= 0x7c426214;
4219 static const uint32_t add_3_3_2
= 0x7c631214;
4220 static const uint32_t add_3_3_13
= 0x7c636a14;
4221 static const uint32_t add_3_12_2
= 0x7c6c1214;
4222 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4223 static const uint32_t add_11_0_11
= 0x7d605a14;
4224 static const uint32_t add_11_2_11
= 0x7d625a14;
4225 static const uint32_t add_11_11_2
= 0x7d6b1214;
4226 static const uint32_t add_12_11_12
= 0x7d8b6214;
4227 static const uint32_t addi_0_12
= 0x380c0000;
4228 static const uint32_t addi_2_2
= 0x38420000;
4229 static const uint32_t addi_3_3
= 0x38630000;
4230 static const uint32_t addi_11_11
= 0x396b0000;
4231 static const uint32_t addi_12_1
= 0x39810000;
4232 static const uint32_t addi_12_11
= 0x398b0000;
4233 static const uint32_t addi_12_12
= 0x398c0000;
4234 static const uint32_t addis_0_2
= 0x3c020000;
4235 static const uint32_t addis_0_13
= 0x3c0d0000;
4236 static const uint32_t addis_2_12
= 0x3c4c0000;
4237 static const uint32_t addis_11_2
= 0x3d620000;
4238 static const uint32_t addis_11_11
= 0x3d6b0000;
4239 static const uint32_t addis_11_30
= 0x3d7e0000;
4240 static const uint32_t addis_12_1
= 0x3d810000;
4241 static const uint32_t addis_12_2
= 0x3d820000;
4242 static const uint32_t addis_12_11
= 0x3d8b0000;
4243 static const uint32_t addis_12_12
= 0x3d8c0000;
4244 static const uint32_t b
= 0x48000000;
4245 static const uint32_t bcl_20_31
= 0x429f0005;
4246 static const uint32_t bctr
= 0x4e800420;
4247 static const uint32_t bctrl
= 0x4e800421;
4248 static const uint32_t beqlr
= 0x4d820020;
4249 static const uint32_t blr
= 0x4e800020;
4250 static const uint32_t bnectr_p4
= 0x4ce20420;
4251 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4252 static const uint32_t cmpldi_2_0
= 0x28220000;
4253 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4254 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4255 static const uint32_t cror_15_15_15
= 0x4def7b82;
4256 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4257 static const uint32_t ld_0_1
= 0xe8010000;
4258 static const uint32_t ld_0_11
= 0xe80b0000;
4259 static const uint32_t ld_0_12
= 0xe80c0000;
4260 static const uint32_t ld_2_1
= 0xe8410000;
4261 static const uint32_t ld_2_2
= 0xe8420000;
4262 static const uint32_t ld_2_11
= 0xe84b0000;
4263 static const uint32_t ld_2_12
= 0xe84c0000;
4264 static const uint32_t ld_11_1
= 0xe9610000;
4265 static const uint32_t ld_11_2
= 0xe9620000;
4266 static const uint32_t ld_11_3
= 0xe9630000;
4267 static const uint32_t ld_11_11
= 0xe96b0000;
4268 static const uint32_t ld_12_2
= 0xe9820000;
4269 static const uint32_t ld_12_3
= 0xe9830000;
4270 static const uint32_t ld_12_11
= 0xe98b0000;
4271 static const uint32_t ld_12_12
= 0xe98c0000;
4272 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4273 static const uint32_t lfd_0_1
= 0xc8010000;
4274 static const uint32_t li_0_0
= 0x38000000;
4275 static const uint32_t li_11_0
= 0x39600000;
4276 static const uint32_t li_12_0
= 0x39800000;
4277 static const uint32_t lis_0
= 0x3c000000;
4278 static const uint32_t lis_2
= 0x3c400000;
4279 static const uint32_t lis_11
= 0x3d600000;
4280 static const uint32_t lis_12
= 0x3d800000;
4281 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4282 static const uint32_t lwz_0_12
= 0x800c0000;
4283 static const uint32_t lwz_11_3
= 0x81630000;
4284 static const uint32_t lwz_11_11
= 0x816b0000;
4285 static const uint32_t lwz_11_30
= 0x817e0000;
4286 static const uint32_t lwz_12_3
= 0x81830000;
4287 static const uint32_t lwz_12_12
= 0x818c0000;
4288 static const uint32_t lwzu_0_12
= 0x840c0000;
4289 static const uint32_t mflr_0
= 0x7c0802a6;
4290 static const uint32_t mflr_11
= 0x7d6802a6;
4291 static const uint32_t mflr_12
= 0x7d8802a6;
4292 static const uint32_t mr_0_3
= 0x7c601b78;
4293 static const uint32_t mr_3_0
= 0x7c030378;
4294 static const uint32_t mtctr_0
= 0x7c0903a6;
4295 static const uint32_t mtctr_11
= 0x7d6903a6;
4296 static const uint32_t mtctr_12
= 0x7d8903a6;
4297 static const uint32_t mtlr_0
= 0x7c0803a6;
4298 static const uint32_t mtlr_11
= 0x7d6803a6;
4299 static const uint32_t mtlr_12
= 0x7d8803a6;
4300 static const uint32_t nop
= 0x60000000;
4301 static const uint32_t ori_0_0_0
= 0x60000000;
4302 static const uint32_t ori_11_11_0
= 0x616b0000;
4303 static const uint32_t ori_12_12_0
= 0x618c0000;
4304 static const uint32_t oris_12_12_0
= 0x658c0000;
4305 static const uint32_t sldi_11_11_34
= 0x796b1746;
4306 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4307 static const uint32_t srdi_0_0_2
= 0x7800f082;
4308 static const uint32_t std_0_1
= 0xf8010000;
4309 static const uint32_t std_0_12
= 0xf80c0000;
4310 static const uint32_t std_2_1
= 0xf8410000;
4311 static const uint32_t std_11_1
= 0xf9610000;
4312 static const uint32_t stfd_0_1
= 0xd8010000;
4313 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4314 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4315 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4316 static const uint32_t xor_2_12_12
= 0x7d826278;
4317 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4319 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4320 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4321 static const uint64_t pnop
= 0x0700000000000000ULL
;
4323 // Write out the PLT.
4325 template<int size
, bool big_endian
>
4327 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4329 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4331 const section_size_type offset
= this->offset();
4332 const section_size_type oview_size
4333 = convert_to_section_size_type(this->data_size());
4334 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4335 unsigned char* pov
= oview
;
4336 unsigned char* endpov
= oview
+ oview_size
;
4338 // The address of the .glink branch table
4339 const Output_data_glink
<size
, big_endian
>* glink
4340 = this->targ_
->glink_section();
4341 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4343 while (pov
< endpov
)
4345 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4350 of
->write_output_view(offset
, oview_size
, oview
);
4354 // Create the PLT section.
4356 template<int size
, bool big_endian
>
4358 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4361 if (this->plt_
== NULL
)
4363 if (this->got_
== NULL
)
4364 this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
4366 if (this->glink_
== NULL
)
4367 make_glink_section(layout
);
4369 // Ensure that .rela.dyn always appears before .rela.plt This is
4370 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4371 // needs to include .rela.plt in its range.
4372 this->rela_dyn_section(layout
);
4374 Reloc_section
* plt_rel
= new Reloc_section(false);
4375 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4376 elfcpp::SHF_ALLOC
, plt_rel
,
4377 ORDER_DYNAMIC_PLT_RELOCS
, false);
4379 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4381 layout
->add_output_section_data(".plt",
4383 ? elfcpp::SHT_PROGBITS
4384 : elfcpp::SHT_NOBITS
),
4385 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4392 Output_section
* rela_plt_os
= plt_rel
->output_section();
4393 rela_plt_os
->set_info_section(this->plt_
->output_section());
4397 // Create the IPLT section.
4399 template<int size
, bool big_endian
>
4401 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4404 if (this->iplt_
== NULL
)
4406 this->make_plt_section(symtab
, layout
);
4407 this->make_lplt_section(layout
);
4409 Reloc_section
* iplt_rel
= new Reloc_section(false);
4410 if (this->rela_dyn_
->output_section())
4411 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4413 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4415 if (this->plt_
->output_section())
4416 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4420 // Create the LPLT section.
4422 template<int size
, bool big_endian
>
4424 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4426 if (this->lplt_
== NULL
)
4428 Reloc_section
* lplt_rel
= NULL
;
4429 if (parameters
->options().output_is_position_independent())
4431 lplt_rel
= new Reloc_section(false);
4432 this->rela_dyn_section(layout
);
4433 if (this->rela_dyn_
->output_section())
4434 this->rela_dyn_
->output_section()
4435 ->add_output_section_data(lplt_rel
);
4438 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4440 this->make_brlt_section(layout
);
4441 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4442 this->brlt_section_
->output_section()
4443 ->add_output_section_data(this->lplt_
);
4445 layout
->add_output_section_data(".branch_lt",
4446 elfcpp::SHT_PROGBITS
,
4447 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4454 // A section for huge long branch addresses, similar to plt section.
4456 template<int size
, bool big_endian
>
4457 class Output_data_brlt_powerpc
: public Output_section_data_build
4460 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4461 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4462 size
, big_endian
> Reloc_section
;
4464 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4465 Reloc_section
* brlt_rel
)
4466 : Output_section_data_build(size
== 32 ? 4 : 8),
4474 this->reset_data_size();
4475 this->rel_
->reset_data_size();
4479 finalize_brlt_sizes()
4481 this->finalize_data_size();
4482 this->rel_
->finalize_data_size();
4485 // Add a reloc for an entry in the BRLT.
4487 add_reloc(Address to
, unsigned int off
)
4488 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4490 // Update section and reloc section size.
4492 set_current_size(unsigned int num_branches
)
4494 this->reset_address_and_file_offset();
4495 this->set_current_data_size(num_branches
* 16);
4496 this->finalize_data_size();
4497 Output_section
* os
= this->output_section();
4498 os
->set_section_offsets_need_adjustment();
4499 if (this->rel_
!= NULL
)
4501 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4502 this->rel_
->reset_address_and_file_offset();
4503 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4504 this->rel_
->finalize_data_size();
4505 Output_section
* os
= this->rel_
->output_section();
4506 os
->set_section_offsets_need_adjustment();
4512 do_adjust_output_section(Output_section
* os
)
4517 // Write to a map file.
4519 do_print_to_mapfile(Mapfile
* mapfile
) const
4520 { mapfile
->print_output_data(this, "** BRLT"); }
4523 // Write out the BRLT data.
4525 do_write(Output_file
*);
4527 // The reloc section.
4528 Reloc_section
* rel_
;
4529 Target_powerpc
<size
, big_endian
>* targ_
;
4532 // Make the branch lookup table section.
4534 template<int size
, bool big_endian
>
4536 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4538 if (size
== 64 && this->brlt_section_
== NULL
)
4540 Reloc_section
* brlt_rel
= NULL
;
4541 bool is_pic
= parameters
->options().output_is_position_independent();
4544 // When PIC we can't fill in .branch_lt but must initialise at
4545 // runtime via dynamic relocations.
4546 this->rela_dyn_section(layout
);
4547 brlt_rel
= new Reloc_section(false);
4548 if (this->rela_dyn_
->output_section())
4549 this->rela_dyn_
->output_section()
4550 ->add_output_section_data(brlt_rel
);
4553 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4554 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4555 this->plt_
->output_section()
4556 ->add_output_section_data(this->brlt_section_
);
4558 layout
->add_output_section_data(".branch_lt",
4559 elfcpp::SHT_PROGBITS
,
4560 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4561 this->brlt_section_
,
4567 // Write out .branch_lt when non-PIC.
4569 template<int size
, bool big_endian
>
4571 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4573 if (size
== 64 && !parameters
->options().output_is_position_independent())
4575 const section_size_type offset
= this->offset();
4576 const section_size_type oview_size
4577 = convert_to_section_size_type(this->data_size());
4578 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4580 this->targ_
->write_branch_lookup_table(oview
);
4581 of
->write_output_view(offset
, oview_size
, oview
);
4585 static inline uint32_t
4591 static inline uint32_t
4597 static inline uint32_t
4600 return hi(a
+ 0x8000);
4603 static inline uint64_t
4606 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4609 static inline uint64_t
4612 return (v
+ (1ULL << 33)) >> 34;
4618 static const unsigned char eh_frame_cie
[12];
4622 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4625 'z', 'R', 0, // Augmentation string.
4626 4, // Code alignment.
4627 0x80 - size
/ 8 , // Data alignment.
4629 1, // Augmentation size.
4630 (elfcpp::DW_EH_PE_pcrel
4631 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4632 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4635 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4636 static const unsigned char glink_eh_frame_fde_64v1
[] =
4638 0, 0, 0, 0, // Replaced with offset to .glink.
4639 0, 0, 0, 0, // Replaced with size of .glink.
4640 0, // Augmentation size.
4641 elfcpp::DW_CFA_advance_loc
+ 2,
4642 elfcpp::DW_CFA_register
, 65, 12,
4643 elfcpp::DW_CFA_advance_loc
+ 4,
4644 elfcpp::DW_CFA_restore_extended
, 65
4647 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4648 static const unsigned char glink_eh_frame_fde_64v2
[] =
4650 0, 0, 0, 0, // Replaced with offset to .glink.
4651 0, 0, 0, 0, // Replaced with size of .glink.
4652 0, // Augmentation size.
4653 elfcpp::DW_CFA_advance_loc
+ 2,
4654 elfcpp::DW_CFA_register
, 65, 0,
4655 elfcpp::DW_CFA_advance_loc
+ 2,
4656 elfcpp::DW_CFA_restore_extended
, 65
4659 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4661 0, 0, 0, 0, // Replaced with offset to .glink.
4662 0, 0, 0, 0, // Replaced with size of .glink.
4663 0, // Augmentation size.
4664 elfcpp::DW_CFA_advance_loc
+ 3,
4665 elfcpp::DW_CFA_register
, 65, 0,
4666 elfcpp::DW_CFA_advance_loc
+ 2,
4667 elfcpp::DW_CFA_restore_extended
, 65
4670 // Describe __glink_PLTresolve use of LR, 32-bit version.
4671 static const unsigned char glink_eh_frame_fde_32
[] =
4673 0, 0, 0, 0, // Replaced with offset to .glink.
4674 0, 0, 0, 0, // Replaced with size of .glink.
4675 0, // Augmentation size.
4676 elfcpp::DW_CFA_advance_loc
+ 2,
4677 elfcpp::DW_CFA_register
, 65, 0,
4678 elfcpp::DW_CFA_advance_loc
+ 4,
4679 elfcpp::DW_CFA_restore_extended
, 65
4682 static const unsigned char default_fde
[] =
4684 0, 0, 0, 0, // Replaced with offset to stubs.
4685 0, 0, 0, 0, // Replaced with size of stubs.
4686 0, // Augmentation size.
4687 elfcpp::DW_CFA_nop
, // Pad.
4692 template<bool big_endian
>
4694 write_insn(unsigned char* p
, uint32_t v
)
4696 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4700 static inline unsigned int
4703 if (!parameters
->options().user_set_plt_align())
4704 return size
== 64 ? 32 : 8;
4705 return 1 << parameters
->options().plt_align();
4708 // Stub_table holds information about plt and long branch stubs.
4709 // Stubs are built in an area following some input section determined
4710 // by group_sections(). This input section is converted to a relaxed
4711 // input section allowing it to be resized to accommodate the stubs
4713 template<int size
, bool big_endian
>
4714 class Stub_table
: public Output_relaxed_input_section
4719 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4720 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4721 r2save_(0), localentry0_(0), tocoff_(0)
4726 unsigned int iter_
: 1;
4727 unsigned int notoc_
: 1;
4728 unsigned int toc_
: 1;
4729 unsigned int r2save_
: 1;
4730 unsigned int localentry0_
: 1;
4731 unsigned int tocoff_
: 8;
4733 struct Branch_stub_ent
4735 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4736 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4737 other_(0), tocoff_(0)
4741 unsigned int iter_
: 1;
4742 unsigned int notoc_
: 1;
4743 unsigned int toc_
: 1;
4744 unsigned int save_res_
: 1;
4745 unsigned int other_
: 3;
4746 unsigned int tocoff_
: 8;
4748 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4749 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4751 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4752 Output_section
* output_section
,
4753 const Output_section::Input_section
* owner
,
4755 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4757 ->section_addralign(owner
->shndx())),
4758 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4759 orig_data_size_(owner
->current_data_size()),
4760 plt_size_(0), last_plt_size_(0),
4761 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4762 need_save_res_(false), need_resize_(false), resizing_(false),
4765 this->set_output_section(output_section
);
4767 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4768 new_relaxed
.push_back(this);
4769 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4772 // Add a plt call stub.
4774 add_plt_call_entry(Address
,
4775 const Sized_relobj_file
<size
, big_endian
>*,
4782 add_plt_call_entry(Address
,
4783 const Sized_relobj_file
<size
, big_endian
>*,
4789 // Find a given plt call stub.
4791 find_plt_call_entry(const Symbol
*) const;
4794 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4795 unsigned int) const;
4798 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4804 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4809 // Add a long branch stub.
4811 add_long_branch_entry(unsigned int, Address
, Address
, unsigned int, bool);
4813 const Branch_stub_ent
*
4814 find_long_branch_entry(Address
) const;
4817 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4819 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4820 if (max_branch_offset
== 0)
4822 gold_assert(from
!= invalid_address
);
4823 Address loc
= off
+ this->stub_address();
4824 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4828 clear_stubs(bool all
)
4830 this->plt_call_stubs_
.clear();
4831 this->plt_size_
= 0;
4832 this->long_branch_stubs_
.clear();
4833 this->branch_size_
= 0;
4834 this->need_save_res_
= false;
4837 this->last_plt_size_
= 0;
4838 this->last_branch_size_
= 0;
4844 { return need_resize_
; }
4847 set_resizing(bool val
)
4849 this->resizing_
= val
;
4852 this->need_resize_
= false;
4853 this->plt_size_
= 0;
4854 this->branch_size_
= 0;
4855 this->need_save_res_
= false;
4860 set_address_and_size(const Output_section
* os
, Address off
)
4862 Address start_off
= off
;
4863 off
+= this->orig_data_size_
;
4864 Address my_size
= this->plt_size_
+ this->branch_size_
;
4865 if (this->need_save_res_
)
4866 my_size
+= this->targ_
->savres_section()->data_size();
4868 off
= align_address(off
, this->stub_align());
4869 // Include original section size and alignment padding in size
4870 my_size
+= off
- start_off
;
4871 // Ensure new size is always larger than min size
4872 // threshold. Alignment requirement is included in "my_size", so
4873 // increase "my_size" does not invalidate alignment.
4874 if (my_size
< this->min_size_threshold_
)
4875 my_size
= this->min_size_threshold_
;
4876 this->reset_address_and_file_offset();
4877 this->set_current_data_size(my_size
);
4878 this->set_address_and_file_offset(os
->address() + start_off
,
4879 os
->offset() + start_off
);
4884 stub_address() const
4886 return align_address(this->address() + this->orig_data_size_
,
4887 this->stub_align());
4893 return align_address(this->offset() + this->orig_data_size_
,
4894 this->stub_align());
4899 { return this->plt_size_
; }
4903 { return this->branch_size_
; }
4906 set_min_size_threshold(Address min_size
)
4907 { this->min_size_threshold_
= min_size
; }
4910 define_stub_syms(Symbol_table
*);
4915 Output_section
* os
= this->output_section();
4916 if (os
->addralign() < this->stub_align())
4918 os
->set_addralign(this->stub_align());
4919 // FIXME: get rid of the insane checkpointing.
4920 // We can't increase alignment of the input section to which
4921 // stubs are attached; The input section may be .init which
4922 // is pasted together with other .init sections to form a
4923 // function. Aligning might insert zero padding resulting in
4924 // sigill. However we do need to increase alignment of the
4925 // output section so that the align_address() on offset in
4926 // set_address_and_size() adds the same padding as the
4927 // align_address() on address in stub_address().
4928 // What's more, we need this alignment for the layout done in
4929 // relaxation_loop_body() so that the output section starts at
4930 // a suitably aligned address.
4931 os
->checkpoint_set_addralign(this->stub_align());
4933 if (this->last_plt_size_
!= this->plt_size_
4934 || this->last_branch_size_
!= this->branch_size_
)
4936 this->last_plt_size_
= this->plt_size_
;
4937 this->last_branch_size_
= this->branch_size_
;
4943 // Add .eh_frame info for this stub section.
4945 add_eh_frame(Layout
* layout
);
4947 // Remove .eh_frame info for this stub section.
4949 remove_eh_frame(Layout
* layout
);
4951 Target_powerpc
<size
, big_endian
>*
4957 class Plt_stub_key_hash
;
4958 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4959 Plt_stub_key_hash
> Plt_stub_entries
;
4960 class Branch_stub_key
;
4961 class Branch_stub_key_hash
;
4962 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4963 Branch_stub_key_hash
> Branch_stub_entries
;
4965 // Alignment of stub section.
4969 unsigned int min_align
= size
== 64 ? 32 : 16;
4970 unsigned int user_align
= 1 << parameters
->options().plt_align();
4971 return std::max(user_align
, min_align
);
4974 // Return the plt offset for the given call stub.
4976 plt_off(typename
Plt_stub_entries::const_iterator p
,
4977 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4979 const Symbol
* gsym
= p
->first
.sym_
;
4981 return this->targ_
->plt_off(gsym
, sec
);
4984 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4985 unsigned int local_sym_index
= p
->first
.locsym_
;
4986 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4990 // Size of a given plt call stub.
4992 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4995 plt_call_align(unsigned int bytes
) const
4997 unsigned int align
= param_plt_align
<size
>();
4998 return (bytes
+ align
- 1) & -align
;
5001 // Return long branch stub size.
5003 branch_stub_size(typename
Branch_stub_entries::iterator p
,
5007 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
5010 build_tls_opt_tail(unsigned char* p
);
5013 plt_error(const Plt_stub_key
& p
);
5017 do_write(Output_file
*);
5019 // Plt call stub keys.
5023 Plt_stub_key(const Symbol
* sym
)
5024 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5027 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5028 unsigned int locsym_index
)
5029 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5032 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5034 unsigned int r_type
,
5036 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5039 this->addend_
= addend
;
5040 else if (parameters
->options().output_is_position_independent()
5041 && (r_type
== elfcpp::R_PPC_PLTREL24
5042 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5044 this->addend_
= addend
;
5045 if (this->addend_
>= 32768)
5046 this->object_
= object
;
5050 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5051 unsigned int locsym_index
,
5052 unsigned int r_type
,
5054 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5057 this->addend_
= addend
;
5058 else if (parameters
->options().output_is_position_independent()
5059 && (r_type
== elfcpp::R_PPC_PLTREL24
5060 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5061 this->addend_
= addend
;
5064 bool operator==(const Plt_stub_key
& that
) const
5066 return (this->sym_
== that
.sym_
5067 && this->object_
== that
.object_
5068 && this->addend_
== that
.addend_
5069 && this->locsym_
== that
.locsym_
);
5073 const Sized_relobj_file
<size
, big_endian
>* object_
;
5074 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5075 unsigned int locsym_
;
5078 class Plt_stub_key_hash
5081 size_t operator()(const Plt_stub_key
& ent
) const
5083 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5084 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5090 // Long branch stub keys.
5091 class Branch_stub_key
5094 Branch_stub_key(Address to
)
5098 bool operator==(const Branch_stub_key
& that
) const
5100 return this->dest_
== that
.dest_
;
5106 class Branch_stub_key_hash
5109 size_t operator()(const Branch_stub_key
& key
) const
5110 { return key
.dest_
; }
5113 // In a sane world this would be a global.
5114 Target_powerpc
<size
, big_endian
>* targ_
;
5115 // Map sym/object/addend to stub offset.
5116 Plt_stub_entries plt_call_stubs_
;
5117 // Map destination address to stub offset.
5118 Branch_stub_entries long_branch_stubs_
;
5119 // size of input section
5120 section_size_type orig_data_size_
;
5122 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5123 // Some rare cases cause (PR/20529) fluctuation in stub table
5124 // size, which leads to an endless relax loop. This is to be fixed
5125 // by, after the first few iterations, allowing only increase of
5126 // stub table size. This variable sets the minimal possible size of
5127 // a stub table, it is zero for the first few iterations, then
5128 // increases monotonically.
5129 Address min_size_threshold_
;
5130 // Set if this stub group needs a copy of out-of-line register
5131 // save/restore functions.
5132 bool need_save_res_
;
5133 // Set when notoc_/r2save_ changes after sizing a stub
5135 // Set when resizing stubs
5137 // Per stub table unique identifier.
5141 // Add a plt call stub, if we do not already have one for this
5142 // sym/object/addend combo.
5144 template<int size
, bool big_endian
>
5146 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5148 const Sized_relobj_file
<size
, big_endian
>* object
,
5150 unsigned int r_type
,
5154 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5155 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5156 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5157 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5161 && this->targ_
->is_elfv2_localentry0(gsym
))
5163 p
.first
->second
.localentry0_
= 1;
5164 this->targ_
->set_has_localentry0();
5166 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5168 if (!p
.second
&& !p
.first
->second
.notoc_
5169 && (!this->targ_
->power10_stubs()
5170 || this->targ_
->power10_stubs_auto()))
5171 this->need_resize_
= true;
5172 p
.first
->second
.notoc_
= 1;
5176 if (!p
.second
&& !p
.first
->second
.toc_
)
5177 this->need_resize_
= true;
5178 p
.first
->second
.toc_
= 1;
5179 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5181 if (!p
.second
&& !p
.first
->second
.r2save_
)
5182 this->need_resize_
= true;
5183 p
.first
->second
.r2save_
= 1;
5187 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5189 if (this->resizing_
)
5191 p
.first
->second
.iter_
= 1;
5192 p
.first
->second
.off_
= this->plt_size_
;
5194 this->plt_size_
+= this->plt_call_size(p
.first
);
5195 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5196 this->targ_
->set_has_tls_get_addr_opt();
5197 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5199 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5202 template<int size
, bool big_endian
>
5204 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5206 const Sized_relobj_file
<size
, big_endian
>* object
,
5207 unsigned int locsym_index
,
5208 unsigned int r_type
,
5212 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5213 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5214 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5215 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5219 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5221 p
.first
->second
.localentry0_
= 1;
5222 this->targ_
->set_has_localentry0();
5224 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5226 if (!p
.second
&& !p
.first
->second
.notoc_
5227 && (!this->targ_
->power10_stubs()
5228 || this->targ_
->power10_stubs_auto()))
5229 this->need_resize_
= true;
5230 p
.first
->second
.notoc_
= 1;
5234 if (!p
.second
&& !p
.first
->second
.toc_
)
5235 this->need_resize_
= true;
5236 p
.first
->second
.toc_
= 1;
5237 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5239 if (!p
.second
&& !p
.first
->second
.r2save_
)
5240 this->need_resize_
= true;
5241 p
.first
->second
.r2save_
= 1;
5245 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5247 if (this->resizing_
)
5249 p
.first
->second
.iter_
= 1;
5250 p
.first
->second
.off_
= this->plt_size_
;
5252 this->plt_size_
+= this->plt_call_size(p
.first
);
5253 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5255 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5258 // Find a plt call stub.
5260 template<int size
, bool big_endian
>
5261 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5262 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5263 const Sized_relobj_file
<size
, big_endian
>* object
,
5265 unsigned int r_type
,
5266 Address addend
) const
5268 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5269 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5270 if (p
== this->plt_call_stubs_
.end())
5275 template<int size
, bool big_endian
>
5276 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5277 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5279 Plt_stub_key
key(gsym
);
5280 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5281 if (p
== this->plt_call_stubs_
.end())
5286 template<int size
, bool big_endian
>
5287 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5288 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5289 const Sized_relobj_file
<size
, big_endian
>* object
,
5290 unsigned int locsym_index
,
5291 unsigned int r_type
,
5292 Address addend
) const
5294 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5295 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5296 if (p
== this->plt_call_stubs_
.end())
5301 template<int size
, bool big_endian
>
5302 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5303 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5304 const Sized_relobj_file
<size
, big_endian
>* object
,
5305 unsigned int locsym_index
) const
5307 Plt_stub_key
key(object
, locsym_index
);
5308 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5309 if (p
== this->plt_call_stubs_
.end())
5314 // Add a long branch stub if we don't already have one to given
5317 template<int size
, bool big_endian
>
5319 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5320 unsigned int r_type
,
5326 Branch_stub_key
key(to
);
5327 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5328 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5329 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5330 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5333 if (!p
.second
&& !p
.first
->second
.notoc_
)
5334 this->need_resize_
= true;
5335 p
.first
->second
.notoc_
= true;
5339 if (!p
.second
&& !p
.first
->second
.toc_
)
5340 this->need_resize_
= true;
5341 p
.first
->second
.toc_
= true;
5343 if (size
== 64 && p
.first
->second
.other_
== 0)
5344 p
.first
->second
.other_
= other
;
5345 gold_assert(save_res
== p
.first
->second
.save_res_
);
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->branch_size_
;
5354 this->need_save_res_
= true;
5357 bool need_lt
= false;
5358 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5359 this->branch_size_
+= stub_size
;
5360 if (size
== 64 && need_lt
)
5361 this->targ_
->add_branch_lookup_table(to
);
5364 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5367 // Find long branch stub offset.
5369 template<int size
, bool big_endian
>
5370 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5371 Stub_table
<size
, big_endian
>::find_long_branch_entry(Address to
) const
5373 Branch_stub_key
key(to
);
5374 typename
Branch_stub_entries::const_iterator p
5375 = this->long_branch_stubs_
.find(key
);
5376 if (p
== this->long_branch_stubs_
.end())
5381 template<bool big_endian
>
5383 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5387 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5388 else if (delta
< 256)
5390 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5391 fde
.push_back(delta
);
5393 else if (delta
< 65536)
5395 fde
.resize(fde
.size() + 3);
5396 unsigned char *p
= &*fde
.end() - 3;
5397 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5398 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5402 fde
.resize(fde
.size() + 5);
5403 unsigned char *p
= &*fde
.end() - 5;
5404 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5405 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5409 template<typename T
>
5411 stub_sort(T s1
, T s2
)
5413 return s1
->second
.off_
< s2
->second
.off_
;
5416 // Add .eh_frame info for this stub section. Unlike other linker
5417 // generated .eh_frame this is added late in the link, because we
5418 // only want the .eh_frame info if this particular stub section is
5421 template<int size
, bool big_endian
>
5423 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5426 || !parameters
->options().ld_generated_unwind_info())
5429 // Since we add stub .eh_frame info late, it must be placed
5430 // after all other linker generated .eh_frame info so that
5431 // merge mapping need not be updated for input sections.
5432 // There is no provision to use a different CIE to that used
5434 if (!this->targ_
->has_glink())
5437 typedef typename
Plt_stub_entries::iterator plt_iter
;
5438 std::vector
<plt_iter
> calls
;
5439 if (!this->plt_call_stubs_
.empty())
5440 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5441 cs
!= this->plt_call_stubs_
.end();
5443 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5444 && cs
->second
.r2save_
5445 && !cs
->second
.localentry0_
)
5446 || (cs
->second
.notoc_
5447 && !this->targ_
->power10_stubs()))
5448 calls
.push_back(cs
);
5449 if (calls
.size() > 1)
5450 std::stable_sort(calls
.begin(), calls
.end(),
5451 stub_sort
<plt_iter
>);
5453 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5454 std::vector
<branch_iter
> branches
;
5455 if (!this->long_branch_stubs_
.empty()
5456 && !this->targ_
->power10_stubs())
5457 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5458 bs
!= this->long_branch_stubs_
.end();
5460 if (bs
->second
.notoc_
)
5461 branches
.push_back(bs
);
5462 if (branches
.size() > 1)
5463 std::stable_sort(branches
.begin(), branches
.end(),
5464 stub_sort
<branch_iter
>);
5466 if (calls
.empty() && branches
.empty())
5469 unsigned int last_eh_loc
= 0;
5470 // offset pcrel sdata4, size udata4, and augmentation size byte.
5471 std::vector
<unsigned char> fde(9, 0);
5473 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5475 plt_iter cs
= calls
[i
];
5476 unsigned int off
= cs
->second
.off_
;
5477 // The __tls_get_addr_opt call stub needs to describe where
5478 // it saves LR, to support exceptions that might be thrown
5479 // from __tls_get_addr, and to support asynchronous exceptions.
5480 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5483 if (cs
->second
.r2save_
5484 && !cs
->second
.localentry0_
)
5487 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5488 fde
.resize(fde
.size() + 6);
5489 unsigned char* p
= &*fde
.end() - 6;
5490 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5492 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5493 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5494 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5495 *p
++ = elfcpp::DW_CFA_restore_extended
;
5497 last_eh_loc
= off
+ delta
;
5501 // notoc stubs also should describe LR changes, to support
5502 // asynchronous exceptions.
5503 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5504 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5505 fde
.resize(fde
.size() + 6);
5506 unsigned char* p
= &*fde
.end() - 6;
5507 *p
++ = elfcpp::DW_CFA_register
;
5510 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5511 *p
++ = elfcpp::DW_CFA_restore_extended
;
5513 last_eh_loc
= off
+ 8;
5516 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5518 branch_iter bs
= branches
[i
];
5519 unsigned int off
= bs
->second
.off_
+ 8;
5520 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5521 fde
.resize(fde
.size() + 6);
5522 unsigned char* p
= &*fde
.end() - 6;
5523 *p
++ = elfcpp::DW_CFA_register
;
5526 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5527 *p
++ = elfcpp::DW_CFA_restore_extended
;
5529 last_eh_loc
= off
+ 8;
5532 layout
->add_eh_frame_for_plt(this,
5533 Eh_cie
<size
>::eh_frame_cie
,
5534 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5535 &*fde
.begin(), fde
.size());
5538 template<int size
, bool big_endian
>
5540 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5543 && parameters
->options().ld_generated_unwind_info()
5544 && this->targ_
->has_glink())
5545 layout
->remove_eh_frame_for_plt(this,
5546 Eh_cie
<size
>::eh_frame_cie
,
5547 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5550 // A class to handle .glink.
5552 template<int size
, bool big_endian
>
5553 class Output_data_glink
: public Output_section_data
5556 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5557 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5559 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5560 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5561 end_branch_table_(), ge_size_(0)
5565 add_eh_frame(Layout
* layout
);
5568 add_global_entry(const Symbol
*);
5571 find_global_entry(const Symbol
*) const;
5574 global_entry_align(unsigned int off
) const
5576 unsigned int align
= param_plt_align
<size
>();
5577 return (off
+ align
- 1) & -align
;
5581 global_entry_off() const
5583 return this->global_entry_align(this->end_branch_table_
);
5587 global_entry_address() const
5589 gold_assert(this->is_data_size_valid());
5590 return this->address() + this->global_entry_off();
5594 pltresolve_size() const
5598 + (this->targ_
->abiversion() < 2 ? 11 * 4
5599 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5604 // Write to a map file.
5606 do_print_to_mapfile(Mapfile
* mapfile
) const
5607 { mapfile
->print_output_data(this, _("** glink")); }
5611 set_final_data_size();
5615 do_write(Output_file
*);
5617 // Allows access to .got and .plt for do_write.
5618 Target_powerpc
<size
, big_endian
>* targ_
;
5620 // Map sym to stub offset.
5621 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5622 Global_entry_stub_entries global_entry_stubs_
;
5624 unsigned int end_branch_table_
, ge_size_
;
5627 template<int size
, bool big_endian
>
5629 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5631 if (!parameters
->options().ld_generated_unwind_info())
5636 if (this->targ_
->abiversion() < 2)
5637 layout
->add_eh_frame_for_plt(this,
5638 Eh_cie
<64>::eh_frame_cie
,
5639 sizeof (Eh_cie
<64>::eh_frame_cie
),
5640 glink_eh_frame_fde_64v1
,
5641 sizeof (glink_eh_frame_fde_64v1
));
5642 else if (this->targ_
->has_localentry0())
5643 layout
->add_eh_frame_for_plt(this,
5644 Eh_cie
<64>::eh_frame_cie
,
5645 sizeof (Eh_cie
<64>::eh_frame_cie
),
5646 glink_eh_frame_fde_64v2_localentry0
,
5647 sizeof (glink_eh_frame_fde_64v2
));
5649 layout
->add_eh_frame_for_plt(this,
5650 Eh_cie
<64>::eh_frame_cie
,
5651 sizeof (Eh_cie
<64>::eh_frame_cie
),
5652 glink_eh_frame_fde_64v2
,
5653 sizeof (glink_eh_frame_fde_64v2
));
5657 // 32-bit .glink can use the default since the CIE return
5658 // address reg, LR, is valid.
5659 layout
->add_eh_frame_for_plt(this,
5660 Eh_cie
<32>::eh_frame_cie
,
5661 sizeof (Eh_cie
<32>::eh_frame_cie
),
5663 sizeof (default_fde
));
5664 // Except where LR is used in a PIC __glink_PLTresolve.
5665 if (parameters
->options().output_is_position_independent())
5666 layout
->add_eh_frame_for_plt(this,
5667 Eh_cie
<32>::eh_frame_cie
,
5668 sizeof (Eh_cie
<32>::eh_frame_cie
),
5669 glink_eh_frame_fde_32
,
5670 sizeof (glink_eh_frame_fde_32
));
5674 template<int size
, bool big_endian
>
5676 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5678 unsigned int off
= this->global_entry_align(this->ge_size_
);
5679 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5680 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5682 this->ge_size_
= off
+ 16;
5685 template<int size
, bool big_endian
>
5686 typename Output_data_glink
<size
, big_endian
>::Address
5687 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5689 typename
Global_entry_stub_entries::const_iterator p
5690 = this->global_entry_stubs_
.find(gsym
);
5691 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5694 template<int size
, bool big_endian
>
5696 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5698 unsigned int count
= this->targ_
->plt_entry_count();
5699 section_size_type total
= 0;
5705 // space for branch table
5706 total
+= 4 * (count
- 1);
5708 total
+= -total
& 15;
5709 total
+= this->pltresolve_size();
5713 total
+= this->pltresolve_size();
5715 // space for branch table
5717 if (this->targ_
->abiversion() < 2)
5721 total
+= 4 * (count
- 0x8000);
5725 this->end_branch_table_
= total
;
5726 total
= this->global_entry_align(total
);
5727 total
+= this->ge_size_
;
5729 this->set_data_size(total
);
5732 // Define symbols on stubs, identifying the stub.
5734 template<int size
, bool big_endian
>
5736 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5738 if (!this->plt_call_stubs_
.empty())
5740 // The key for the plt call stub hash table includes addresses,
5741 // therefore traversal order depends on those addresses, which
5742 // can change between runs if gold is a PIE. Unfortunately the
5743 // output .symtab ordering depends on the order in which symbols
5744 // are added to the linker symtab. We want reproducible output
5745 // so must sort the call stub symbols.
5746 typedef typename
Plt_stub_entries::iterator plt_iter
;
5747 std::vector
<plt_iter
> sorted
;
5748 sorted
.resize(this->plt_call_stubs_
.size());
5750 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5751 cs
!= this->plt_call_stubs_
.end();
5753 sorted
[cs
->second
.indx_
] = cs
;
5755 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5757 plt_iter cs
= sorted
[i
];
5760 if (cs
->first
.addend_
!= 0)
5761 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5764 if (cs
->first
.object_
)
5766 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5767 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5768 sprintf(obj
, "%x:", ppcobj
->uniq());
5771 const char *symname
;
5772 if (cs
->first
.sym_
== NULL
)
5774 sprintf(localname
, "%x", cs
->first
.locsym_
);
5775 symname
= localname
;
5777 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5778 symname
= this->targ_
->tls_get_addr_opt()->name();
5780 symname
= cs
->first
.sym_
->name();
5781 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5782 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5784 = this->stub_address() - this->address() + cs
->second
.off_
;
5785 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5786 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5790 typedef typename
Branch_stub_entries::iterator branch_iter
;
5791 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5792 bs
!= this->long_branch_stubs_
.end();
5795 if (bs
->second
.save_res_
)
5798 char* name
= new char[8 + 13 + 16 + 1];
5799 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5800 static_cast<unsigned long long>(bs
->first
.dest_
));
5801 Address value
= (this->stub_address() - this->address()
5802 + this->plt_size_
+ bs
->second
.off_
);
5803 bool need_lt
= false;
5804 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5805 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5809 // Emit the start of a __tls_get_addr_opt plt call stub.
5811 template<int size
, bool big_endian
>
5813 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5816 unsigned char* p
= *pp
;
5819 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5821 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5823 write_insn
<big_endian
>(p
, mr_0_3
);
5825 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5827 write_insn
<big_endian
>(p
, add_3_12_13
);
5829 write_insn
<big_endian
>(p
, beqlr
);
5831 write_insn
<big_endian
>(p
, mr_3_0
);
5835 write_insn
<big_endian
>(p
, mflr_11
);
5837 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5843 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5845 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5847 write_insn
<big_endian
>(p
, mr_0_3
);
5849 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5851 write_insn
<big_endian
>(p
, add_3_12_2
);
5853 write_insn
<big_endian
>(p
, beqlr
);
5855 write_insn
<big_endian
>(p
, mr_3_0
);
5857 write_insn
<big_endian
>(p
, nop
);
5863 // Emit the tail of a __tls_get_addr_opt plt call stub.
5865 template<int size
, bool big_endian
>
5867 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5869 write_insn
<big_endian
>(p
, bctrl
);
5871 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5873 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5875 write_insn
<big_endian
>(p
, mtlr_11
);
5877 write_insn
<big_endian
>(p
, blr
);
5880 // Emit pc-relative plt call stub code.
5882 template<bool big_endian
>
5883 static unsigned char*
5884 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5887 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5892 write_insn
<big_endian
>(p
, nop
);
5900 write_insn
<big_endian
>(p
, insn
>> 32);
5902 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5904 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5907 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5911 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5914 insn
= paddi_12_pc
| d34(off
);
5915 write_insn
<big_endian
>(p
, insn
>> 32);
5917 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5921 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5925 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5927 write_insn
<big_endian
>(p
, add_12_11_12
);
5932 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5934 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5938 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5941 insn
= paddi_12_pc
| d34(off
);
5942 write_insn
<big_endian
>(p
, insn
>> 32);
5944 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5948 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5952 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5954 write_insn
<big_endian
>(p
, add_12_11_12
);
5960 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5961 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5966 // lis %r12,xxx-1b@highest
5967 // ori %r12,%r12,xxx-1b@higher
5968 // sldi %r12,%r12,32
5969 // oris %r12,%r12,xxx-1b@high
5970 // ori %r12,%r12,xxx-1b@l
5971 // add/ldx %r12,%r11,%r12
5973 template<bool big_endian
>
5974 static unsigned char*
5975 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5977 write_insn
<big_endian
>(p
, mflr_12
);
5979 write_insn
<big_endian
>(p
, bcl_20_31
);
5981 write_insn
<big_endian
>(p
, mflr_11
);
5983 write_insn
<big_endian
>(p
, mtlr_12
);
5985 if (off
+ 0x8000 < 0x10000)
5988 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5990 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5992 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5994 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5997 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5999 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
6003 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
6005 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
6010 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
6012 if (((off
>> 32) & 0xffff) != 0)
6014 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
6018 if (((off
>> 32) & 0xffffffffULL
) != 0)
6020 write_insn
<big_endian
>(p
, sldi_12_12_32
);
6025 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
6030 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6034 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6036 write_insn
<big_endian
>(p
, add_12_11_12
);
6042 // Size of a given plt call stub.
6044 template<int size
, bool big_endian
>
6046 Stub_table
<size
, big_endian
>::plt_call_size(
6047 typename
Plt_stub_entries::iterator p
) const
6051 const Symbol
* gsym
= p
->first
.sym_
;
6053 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
6056 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6057 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6058 plt_addr
+= plt
->address();
6059 if (this->targ_
->power10_stubs()
6060 && this->targ_
->power10_stubs_auto())
6062 unsigned int bytes
= 0;
6063 if (p
->second
.notoc_
)
6065 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6067 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6068 uint64_t odd
= from
& 4;
6069 uint64_t off
= plt_addr
- from
;
6070 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6071 bytes
+= odd
+ 4 * 4;
6072 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6076 bytes
= this->plt_call_align(bytes
);
6078 unsigned int tail
= 0;
6081 p
->second
.tocoff_
= bytes
;
6082 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6085 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6091 if (p
->second
.r2save_
)
6093 uint64_t got_addr
= this->targ_
->toc_pointer();
6094 uint64_t off
= plt_addr
- got_addr
;
6095 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6097 return bytes
+ tail
;
6101 unsigned int bytes
= 0;
6102 unsigned int tail
= 0;
6103 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6106 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6113 if (p
->second
.r2save_
)
6116 if (this->targ_
->power10_stubs())
6118 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6119 uint64_t odd
= from
& 4;
6120 uint64_t off
= plt_addr
- from
;
6121 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6122 bytes
+= odd
+ 4 * 4;
6123 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6127 return bytes
+ tail
;
6130 if (p
->second
.notoc_
)
6132 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6133 uint64_t off
= plt_addr
- from
;
6134 if (off
+ 0x8000 < 0x10000)
6136 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6141 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6142 && ((off
>> 32) & 0xffff) != 0)
6144 if (((off
>> 32) & 0xffffffffULL
) != 0)
6151 return bytes
+ tail
;
6154 uint64_t got_addr
= this->targ_
->toc_pointer();
6155 uint64_t off
= plt_addr
- got_addr
;
6156 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6157 if (this->targ_
->abiversion() < 2)
6159 bool static_chain
= parameters
->options().plt_static_chain();
6160 bool thread_safe
= this->targ_
->plt_thread_safe();
6164 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6166 return bytes
+ tail
;
6170 // Return long branch stub size.
6172 template<int size
, bool big_endian
>
6174 Stub_table
<size
, big_endian
>::branch_stub_size(
6175 typename
Branch_stub_entries::iterator p
,
6178 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6181 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6183 if (parameters
->options().output_is_position_independent())
6188 uint64_t off
= p
->first
.dest_
- loc
;
6189 unsigned int bytes
= 0;
6190 if (p
->second
.notoc_
)
6192 if (this->targ_
->power10_stubs())
6194 Address odd
= loc
& 4;
6195 if (off
+ (1 << 25) < 2 << 25)
6197 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6199 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6203 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6205 p
->second
.tocoff_
= bytes
;
6210 if (off
+ 0x8000 < 0x10000)
6212 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6214 if (off
+ 24 + (1 << 25) < 2 << 25)
6220 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6221 && ((off
>> 32) & 0xffff) != 0)
6223 if (((off
>> 32) & 0xffffffffULL
) != 0)
6233 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6234 if (off
+ (1 << 25) < 2 << 25)
6236 if (!this->targ_
->power10_stubs()
6237 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6242 template<int size
, bool big_endian
>
6244 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6247 gold_error(_("linkage table error against `%s'"),
6248 p
.sym_
->demangled_name().c_str());
6250 gold_error(_("linkage table error against `%s:[local %u]'"),
6251 p
.object_
->name().c_str(),
6255 // Write out plt and long branch stub code.
6257 template<int size
, bool big_endian
>
6259 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6261 if (this->plt_call_stubs_
.empty()
6262 && this->long_branch_stubs_
.empty())
6265 const section_size_type start_off
= this->offset();
6266 const section_size_type off
= this->stub_offset();
6267 const section_size_type oview_size
=
6268 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6269 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6273 && this->targ_
->power10_stubs())
6275 if (!this->plt_call_stubs_
.empty())
6277 // Write out plt call stubs.
6278 typename
Plt_stub_entries::const_iterator cs
;
6279 for (cs
= this->plt_call_stubs_
.begin();
6280 cs
!= this->plt_call_stubs_
.end();
6283 p
= oview
+ cs
->second
.off_
;
6284 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6285 Address pltoff
= this->plt_off(cs
, &plt
);
6286 Address plt_addr
= pltoff
+ plt
->address();
6287 if (this->targ_
->power10_stubs_auto())
6289 if (cs
->second
.notoc_
)
6291 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6292 this->build_tls_opt_head(&p
, false);
6293 Address from
= this->stub_address() + (p
- oview
);
6294 Address delta
= plt_addr
- from
;
6295 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6297 write_insn
<big_endian
>(p
, mtctr_12
);
6299 write_insn
<big_endian
>(p
, bctr
);
6301 p
= oview
+ this->plt_call_align(p
- oview
);
6303 if (cs
->second
.toc_
)
6305 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6308 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6309 this->build_tls_opt_head(&p
, save_lr
);
6311 Address got_addr
= this->targ_
->toc_pointer();
6312 Address off
= plt_addr
- got_addr
;
6314 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6315 this->plt_error(cs
->first
);
6317 if (cs
->second
.r2save_
)
6319 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6324 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6326 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6331 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6334 write_insn
<big_endian
>(p
, mtctr_12
);
6336 if (cs
->second
.r2save_
6337 && !cs
->second
.localentry0_
6338 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6339 this->build_tls_opt_tail(p
);
6341 write_insn
<big_endian
>(p
, bctr
);
6346 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6349 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6350 this->build_tls_opt_head(&p
, save_lr
);
6352 if (cs
->second
.r2save_
)
6354 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6357 Address from
= this->stub_address() + (p
- oview
);
6358 Address delta
= plt_addr
- from
;
6359 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6360 write_insn
<big_endian
>(p
, mtctr_12
);
6362 if (cs
->second
.r2save_
6363 && !cs
->second
.localentry0_
6364 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6365 this->build_tls_opt_tail(p
);
6367 write_insn
<big_endian
>(p
, bctr
);
6372 // Write out long branch stubs.
6373 typename
Branch_stub_entries::const_iterator bs
;
6374 for (bs
= this->long_branch_stubs_
.begin();
6375 bs
!= this->long_branch_stubs_
.end();
6378 if (bs
->second
.save_res_
)
6380 Address off
= this->plt_size_
+ bs
->second
.off_
;
6382 Address loc
= this->stub_address() + off
;
6383 Address delta
= bs
->first
.dest_
- loc
;
6384 if (this->targ_
->power10_stubs_auto())
6386 if (bs
->second
.notoc_
)
6388 unsigned char* startp
= p
;
6389 p
= build_power10_offset
<big_endian
>(p
, delta
,
6391 delta
-= p
- startp
;
6393 if (delta
+ (1 << 25) < 2 << 25)
6394 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6397 write_insn
<big_endian
>(p
, mtctr_12
);
6399 write_insn
<big_endian
>(p
, bctr
);
6402 delta
-= p
- startp
;
6404 if (bs
->second
.toc_
)
6406 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6407 if (delta
+ (1 << 25) >= 2 << 25)
6410 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6411 gold_assert(brlt_addr
!= invalid_address
);
6412 brlt_addr
+= this->targ_
->brlt_section()->address();
6413 Address got_addr
= this->targ_
->toc_pointer();
6414 Address brltoff
= brlt_addr
- got_addr
;
6415 if (ha(brltoff
) == 0)
6417 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6422 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6424 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6428 if (delta
+ (1 << 25) < 2 << 25)
6429 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6432 write_insn
<big_endian
>(p
, mtctr_12
);
6434 write_insn
<big_endian
>(p
, bctr
);
6440 if (!bs
->second
.notoc_
)
6441 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6442 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6444 unsigned char* startp
= p
;
6445 p
= build_power10_offset
<big_endian
>(p
, delta
,
6447 delta
-= p
- startp
;
6449 if (delta
+ (1 << 25) < 2 << 25)
6450 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6453 write_insn
<big_endian
>(p
, mtctr_12
);
6455 write_insn
<big_endian
>(p
, bctr
);
6460 else if (size
== 64)
6463 if (!this->plt_call_stubs_
.empty()
6464 && this->targ_
->abiversion() >= 2)
6466 // Write out plt call stubs for ELFv2.
6467 typename
Plt_stub_entries::const_iterator cs
;
6468 for (cs
= this->plt_call_stubs_
.begin();
6469 cs
!= this->plt_call_stubs_
.end();
6472 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6473 Address pltoff
= this->plt_off(cs
, &plt
);
6474 Address plt_addr
= pltoff
+ plt
->address();
6476 p
= oview
+ cs
->second
.off_
;
6477 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6479 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6480 this->build_tls_opt_head(&p
, save_lr
);
6482 if (cs
->second
.r2save_
)
6484 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6487 if (cs
->second
.notoc_
)
6489 Address from
= this->stub_address() + (p
- oview
) + 8;
6490 Address off
= plt_addr
- from
;
6491 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6495 Address got_addr
= this->targ_
->toc_pointer();
6496 Address off
= plt_addr
- got_addr
;
6498 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6499 this->plt_error(cs
->first
);
6503 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6505 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6510 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6514 write_insn
<big_endian
>(p
, mtctr_12
);
6516 if (cs
->second
.r2save_
6517 && !cs
->second
.localentry0_
6518 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6519 this->build_tls_opt_tail(p
);
6521 write_insn
<big_endian
>(p
, bctr
);
6524 else if (!this->plt_call_stubs_
.empty())
6526 // Write out plt call stubs for ELFv1.
6527 typename
Plt_stub_entries::const_iterator cs
;
6528 for (cs
= this->plt_call_stubs_
.begin();
6529 cs
!= this->plt_call_stubs_
.end();
6532 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6533 Address pltoff
= this->plt_off(cs
, &plt
);
6534 Address plt_addr
= pltoff
+ plt
->address();
6535 Address got_addr
= this->targ_
->toc_pointer();
6536 Address off
= plt_addr
- got_addr
;
6538 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6539 || cs
->second
.notoc_
)
6540 this->plt_error(cs
->first
);
6542 bool static_chain
= parameters
->options().plt_static_chain();
6543 bool thread_safe
= this->targ_
->plt_thread_safe();
6544 bool use_fake_dep
= false;
6545 Address cmp_branch_off
= 0;
6548 unsigned int pltindex
6549 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6550 / this->targ_
->plt_entry_size());
6552 = (this->targ_
->glink_section()->pltresolve_size()
6554 if (pltindex
> 32768)
6555 glinkoff
+= (pltindex
- 32768) * 4;
6557 = this->targ_
->glink_section()->address() + glinkoff
;
6559 = (this->stub_address() + cs
->second
.off_
+ 20
6560 + 4 * cs
->second
.r2save_
6561 + 4 * (ha(off
) != 0)
6562 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6563 + 4 * static_chain
);
6564 cmp_branch_off
= to
- from
;
6565 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6568 p
= oview
+ cs
->second
.off_
;
6569 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6571 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6572 this->build_tls_opt_head(&p
, save_lr
);
6573 use_fake_dep
= thread_safe
;
6575 if (cs
->second
.r2save_
)
6577 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6582 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6584 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6586 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6588 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6592 write_insn
<big_endian
>(p
, mtctr_12
);
6596 write_insn
<big_endian
>(p
, xor_2_12_12
);
6598 write_insn
<big_endian
>(p
, add_11_11_2
);
6601 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6605 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6611 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6613 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6615 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6619 write_insn
<big_endian
>(p
, mtctr_12
);
6623 write_insn
<big_endian
>(p
, xor_11_12_12
);
6625 write_insn
<big_endian
>(p
, add_2_2_11
);
6630 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6633 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6636 if (cs
->second
.r2save_
6637 && !cs
->second
.localentry0_
6638 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6639 this->build_tls_opt_tail(p
);
6640 else if (thread_safe
&& !use_fake_dep
)
6642 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6644 write_insn
<big_endian
>(p
, bnectr_p4
);
6646 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6649 write_insn
<big_endian
>(p
, bctr
);
6653 // Write out long branch stubs.
6654 typename
Branch_stub_entries::const_iterator bs
;
6655 for (bs
= this->long_branch_stubs_
.begin();
6656 bs
!= this->long_branch_stubs_
.end();
6659 if (bs
->second
.save_res_
)
6661 Address off
= this->plt_size_
+ bs
->second
.off_
;
6663 Address loc
= this->stub_address() + off
;
6664 Address delta
= bs
->first
.dest_
- loc
;
6665 if (!bs
->second
.notoc_
)
6666 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6667 if (bs
->second
.notoc_
)
6669 unsigned char* startp
= p
;
6670 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6671 delta
-= p
- startp
;
6673 else if (delta
+ (1 << 25) >= 2 << 25)
6676 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6677 gold_assert(brlt_addr
!= invalid_address
);
6678 brlt_addr
+= this->targ_
->brlt_section()->address();
6679 Address got_addr
= this->targ_
->toc_pointer();
6680 Address brltoff
= brlt_addr
- got_addr
;
6681 if (ha(brltoff
) == 0)
6683 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6688 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6690 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6694 if (delta
+ (1 << 25) < 2 << 25)
6695 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6698 write_insn
<big_endian
>(p
, mtctr_12
);
6700 write_insn
<big_endian
>(p
, bctr
);
6706 if (!this->plt_call_stubs_
.empty())
6708 // The address of _GLOBAL_OFFSET_TABLE_.
6709 Address g_o_t
= invalid_address
;
6711 // Write out plt call stubs.
6712 typename
Plt_stub_entries::const_iterator cs
;
6713 for (cs
= this->plt_call_stubs_
.begin();
6714 cs
!= this->plt_call_stubs_
.end();
6717 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6718 Address plt_addr
= this->plt_off(cs
, &plt
);
6719 plt_addr
+= plt
->address();
6721 p
= oview
+ cs
->second
.off_
;
6722 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6723 this->build_tls_opt_head(&p
, false);
6724 if (parameters
->options().output_is_position_independent())
6727 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6728 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6729 (cs
->first
.object_
));
6730 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6732 unsigned int got2
= ppcobj
->got2_shndx();
6733 got_addr
= ppcobj
->get_output_section_offset(got2
);
6734 gold_assert(got_addr
!= invalid_address
);
6735 got_addr
+= (ppcobj
->output_section(got2
)->address()
6736 + cs
->first
.addend_
);
6740 if (g_o_t
== invalid_address
)
6741 g_o_t
= this->targ_
->toc_pointer();
6745 Address off
= plt_addr
- got_addr
;
6747 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6750 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6752 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6757 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6759 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6762 write_insn
<big_endian
>(p
, mtctr_11
);
6764 write_insn
<big_endian
>(p
, bctr
);
6768 // Write out long branch stubs.
6769 typename
Branch_stub_entries::const_iterator bs
;
6770 for (bs
= this->long_branch_stubs_
.begin();
6771 bs
!= this->long_branch_stubs_
.end();
6774 if (bs
->second
.save_res_
)
6776 Address off
= this->plt_size_
+ bs
->second
.off_
;
6778 Address loc
= this->stub_address() + off
;
6779 Address delta
= bs
->first
.dest_
- loc
;
6780 if (delta
+ (1 << 25) < 2 << 25)
6781 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6782 else if (!parameters
->options().output_is_position_independent())
6784 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6786 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6791 write_insn
<big_endian
>(p
, mflr_0
);
6793 write_insn
<big_endian
>(p
, bcl_20_31
);
6795 write_insn
<big_endian
>(p
, mflr_12
);
6797 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6799 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6801 write_insn
<big_endian
>(p
, mtlr_0
);
6804 write_insn
<big_endian
>(p
, mtctr_12
);
6806 write_insn
<big_endian
>(p
, bctr
);
6809 if (this->need_save_res_
)
6811 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6812 memcpy (p
, this->targ_
->savres_section()->contents(),
6813 this->targ_
->savres_section()->data_size());
6817 // Write out .glink.
6819 template<int size
, bool big_endian
>
6821 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6823 const section_size_type off
= this->offset();
6824 const section_size_type oview_size
=
6825 convert_to_section_size_type(this->data_size());
6826 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6829 // The base address of the .plt section.
6830 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6831 Address plt_base
= this->targ_
->plt_section()->address();
6835 if (this->end_branch_table_
!= 0)
6837 // Write pltresolve stub.
6839 Address after_bcl
= this->address() + 16;
6840 Address pltoff
= plt_base
- after_bcl
;
6842 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6844 if (this->targ_
->abiversion() < 2)
6846 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6847 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6848 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6849 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6850 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6851 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6852 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6853 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6854 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6855 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6859 if (this->targ_
->has_localentry0())
6861 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6863 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6864 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6865 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6866 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6867 if (this->targ_
->has_localentry0())
6869 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
6873 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
6875 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6876 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
6877 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
6878 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6879 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6880 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6881 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6883 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6884 gold_assert(p
== oview
+ this->pltresolve_size());
6886 // Write lazy link call stubs.
6888 while (p
< oview
+ this->end_branch_table_
)
6890 if (this->targ_
->abiversion() < 2)
6894 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6898 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6899 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6902 uint32_t branch_off
= 8 - (p
- oview
);
6903 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6908 Address plt_base
= this->targ_
->plt_section()->address();
6909 Address iplt_base
= invalid_address
;
6910 unsigned int global_entry_off
= this->global_entry_off();
6911 Address global_entry_base
= this->address() + global_entry_off
;
6912 typename
Global_entry_stub_entries::const_iterator ge
;
6913 for (ge
= this->global_entry_stubs_
.begin();
6914 ge
!= this->global_entry_stubs_
.end();
6917 p
= oview
+ global_entry_off
+ ge
->second
;
6918 Address plt_addr
= ge
->first
->plt_offset();
6919 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6920 && ge
->first
->can_use_relative_reloc(false))
6922 if (iplt_base
== invalid_address
)
6923 iplt_base
= this->targ_
->iplt_section()->address();
6924 plt_addr
+= iplt_base
;
6927 plt_addr
+= plt_base
;
6928 Address my_addr
= global_entry_base
+ ge
->second
;
6929 Address off
= plt_addr
- my_addr
;
6931 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6932 gold_error(_("linkage table error against `%s'"),
6933 ge
->first
->demangled_name().c_str());
6935 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6936 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6937 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6938 write_insn
<big_endian
>(p
, bctr
);
6943 // The address of _GLOBAL_OFFSET_TABLE_.
6944 Address g_o_t
= this->targ_
->toc_pointer();
6946 // Write out pltresolve branch table.
6948 unsigned int the_end
= oview_size
- this->pltresolve_size();
6949 unsigned char* end_p
= oview
+ the_end
;
6950 while (p
< end_p
- 8 * 4)
6951 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6953 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6955 // Write out pltresolve call stub.
6956 end_p
= oview
+ oview_size
;
6957 if (parameters
->options().output_is_position_independent())
6959 Address res0_off
= 0;
6960 Address after_bcl_off
= the_end
+ 12;
6961 Address bcl_res0
= after_bcl_off
- res0_off
;
6963 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6965 write_insn
<big_endian
>(p
, mflr_0
);
6967 write_insn
<big_endian
>(p
, bcl_20_31
);
6969 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6971 write_insn
<big_endian
>(p
, mflr_12
);
6973 write_insn
<big_endian
>(p
, mtlr_0
);
6975 write_insn
<big_endian
>(p
, sub_11_11_12
);
6978 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6980 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6982 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6984 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6986 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6990 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6992 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6995 write_insn
<big_endian
>(p
, mtctr_0
);
6997 write_insn
<big_endian
>(p
, add_0_11_11
);
6999 write_insn
<big_endian
>(p
, add_11_0_11
);
7003 Address res0
= this->address();
7005 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7007 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7009 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7010 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7012 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7014 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7016 write_insn
<big_endian
>(p
, mtctr_0
);
7018 write_insn
<big_endian
>(p
, add_0_11_11
);
7020 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7021 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7023 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7025 write_insn
<big_endian
>(p
, add_11_0_11
);
7028 write_insn
<big_endian
>(p
, bctr
);
7032 write_insn
<big_endian
>(p
, nop
);
7037 of
->write_output_view(off
, oview_size
, oview
);
7041 // A class to handle linker generated save/restore functions.
7043 template<int size
, bool big_endian
>
7044 class Output_data_save_res
: public Output_section_data_build
7047 Output_data_save_res(Symbol_table
* symtab
);
7049 const unsigned char*
7056 // Write to a map file.
7058 do_print_to_mapfile(Mapfile
* mapfile
) const
7059 { mapfile
->print_output_data(this, _("** save/restore")); }
7062 do_write(Output_file
*);
7065 // The maximum size of save/restore contents.
7066 static const unsigned int savres_max
= 218*4;
7069 savres_define(Symbol_table
* symtab
,
7071 unsigned int lo
, unsigned int hi
,
7072 unsigned char* write_ent(unsigned char*, int),
7073 unsigned char* write_tail(unsigned char*, int));
7075 unsigned char *contents_
;
7078 template<bool big_endian
>
7079 static unsigned char*
7080 savegpr0(unsigned char* p
, int r
)
7082 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7083 write_insn
<big_endian
>(p
, insn
);
7087 template<bool big_endian
>
7088 static unsigned char*
7089 savegpr0_tail(unsigned char* p
, int r
)
7091 p
= savegpr0
<big_endian
>(p
, r
);
7092 uint32_t insn
= std_0_1
+ 16;
7093 write_insn
<big_endian
>(p
, insn
);
7095 write_insn
<big_endian
>(p
, blr
);
7099 template<bool big_endian
>
7100 static unsigned char*
7101 restgpr0(unsigned char* p
, int r
)
7103 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7104 write_insn
<big_endian
>(p
, insn
);
7108 template<bool big_endian
>
7109 static unsigned char*
7110 restgpr0_tail(unsigned char* p
, int r
)
7112 uint32_t insn
= ld_0_1
+ 16;
7113 write_insn
<big_endian
>(p
, insn
);
7115 p
= restgpr0
<big_endian
>(p
, r
);
7116 write_insn
<big_endian
>(p
, mtlr_0
);
7120 p
= restgpr0
<big_endian
>(p
, 30);
7121 p
= restgpr0
<big_endian
>(p
, 31);
7123 write_insn
<big_endian
>(p
, blr
);
7127 template<bool big_endian
>
7128 static unsigned char*
7129 savegpr1(unsigned char* p
, int r
)
7131 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7132 write_insn
<big_endian
>(p
, insn
);
7136 template<bool big_endian
>
7137 static unsigned char*
7138 savegpr1_tail(unsigned char* p
, int r
)
7140 p
= savegpr1
<big_endian
>(p
, r
);
7141 write_insn
<big_endian
>(p
, blr
);
7145 template<bool big_endian
>
7146 static unsigned char*
7147 restgpr1(unsigned char* p
, int r
)
7149 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7150 write_insn
<big_endian
>(p
, insn
);
7154 template<bool big_endian
>
7155 static unsigned char*
7156 restgpr1_tail(unsigned char* p
, int r
)
7158 p
= restgpr1
<big_endian
>(p
, r
);
7159 write_insn
<big_endian
>(p
, blr
);
7163 template<bool big_endian
>
7164 static unsigned char*
7165 savefpr(unsigned char* p
, int r
)
7167 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7168 write_insn
<big_endian
>(p
, insn
);
7172 template<bool big_endian
>
7173 static unsigned char*
7174 savefpr0_tail(unsigned char* p
, int r
)
7176 p
= savefpr
<big_endian
>(p
, r
);
7177 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7179 write_insn
<big_endian
>(p
, blr
);
7183 template<bool big_endian
>
7184 static unsigned char*
7185 restfpr(unsigned char* p
, int r
)
7187 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7188 write_insn
<big_endian
>(p
, insn
);
7192 template<bool big_endian
>
7193 static unsigned char*
7194 restfpr0_tail(unsigned char* p
, int r
)
7196 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7198 p
= restfpr
<big_endian
>(p
, r
);
7199 write_insn
<big_endian
>(p
, mtlr_0
);
7203 p
= restfpr
<big_endian
>(p
, 30);
7204 p
= restfpr
<big_endian
>(p
, 31);
7206 write_insn
<big_endian
>(p
, blr
);
7210 template<bool big_endian
>
7211 static unsigned char*
7212 savefpr1_tail(unsigned char* p
, int r
)
7214 p
= savefpr
<big_endian
>(p
, r
);
7215 write_insn
<big_endian
>(p
, blr
);
7219 template<bool big_endian
>
7220 static unsigned char*
7221 restfpr1_tail(unsigned char* p
, int r
)
7223 p
= restfpr
<big_endian
>(p
, r
);
7224 write_insn
<big_endian
>(p
, blr
);
7228 template<bool big_endian
>
7229 static unsigned char*
7230 savevr(unsigned char* p
, int r
)
7232 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7233 write_insn
<big_endian
>(p
, insn
);
7235 insn
= stvx_0_12_0
+ (r
<< 21);
7236 write_insn
<big_endian
>(p
, insn
);
7240 template<bool big_endian
>
7241 static unsigned char*
7242 savevr_tail(unsigned char* p
, int r
)
7244 p
= savevr
<big_endian
>(p
, r
);
7245 write_insn
<big_endian
>(p
, blr
);
7249 template<bool big_endian
>
7250 static unsigned char*
7251 restvr(unsigned char* p
, int r
)
7253 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7254 write_insn
<big_endian
>(p
, insn
);
7256 insn
= lvx_0_12_0
+ (r
<< 21);
7257 write_insn
<big_endian
>(p
, insn
);
7261 template<bool big_endian
>
7262 static unsigned char*
7263 restvr_tail(unsigned char* p
, int r
)
7265 p
= restvr
<big_endian
>(p
, r
);
7266 write_insn
<big_endian
>(p
, blr
);
7271 template<int size
, bool big_endian
>
7272 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7273 Symbol_table
* symtab
)
7274 : Output_section_data_build(4),
7277 this->savres_define(symtab
,
7278 "_savegpr0_", 14, 31,
7279 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7280 this->savres_define(symtab
,
7281 "_restgpr0_", 14, 29,
7282 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7283 this->savres_define(symtab
,
7284 "_restgpr0_", 30, 31,
7285 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7286 this->savres_define(symtab
,
7287 "_savegpr1_", 14, 31,
7288 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7289 this->savres_define(symtab
,
7290 "_restgpr1_", 14, 31,
7291 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7292 this->savres_define(symtab
,
7293 "_savefpr_", 14, 31,
7294 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7295 this->savres_define(symtab
,
7296 "_restfpr_", 14, 29,
7297 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7298 this->savres_define(symtab
,
7299 "_restfpr_", 30, 31,
7300 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7301 this->savres_define(symtab
,
7303 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7304 this->savres_define(symtab
,
7306 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7307 this->savres_define(symtab
,
7309 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7310 this->savres_define(symtab
,
7312 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7315 template<int size
, bool big_endian
>
7317 Output_data_save_res
<size
, big_endian
>::savres_define(
7318 Symbol_table
* symtab
,
7320 unsigned int lo
, unsigned int hi
,
7321 unsigned char* write_ent(unsigned char*, int),
7322 unsigned char* write_tail(unsigned char*, int))
7324 size_t len
= strlen(name
);
7325 bool writing
= false;
7328 memcpy(sym
, name
, len
);
7331 for (unsigned int i
= lo
; i
<= hi
; i
++)
7333 sym
[len
+ 0] = i
/ 10 + '0';
7334 sym
[len
+ 1] = i
% 10 + '0';
7335 Symbol
* gsym
= symtab
->lookup(sym
);
7336 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7337 writing
= writing
|| refd
;
7340 if (this->contents_
== NULL
)
7341 this->contents_
= new unsigned char[this->savres_max
];
7343 section_size_type value
= this->current_data_size();
7344 unsigned char* p
= this->contents_
+ value
;
7346 p
= write_ent(p
, i
);
7348 p
= write_tail(p
, i
);
7349 section_size_type cur_size
= p
- this->contents_
;
7350 this->set_current_data_size(cur_size
);
7352 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7353 this, value
, cur_size
- value
,
7354 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7355 elfcpp::STV_HIDDEN
, 0, false, false);
7360 // Write out save/restore.
7362 template<int size
, bool big_endian
>
7364 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7366 const section_size_type off
= this->offset();
7367 const section_size_type oview_size
=
7368 convert_to_section_size_type(this->data_size());
7369 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7370 memcpy(oview
, this->contents_
, oview_size
);
7371 of
->write_output_view(off
, oview_size
, oview
);
7375 // Create the glink section.
7377 template<int size
, bool big_endian
>
7379 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7381 if (this->glink_
== NULL
)
7383 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7384 this->glink_
->add_eh_frame(layout
);
7385 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7386 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7387 this->glink_
, ORDER_TEXT
, false);
7391 // Create a PLT entry for a global symbol.
7393 template<int size
, bool big_endian
>
7395 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7399 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7400 && gsym
->can_use_relative_reloc(false))
7402 if (this->iplt_
== NULL
)
7403 this->make_iplt_section(symtab
, layout
);
7404 this->iplt_
->add_ifunc_entry(gsym
);
7408 if (this->plt_
== NULL
)
7409 this->make_plt_section(symtab
, layout
);
7410 this->plt_
->add_entry(gsym
);
7414 // Make a PLT entry for a local symbol.
7416 template<int size
, bool big_endian
>
7418 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7420 Sized_relobj_file
<size
, big_endian
>* relobj
,
7423 if (this->lplt_
== NULL
)
7424 this->make_lplt_section(layout
);
7425 this->lplt_
->add_local_entry(relobj
, r_sym
);
7428 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7430 template<int size
, bool big_endian
>
7432 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7433 Symbol_table
* symtab
,
7435 Sized_relobj_file
<size
, big_endian
>* relobj
,
7438 if (this->iplt_
== NULL
)
7439 this->make_iplt_section(symtab
, layout
);
7440 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7443 // Return the number of entries in the PLT.
7445 template<int size
, bool big_endian
>
7447 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7449 if (this->plt_
== NULL
)
7451 return this->plt_
->entry_count();
7454 // Create a GOT entry for local dynamic __tls_get_addr calls.
7456 template<int size
, bool big_endian
>
7458 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7459 Symbol_table
* symtab
,
7461 Sized_relobj_file
<size
, big_endian
>* object
)
7463 if (this->tlsld_got_offset_
== -1U)
7465 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7466 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7467 Output_data_got_powerpc
<size
, big_endian
>* got
7468 = this->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
7469 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7470 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7472 this->tlsld_got_offset_
= got_offset
;
7474 return this->tlsld_got_offset_
;
7477 // Get the Reference_flags for a particular relocation.
7479 template<int size
, bool big_endian
>
7481 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7482 unsigned int r_type
,
7483 const Target_powerpc
* target
)
7489 case elfcpp::R_POWERPC_NONE
:
7490 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7491 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7492 case elfcpp::R_PPC64_TOC
:
7493 // No symbol reference.
7496 case elfcpp::R_PPC64_ADDR64
:
7497 case elfcpp::R_PPC64_UADDR64
:
7498 case elfcpp::R_POWERPC_ADDR32
:
7499 case elfcpp::R_POWERPC_UADDR32
:
7500 case elfcpp::R_POWERPC_ADDR16
:
7501 case elfcpp::R_POWERPC_UADDR16
:
7502 case elfcpp::R_POWERPC_ADDR16_LO
:
7503 case elfcpp::R_POWERPC_ADDR16_HI
:
7504 case elfcpp::R_POWERPC_ADDR16_HA
:
7505 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7506 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7507 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7508 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7509 case elfcpp::R_PPC64_D34
:
7510 case elfcpp::R_PPC64_D34_LO
:
7511 case elfcpp::R_PPC64_D34_HI30
:
7512 case elfcpp::R_PPC64_D34_HA30
:
7513 case elfcpp::R_PPC64_D28
:
7514 ref
= Symbol::ABSOLUTE_REF
;
7517 case elfcpp::R_POWERPC_ADDR24
:
7518 case elfcpp::R_POWERPC_ADDR14
:
7519 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7520 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7521 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7524 case elfcpp::R_PPC64_REL64
:
7525 case elfcpp::R_POWERPC_REL32
:
7526 case elfcpp::R_PPC_LOCAL24PC
:
7527 case elfcpp::R_POWERPC_REL16
:
7528 case elfcpp::R_POWERPC_REL16_LO
:
7529 case elfcpp::R_POWERPC_REL16_HI
:
7530 case elfcpp::R_POWERPC_REL16_HA
:
7531 case elfcpp::R_PPC64_REL16_HIGH
:
7532 case elfcpp::R_PPC64_REL16_HIGHA
:
7533 case elfcpp::R_PPC64_REL16_HIGHER
:
7534 case elfcpp::R_PPC64_REL16_HIGHERA
:
7535 case elfcpp::R_PPC64_REL16_HIGHEST
:
7536 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7537 case elfcpp::R_PPC64_PCREL34
:
7538 case elfcpp::R_PPC64_REL16_HIGHER34
:
7539 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7540 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7541 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7542 case elfcpp::R_PPC64_PCREL28
:
7543 ref
= Symbol::RELATIVE_REF
;
7546 case elfcpp::R_PPC64_REL24_NOTOC
:
7550 case elfcpp::R_POWERPC_REL24
:
7551 case elfcpp::R_PPC_PLTREL24
:
7552 case elfcpp::R_POWERPC_REL14
:
7553 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7554 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7555 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7558 case elfcpp::R_POWERPC_GOT16
:
7559 case elfcpp::R_POWERPC_GOT16_LO
:
7560 case elfcpp::R_POWERPC_GOT16_HI
:
7561 case elfcpp::R_POWERPC_GOT16_HA
:
7562 case elfcpp::R_PPC64_GOT16_DS
:
7563 case elfcpp::R_PPC64_GOT16_LO_DS
:
7564 case elfcpp::R_PPC64_GOT_PCREL34
:
7565 case elfcpp::R_PPC64_TOC16
:
7566 case elfcpp::R_PPC64_TOC16_LO
:
7567 case elfcpp::R_PPC64_TOC16_HI
:
7568 case elfcpp::R_PPC64_TOC16_HA
:
7569 case elfcpp::R_PPC64_TOC16_DS
:
7570 case elfcpp::R_PPC64_TOC16_LO_DS
:
7571 case elfcpp::R_POWERPC_PLT16_LO
:
7572 case elfcpp::R_POWERPC_PLT16_HI
:
7573 case elfcpp::R_POWERPC_PLT16_HA
:
7574 case elfcpp::R_PPC64_PLT16_LO_DS
:
7575 case elfcpp::R_PPC64_PLT_PCREL34
:
7576 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7577 ref
= Symbol::RELATIVE_REF
;
7580 case elfcpp::R_POWERPC_GOT_TPREL16
:
7581 case elfcpp::R_POWERPC_TLS
:
7582 case elfcpp::R_PPC64_TLSGD
:
7583 case elfcpp::R_PPC64_TLSLD
:
7584 case elfcpp::R_PPC64_TPREL34
:
7585 case elfcpp::R_PPC64_DTPREL34
:
7586 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7587 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7588 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7589 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7590 ref
= Symbol::TLS_REF
;
7593 case elfcpp::R_POWERPC_COPY
:
7594 case elfcpp::R_POWERPC_GLOB_DAT
:
7595 case elfcpp::R_POWERPC_JMP_SLOT
:
7596 case elfcpp::R_POWERPC_RELATIVE
:
7597 case elfcpp::R_POWERPC_DTPMOD
:
7599 // Not expected. We will give an error later.
7603 if (size
== 64 && target
->abiversion() < 2)
7604 ref
|= Symbol::FUNC_DESC_ABI
;
7608 // Report an unsupported relocation against a local symbol.
7610 template<int size
, bool big_endian
>
7612 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7613 Sized_relobj_file
<size
, big_endian
>* object
,
7614 unsigned int r_type
)
7616 gold_error(_("%s: unsupported reloc %u against local symbol"),
7617 object
->name().c_str(), r_type
);
7620 // We are about to emit a dynamic relocation of type R_TYPE. If the
7621 // dynamic linker does not support it, issue an error.
7623 template<int size
, bool big_endian
>
7625 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7626 unsigned int r_type
)
7628 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7630 // These are the relocation types supported by glibc for both 32-bit
7631 // and 64-bit powerpc.
7634 case elfcpp::R_POWERPC_NONE
:
7635 case elfcpp::R_POWERPC_RELATIVE
:
7636 case elfcpp::R_POWERPC_GLOB_DAT
:
7637 case elfcpp::R_POWERPC_DTPMOD
:
7638 case elfcpp::R_POWERPC_DTPREL
:
7639 case elfcpp::R_POWERPC_TPREL
:
7640 case elfcpp::R_POWERPC_JMP_SLOT
:
7641 case elfcpp::R_POWERPC_COPY
:
7642 case elfcpp::R_POWERPC_IRELATIVE
:
7643 case elfcpp::R_POWERPC_ADDR32
:
7644 case elfcpp::R_POWERPC_UADDR32
:
7645 case elfcpp::R_POWERPC_ADDR24
:
7646 case elfcpp::R_POWERPC_ADDR16
:
7647 case elfcpp::R_POWERPC_UADDR16
:
7648 case elfcpp::R_POWERPC_ADDR16_LO
:
7649 case elfcpp::R_POWERPC_ADDR16_HI
:
7650 case elfcpp::R_POWERPC_ADDR16_HA
:
7651 case elfcpp::R_POWERPC_ADDR14
:
7652 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7653 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7654 case elfcpp::R_POWERPC_REL32
:
7655 case elfcpp::R_POWERPC_TPREL16
:
7656 case elfcpp::R_POWERPC_TPREL16_LO
:
7657 case elfcpp::R_POWERPC_TPREL16_HI
:
7658 case elfcpp::R_POWERPC_TPREL16_HA
:
7669 // These are the relocation types supported only on 64-bit.
7670 case elfcpp::R_PPC64_ADDR64
:
7671 case elfcpp::R_PPC64_UADDR64
:
7672 case elfcpp::R_PPC64_JMP_IREL
:
7673 case elfcpp::R_PPC64_ADDR16_DS
:
7674 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7675 case elfcpp::R_PPC64_ADDR16_HIGH
:
7676 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7677 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7678 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7679 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7680 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7681 case elfcpp::R_PPC64_REL64
:
7682 case elfcpp::R_POWERPC_ADDR30
:
7683 case elfcpp::R_PPC64_TPREL16_DS
:
7684 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7685 case elfcpp::R_PPC64_TPREL16_HIGH
:
7686 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7687 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7688 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7689 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7690 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7701 // These are the relocation types supported only on 32-bit.
7702 // ??? glibc ld.so doesn't need to support these.
7703 case elfcpp::R_POWERPC_REL24
:
7704 case elfcpp::R_POWERPC_DTPREL16
:
7705 case elfcpp::R_POWERPC_DTPREL16_LO
:
7706 case elfcpp::R_POWERPC_DTPREL16_HI
:
7707 case elfcpp::R_POWERPC_DTPREL16_HA
:
7715 // This prevents us from issuing more than one error per reloc
7716 // section. But we can still wind up issuing more than one
7717 // error per object file.
7718 if (this->issued_non_pic_error_
)
7720 gold_assert(parameters
->options().output_is_position_independent());
7721 object
->error(_("requires unsupported dynamic reloc; "
7722 "recompile with -fPIC"));
7723 this->issued_non_pic_error_
= true;
7727 // Return whether we need to make a PLT entry for a relocation of the
7728 // given type against a STT_GNU_IFUNC symbol.
7730 template<int size
, bool big_endian
>
7732 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7733 Target_powerpc
<size
, big_endian
>* target
,
7734 Sized_relobj_file
<size
, big_endian
>* object
,
7735 unsigned int r_type
,
7738 // In non-pic code any reference will resolve to the plt call stub
7739 // for the ifunc symbol.
7740 if ((size
== 32 || target
->abiversion() >= 2)
7741 && !parameters
->options().output_is_position_independent())
7746 // Word size refs from data sections are OK, but don't need a PLT entry.
7747 case elfcpp::R_POWERPC_ADDR32
:
7748 case elfcpp::R_POWERPC_UADDR32
:
7753 case elfcpp::R_PPC64_ADDR64
:
7754 case elfcpp::R_PPC64_UADDR64
:
7759 // GOT refs are good, but also don't need a PLT entry.
7760 case elfcpp::R_POWERPC_GOT16
:
7761 case elfcpp::R_POWERPC_GOT16_LO
:
7762 case elfcpp::R_POWERPC_GOT16_HI
:
7763 case elfcpp::R_POWERPC_GOT16_HA
:
7764 case elfcpp::R_PPC64_GOT16_DS
:
7765 case elfcpp::R_PPC64_GOT16_LO_DS
:
7766 case elfcpp::R_PPC64_GOT_PCREL34
:
7769 // PLT relocs are OK and need a PLT entry.
7770 case elfcpp::R_POWERPC_PLT16_LO
:
7771 case elfcpp::R_POWERPC_PLT16_HI
:
7772 case elfcpp::R_POWERPC_PLT16_HA
:
7773 case elfcpp::R_PPC64_PLT16_LO_DS
:
7774 case elfcpp::R_POWERPC_PLTSEQ
:
7775 case elfcpp::R_POWERPC_PLTCALL
:
7776 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7777 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7778 case elfcpp::R_PPC64_PLT_PCREL34
:
7779 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7783 // Function calls are good, and these do need a PLT entry.
7784 case elfcpp::R_PPC64_REL24_NOTOC
:
7788 case elfcpp::R_POWERPC_ADDR24
:
7789 case elfcpp::R_POWERPC_ADDR14
:
7790 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7791 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7792 case elfcpp::R_POWERPC_REL24
:
7793 case elfcpp::R_PPC_PLTREL24
:
7794 case elfcpp::R_POWERPC_REL14
:
7795 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7796 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7803 // Anything else is a problem.
7804 // If we are building a static executable, the libc startup function
7805 // responsible for applying indirect function relocations is going
7806 // to complain about the reloc type.
7807 // If we are building a dynamic executable, we will have a text
7808 // relocation. The dynamic loader will set the text segment
7809 // writable and non-executable to apply text relocations. So we'll
7810 // segfault when trying to run the indirection function to resolve
7813 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7814 object
->name().c_str(), r_type
);
7818 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7822 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7824 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7825 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7826 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7827 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7828 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7829 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7830 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7831 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7832 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7833 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7834 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7835 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7836 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7837 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7838 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7839 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7840 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7841 /* Exclude lfqu by testing reloc. If relocs are ever
7842 defined for the reduced D field in psq_lu then those
7843 will need testing too. */
7844 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7845 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7846 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7848 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7849 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7850 /* Exclude stfqu. psq_stu as above for psq_lu. */
7851 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7852 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7853 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7854 && (insn
& 1) == 0));
7857 // Scan a relocation for a local symbol.
7859 template<int size
, bool big_endian
>
7861 Target_powerpc
<size
, big_endian
>::Scan::local(
7862 Symbol_table
* symtab
,
7864 Target_powerpc
<size
, big_endian
>* target
,
7865 Sized_relobj_file
<size
, big_endian
>* object
,
7866 unsigned int data_shndx
,
7867 Output_section
* output_section
,
7868 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7869 unsigned int r_type
,
7870 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7873 Powerpc_relobj
<size
, big_endian
>* ppc_object
7874 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7876 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7878 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7879 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7881 this->expect_tls_get_addr_call();
7882 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7883 if (tls_type
!= tls::TLSOPT_NONE
)
7884 this->skip_next_tls_get_addr_call();
7886 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7887 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7889 this->expect_tls_get_addr_call();
7890 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7891 if (tls_type
!= tls::TLSOPT_NONE
)
7892 this->skip_next_tls_get_addr_call();
7898 && data_shndx
== ppc_object
->opd_shndx()
7899 && r_type
== elfcpp::R_PPC64_ADDR64
)
7900 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7904 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7905 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7906 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7908 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7909 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7910 r_type
, r_sym
, reloc
.get_r_addend());
7911 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7916 case elfcpp::R_POWERPC_NONE
:
7917 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7918 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7919 case elfcpp::R_POWERPC_TLS
:
7920 case elfcpp::R_PPC64_ENTRY
:
7921 case elfcpp::R_POWERPC_PLTSEQ
:
7922 case elfcpp::R_POWERPC_PLTCALL
:
7923 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7924 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7925 case elfcpp::R_PPC64_PCREL_OPT
:
7926 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7927 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7928 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7929 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7930 case elfcpp::R_PPC64_REL16_HIGHER34
:
7931 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7932 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7933 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7934 case elfcpp::R_PPC64_D34
:
7935 case elfcpp::R_PPC64_D34_LO
:
7936 case elfcpp::R_PPC64_D34_HI30
:
7937 case elfcpp::R_PPC64_D34_HA30
:
7938 case elfcpp::R_PPC64_D28
:
7939 case elfcpp::R_PPC64_PCREL34
:
7940 case elfcpp::R_PPC64_PCREL28
:
7941 case elfcpp::R_PPC64_TPREL34
:
7942 case elfcpp::R_PPC64_DTPREL34
:
7945 case elfcpp::R_PPC64_TOC
:
7947 Output_data_got_powerpc
<size
, big_endian
>* got
7948 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
7949 if (parameters
->options().output_is_position_independent())
7951 Address off
= reloc
.get_r_offset();
7953 && target
->abiversion() < 2
7954 && data_shndx
== ppc_object
->opd_shndx()
7955 && ppc_object
->get_opd_discard(off
- 8))
7958 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7959 Address got_off
= got
->g_o_t();
7960 rela_dyn
->add_output_section_relative(got
->output_section(),
7961 elfcpp::R_POWERPC_RELATIVE
,
7963 object
, data_shndx
, off
,
7969 case elfcpp::R_PPC64_ADDR64
:
7970 case elfcpp::R_PPC64_UADDR64
:
7971 case elfcpp::R_POWERPC_ADDR32
:
7972 case elfcpp::R_POWERPC_UADDR32
:
7973 case elfcpp::R_POWERPC_ADDR24
:
7974 case elfcpp::R_POWERPC_ADDR16
:
7975 case elfcpp::R_POWERPC_ADDR16_LO
:
7976 case elfcpp::R_POWERPC_ADDR16_HI
:
7977 case elfcpp::R_POWERPC_ADDR16_HA
:
7978 case elfcpp::R_POWERPC_UADDR16
:
7979 case elfcpp::R_PPC64_ADDR16_HIGH
:
7980 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7981 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7982 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7983 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7984 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7985 case elfcpp::R_PPC64_ADDR16_DS
:
7986 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7987 case elfcpp::R_POWERPC_ADDR14
:
7988 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7989 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7990 // If building a shared library (or a position-independent
7991 // executable), we need to create a dynamic relocation for
7993 if (parameters
->options().output_is_position_independent()
7994 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7996 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7998 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7999 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8000 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8002 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8003 : elfcpp::R_POWERPC_RELATIVE
);
8004 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8005 output_section
, data_shndx
,
8006 reloc
.get_r_offset(),
8007 reloc
.get_r_addend(), false);
8009 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8011 check_non_pic(object
, r_type
);
8012 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8013 data_shndx
, reloc
.get_r_offset(),
8014 reloc
.get_r_addend());
8018 gold_assert(lsym
.get_st_value() == 0);
8019 unsigned int shndx
= lsym
.get_st_shndx();
8021 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8024 object
->error(_("section symbol %u has bad shndx %u"),
8027 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8028 output_section
, data_shndx
,
8029 reloc
.get_r_offset());
8034 case elfcpp::R_PPC64_PLT_PCREL34
:
8035 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8036 case elfcpp::R_POWERPC_PLT16_LO
:
8037 case elfcpp::R_POWERPC_PLT16_HI
:
8038 case elfcpp::R_POWERPC_PLT16_HA
:
8039 case elfcpp::R_PPC64_PLT16_LO_DS
:
8042 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8043 target
->make_local_plt_entry(layout
, object
, r_sym
);
8047 case elfcpp::R_PPC64_REL24_NOTOC
:
8051 case elfcpp::R_POWERPC_REL24
:
8052 case elfcpp::R_PPC_PLTREL24
:
8053 case elfcpp::R_PPC_LOCAL24PC
:
8054 case elfcpp::R_POWERPC_REL14
:
8055 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8056 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8059 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8060 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8061 r_type
, r_sym
, reloc
.get_r_addend());
8065 case elfcpp::R_PPC64_TOCSAVE
:
8066 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8067 // caller has already saved r2 and thus a plt call stub need not
8070 && target
->mark_pltcall(ppc_object
, data_shndx
,
8071 reloc
.get_r_offset() - 4, symtab
))
8073 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8074 unsigned int shndx
= lsym
.get_st_shndx();
8076 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8078 object
->error(_("tocsave symbol %u has bad shndx %u"),
8081 target
->add_tocsave(ppc_object
, shndx
,
8082 lsym
.get_st_value() + reloc
.get_r_addend());
8086 case elfcpp::R_PPC64_REL64
:
8087 case elfcpp::R_POWERPC_REL32
:
8088 case elfcpp::R_POWERPC_REL16
:
8089 case elfcpp::R_POWERPC_REL16_LO
:
8090 case elfcpp::R_POWERPC_REL16_HI
:
8091 case elfcpp::R_POWERPC_REL16_HA
:
8092 case elfcpp::R_POWERPC_REL16DX_HA
:
8093 case elfcpp::R_PPC64_REL16_HIGH
:
8094 case elfcpp::R_PPC64_REL16_HIGHA
:
8095 case elfcpp::R_PPC64_REL16_HIGHER
:
8096 case elfcpp::R_PPC64_REL16_HIGHERA
:
8097 case elfcpp::R_PPC64_REL16_HIGHEST
:
8098 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8099 case elfcpp::R_POWERPC_SECTOFF
:
8100 case elfcpp::R_POWERPC_SECTOFF_LO
:
8101 case elfcpp::R_POWERPC_SECTOFF_HI
:
8102 case elfcpp::R_POWERPC_SECTOFF_HA
:
8103 case elfcpp::R_PPC64_SECTOFF_DS
:
8104 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8105 case elfcpp::R_POWERPC_TPREL16
:
8106 case elfcpp::R_POWERPC_TPREL16_LO
:
8107 case elfcpp::R_POWERPC_TPREL16_HI
:
8108 case elfcpp::R_POWERPC_TPREL16_HA
:
8109 case elfcpp::R_PPC64_TPREL16_DS
:
8110 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8111 case elfcpp::R_PPC64_TPREL16_HIGH
:
8112 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8113 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8114 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8115 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8116 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8117 case elfcpp::R_POWERPC_DTPREL16
:
8118 case elfcpp::R_POWERPC_DTPREL16_LO
:
8119 case elfcpp::R_POWERPC_DTPREL16_HI
:
8120 case elfcpp::R_POWERPC_DTPREL16_HA
:
8121 case elfcpp::R_PPC64_DTPREL16_DS
:
8122 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8123 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8124 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8125 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8126 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8127 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8128 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8129 case elfcpp::R_PPC64_TLSGD
:
8130 case elfcpp::R_PPC64_TLSLD
:
8131 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8134 case elfcpp::R_PPC64_GOT_PCREL34
:
8135 case elfcpp::R_POWERPC_GOT16
:
8136 case elfcpp::R_POWERPC_GOT16_LO
:
8137 case elfcpp::R_POWERPC_GOT16_HI
:
8138 case elfcpp::R_POWERPC_GOT16_HA
:
8139 case elfcpp::R_PPC64_GOT16_DS
:
8140 case elfcpp::R_PPC64_GOT16_LO_DS
:
8142 // The symbol requires a GOT entry.
8143 Got_type got_type
= ((size
== 32
8144 || r_type
== elfcpp::R_POWERPC_GOT16
8145 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8146 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8147 Output_data_got_powerpc
<size
, big_endian
>* got
8148 = target
->got_section(symtab
, layout
, got_type
);
8149 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8150 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8152 if (!parameters
->options().output_is_position_independent())
8155 && (size
== 32 || target
->abiversion() >= 2))
8156 got
->add_local_plt(object
, r_sym
, got_type
, addend
);
8158 got
->add_local(object
, r_sym
, got_type
, addend
);
8160 else if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8162 // If we are generating a shared object or a pie, this
8163 // symbol's GOT entry will be set by a dynamic relocation.
8165 off
= got
->add_constant(0);
8166 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8168 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8170 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8171 : elfcpp::R_POWERPC_RELATIVE
);
8172 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8173 got
, off
, addend
, false);
8178 case elfcpp::R_PPC64_TOC16
:
8179 case elfcpp::R_PPC64_TOC16_LO
:
8180 case elfcpp::R_PPC64_TOC16_HI
:
8181 case elfcpp::R_PPC64_TOC16_HA
:
8182 case elfcpp::R_PPC64_TOC16_DS
:
8183 case elfcpp::R_PPC64_TOC16_LO_DS
:
8184 // We need a GOT section.
8185 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8188 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8189 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8190 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8191 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8192 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8194 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8195 if (tls_type
== tls::TLSOPT_NONE
)
8197 Got_type got_type
= ((size
== 32
8198 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8199 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8200 Output_data_got_powerpc
<size
, big_endian
>* got
8201 = target
->got_section(symtab
, layout
, got_type
);
8202 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8203 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8204 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8205 got
->add_local_tls_pair(object
, r_sym
, got_type
,
8206 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
,
8209 else if (tls_type
== tls::TLSOPT_TO_LE
)
8211 // no GOT relocs needed for Local Exec.
8218 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8219 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8220 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8221 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8222 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8224 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8225 if (tls_type
== tls::TLSOPT_NONE
)
8226 target
->tlsld_got_offset(symtab
, layout
, object
);
8227 else if (tls_type
== tls::TLSOPT_TO_LE
)
8229 // no GOT relocs needed for Local Exec.
8230 if (parameters
->options().emit_relocs())
8232 Output_section
* os
= layout
->tls_segment()->first_section();
8233 gold_assert(os
!= NULL
);
8234 os
->set_needs_symtab_index();
8242 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8243 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8244 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8245 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8246 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8248 Got_type got_type
= ((size
== 32
8249 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
8250 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
8251 Output_data_got_powerpc
<size
, big_endian
>* got
8252 = target
->got_section(symtab
, layout
, got_type
);
8253 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8254 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8255 got
->add_local_tls(object
, r_sym
, got_type
, addend
);
8259 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8260 case elfcpp::R_POWERPC_GOT_TPREL16
:
8261 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8262 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8263 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8265 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8266 if (tls_type
== tls::TLSOPT_NONE
)
8268 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8269 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8270 Got_type got_type
= ((size
== 32
8271 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
8272 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
8273 if (!object
->local_has_got_offset(r_sym
, got_type
, addend
))
8275 Output_data_got_powerpc
<size
, big_endian
>* got
8276 = target
->got_section(symtab
, layout
, got_type
);
8277 unsigned int off
= got
->add_constant(0);
8278 object
->set_local_got_offset(r_sym
, got_type
, off
, addend
);
8280 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8281 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8282 elfcpp::R_POWERPC_TPREL
,
8286 else if (tls_type
== tls::TLSOPT_TO_LE
)
8288 // no GOT relocs needed for Local Exec.
8296 unsupported_reloc_local(object
, r_type
);
8301 && parameters
->options().toc_optimize())
8303 if (data_shndx
== ppc_object
->toc_shndx())
8306 if (r_type
!= elfcpp::R_PPC64_ADDR64
8307 || (is_ifunc
&& target
->abiversion() < 2))
8309 else if (parameters
->options().output_is_position_independent())
8315 unsigned int shndx
= lsym
.get_st_shndx();
8316 if (shndx
>= elfcpp::SHN_LORESERVE
8317 && shndx
!= elfcpp::SHN_XINDEX
)
8322 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8325 enum {no_check
, check_lo
, check_ha
} insn_check
;
8329 insn_check
= no_check
;
8332 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8333 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8334 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8335 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8336 case elfcpp::R_POWERPC_GOT16_HA
:
8337 case elfcpp::R_PPC64_TOC16_HA
:
8338 insn_check
= check_ha
;
8341 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8342 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8343 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8344 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8345 case elfcpp::R_POWERPC_GOT16_LO
:
8346 case elfcpp::R_PPC64_GOT16_LO_DS
:
8347 case elfcpp::R_PPC64_TOC16_LO
:
8348 case elfcpp::R_PPC64_TOC16_LO_DS
:
8349 insn_check
= check_lo
;
8353 section_size_type slen
;
8354 const unsigned char* view
= NULL
;
8355 if (insn_check
!= no_check
)
8357 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8358 section_size_type off
=
8359 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8362 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8363 if (insn_check
== check_lo
8364 ? !ok_lo_toc_insn(insn
, r_type
)
8365 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8366 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8368 ppc_object
->set_no_toc_opt();
8369 gold_warning(_("%s: toc optimization is not supported "
8370 "for %#08x instruction"),
8371 ppc_object
->name().c_str(), insn
);
8380 case elfcpp::R_PPC64_TOC16
:
8381 case elfcpp::R_PPC64_TOC16_LO
:
8382 case elfcpp::R_PPC64_TOC16_HI
:
8383 case elfcpp::R_PPC64_TOC16_HA
:
8384 case elfcpp::R_PPC64_TOC16_DS
:
8385 case elfcpp::R_PPC64_TOC16_LO_DS
:
8386 unsigned int shndx
= lsym
.get_st_shndx();
8387 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8389 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8390 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8392 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8393 if (dst_off
< ppc_object
->section_size(shndx
))
8396 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8398 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8400 // Need to check that the insn is a ld
8402 view
= ppc_object
->section_contents(data_shndx
,
8405 section_size_type off
=
8406 (convert_to_section_size_type(reloc
.get_r_offset())
8407 + (big_endian
? -2 : 3));
8409 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8413 ppc_object
->set_no_toc_opt(dst_off
);
8424 case elfcpp::R_POWERPC_REL32
:
8425 if (ppc_object
->got2_shndx() != 0
8426 && parameters
->options().output_is_position_independent())
8428 unsigned int shndx
= lsym
.get_st_shndx();
8429 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8431 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8432 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8433 && (ppc_object
->section_flags(data_shndx
)
8434 & elfcpp::SHF_EXECINSTR
) != 0)
8435 gold_error(_("%s: unsupported -mbss-plt code"),
8436 ppc_object
->name().c_str());
8446 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8447 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8448 case elfcpp::R_POWERPC_GOT_TPREL16
:
8449 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8450 case elfcpp::R_POWERPC_GOT16
:
8451 case elfcpp::R_PPC64_GOT16_DS
:
8452 case elfcpp::R_PPC64_TOC16
:
8453 case elfcpp::R_PPC64_TOC16_DS
:
8454 ppc_object
->set_has_small_toc_reloc();
8462 case elfcpp::R_PPC64_TPREL16_DS
:
8463 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8464 case elfcpp::R_PPC64_TPREL16_HIGH
:
8465 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8466 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8467 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8468 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8469 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8470 case elfcpp::R_PPC64_TPREL34
:
8474 case elfcpp::R_POWERPC_TPREL16
:
8475 case elfcpp::R_POWERPC_TPREL16_LO
:
8476 case elfcpp::R_POWERPC_TPREL16_HI
:
8477 case elfcpp::R_POWERPC_TPREL16_HA
:
8478 layout
->set_has_static_tls();
8486 case elfcpp::R_POWERPC_TPREL16_HA
:
8487 if (target
->tprel_opt())
8489 section_size_type slen
;
8490 const unsigned char* view
= NULL
;
8491 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8492 section_size_type off
8493 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8496 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8497 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8498 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8499 target
->set_no_tprel_opt();
8504 case elfcpp::R_PPC64_TPREL16_HIGH
:
8505 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8506 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8507 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8508 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8509 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8513 case elfcpp::R_POWERPC_TPREL16_HI
:
8514 target
->set_no_tprel_opt();
8522 case elfcpp::R_PPC64_D34
:
8523 case elfcpp::R_PPC64_D34_LO
:
8524 case elfcpp::R_PPC64_D34_HI30
:
8525 case elfcpp::R_PPC64_D34_HA30
:
8526 case elfcpp::R_PPC64_D28
:
8527 case elfcpp::R_PPC64_PCREL34
:
8528 case elfcpp::R_PPC64_PCREL28
:
8529 case elfcpp::R_PPC64_TPREL34
:
8530 case elfcpp::R_PPC64_DTPREL34
:
8531 case elfcpp::R_PPC64_PLT_PCREL34
:
8532 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8533 case elfcpp::R_PPC64_GOT_PCREL34
:
8534 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8535 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8536 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8537 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8538 target
->set_power10_relocs();
8545 // Report an unsupported relocation against a global symbol.
8547 template<int size
, bool big_endian
>
8549 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8550 Sized_relobj_file
<size
, big_endian
>* object
,
8551 unsigned int r_type
,
8554 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8555 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8558 // Scan a relocation for a global symbol.
8560 template<int size
, bool big_endian
>
8562 Target_powerpc
<size
, big_endian
>::Scan::global(
8563 Symbol_table
* symtab
,
8565 Target_powerpc
<size
, big_endian
>* target
,
8566 Sized_relobj_file
<size
, big_endian
>* object
,
8567 unsigned int data_shndx
,
8568 Output_section
* output_section
,
8569 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8570 unsigned int r_type
,
8573 Powerpc_relobj
<size
, big_endian
>* ppc_object
8574 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8576 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8578 case Track_tls::SKIP
:
8584 if (target
->replace_tls_get_addr(gsym
))
8585 // Change a __tls_get_addr reference to __tls_get_addr_opt
8586 // so dynamic relocs are emitted against the latter symbol.
8587 gsym
= target
->tls_get_addr_opt();
8589 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8590 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8592 this->expect_tls_get_addr_call();
8593 bool final
= gsym
->final_value_is_known();
8594 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8595 if (tls_type
!= tls::TLSOPT_NONE
)
8596 this->skip_next_tls_get_addr_call();
8598 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8599 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8601 this->expect_tls_get_addr_call();
8602 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8603 if (tls_type
!= tls::TLSOPT_NONE
)
8604 this->skip_next_tls_get_addr_call();
8607 // A STT_GNU_IFUNC symbol may require a PLT entry.
8608 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8609 bool pushed_ifunc
= false;
8610 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8612 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8613 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8614 r_type
, r_sym
, reloc
.get_r_addend());
8615 target
->make_plt_entry(symtab
, layout
, gsym
);
8616 pushed_ifunc
= true;
8621 case elfcpp::R_POWERPC_NONE
:
8622 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8623 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8624 case elfcpp::R_PPC_LOCAL24PC
:
8625 case elfcpp::R_POWERPC_TLS
:
8626 case elfcpp::R_PPC64_ENTRY
:
8627 case elfcpp::R_POWERPC_PLTSEQ
:
8628 case elfcpp::R_POWERPC_PLTCALL
:
8629 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8630 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8631 case elfcpp::R_PPC64_PCREL_OPT
:
8632 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8633 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8634 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8635 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8636 case elfcpp::R_PPC64_REL16_HIGHER34
:
8637 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8638 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8639 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8640 case elfcpp::R_PPC64_D34
:
8641 case elfcpp::R_PPC64_D34_LO
:
8642 case elfcpp::R_PPC64_D34_HI30
:
8643 case elfcpp::R_PPC64_D34_HA30
:
8644 case elfcpp::R_PPC64_D28
:
8645 case elfcpp::R_PPC64_PCREL34
:
8646 case elfcpp::R_PPC64_PCREL28
:
8647 case elfcpp::R_PPC64_TPREL34
:
8648 case elfcpp::R_PPC64_DTPREL34
:
8651 case elfcpp::R_PPC64_TOC
:
8653 Output_data_got_powerpc
<size
, big_endian
>* got
8654 = target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8655 if (parameters
->options().output_is_position_independent())
8657 Address off
= reloc
.get_r_offset();
8659 && data_shndx
== ppc_object
->opd_shndx()
8660 && ppc_object
->get_opd_discard(off
- 8))
8663 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8664 Address got_off
= got
->g_o_t();
8665 rela_dyn
->add_output_section_relative(got
->output_section(),
8666 elfcpp::R_POWERPC_RELATIVE
,
8668 object
, data_shndx
, off
,
8674 case elfcpp::R_PPC64_ADDR64
:
8676 && target
->abiversion() < 2
8677 && data_shndx
== ppc_object
->opd_shndx()
8678 && (gsym
->is_defined_in_discarded_section()
8679 || gsym
->object() != object
))
8681 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8685 case elfcpp::R_PPC64_UADDR64
:
8686 case elfcpp::R_POWERPC_ADDR32
:
8687 case elfcpp::R_POWERPC_UADDR32
:
8688 case elfcpp::R_POWERPC_ADDR24
:
8689 case elfcpp::R_POWERPC_ADDR16
:
8690 case elfcpp::R_POWERPC_ADDR16_LO
:
8691 case elfcpp::R_POWERPC_ADDR16_HI
:
8692 case elfcpp::R_POWERPC_ADDR16_HA
:
8693 case elfcpp::R_POWERPC_UADDR16
:
8694 case elfcpp::R_PPC64_ADDR16_HIGH
:
8695 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8696 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8697 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8698 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8699 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8700 case elfcpp::R_PPC64_ADDR16_DS
:
8701 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8702 case elfcpp::R_POWERPC_ADDR14
:
8703 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8704 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8706 // Make a PLT entry if necessary.
8707 if (gsym
->needs_plt_entry())
8709 // Since this is not a PC-relative relocation, we may be
8710 // taking the address of a function. In that case we need to
8711 // set the entry in the dynamic symbol table to the address of
8712 // the PLT call stub.
8713 bool need_ifunc_plt
= false;
8714 if ((size
== 32 || target
->abiversion() >= 2)
8715 && gsym
->is_from_dynobj()
8716 && !parameters
->options().output_is_position_independent())
8718 gsym
->set_needs_dynsym_value();
8719 need_ifunc_plt
= true;
8721 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8723 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8724 target
->push_branch(ppc_object
, data_shndx
,
8725 reloc
.get_r_offset(), r_type
, r_sym
,
8726 reloc
.get_r_addend());
8727 target
->make_plt_entry(symtab
, layout
, gsym
);
8730 // Make a dynamic relocation if necessary.
8731 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8732 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8734 if (!parameters
->options().output_is_position_independent()
8735 && gsym
->may_need_copy_reloc())
8737 target
->copy_reloc(symtab
, layout
, object
,
8738 data_shndx
, output_section
, gsym
, reloc
);
8740 else if ((((size
== 32
8741 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8743 && r_type
== elfcpp::R_PPC64_ADDR64
8744 && target
->abiversion() >= 2))
8745 && gsym
->can_use_relative_reloc(false)
8746 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8747 && parameters
->options().shared()))
8749 && r_type
== elfcpp::R_PPC64_ADDR64
8750 && target
->abiversion() < 2
8751 && (gsym
->can_use_relative_reloc(false)
8752 || data_shndx
== ppc_object
->opd_shndx())))
8754 Reloc_section
* rela_dyn
8755 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8756 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8757 : elfcpp::R_POWERPC_RELATIVE
);
8758 rela_dyn
->add_symbolless_global_addend(
8759 gsym
, dynrel
, output_section
, object
, data_shndx
,
8760 reloc
.get_r_offset(), reloc
.get_r_addend());
8764 Reloc_section
* rela_dyn
8765 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8766 check_non_pic(object
, r_type
);
8767 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8769 reloc
.get_r_offset(),
8770 reloc
.get_r_addend());
8773 && parameters
->options().toc_optimize()
8774 && data_shndx
== ppc_object
->toc_shndx())
8775 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8781 case elfcpp::R_PPC64_PLT_PCREL34
:
8782 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8783 case elfcpp::R_POWERPC_PLT16_LO
:
8784 case elfcpp::R_POWERPC_PLT16_HI
:
8785 case elfcpp::R_POWERPC_PLT16_HA
:
8786 case elfcpp::R_PPC64_PLT16_LO_DS
:
8788 target
->make_plt_entry(symtab
, layout
, gsym
);
8791 case elfcpp::R_PPC64_REL24_NOTOC
:
8795 case elfcpp::R_PPC_PLTREL24
:
8796 case elfcpp::R_POWERPC_REL24
:
8799 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8800 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8801 r_type
, r_sym
, reloc
.get_r_addend());
8802 if (gsym
->needs_plt_entry()
8803 || (!gsym
->final_value_is_known()
8804 && (gsym
->is_undefined()
8805 || gsym
->is_from_dynobj()
8806 || gsym
->is_preemptible())))
8807 target
->make_plt_entry(symtab
, layout
, gsym
);
8811 case elfcpp::R_PPC64_REL64
:
8812 case elfcpp::R_POWERPC_REL32
:
8813 // Make a dynamic relocation if necessary.
8814 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8816 if (!parameters
->options().output_is_position_independent()
8817 && gsym
->may_need_copy_reloc())
8819 target
->copy_reloc(symtab
, layout
, object
,
8820 data_shndx
, output_section
, gsym
,
8825 Reloc_section
* rela_dyn
8826 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8827 check_non_pic(object
, r_type
);
8828 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8829 data_shndx
, reloc
.get_r_offset(),
8830 reloc
.get_r_addend());
8835 case elfcpp::R_POWERPC_REL14
:
8836 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8837 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8840 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8841 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8842 r_type
, r_sym
, reloc
.get_r_addend());
8846 case elfcpp::R_PPC64_TOCSAVE
:
8847 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8848 // caller has already saved r2 and thus a plt call stub need not
8851 && target
->mark_pltcall(ppc_object
, data_shndx
,
8852 reloc
.get_r_offset() - 4, symtab
))
8854 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8856 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8858 object
->error(_("tocsave symbol %u has bad shndx %u"),
8862 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8863 target
->add_tocsave(ppc_object
, shndx
,
8864 sym
->value() + reloc
.get_r_addend());
8869 case elfcpp::R_POWERPC_REL16
:
8870 case elfcpp::R_POWERPC_REL16_LO
:
8871 case elfcpp::R_POWERPC_REL16_HI
:
8872 case elfcpp::R_POWERPC_REL16_HA
:
8873 case elfcpp::R_POWERPC_REL16DX_HA
:
8874 case elfcpp::R_PPC64_REL16_HIGH
:
8875 case elfcpp::R_PPC64_REL16_HIGHA
:
8876 case elfcpp::R_PPC64_REL16_HIGHER
:
8877 case elfcpp::R_PPC64_REL16_HIGHERA
:
8878 case elfcpp::R_PPC64_REL16_HIGHEST
:
8879 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8880 case elfcpp::R_POWERPC_SECTOFF
:
8881 case elfcpp::R_POWERPC_SECTOFF_LO
:
8882 case elfcpp::R_POWERPC_SECTOFF_HI
:
8883 case elfcpp::R_POWERPC_SECTOFF_HA
:
8884 case elfcpp::R_PPC64_SECTOFF_DS
:
8885 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8886 case elfcpp::R_POWERPC_TPREL16
:
8887 case elfcpp::R_POWERPC_TPREL16_LO
:
8888 case elfcpp::R_POWERPC_TPREL16_HI
:
8889 case elfcpp::R_POWERPC_TPREL16_HA
:
8890 case elfcpp::R_PPC64_TPREL16_DS
:
8891 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8892 case elfcpp::R_PPC64_TPREL16_HIGH
:
8893 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8894 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8895 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8896 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8897 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8898 case elfcpp::R_POWERPC_DTPREL16
:
8899 case elfcpp::R_POWERPC_DTPREL16_LO
:
8900 case elfcpp::R_POWERPC_DTPREL16_HI
:
8901 case elfcpp::R_POWERPC_DTPREL16_HA
:
8902 case elfcpp::R_PPC64_DTPREL16_DS
:
8903 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8904 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8905 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8906 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8907 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8908 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8909 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8910 case elfcpp::R_PPC64_TLSGD
:
8911 case elfcpp::R_PPC64_TLSLD
:
8912 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8915 case elfcpp::R_PPC64_GOT_PCREL34
:
8916 case elfcpp::R_POWERPC_GOT16
:
8917 case elfcpp::R_POWERPC_GOT16_LO
:
8918 case elfcpp::R_POWERPC_GOT16_HI
:
8919 case elfcpp::R_POWERPC_GOT16_HA
:
8920 case elfcpp::R_PPC64_GOT16_DS
:
8921 case elfcpp::R_PPC64_GOT16_LO_DS
:
8923 // The symbol requires a GOT entry.
8924 Output_data_got_powerpc
<size
, big_endian
>* got
;
8925 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8926 Got_type got_type
= ((size
== 32
8927 || r_type
== elfcpp::R_POWERPC_GOT16
8928 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
8929 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
8931 got
= target
->got_section(symtab
, layout
, got_type
);
8932 if (gsym
->final_value_is_known())
8935 && (size
== 32 || target
->abiversion() >= 2))
8936 got
->add_global_plt(gsym
, got_type
, addend
);
8938 got
->add_global(gsym
, got_type
, addend
);
8940 else if (!gsym
->has_got_offset(got_type
, addend
))
8942 // If we are generating a shared object or a pie, this
8943 // symbol's GOT entry will be set by a dynamic relocation.
8944 unsigned int off
= got
->add_constant(0);
8945 gsym
->set_got_offset(got_type
, off
, addend
);
8947 Reloc_section
* rela_dyn
8948 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8950 if (gsym
->can_use_relative_reloc(false)
8952 || target
->abiversion() >= 2)
8953 && gsym
->visibility() == elfcpp::STV_PROTECTED
8954 && parameters
->options().shared()))
8956 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8957 : elfcpp::R_POWERPC_RELATIVE
);
8958 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
,
8963 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8964 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, addend
);
8970 case elfcpp::R_PPC64_TOC16
:
8971 case elfcpp::R_PPC64_TOC16_LO
:
8972 case elfcpp::R_PPC64_TOC16_HI
:
8973 case elfcpp::R_PPC64_TOC16_HA
:
8974 case elfcpp::R_PPC64_TOC16_DS
:
8975 case elfcpp::R_PPC64_TOC16_LO_DS
:
8976 // We need a GOT section.
8977 target
->got_section(symtab
, layout
, GOT_TYPE_SMALL
);
8980 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8981 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8982 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8983 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8984 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8986 bool final
= gsym
->final_value_is_known();
8987 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8988 if (tls_type
== tls::TLSOPT_NONE
)
8990 Got_type got_type
= ((size
== 32
8991 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
8992 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
8993 Output_data_got_powerpc
<size
, big_endian
>* got
8994 = target
->got_section(symtab
, layout
, got_type
);
8995 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8996 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
8997 got
->add_global_pair_with_rel(gsym
, got_type
, rela_dyn
,
8998 elfcpp::R_POWERPC_DTPMOD
,
8999 elfcpp::R_POWERPC_DTPREL
,
9002 else if (tls_type
== tls::TLSOPT_TO_IE
)
9004 Got_type got_type
= ((size
== 32
9005 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
9006 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9007 if (!gsym
->has_got_offset(got_type
))
9009 Output_data_got_powerpc
<size
, big_endian
>* got
9010 = target
->got_section(symtab
, layout
, got_type
);
9011 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9012 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9013 if (gsym
->is_undefined()
9014 || gsym
->is_from_dynobj())
9016 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9017 elfcpp::R_POWERPC_TPREL
, addend
);
9021 unsigned int off
= got
->add_constant(0);
9022 gsym
->set_got_offset(got_type
, off
);
9023 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9024 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9029 else if (tls_type
== tls::TLSOPT_TO_LE
)
9031 // no GOT relocs needed for Local Exec.
9038 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9039 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9040 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9041 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9042 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9044 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9045 if (tls_type
== tls::TLSOPT_NONE
)
9046 target
->tlsld_got_offset(symtab
, layout
, object
);
9047 else if (tls_type
== tls::TLSOPT_TO_LE
)
9049 // no GOT relocs needed for Local Exec.
9050 if (parameters
->options().emit_relocs())
9052 Output_section
* os
= layout
->tls_segment()->first_section();
9053 gold_assert(os
!= NULL
);
9054 os
->set_needs_symtab_index();
9062 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9063 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9064 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9065 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9066 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9068 Got_type got_type
= ((size
== 32
9069 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
9070 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
9071 Output_data_got_powerpc
<size
, big_endian
>* got
9072 = target
->got_section(symtab
, layout
, got_type
);
9073 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9074 if (!gsym
->final_value_is_known()
9075 && (gsym
->is_from_dynobj()
9076 || gsym
->is_undefined()
9077 || gsym
->is_preemptible()))
9078 got
->add_global_with_rel(gsym
, got_type
,
9079 target
->rela_dyn_section(layout
),
9080 elfcpp::R_POWERPC_DTPREL
, addend
);
9082 got
->add_global_tls(gsym
, got_type
, addend
);
9086 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9087 case elfcpp::R_POWERPC_GOT_TPREL16
:
9088 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9089 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9090 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9092 bool final
= gsym
->final_value_is_known();
9093 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9094 if (tls_type
== tls::TLSOPT_NONE
)
9096 Got_type got_type
= ((size
== 32
9097 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
9098 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
9099 if (!gsym
->has_got_offset(got_type
))
9101 Output_data_got_powerpc
<size
, big_endian
>* got
9102 = target
->got_section(symtab
, layout
, got_type
);
9103 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9104 uint64_t addend
= size
== 32 ? 0 : reloc
.get_r_addend();
9105 if (gsym
->is_undefined()
9106 || gsym
->is_from_dynobj())
9108 got
->add_global_with_rel(gsym
, got_type
, rela_dyn
,
9109 elfcpp::R_POWERPC_TPREL
, addend
);
9113 unsigned int off
= got
->add_constant(0);
9114 gsym
->set_got_offset(got_type
, off
);
9115 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9116 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9121 else if (tls_type
== tls::TLSOPT_TO_LE
)
9123 // no GOT relocs needed for Local Exec.
9131 unsupported_reloc_global(object
, r_type
, gsym
);
9136 && parameters
->options().toc_optimize())
9138 if (data_shndx
== ppc_object
->toc_shndx())
9141 if (r_type
!= elfcpp::R_PPC64_ADDR64
9142 || (is_ifunc
&& target
->abiversion() < 2))
9144 else if (parameters
->options().output_is_position_independent()
9145 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9148 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9151 enum {no_check
, check_lo
, check_ha
} insn_check
;
9155 insn_check
= no_check
;
9158 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9159 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9160 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9161 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9162 case elfcpp::R_POWERPC_GOT16_HA
:
9163 case elfcpp::R_PPC64_TOC16_HA
:
9164 insn_check
= check_ha
;
9167 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9168 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9169 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9170 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9171 case elfcpp::R_POWERPC_GOT16_LO
:
9172 case elfcpp::R_PPC64_GOT16_LO_DS
:
9173 case elfcpp::R_PPC64_TOC16_LO
:
9174 case elfcpp::R_PPC64_TOC16_LO_DS
:
9175 insn_check
= check_lo
;
9179 section_size_type slen
;
9180 const unsigned char* view
= NULL
;
9181 if (insn_check
!= no_check
)
9183 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9184 section_size_type off
=
9185 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9188 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9189 if (insn_check
== check_lo
9190 ? !ok_lo_toc_insn(insn
, r_type
)
9191 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9192 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9194 ppc_object
->set_no_toc_opt();
9195 gold_warning(_("%s: toc optimization is not supported "
9196 "for %#08x instruction"),
9197 ppc_object
->name().c_str(), insn
);
9206 case elfcpp::R_PPC64_TOC16
:
9207 case elfcpp::R_PPC64_TOC16_LO
:
9208 case elfcpp::R_PPC64_TOC16_HI
:
9209 case elfcpp::R_PPC64_TOC16_HA
:
9210 case elfcpp::R_PPC64_TOC16_DS
:
9211 case elfcpp::R_PPC64_TOC16_LO_DS
:
9212 if (gsym
->source() == Symbol::FROM_OBJECT
9213 && !gsym
->object()->is_dynamic())
9215 Powerpc_relobj
<size
, big_endian
>* sym_object
9216 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9218 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9219 if (shndx
== sym_object
->toc_shndx())
9221 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9222 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9223 if (dst_off
< sym_object
->section_size(shndx
))
9226 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9228 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9230 // Need to check that the insn is a ld
9232 view
= ppc_object
->section_contents(data_shndx
,
9235 section_size_type off
=
9236 (convert_to_section_size_type(reloc
.get_r_offset())
9237 + (big_endian
? -2 : 3));
9239 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9243 sym_object
->set_no_toc_opt(dst_off
);
9255 case elfcpp::R_PPC_LOCAL24PC
:
9256 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9257 gold_error(_("%s: unsupported -mbss-plt code"),
9258 ppc_object
->name().c_str());
9267 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9268 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9269 case elfcpp::R_POWERPC_GOT_TPREL16
:
9270 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9271 case elfcpp::R_POWERPC_GOT16
:
9272 case elfcpp::R_PPC64_GOT16_DS
:
9273 case elfcpp::R_PPC64_TOC16
:
9274 case elfcpp::R_PPC64_TOC16_DS
:
9275 ppc_object
->set_has_small_toc_reloc();
9283 case elfcpp::R_PPC64_TPREL16_DS
:
9284 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9285 case elfcpp::R_PPC64_TPREL16_HIGH
:
9286 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9287 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9288 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9289 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9290 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9291 case elfcpp::R_PPC64_TPREL34
:
9295 case elfcpp::R_POWERPC_TPREL16
:
9296 case elfcpp::R_POWERPC_TPREL16_LO
:
9297 case elfcpp::R_POWERPC_TPREL16_HI
:
9298 case elfcpp::R_POWERPC_TPREL16_HA
:
9299 layout
->set_has_static_tls();
9307 case elfcpp::R_POWERPC_TPREL16_HA
:
9308 if (target
->tprel_opt())
9310 section_size_type slen
;
9311 const unsigned char* view
= NULL
;
9312 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9313 section_size_type off
9314 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9317 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9318 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9319 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9320 target
->set_no_tprel_opt();
9325 case elfcpp::R_PPC64_TPREL16_HIGH
:
9326 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9327 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9328 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9329 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9330 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9334 case elfcpp::R_POWERPC_TPREL16_HI
:
9335 target
->set_no_tprel_opt();
9343 case elfcpp::R_PPC64_D34
:
9344 case elfcpp::R_PPC64_D34_LO
:
9345 case elfcpp::R_PPC64_D34_HI30
:
9346 case elfcpp::R_PPC64_D34_HA30
:
9347 case elfcpp::R_PPC64_D28
:
9348 case elfcpp::R_PPC64_PCREL34
:
9349 case elfcpp::R_PPC64_PCREL28
:
9350 case elfcpp::R_PPC64_TPREL34
:
9351 case elfcpp::R_PPC64_DTPREL34
:
9352 case elfcpp::R_PPC64_PLT_PCREL34
:
9353 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9354 case elfcpp::R_PPC64_GOT_PCREL34
:
9355 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9356 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9357 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9358 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9359 target
->set_power10_relocs();
9366 // Process relocations for gc.
9368 template<int size
, bool big_endian
>
9370 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9371 Symbol_table
* symtab
,
9373 Sized_relobj_file
<size
, big_endian
>* object
,
9374 unsigned int data_shndx
,
9376 const unsigned char* prelocs
,
9378 Output_section
* output_section
,
9379 bool needs_special_offset_handling
,
9380 size_t local_symbol_count
,
9381 const unsigned char* plocal_symbols
)
9383 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9384 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9387 Powerpc_relobj
<size
, big_endian
>* ppc_object
9388 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9390 ppc_object
->set_opd_valid();
9391 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9393 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9394 for (p
= ppc_object
->access_from_map()->begin();
9395 p
!= ppc_object
->access_from_map()->end();
9398 Address dst_off
= p
->first
;
9399 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9400 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9401 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9403 Relobj
* src_obj
= s
->first
;
9404 unsigned int src_indx
= s
->second
;
9405 symtab
->gc()->add_reference(src_obj
, src_indx
,
9406 ppc_object
, dst_indx
);
9410 ppc_object
->access_from_map()->clear();
9411 ppc_object
->process_gc_mark(symtab
);
9412 // Don't look at .opd relocs as .opd will reference everything.
9416 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9425 needs_special_offset_handling
,
9430 // Handle target specific gc actions when adding a gc reference from
9431 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9432 // and DST_OFF. For powerpc64, this adds a referenc to the code
9433 // section of a function descriptor.
9435 template<int size
, bool big_endian
>
9437 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9438 Symbol_table
* symtab
,
9440 unsigned int src_shndx
,
9442 unsigned int dst_shndx
,
9443 Address dst_off
) const
9445 if (size
!= 64 || dst_obj
->is_dynamic())
9448 Powerpc_relobj
<size
, big_endian
>* ppc_object
9449 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9450 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9452 if (ppc_object
->opd_valid())
9454 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9455 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9459 // If we haven't run scan_opd_relocs, we must delay
9460 // processing this function descriptor reference.
9461 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9466 // Add any special sections for this symbol to the gc work list.
9467 // For powerpc64, this adds the code section of a function
9470 template<int size
, bool big_endian
>
9472 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9473 Symbol_table
* symtab
,
9476 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9478 Powerpc_relobj
<size
, big_endian
>* ppc_object
9479 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9481 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9482 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9484 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9485 Address dst_off
= gsym
->value();
9486 if (ppc_object
->opd_valid())
9488 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9489 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9493 ppc_object
->add_gc_mark(dst_off
);
9498 // For a symbol location in .opd, set LOC to the location of the
9501 template<int size
, bool big_endian
>
9503 Target_powerpc
<size
, big_endian
>::do_function_location(
9504 Symbol_location
* loc
) const
9506 if (size
== 64 && loc
->shndx
!= 0)
9508 if (loc
->object
->is_dynamic())
9510 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9511 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9512 if (loc
->shndx
== ppc_object
->opd_shndx())
9515 Address off
= loc
->offset
- ppc_object
->opd_address();
9516 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9517 loc
->offset
= dest_off
;
9522 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9523 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9524 if (loc
->shndx
== ppc_object
->opd_shndx())
9527 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9528 loc
->offset
= dest_off
;
9534 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9535 // compiled with -fsplit-stack. The function calls non-split-stack
9536 // code. Change the function to ensure it has enough stack space to
9537 // call some random function.
9539 template<int size
, bool big_endian
>
9541 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9544 section_offset_type fnoffset
,
9545 section_size_type fnsize
,
9546 const unsigned char* prelocs
,
9548 unsigned char* view
,
9549 section_size_type view_size
,
9551 std::string
* to
) const
9553 // 32-bit not supported.
9557 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9558 prelocs
, reloc_count
, view
, view_size
,
9563 // The function always starts with
9564 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9565 // addis %r12,%r1,-allocate@ha
9566 // addi %r12,%r12,-allocate@l
9568 // but note that the addis or addi may be replaced with a nop
9570 unsigned char *entry
= view
+ fnoffset
;
9571 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9573 if ((insn
& 0xffff0000) == addis_2_12
)
9575 /* Skip ELFv2 global entry code. */
9577 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9580 unsigned char *pinsn
= entry
;
9582 const uint32_t ld_private_ss
= 0xe80d8fc0;
9583 if (insn
== ld_private_ss
)
9585 int32_t allocate
= 0;
9589 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9590 if ((insn
& 0xffff0000) == addis_12_1
)
9591 allocate
+= (insn
& 0xffff) << 16;
9592 else if ((insn
& 0xffff0000) == addi_12_1
9593 || (insn
& 0xffff0000) == addi_12_12
)
9594 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9595 else if (insn
!= nop
)
9598 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9600 int extra
= parameters
->options().split_stack_adjust_size();
9602 if (allocate
>= 0 || extra
< 0)
9604 object
->error(_("split-stack stack size overflow at "
9605 "section %u offset %0zx"),
9606 shndx
, static_cast<size_t>(fnoffset
));
9610 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9611 if (insn
!= addis_12_1
)
9613 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9615 insn
= addi_12_12
| (allocate
& 0xffff);
9616 if (insn
!= addi_12_12
)
9618 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9624 insn
= addi_12_1
| (allocate
& 0xffff);
9625 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9628 if (pinsn
!= entry
+ 12)
9629 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9637 if (!object
->has_no_split_stack())
9638 object
->error(_("failed to match split-stack sequence at "
9639 "section %u offset %0zx"),
9640 shndx
, static_cast<size_t>(fnoffset
));
9644 // Scan relocations for a section.
9646 template<int size
, bool big_endian
>
9648 Target_powerpc
<size
, big_endian
>::scan_relocs(
9649 Symbol_table
* symtab
,
9651 Sized_relobj_file
<size
, big_endian
>* object
,
9652 unsigned int data_shndx
,
9653 unsigned int sh_type
,
9654 const unsigned char* prelocs
,
9656 Output_section
* output_section
,
9657 bool needs_special_offset_handling
,
9658 size_t local_symbol_count
,
9659 const unsigned char* plocal_symbols
)
9661 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9662 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9665 if (!this->plt_localentry0_init_
)
9667 bool plt_localentry0
= false;
9669 && this->abiversion() >= 2)
9671 if (parameters
->options().user_set_plt_localentry())
9672 plt_localentry0
= parameters
->options().plt_localentry();
9674 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9675 gold_warning(_("--plt-localentry is especially dangerous without "
9676 "ld.so support to detect ABI violations"));
9678 this->plt_localentry0_
= plt_localentry0
;
9679 this->plt_localentry0_init_
= true;
9682 if (sh_type
== elfcpp::SHT_REL
)
9684 gold_error(_("%s: unsupported REL reloc section"),
9685 object
->name().c_str());
9689 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9698 needs_special_offset_handling
,
9702 if (this->plt_localentry0_
&& this->power10_relocs_
)
9704 gold_warning(_("--plt-localentry is incompatible with "
9705 "power10 pc-relative code"));
9706 this->plt_localentry0_
= false;
9710 // Functor class for processing the global symbol table.
9711 // Removes symbols defined on discarded opd entries.
9713 template<bool big_endian
>
9714 class Global_symbol_visitor_opd
9717 Global_symbol_visitor_opd()
9721 operator()(Sized_symbol
<64>* sym
)
9723 if (sym
->has_symtab_index()
9724 || sym
->source() != Symbol::FROM_OBJECT
9725 || !sym
->in_real_elf())
9728 if (sym
->object()->is_dynamic())
9731 Powerpc_relobj
<64, big_endian
>* symobj
9732 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9733 if (symobj
->opd_shndx() == 0)
9737 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9738 if (shndx
== symobj
->opd_shndx()
9739 && symobj
->get_opd_discard(sym
->value()))
9741 sym
->set_undefined();
9742 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9743 sym
->set_is_defined_in_discarded_section();
9744 sym
->set_symtab_index(-1U);
9749 template<int size
, bool big_endian
>
9751 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9753 Symbol_table
* symtab
)
9757 Output_data_save_res
<size
, big_endian
>* savres
9758 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9759 this->savres_section_
= savres
;
9760 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9761 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9762 savres
, ORDER_TEXT
, false);
9766 // Sort linker created .got section first (for the header), then input
9767 // sections belonging to files using small model code.
9769 template<bool big_endian
>
9770 class Sort_toc_sections
9772 const Output_section_data
*
9773 small_got_section() const
9775 return (static_cast<Target_powerpc
<64, big_endian
>*>(
9776 parameters
->sized_target
<64, big_endian
>())
9777 ->got_section(GOT_TYPE_SMALL
));
9781 rank(const Output_section::Input_section
& isec
) const
9783 if (!isec
.is_input_section())
9785 if (isec
.output_section_data() == this->small_got_section())
9789 if (static_cast<const Powerpc_relobj
<64, big_endian
>*>(isec
.relobj())
9790 ->has_small_toc_reloc())
9797 operator()(const Output_section::Input_section
& is1
,
9798 const Output_section::Input_section
& is2
) const
9800 return rank(is1
) < rank(is2
);
9804 // Finalize the sections.
9806 template<int size
, bool big_endian
>
9808 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9810 const Input_objects
* input_objects
,
9811 Symbol_table
* symtab
)
9813 if (parameters
->doing_static_link())
9815 // At least some versions of glibc elf-init.o have a strong
9816 // reference to __rela_iplt marker syms. A weak ref would be
9818 if (this->iplt_
!= NULL
)
9820 Reloc_section
* rel
= this->iplt_
->rel_plt();
9821 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9822 Symbol_table::PREDEFINED
, rel
, 0, 0,
9823 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9824 elfcpp::STV_HIDDEN
, 0, false, true);
9825 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9826 Symbol_table::PREDEFINED
, rel
, 0, 0,
9827 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9828 elfcpp::STV_HIDDEN
, 0, true, true);
9832 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9833 Symbol_table::PREDEFINED
, 0, 0,
9834 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9835 elfcpp::STV_HIDDEN
, 0, true, false);
9836 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9837 Symbol_table::PREDEFINED
, 0, 0,
9838 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9839 elfcpp::STV_HIDDEN
, 0, true, false);
9845 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9846 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9848 if (!parameters
->options().relocatable())
9850 this->define_save_restore_funcs(layout
, symtab
);
9852 // Annoyingly, we need to make these sections now whether or
9853 // not we need them. If we delay until do_relax then we
9854 // need to mess with the relaxation machinery checkpointing.
9855 this->got_section(symtab
, layout
, GOT_TYPE_STANDARD
);
9856 this->make_brlt_section(layout
);
9858 // FIXME, maybe. Here we could run through all the got
9859 // entries in the small got section, removing any duplicates
9860 // found in the big got section and renumbering offsets.
9862 if (parameters
->options().toc_sort())
9864 Output_section
* os
= this->got_
->output_section();
9865 if (os
!= NULL
&& os
->input_sections().size() > 1)
9866 std::stable_sort(os
->input_sections().begin(),
9867 os
->input_sections().end(),
9868 Sort_toc_sections
<big_endian
>());
9873 // Fill in some more dynamic tags.
9874 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9877 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9879 : this->plt_
->rel_plt());
9880 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9881 this->rela_dyn_
, true, size
== 32);
9885 if (this->got_
!= NULL
)
9887 this->got_
->finalize_data_size();
9888 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9889 this->got_
, this->got_
->g_o_t());
9891 if (this->has_tls_get_addr_opt_
)
9892 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9896 if (this->glink_
!= NULL
)
9898 this->glink_
->finalize_data_size();
9899 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9901 (this->glink_
->pltresolve_size()
9904 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9905 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9906 ((this->has_localentry0_
9907 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9908 | (this->has_tls_get_addr_opt_
9909 ? elfcpp::PPC64_OPT_TLS
: 0)));
9913 // Emit any relocs we saved in an attempt to avoid generating COPY
9915 if (this->copy_relocs_
.any_saved_relocs())
9916 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9918 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9919 p
!= input_objects
->relobj_end();
9922 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9923 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9924 if (ppc_relobj
->attributes_section_data())
9925 this->merge_object_attributes(ppc_relobj
,
9926 ppc_relobj
->attributes_section_data());
9928 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9929 p
!= input_objects
->dynobj_end();
9932 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9933 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9934 if (ppc_dynobj
->attributes_section_data())
9935 this->merge_object_attributes(ppc_dynobj
,
9936 ppc_dynobj
->attributes_section_data());
9939 // Create a .gnu.attributes section if we have merged any attributes
9941 if (this->attributes_section_data_
!= NULL
9942 && this->attributes_section_data_
->size() != 0)
9944 Output_attributes_section_data
* attributes_section
9945 = new Output_attributes_section_data(*this->attributes_section_data_
);
9946 layout
->add_output_section_data(".gnu.attributes",
9947 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9948 attributes_section
, ORDER_INVALID
, false);
9952 // Merge object attributes from input file called NAME with those of the
9953 // output. The input object attributes are in the object pointed by PASD.
9955 template<int size
, bool big_endian
>
9957 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9959 const Attributes_section_data
* pasd
)
9961 // Return if there is no attributes section data.
9965 // Create output object attributes.
9966 if (this->attributes_section_data_
== NULL
)
9967 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9969 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9970 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9971 Object_attribute
* out_attr
9972 = this->attributes_section_data_
->known_attributes(vendor
);
9974 const char* name
= obj
->name().c_str();
9978 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9979 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9980 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9981 bool warn_only
= obj
->is_dynamic();
9982 if (in_fp
!= out_fp
)
9985 if ((in_fp
& 3) == 0)
9987 else if ((out_fp
& 3) == 0)
9991 out_fp
|= in_fp
& 3;
9992 out_attr
[tag
].set_int_value(out_fp
);
9993 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9994 this->last_fp_
= name
;
9997 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9999 err
= N_("%s uses hard float, %s uses soft float");
10000 first
= this->last_fp_
;
10003 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10005 err
= N_("%s uses hard float, %s uses soft float");
10007 second
= this->last_fp_
;
10009 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10011 err
= N_("%s uses double-precision hard float, "
10012 "%s uses single-precision hard float");
10013 first
= this->last_fp_
;
10016 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10018 err
= N_("%s uses double-precision hard float, "
10019 "%s uses single-precision hard float");
10021 second
= this->last_fp_
;
10024 if (err
|| (in_fp
& 0xc) == 0)
10026 else if ((out_fp
& 0xc) == 0)
10030 out_fp
|= in_fp
& 0xc;
10031 out_attr
[tag
].set_int_value(out_fp
);
10032 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10033 this->last_ld_
= name
;
10036 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10038 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10040 second
= this->last_ld_
;
10042 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10044 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10045 first
= this->last_ld_
;
10048 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10050 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10051 first
= this->last_ld_
;
10054 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10056 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10058 second
= this->last_ld_
;
10063 if (parameters
->options().warn_mismatch())
10066 gold_warning(_(err
), first
, second
);
10068 gold_error(_(err
), first
, second
);
10070 // Arrange for this attribute to be deleted. It's better to
10071 // say "don't know" about a file than to wrongly claim compliance.
10073 out_attr
[tag
].set_type(0);
10079 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10080 int in_vec
= in_attr
[tag
].int_value() & 3;
10081 int out_vec
= out_attr
[tag
].int_value() & 3;
10082 if (in_vec
!= out_vec
)
10087 else if (out_vec
== 0)
10090 out_attr
[tag
].set_int_value(out_vec
);
10091 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10092 this->last_vec_
= name
;
10094 // For now, allow generic to transition to AltiVec or SPE
10095 // without a warning. If GCC marked files with their stack
10096 // alignment and used don't-care markings for files which are
10097 // not affected by the vector ABI, we could warn about this
10099 else if (in_vec
== 1)
10101 else if (out_vec
== 1)
10104 out_attr
[tag
].set_int_value(out_vec
);
10105 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10106 this->last_vec_
= name
;
10108 else if (out_vec
< in_vec
)
10110 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10111 first
= this->last_vec_
;
10114 else if (out_vec
> in_vec
)
10116 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10118 second
= this->last_vec_
;
10122 if (parameters
->options().warn_mismatch())
10123 gold_error(_(err
), first
, second
);
10124 out_attr
[tag
].set_type(0);
10128 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10129 int in_struct
= in_attr
[tag
].int_value() & 3;
10130 int out_struct
= out_attr
[tag
].int_value() & 3;
10131 if (in_struct
!= out_struct
)
10134 if (in_struct
== 0 || in_struct
== 3)
10136 else if (out_struct
== 0)
10138 out_struct
= in_struct
;
10139 out_attr
[tag
].set_int_value(out_struct
);
10140 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10141 this->last_struct_
= name
;
10143 else if (out_struct
< in_struct
)
10145 err
= N_("%s uses r3/r4 for small structure returns, "
10147 first
= this->last_struct_
;
10150 else if (out_struct
> in_struct
)
10152 err
= N_("%s uses r3/r4 for small structure returns, "
10155 second
= this->last_struct_
;
10159 if (parameters
->options().warn_mismatch())
10160 gold_error(_(err
), first
, second
);
10161 out_attr
[tag
].set_type(0);
10166 // Merge Tag_compatibility attributes and any common GNU ones.
10167 this->attributes_section_data_
->merge(name
, pasd
);
10170 // Emit any saved relocs, and mark toc entries using any of these
10171 // relocs as not optimizable.
10173 template<int sh_type
, int size
, bool big_endian
>
10175 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10176 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10179 && parameters
->options().toc_optimize())
10181 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10182 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10183 p
!= this->entries_
.end();
10186 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10189 // If the symbol is no longer defined in a dynamic object,
10190 // then we emitted a COPY relocation. If it is still
10191 // dynamic then we'll need dynamic relocations and thus
10192 // can't optimize toc entries.
10193 if (entry
.sym_
->is_from_dynobj())
10195 Powerpc_relobj
<size
, big_endian
>* ppc_object
10196 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10197 if (entry
.shndx_
== ppc_object
->toc_shndx())
10198 ppc_object
->set_no_toc_opt(entry
.address_
);
10203 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10206 // Return the value to use for a branch relocation.
10208 template<int size
, bool big_endian
>
10210 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10211 const Symbol_table
* symtab
,
10212 const Sized_symbol
<size
>* gsym
,
10213 Powerpc_relobj
<size
, big_endian
>* object
,
10215 unsigned int *dest_shndx
)
10217 if (size
== 32 || this->abiversion() >= 2)
10218 gold_unreachable();
10221 // If the symbol is defined in an opd section, ie. is a function
10222 // descriptor, use the function descriptor code entry address
10223 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10225 && (gsym
->source() != Symbol::FROM_OBJECT
10226 || gsym
->object()->is_dynamic()))
10229 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10230 unsigned int shndx
= symobj
->opd_shndx();
10233 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10234 if (opd_addr
== invalid_address
)
10236 opd_addr
+= symobj
->output_section_address(shndx
);
10237 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10240 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10241 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10244 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10245 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10246 *dest_shndx
= folded
.second
;
10248 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10249 if (sec_addr
== invalid_address
)
10252 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10253 *value
= sec_addr
+ sec_off
;
10260 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10262 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10265 if (gsym
->is_from_dynobj()
10266 || gsym
->is_undefined()
10267 || gsym
->is_preemptible())
10270 if (gsym
->is_absolute())
10271 return !parameters
->options().output_is_position_independent();
10278 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10280 if (psymval
->is_ifunc_symbol())
10284 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10286 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10289 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10290 // pld ra,symbol@got@pcrel
10291 // load/store rt,0(ra)
10293 // pla ra,symbol@pcrel
10294 // load/store rt,0(ra)
10295 // may be translated to
10296 // pload/pstore rt,symbol@pcrel
10298 // This function returns true if the optimization is possible, placing
10299 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10301 // On entry to this function, the linker has already determined that
10302 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10303 // while *PINSN2 is the second instruction.
10306 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10308 uint32_t insn2
= *pinsn2
>> 32;
10311 // Check that regs match.
10312 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10315 switch ((insn2
>> 26) & 63)
10331 // These are the PMLS cases, where we just need to tack a prefix
10332 // on the insn. Check that the D field is zero.
10333 if ((insn2
& 0xffff) != 0)
10335 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10336 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10339 case 58: // lwa, ld
10340 if ((insn2
& 0xfffd) != 0)
10342 i1new
= ((1ULL << 58) | (1ULL << 52)
10343 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10344 | (insn2
& (31ULL << 21)));
10347 case 57: // lxsd, lxssp
10348 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10350 i1new
= ((1ULL << 58) | (1ULL << 52)
10351 | ((40ULL | (insn2
& 3)) << 26)
10352 | (insn2
& (31ULL << 21)));
10355 case 61: // stxsd, stxssp, lxv, stxv
10356 if ((insn2
& 3) == 0)
10358 else if ((insn2
& 3) >= 2)
10360 if ((insn2
& 0xfffc) != 0)
10362 i1new
= ((1ULL << 58) | (1ULL << 52)
10363 | ((44ULL | (insn2
& 3)) << 26)
10364 | (insn2
& (31ULL << 21)));
10368 if ((insn2
& 0xfff0) != 0)
10370 i1new
= ((1ULL << 58) | (1ULL << 52)
10371 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10372 | (insn2
& (31ULL << 21)));
10377 if ((insn2
& 0xffff) != 0)
10379 i1new
= ((1ULL << 58) | (1ULL << 52)
10380 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10383 case 62: // std, stq
10384 if ((insn2
& 0xfffd) != 0)
10386 i1new
= ((1ULL << 58) | (1ULL << 52)
10387 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10388 | (insn2
& (31ULL << 21)));
10393 *pinsn2
= (uint64_t) nop
<< 32;
10397 // Perform a relocation.
10399 template<int size
, bool big_endian
>
10401 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10402 const Relocate_info
<size
, big_endian
>* relinfo
,
10404 Target_powerpc
* target
,
10405 Output_section
* os
,
10407 const unsigned char* preloc
,
10408 const Sized_symbol
<size
>* gsym
,
10409 const Symbol_value
<size
>* psymval
,
10410 unsigned char* view
,
10412 section_size_type view_size
)
10414 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10415 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10416 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10421 if (target
->replace_tls_get_addr(gsym
))
10422 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10424 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10425 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10426 Powerpc_relobj
<size
, big_endian
>* const object
10427 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10428 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10430 case Track_tls::NOT_EXPECTED
:
10431 // No warning. This will result in really old code without tls
10432 // marker relocs being mis-optimised, but there shouldn't be too
10433 // much of that code around. The problem with warning is that
10434 // glibc and libphobos both construct direct calls to
10435 // __tls_get_addr in a way that is harmless.
10437 case Track_tls::EXPECTED
:
10438 // We have already complained.
10440 case Track_tls::SKIP
:
10441 if (is_plt16_reloc
<size
>(r_type
)
10442 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10443 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10445 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10446 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10448 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10450 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10451 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10453 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10454 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10456 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10457 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10458 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10461 case Track_tls::NORMAL
:
10465 // Offset from start of insn to d-field reloc.
10466 const int d_offset
= big_endian
? 2 : 0;
10469 bool has_stub_value
= false;
10470 bool localentry0
= false;
10471 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10472 bool has_plt_offset
10474 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10475 : object
->local_has_plt_offset(r_sym
));
10477 && !is_got_reloc(r_type
)
10478 && !is_plt16_reloc
<size
>(r_type
)
10479 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10480 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10481 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10482 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10483 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10484 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10485 && (!psymval
->is_ifunc_symbol()
10486 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10490 && target
->abiversion() >= 2
10491 && !parameters
->options().output_is_position_independent()
10492 && !is_branch_reloc
<size
>(r_type
))
10494 Address off
= target
->glink_section()->find_global_entry(gsym
);
10495 if (off
!= invalid_address
)
10497 value
= target
->glink_section()->global_entry_address() + off
;
10498 has_stub_value
= true;
10503 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10504 if (target
->stub_tables().size() == 1)
10505 stub_table
= target
->stub_tables()[0];
10506 if (stub_table
== NULL
10509 && !parameters
->options().output_is_position_independent()
10510 && !is_branch_reloc
<size
>(r_type
)))
10511 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10512 if (stub_table
== NULL
)
10514 // This is a ref from a data section to an ifunc symbol,
10515 // or a non-branch reloc for which we always want to use
10516 // one set of stubs for resolving function addresses.
10517 if (target
->stub_tables().size() != 0)
10518 stub_table
= target
->stub_tables()[0];
10520 if (stub_table
!= NULL
)
10522 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10524 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10525 rela
.get_r_addend());
10527 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10528 rela
.get_r_addend());
10531 value
= stub_table
->stub_address() + ent
->off_
;
10532 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10533 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10534 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10536 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10537 value
+= ent
->tocoff_
;
10541 && target
->is_tls_get_addr_opt(gsym
)))
10543 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10545 if (!(target
->power10_stubs()
10546 && target
->power10_stubs_auto()))
10549 else if (relnum
< reloc_count
- 1)
10551 Reltype
next_rela(preloc
+ reloc_size
);
10552 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10553 == elfcpp::R_PPC64_TOCSAVE
10554 && (next_rela
.get_r_offset()
10555 == rela
.get_r_offset() + 4))
10559 localentry0
= ent
->localentry0_
;
10560 has_stub_value
= true;
10564 // We don't care too much about bogus debug references to
10565 // non-local functions, but otherwise there had better be a plt
10566 // call stub or global entry stub as appropriate.
10567 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10570 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10571 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10572 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10574 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10576 value
= target
->plt_off(gsym
, &plt
);
10578 value
= target
->plt_off(object
, r_sym
, &plt
);
10579 value
+= plt
->address();
10583 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10584 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10585 value
-= target
->toc_pointer();
10587 else if (parameters
->options().output_is_position_independent())
10589 if (rela
.get_r_addend() >= 32768)
10591 unsigned int got2
= object
->got2_shndx();
10592 value
-= (object
->get_output_section_offset(got2
)
10593 + object
->output_section(got2
)->address()
10594 + rela
.get_r_addend());
10597 value
-= target
->toc_pointer();
10600 else if (!has_plt_offset
10601 && (is_plt16_reloc
<size
>(r_type
)
10602 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10603 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10605 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10606 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10607 r_type
= elfcpp::R_POWERPC_NONE
;
10609 else if (!has_plt_offset
10610 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10611 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10613 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10614 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10615 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10616 r_type
= elfcpp::R_POWERPC_NONE
;
10618 else if (is_got_reloc(r_type
))
10620 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10621 Got_type got_type
= ((size
== 32
10622 || r_type
== elfcpp::R_POWERPC_GOT16
10623 || r_type
== elfcpp::R_PPC64_GOT16_DS
)
10624 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10626 value
= gsym
->got_offset(got_type
, addend
);
10628 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10629 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10630 value
+= target
->got_section(got_type
)->address();
10632 value
-= target
->got_base_offset(got_type
);
10634 else if (r_type
== elfcpp::R_PPC64_TOC
)
10636 value
= target
->toc_pointer();
10638 else if (gsym
!= NULL
10639 && (r_type
== elfcpp::R_POWERPC_REL24
10640 || r_type
== elfcpp::R_PPC_PLTREL24
)
10645 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10646 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10647 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10648 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10650 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10651 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10652 if ((insn
& 1) != 0
10654 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10656 elfcpp::Swap
<32, big_endian
>::
10657 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10658 can_plt_call
= true;
10663 // If we don't have a branch and link followed by a nop,
10664 // we can't go via the plt because there is no place to
10665 // put a toc restoring instruction.
10666 // Unless we know we won't be returning.
10667 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10668 can_plt_call
= true;
10672 // g++ as of 20130507 emits self-calls without a
10673 // following nop. This is arguably wrong since we have
10674 // conflicting information. On the one hand a global
10675 // symbol and on the other a local call sequence, but
10676 // don't error for this special case.
10677 // It isn't possible to cheaply verify we have exactly
10678 // such a call. Allow all calls to the same section.
10680 Address code
= value
;
10681 if (gsym
->source() == Symbol::FROM_OBJECT
10682 && gsym
->object() == object
)
10684 unsigned int dest_shndx
= 0;
10685 if (target
->abiversion() < 2)
10687 Address addend
= rela
.get_r_addend();
10688 code
= psymval
->value(object
, addend
);
10689 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10690 &code
, &dest_shndx
);
10693 if (dest_shndx
== 0)
10694 dest_shndx
= gsym
->shndx(&is_ordinary
);
10695 ok
= dest_shndx
== relinfo
->data_shndx
;
10699 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10700 _("call lacks nop, can't restore toc; "
10701 "recompile with -fPIC"));
10707 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10708 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10709 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10710 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10711 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10713 // First instruction of a global dynamic sequence, arg setup insn.
10714 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10715 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10716 Got_type got_type
= ((size
== 32
10717 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
)
10718 ? GOT_TYPE_SMALL
: GOT_TYPE_STANDARD
);
10719 if (tls_type
== tls::TLSOPT_NONE
)
10720 got_type
= Got_type(got_type
| GOT_TYPE_TLSGD
);
10721 else if (tls_type
== tls::TLSOPT_TO_IE
)
10722 got_type
= Got_type(got_type
| GOT_TYPE_TPREL
);
10723 if ((got_type
& ~GOT_TYPE_SMALL
) != GOT_TYPE_STANDARD
)
10725 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10727 value
= gsym
->got_offset(got_type
, addend
);
10729 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10730 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10731 value
+= target
->got_section(got_type
)->address();
10733 value
-= target
->got_base_offset(got_type
);
10735 if (tls_type
== tls::TLSOPT_TO_IE
)
10737 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10739 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10740 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10742 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10744 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10745 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10746 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10747 pinsn
& 0xffffffff);
10748 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10752 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10753 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10755 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10756 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10757 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10759 insn
|= 32 << 26; // lwz
10761 insn
|= 58 << 26; // ld
10762 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10764 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10765 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10768 else if (tls_type
== tls::TLSOPT_TO_LE
)
10770 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10772 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10773 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10775 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10776 // pla pcrel -> paddi r13
10777 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10778 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10779 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10780 pinsn
& 0xffffffff);
10781 r_type
= elfcpp::R_PPC64_TPREL34
;
10782 value
= psymval
->value(object
, rela
.get_r_addend());
10786 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10787 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10789 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10790 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10791 insn
&= (1 << 26) - (1 << 21); // extract rt
10795 insn
|= addis_0_13
;
10796 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10797 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10798 value
= psymval
->value(object
, rela
.get_r_addend());
10802 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10804 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10805 r_type
= elfcpp::R_POWERPC_NONE
;
10810 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10811 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10812 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10813 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10814 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10816 // First instruction of a local dynamic sequence, arg setup insn.
10817 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10818 if (tls_type
== tls::TLSOPT_NONE
)
10820 value
= target
->tlsld_got_offset();
10821 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10822 value
+= target
->got_section(GOT_TYPE_SMALL
)->address();
10824 value
-= target
->got_base_offset(GOT_TYPE_SMALL
);
10828 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10829 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10831 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10832 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10834 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10835 // pla pcrel -> paddi r13
10836 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10837 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10838 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10839 pinsn
& 0xffffffff);
10840 r_type
= elfcpp::R_PPC64_TPREL34
;
10841 value
= dtp_offset
;
10843 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10844 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10846 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10847 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10848 insn
&= (1 << 26) - (1 << 21); // extract rt
10852 insn
|= addis_0_13
;
10853 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10854 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10855 value
= dtp_offset
;
10859 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10861 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10862 r_type
= elfcpp::R_POWERPC_NONE
;
10866 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10867 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10868 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10869 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10870 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10872 // Accesses relative to a local dynamic sequence address,
10873 // no optimisation here.
10874 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10875 Got_type got_type
= ((size
== 32
10876 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
)
10877 ? GOT_TYPE_SMALL_DTPREL
: GOT_TYPE_DTPREL
);
10879 value
= gsym
->got_offset(got_type
, addend
);
10881 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10882 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10883 value
+= target
->got_section(got_type
)->address();
10885 value
-= target
->got_base_offset(got_type
);
10887 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10888 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10889 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10890 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10891 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10893 // First instruction of initial exec sequence.
10894 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10895 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10896 if (tls_type
== tls::TLSOPT_NONE
)
10898 uint64_t addend
= size
== 32 ? 0 : rela
.get_r_addend();
10899 Got_type got_type
= ((size
== 32
10900 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16
)
10901 ? GOT_TYPE_SMALL_TPREL
: GOT_TYPE_TPREL
);
10903 value
= gsym
->got_offset(got_type
, addend
);
10905 value
= object
->local_got_offset(r_sym
, got_type
, addend
);
10906 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10907 value
+= target
->got_section(got_type
)->address();
10909 value
-= target
->got_base_offset(got_type
);
10913 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10914 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10916 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10917 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10919 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10920 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10921 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10922 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10923 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10924 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10925 pinsn
& 0xffffffff);
10926 r_type
= elfcpp::R_PPC64_TPREL34
;
10927 value
= psymval
->value(object
, rela
.get_r_addend());
10929 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10930 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10932 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10933 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10934 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10938 insn
|= addis_0_13
;
10939 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10940 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10941 value
= psymval
->value(object
, rela
.get_r_addend());
10945 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10947 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10948 r_type
= elfcpp::R_POWERPC_NONE
;
10952 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10953 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10955 // Second instruction of a global dynamic sequence,
10956 // the __tls_get_addr call
10957 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10958 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10959 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10960 if (tls_type
!= tls::TLSOPT_NONE
)
10962 if (tls_type
== tls::TLSOPT_TO_IE
)
10964 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10965 Insn insn
= add_3_3_13
;
10968 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10969 r_type
= elfcpp::R_POWERPC_NONE
;
10973 bool is_pcrel
= false;
10974 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10975 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10976 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10977 if (relnum
< reloc_count
- 1)
10979 Reltype
next_rela(preloc
+ reloc_size
);
10980 unsigned int r_type2
10981 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10982 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10983 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10984 && next_rela
.get_r_offset() == rela
.get_r_offset())
10987 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10990 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10991 r_type
= elfcpp::R_POWERPC_NONE
;
10995 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10996 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10998 value
= psymval
->value(object
, rela
.get_r_addend());
11001 this->skip_next_tls_get_addr_call();
11004 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11005 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11007 // Second instruction of a local dynamic sequence,
11008 // the __tls_get_addr call
11009 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11010 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
11011 if (tls_type
== tls::TLSOPT_TO_LE
)
11013 bool is_pcrel
= false;
11014 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11015 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11016 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11017 if (relnum
< reloc_count
- 1)
11019 Reltype
next_rela(preloc
+ reloc_size
);
11020 unsigned int r_type2
11021 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11022 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11023 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11024 && next_rela
.get_r_offset() == rela
.get_r_offset())
11027 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11030 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11031 r_type
= elfcpp::R_POWERPC_NONE
;
11035 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11036 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11038 value
= dtp_offset
;
11040 this->skip_next_tls_get_addr_call();
11043 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11045 // Second instruction of an initial exec sequence
11046 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11047 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11048 if (tls_type
== tls::TLSOPT_TO_LE
)
11050 Address roff
= rela
.get_r_offset() & 3;
11051 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11052 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11053 unsigned int reg
= size
== 32 ? 2 : 13;
11054 insn
= at_tls_transform(insn
, reg
);
11055 gold_assert(insn
!= 0);
11058 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11059 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11061 value
= psymval
->value(object
, rela
.get_r_addend());
11063 else if (roff
== 1)
11065 // For pcrel IE to LE we already have the full offset
11066 // and thus don't need an addi here. A nop or mr will do.
11067 if ((insn
& (0x3f << 26)) == 14 << 26)
11069 // Extract regs from addi rt,ra,si.
11070 unsigned int rt
= (insn
>> 21) & 0x1f;
11071 unsigned int ra
= (insn
>> 16) & 0x1f;
11076 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11077 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11078 insn
|= (31u << 26) | (444u << 1);
11081 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11082 r_type
= elfcpp::R_POWERPC_NONE
;
11086 else if (!has_stub_value
)
11088 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11089 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11091 // PLTCALL without plt entry => convert to direct call
11092 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11093 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11094 insn
= (insn
& 1) | b
;
11095 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11097 r_type
= elfcpp::R_PPC_PLTREL24
;
11098 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11099 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11101 r_type
= elfcpp::R_POWERPC_REL24
;
11103 Address addend
= 0;
11105 && (r_type
== elfcpp::R_PPC_PLTREL24
11106 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11107 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11108 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11109 addend
= rela
.get_r_addend();
11110 value
= psymval
->value(object
, addend
);
11111 unsigned int local_ent
= 0;
11112 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11114 if (target
->abiversion() >= 2)
11117 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11119 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11123 unsigned int dest_shndx
;
11124 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11125 &value
, &dest_shndx
);
11128 Address max_branch
= max_branch_delta
<size
>(r_type
);
11129 if (max_branch
!= 0
11130 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11132 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
11134 ? object
->ppc64_needs_toc(gsym
)
11135 : object
->ppc64_needs_toc(r_sym
)))))
11137 Stub_table
<size
, big_endian
>* stub_table
11138 = object
->stub_table(relinfo
->data_shndx
);
11139 if (stub_table
!= NULL
)
11141 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11142 = stub_table
->find_long_branch_entry(value
);
11145 if (ent
->save_res_
)
11146 value
= (value
- target
->savres_section()->address()
11147 + stub_table
->stub_address()
11148 + stub_table
->plt_size()
11149 + stub_table
->branch_size());
11152 value
= (stub_table
->stub_address()
11153 + stub_table
->plt_size()
11156 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
11157 value
+= ent
->tocoff_
;
11159 has_stub_value
= true;
11163 if (!has_stub_value
)
11164 value
+= local_ent
;
11169 case elfcpp::R_PPC64_REL24_NOTOC
:
11173 case elfcpp::R_PPC64_REL64
:
11174 case elfcpp::R_POWERPC_REL32
:
11175 case elfcpp::R_POWERPC_REL24
:
11176 case elfcpp::R_PPC_PLTREL24
:
11177 case elfcpp::R_PPC_LOCAL24PC
:
11178 case elfcpp::R_POWERPC_REL16
:
11179 case elfcpp::R_POWERPC_REL16_LO
:
11180 case elfcpp::R_POWERPC_REL16_HI
:
11181 case elfcpp::R_POWERPC_REL16_HA
:
11182 case elfcpp::R_POWERPC_REL16DX_HA
:
11183 case elfcpp::R_PPC64_REL16_HIGH
:
11184 case elfcpp::R_PPC64_REL16_HIGHA
:
11185 case elfcpp::R_PPC64_REL16_HIGHER
:
11186 case elfcpp::R_PPC64_REL16_HIGHERA
:
11187 case elfcpp::R_PPC64_REL16_HIGHEST
:
11188 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11189 case elfcpp::R_POWERPC_REL14
:
11190 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11191 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11192 case elfcpp::R_PPC64_PCREL34
:
11193 case elfcpp::R_PPC64_GOT_PCREL34
:
11194 case elfcpp::R_PPC64_PLT_PCREL34
:
11195 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11196 case elfcpp::R_PPC64_PCREL28
:
11197 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11198 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11199 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11200 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11201 case elfcpp::R_PPC64_REL16_HIGHER34
:
11202 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11203 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11204 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11208 case elfcpp::R_PPC64_TOC16
:
11209 case elfcpp::R_PPC64_TOC16_LO
:
11210 case elfcpp::R_PPC64_TOC16_HI
:
11211 case elfcpp::R_PPC64_TOC16_HA
:
11212 case elfcpp::R_PPC64_TOC16_DS
:
11213 case elfcpp::R_PPC64_TOC16_LO_DS
:
11214 // Subtract the TOC base address.
11215 value
-= target
->toc_pointer();
11218 case elfcpp::R_POWERPC_SECTOFF
:
11219 case elfcpp::R_POWERPC_SECTOFF_LO
:
11220 case elfcpp::R_POWERPC_SECTOFF_HI
:
11221 case elfcpp::R_POWERPC_SECTOFF_HA
:
11222 case elfcpp::R_PPC64_SECTOFF_DS
:
11223 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11225 value
-= os
->address();
11228 case elfcpp::R_PPC64_TPREL16_DS
:
11229 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11230 case elfcpp::R_PPC64_TPREL16_HIGH
:
11231 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11233 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11236 case elfcpp::R_POWERPC_TPREL16
:
11237 case elfcpp::R_POWERPC_TPREL16_LO
:
11238 case elfcpp::R_POWERPC_TPREL16_HI
:
11239 case elfcpp::R_POWERPC_TPREL16_HA
:
11240 case elfcpp::R_POWERPC_TPREL
:
11241 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11242 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11243 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11244 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11245 case elfcpp::R_PPC64_TPREL34
:
11246 // tls symbol values are relative to tls_segment()->vaddr()
11247 value
-= tp_offset
;
11250 case elfcpp::R_PPC64_DTPREL16_DS
:
11251 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11252 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11253 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11254 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11255 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11257 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11258 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11261 case elfcpp::R_POWERPC_DTPREL16
:
11262 case elfcpp::R_POWERPC_DTPREL16_LO
:
11263 case elfcpp::R_POWERPC_DTPREL16_HI
:
11264 case elfcpp::R_POWERPC_DTPREL16_HA
:
11265 case elfcpp::R_POWERPC_DTPREL
:
11266 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11267 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11268 case elfcpp::R_PPC64_DTPREL34
:
11269 // tls symbol values are relative to tls_segment()->vaddr()
11270 value
-= dtp_offset
;
11273 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11275 value
+= object
->ppc64_local_entry_offset(gsym
);
11277 value
+= object
->ppc64_local_entry_offset(r_sym
);
11284 Insn branch_bit
= 0;
11287 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11288 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11289 branch_bit
= 1 << 21;
11291 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11292 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11294 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11295 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11296 insn
&= ~(1 << 21);
11297 insn
|= branch_bit
;
11298 if (this->is_isa_v2
)
11300 // Set 'a' bit. This is 0b00010 in BO field for branch
11301 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11302 // for branch on CTR insns (BO == 1a00t or 1a01t).
11303 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11304 insn
|= 0x02 << 21;
11305 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11306 insn
|= 0x08 << 21;
11312 // Invert 'y' bit if not the default.
11313 if (static_cast<Signed_address
>(value
) < 0)
11316 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11320 case elfcpp::R_POWERPC_PLT16_HA
:
11322 && !parameters
->options().output_is_position_independent())
11324 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11325 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11327 // Convert addis to lis.
11328 if ((insn
& (0x3f << 26)) == 15u << 26
11329 && (insn
& (0x1f << 16)) != 0)
11331 insn
&= ~(0x1f << 16);
11332 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11342 ? relative_value_is_known(gsym
)
11343 : relative_value_is_known(psymval
))
11348 uint64_t pinsn
, pinsn2
;
11355 // Multi-instruction sequences that access the GOT/TOC can
11356 // be optimized, eg.
11357 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11358 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11360 // addis ra,r2,0; addi rb,ra,x@toc@l;
11361 // to nop; addi rb,r2,x@toc;
11362 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11363 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11364 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11365 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11366 case elfcpp::R_POWERPC_GOT16_HA
:
11367 case elfcpp::R_PPC64_TOC16_HA
:
11368 if (size
== 64 && parameters
->options().toc_optimize())
11370 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11371 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11372 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11373 && object
->make_toc_relative(target
, &value
))
11374 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11375 && object
->make_got_relative(target
, psymval
,
11376 rela
.get_r_addend(),
11379 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11380 == ((15u << 26) | (2 << 16)));
11382 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11383 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11384 && value
+ 0x8000 < 0x10000)
11386 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11392 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11393 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11394 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11395 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11396 case elfcpp::R_POWERPC_GOT16_LO
:
11397 case elfcpp::R_PPC64_GOT16_LO_DS
:
11398 case elfcpp::R_PPC64_TOC16_LO
:
11399 case elfcpp::R_PPC64_TOC16_LO_DS
:
11400 if (size
== 64 && parameters
->options().toc_optimize())
11402 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11403 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11404 bool changed
= false;
11405 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11406 && object
->make_toc_relative(target
, &value
))
11407 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11408 && object
->make_got_relative(target
, psymval
,
11409 rela
.get_r_addend(),
11412 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11413 insn
^= (14u << 26) ^ (58u << 26);
11414 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11417 if (ok_lo_toc_insn(insn
, r_type
)
11418 && value
+ 0x8000 < 0x10000)
11420 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11422 // Transform addic to addi when we change reg.
11423 insn
&= ~((0x3f << 26) | (0x1f << 16));
11424 insn
|= (14u << 26) | (2 << 16);
11428 insn
&= ~(0x1f << 16);
11434 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11438 case elfcpp::R_PPC64_GOT_PCREL34
:
11439 if (size
== 64 && parameters
->options().toc_optimize())
11441 iview
= reinterpret_cast<Insn
*>(view
);
11442 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11444 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11445 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11446 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11449 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11451 if (relval
+ (1ULL << 33) < 1ULL << 34)
11454 // Replace with paddi
11455 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11456 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11457 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11458 pinsn
& 0xffffffff);
11464 case elfcpp::R_PPC64_PCREL34
:
11467 iview
= reinterpret_cast<Insn
*>(view
);
11468 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11470 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11471 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11472 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11473 | (14ULL << 26) /* paddi */))
11477 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11478 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11479 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11480 if (relnum
>= reloc_count
- 1)
11483 Reltype
next_rela(preloc
+ reloc_size
);
11484 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11485 != elfcpp::R_PPC64_PCREL_OPT
)
11486 || next_rela
.get_r_offset() != rela
.get_r_offset())
11489 Address off
= next_rela
.get_r_addend();
11491 off
= 8; // zero means next insn.
11492 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11495 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11496 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11498 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11500 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11502 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11503 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11504 pinsn
& 0xffffffff);
11505 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11510 case elfcpp::R_POWERPC_TPREL16_HA
:
11511 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11513 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11514 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11519 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11521 // R_PPC_TLSGD, R_PPC_TLSLD
11524 case elfcpp::R_POWERPC_TPREL16_LO
:
11525 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11527 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11528 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11529 insn
&= ~(0x1f << 16);
11530 insn
|= (size
== 32 ? 2 : 13) << 16;
11531 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11535 case elfcpp::R_PPC64_ENTRY
:
11538 value
= target
->toc_pointer();
11539 if (value
+ 0x80008000 <= 0xffffffff
11540 && !parameters
->options().output_is_position_independent())
11542 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11543 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11544 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11546 if ((insn1
& ~0xfffc) == ld_2_12
11547 && insn2
== add_2_2_12
)
11549 insn1
= lis_2
+ ha(value
);
11550 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11551 insn2
= addi_2_2
+ l(value
);
11552 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11559 if (value
+ 0x80008000 <= 0xffffffff)
11561 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11562 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11563 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11565 if ((insn1
& ~0xfffc) == ld_2_12
11566 && insn2
== add_2_2_12
)
11568 insn1
= addis_2_12
+ ha(value
);
11569 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11570 insn2
= addi_2_2
+ l(value
);
11571 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11579 case elfcpp::R_POWERPC_REL16_LO
:
11580 // If we are generating a non-PIC executable, edit
11581 // 0: addis 2,12,.TOC.-0b@ha
11582 // addi 2,2,.TOC.-0b@l
11583 // used by ELFv2 global entry points to set up r2, to
11585 // addi 2,2,.TOC.@l
11586 // if .TOC. is in range. */
11588 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11591 && target
->abiversion() >= 2
11592 && !parameters
->options().output_is_position_independent()
11593 && rela
.get_r_addend() == d_offset
+ 4
11595 && strcmp(gsym
->name(), ".TOC.") == 0)
11597 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11598 Reltype
prev_rela(preloc
- reloc_size
);
11599 if ((prev_rela
.get_r_info()
11600 == elfcpp::elf_r_info
<size
>(r_sym
,
11601 elfcpp::R_POWERPC_REL16_HA
))
11602 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11603 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11605 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11606 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11607 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11609 if ((insn1
& 0xffff0000) == addis_2_12
11610 && (insn2
& 0xffff0000) == addi_2_2
)
11612 insn1
= lis_2
+ ha(value
+ address
- 4);
11613 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11614 insn2
= addi_2_2
+ l(value
+ address
- 4);
11615 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11618 relinfo
->rr
->set_strategy(relnum
- 1,
11619 Relocatable_relocs::RELOC_SPECIAL
);
11620 relinfo
->rr
->set_strategy(relnum
,
11621 Relocatable_relocs::RELOC_SPECIAL
);
11631 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11632 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11635 case elfcpp::R_POWERPC_ADDR32
:
11636 case elfcpp::R_POWERPC_UADDR32
:
11638 overflow
= Reloc::CHECK_BITFIELD
;
11641 case elfcpp::R_POWERPC_REL32
:
11642 case elfcpp::R_POWERPC_REL16DX_HA
:
11644 overflow
= Reloc::CHECK_SIGNED
;
11647 case elfcpp::R_POWERPC_UADDR16
:
11648 overflow
= Reloc::CHECK_BITFIELD
;
11651 case elfcpp::R_POWERPC_ADDR16
:
11652 // We really should have three separate relocations,
11653 // one for 16-bit data, one for insns with 16-bit signed fields,
11654 // and one for insns with 16-bit unsigned fields.
11655 overflow
= Reloc::CHECK_BITFIELD
;
11656 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11657 overflow
= Reloc::CHECK_LOW_INSN
;
11660 case elfcpp::R_POWERPC_ADDR16_HI
:
11661 case elfcpp::R_POWERPC_ADDR16_HA
:
11662 case elfcpp::R_POWERPC_GOT16_HI
:
11663 case elfcpp::R_POWERPC_GOT16_HA
:
11664 case elfcpp::R_POWERPC_PLT16_HI
:
11665 case elfcpp::R_POWERPC_PLT16_HA
:
11666 case elfcpp::R_POWERPC_SECTOFF_HI
:
11667 case elfcpp::R_POWERPC_SECTOFF_HA
:
11668 case elfcpp::R_PPC64_TOC16_HI
:
11669 case elfcpp::R_PPC64_TOC16_HA
:
11670 case elfcpp::R_PPC64_PLTGOT16_HI
:
11671 case elfcpp::R_PPC64_PLTGOT16_HA
:
11672 case elfcpp::R_POWERPC_TPREL16_HI
:
11673 case elfcpp::R_POWERPC_TPREL16_HA
:
11674 case elfcpp::R_POWERPC_DTPREL16_HI
:
11675 case elfcpp::R_POWERPC_DTPREL16_HA
:
11676 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11677 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11678 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11679 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11680 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11681 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11682 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11683 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11684 case elfcpp::R_POWERPC_REL16_HI
:
11685 case elfcpp::R_POWERPC_REL16_HA
:
11687 overflow
= Reloc::CHECK_HIGH_INSN
;
11690 case elfcpp::R_POWERPC_REL16
:
11691 case elfcpp::R_PPC64_TOC16
:
11692 case elfcpp::R_POWERPC_GOT16
:
11693 case elfcpp::R_POWERPC_SECTOFF
:
11694 case elfcpp::R_POWERPC_TPREL16
:
11695 case elfcpp::R_POWERPC_DTPREL16
:
11696 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11697 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11698 case elfcpp::R_POWERPC_GOT_TPREL16
:
11699 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11700 overflow
= Reloc::CHECK_LOW_INSN
;
11703 case elfcpp::R_PPC64_REL24_NOTOC
:
11707 case elfcpp::R_POWERPC_ADDR24
:
11708 case elfcpp::R_POWERPC_ADDR14
:
11709 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11710 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11711 case elfcpp::R_PPC64_ADDR16_DS
:
11712 case elfcpp::R_POWERPC_REL24
:
11713 case elfcpp::R_PPC_PLTREL24
:
11714 case elfcpp::R_PPC_LOCAL24PC
:
11715 case elfcpp::R_PPC64_TPREL16_DS
:
11716 case elfcpp::R_PPC64_DTPREL16_DS
:
11717 case elfcpp::R_PPC64_TOC16_DS
:
11718 case elfcpp::R_PPC64_GOT16_DS
:
11719 case elfcpp::R_PPC64_SECTOFF_DS
:
11720 case elfcpp::R_POWERPC_REL14
:
11721 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11722 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11723 case elfcpp::R_PPC64_D34
:
11724 case elfcpp::R_PPC64_PCREL34
:
11725 case elfcpp::R_PPC64_GOT_PCREL34
:
11726 case elfcpp::R_PPC64_PLT_PCREL34
:
11727 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11728 case elfcpp::R_PPC64_D28
:
11729 case elfcpp::R_PPC64_PCREL28
:
11730 case elfcpp::R_PPC64_TPREL34
:
11731 case elfcpp::R_PPC64_DTPREL34
:
11732 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11733 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11734 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11735 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11736 overflow
= Reloc::CHECK_SIGNED
;
11740 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11743 if (overflow
== Reloc::CHECK_LOW_INSN
11744 || overflow
== Reloc::CHECK_HIGH_INSN
)
11746 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11748 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11749 overflow
= Reloc::CHECK_BITFIELD
;
11750 else if (overflow
== Reloc::CHECK_LOW_INSN
11751 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11752 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11753 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11754 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11755 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11756 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11757 overflow
= Reloc::CHECK_UNSIGNED
;
11759 overflow
= Reloc::CHECK_SIGNED
;
11762 bool maybe_dq_reloc
= false;
11763 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11764 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11767 case elfcpp::R_POWERPC_NONE
:
11768 case elfcpp::R_POWERPC_TLS
:
11769 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11770 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11771 case elfcpp::R_POWERPC_PLTSEQ
:
11772 case elfcpp::R_POWERPC_PLTCALL
:
11773 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11774 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11775 case elfcpp::R_PPC64_PCREL_OPT
:
11778 case elfcpp::R_PPC64_ADDR64
:
11779 case elfcpp::R_PPC64_REL64
:
11780 case elfcpp::R_PPC64_TOC
:
11781 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11782 Reloc::addr64(view
, value
);
11785 case elfcpp::R_POWERPC_TPREL
:
11786 case elfcpp::R_POWERPC_DTPREL
:
11788 Reloc::addr64(view
, value
);
11790 status
= Reloc::addr32(view
, value
, overflow
);
11793 case elfcpp::R_PPC64_UADDR64
:
11794 Reloc::addr64_u(view
, value
);
11797 case elfcpp::R_POWERPC_ADDR32
:
11798 status
= Reloc::addr32(view
, value
, overflow
);
11801 case elfcpp::R_POWERPC_REL32
:
11802 case elfcpp::R_POWERPC_UADDR32
:
11803 status
= Reloc::addr32_u(view
, value
, overflow
);
11806 case elfcpp::R_PPC64_REL24_NOTOC
:
11808 goto unsupp
; // R_PPC_EMB_RELSDA
11810 case elfcpp::R_POWERPC_ADDR24
:
11811 case elfcpp::R_POWERPC_REL24
:
11812 case elfcpp::R_PPC_PLTREL24
:
11813 case elfcpp::R_PPC_LOCAL24PC
:
11814 status
= Reloc::addr24(view
, value
, overflow
);
11817 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11818 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11819 case elfcpp::R_POWERPC_GOT_TPREL16
:
11820 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11823 // On ppc64 these are all ds form
11824 maybe_dq_reloc
= true;
11828 case elfcpp::R_POWERPC_ADDR16
:
11829 case elfcpp::R_POWERPC_REL16
:
11830 case elfcpp::R_PPC64_TOC16
:
11831 case elfcpp::R_POWERPC_GOT16
:
11832 case elfcpp::R_POWERPC_SECTOFF
:
11833 case elfcpp::R_POWERPC_TPREL16
:
11834 case elfcpp::R_POWERPC_DTPREL16
:
11835 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11836 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11837 case elfcpp::R_POWERPC_ADDR16_LO
:
11838 case elfcpp::R_POWERPC_REL16_LO
:
11839 case elfcpp::R_PPC64_TOC16_LO
:
11840 case elfcpp::R_POWERPC_GOT16_LO
:
11841 case elfcpp::R_POWERPC_PLT16_LO
:
11842 case elfcpp::R_POWERPC_SECTOFF_LO
:
11843 case elfcpp::R_POWERPC_TPREL16_LO
:
11844 case elfcpp::R_POWERPC_DTPREL16_LO
:
11845 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11846 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11848 status
= Reloc::addr16(view
, value
, overflow
);
11850 maybe_dq_reloc
= true;
11853 case elfcpp::R_POWERPC_UADDR16
:
11854 status
= Reloc::addr16_u(view
, value
, overflow
);
11857 case elfcpp::R_PPC64_ADDR16_HIGH
:
11858 case elfcpp::R_PPC64_TPREL16_HIGH
:
11859 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11861 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11864 case elfcpp::R_POWERPC_ADDR16_HI
:
11865 case elfcpp::R_POWERPC_REL16_HI
:
11866 case elfcpp::R_PPC64_REL16_HIGH
:
11867 case elfcpp::R_PPC64_TOC16_HI
:
11868 case elfcpp::R_POWERPC_GOT16_HI
:
11869 case elfcpp::R_POWERPC_PLT16_HI
:
11870 case elfcpp::R_POWERPC_SECTOFF_HI
:
11871 case elfcpp::R_POWERPC_TPREL16_HI
:
11872 case elfcpp::R_POWERPC_DTPREL16_HI
:
11873 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11874 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11875 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11876 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11877 Reloc::addr16_hi(view
, value
);
11880 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11881 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11882 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11884 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11887 case elfcpp::R_POWERPC_ADDR16_HA
:
11888 case elfcpp::R_POWERPC_REL16_HA
:
11889 case elfcpp::R_PPC64_REL16_HIGHA
:
11890 case elfcpp::R_PPC64_TOC16_HA
:
11891 case elfcpp::R_POWERPC_GOT16_HA
:
11892 case elfcpp::R_POWERPC_PLT16_HA
:
11893 case elfcpp::R_POWERPC_SECTOFF_HA
:
11894 case elfcpp::R_POWERPC_TPREL16_HA
:
11895 case elfcpp::R_POWERPC_DTPREL16_HA
:
11896 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11897 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11898 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11899 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11900 Reloc::addr16_ha(view
, value
);
11903 case elfcpp::R_POWERPC_REL16DX_HA
:
11904 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11907 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11909 // R_PPC_EMB_NADDR16_LO
11912 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11913 case elfcpp::R_PPC64_REL16_HIGHER
:
11914 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11915 Reloc::addr16_hi2(view
, value
);
11918 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11920 // R_PPC_EMB_NADDR16_HI
11923 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11924 case elfcpp::R_PPC64_REL16_HIGHERA
:
11925 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11926 Reloc::addr16_ha2(view
, value
);
11929 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11931 // R_PPC_EMB_NADDR16_HA
11934 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11935 case elfcpp::R_PPC64_REL16_HIGHEST
:
11936 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11937 Reloc::addr16_hi3(view
, value
);
11940 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11942 // R_PPC_EMB_SDAI16
11945 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11946 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11947 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11948 Reloc::addr16_ha3(view
, value
);
11951 case elfcpp::R_PPC64_DTPREL16_DS
:
11952 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11954 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11957 case elfcpp::R_PPC64_TPREL16_DS
:
11958 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11960 // R_PPC_TLSGD, R_PPC_TLSLD
11963 case elfcpp::R_PPC64_ADDR16_DS
:
11964 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11965 case elfcpp::R_PPC64_TOC16_DS
:
11966 case elfcpp::R_PPC64_TOC16_LO_DS
:
11967 case elfcpp::R_PPC64_GOT16_DS
:
11968 case elfcpp::R_PPC64_GOT16_LO_DS
:
11969 case elfcpp::R_PPC64_PLT16_LO_DS
:
11970 case elfcpp::R_PPC64_SECTOFF_DS
:
11971 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11972 maybe_dq_reloc
= true;
11975 case elfcpp::R_POWERPC_ADDR14
:
11976 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11977 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11978 case elfcpp::R_POWERPC_REL14
:
11979 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11980 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11981 status
= Reloc::addr14(view
, value
, overflow
);
11984 case elfcpp::R_POWERPC_COPY
:
11985 case elfcpp::R_POWERPC_GLOB_DAT
:
11986 case elfcpp::R_POWERPC_JMP_SLOT
:
11987 case elfcpp::R_POWERPC_RELATIVE
:
11988 case elfcpp::R_POWERPC_DTPMOD
:
11989 case elfcpp::R_PPC64_JMP_IREL
:
11990 case elfcpp::R_POWERPC_IRELATIVE
:
11991 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11992 _("unexpected reloc %u in object file"),
11996 case elfcpp::R_PPC64_TOCSAVE
:
12002 Symbol_location loc
;
12003 loc
.object
= relinfo
->object
;
12004 loc
.shndx
= relinfo
->data_shndx
;
12005 loc
.offset
= rela
.get_r_offset();
12006 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12007 if (tocsave
->find(loc
) != tocsave
->end())
12009 // If we've generated plt calls using this tocsave, then
12010 // the nop needs to be changed to save r2.
12011 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12012 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12013 elfcpp::Swap
<32, big_endian
>::
12014 writeval(iview
, std_2_1
+ target
->stk_toc());
12019 case elfcpp::R_PPC_EMB_SDA2I16
:
12020 case elfcpp::R_PPC_EMB_SDA2REL
:
12023 // R_PPC64_TLSGD, R_PPC64_TLSLD
12026 case elfcpp::R_PPC64_D34
:
12027 case elfcpp::R_PPC64_D34_LO
:
12028 case elfcpp::R_PPC64_PCREL34
:
12029 case elfcpp::R_PPC64_GOT_PCREL34
:
12030 case elfcpp::R_PPC64_PLT_PCREL34
:
12031 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12032 case elfcpp::R_PPC64_TPREL34
:
12033 case elfcpp::R_PPC64_DTPREL34
:
12034 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12035 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12036 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12037 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12040 status
= Reloc::addr34(view
, value
, overflow
);
12043 case elfcpp::R_PPC64_D34_HI30
:
12046 Reloc::addr34_hi(view
, value
);
12049 case elfcpp::R_PPC64_D34_HA30
:
12052 Reloc::addr34_ha(view
, value
);
12055 case elfcpp::R_PPC64_D28
:
12056 case elfcpp::R_PPC64_PCREL28
:
12059 status
= Reloc::addr28(view
, value
, overflow
);
12062 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12063 case elfcpp::R_PPC64_REL16_HIGHER34
:
12066 Reloc::addr16_higher34(view
, value
);
12069 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12070 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12073 Reloc::addr16_highera34(view
, value
);
12076 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12077 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12080 Reloc::addr16_highest34(view
, value
);
12083 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12084 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12087 Reloc::addr16_highesta34(view
, value
);
12090 case elfcpp::R_POWERPC_PLT32
:
12091 case elfcpp::R_POWERPC_PLTREL32
:
12092 case elfcpp::R_PPC_SDAREL16
:
12093 case elfcpp::R_POWERPC_ADDR30
:
12094 case elfcpp::R_PPC64_PLT64
:
12095 case elfcpp::R_PPC64_PLTREL64
:
12096 case elfcpp::R_PPC64_PLTGOT16
:
12097 case elfcpp::R_PPC64_PLTGOT16_LO
:
12098 case elfcpp::R_PPC64_PLTGOT16_HI
:
12099 case elfcpp::R_PPC64_PLTGOT16_HA
:
12100 case elfcpp::R_PPC64_PLTGOT16_DS
:
12101 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12102 case elfcpp::R_PPC_TOC16
:
12105 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12106 _("unsupported reloc %u"),
12111 if (maybe_dq_reloc
)
12114 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12116 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12117 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12118 && (insn
& 3) == 1))
12119 status
= Reloc::addr16_dq(view
, value
, overflow
);
12120 else if (size
== 64
12121 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12122 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12123 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12124 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12125 status
= Reloc::addr16_ds(view
, value
, overflow
);
12127 status
= Reloc::addr16(view
, value
, overflow
);
12130 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12133 && gsym
->is_undefined()
12134 && is_branch_reloc
<size
>(r_type
))))
12136 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12137 _("relocation overflow"));
12138 if (has_stub_value
)
12139 gold_info(_("try relinking with a smaller --stub-group-size"));
12145 // Relocate section data.
12147 template<int size
, bool big_endian
>
12149 Target_powerpc
<size
, big_endian
>::relocate_section(
12150 const Relocate_info
<size
, big_endian
>* relinfo
,
12151 unsigned int sh_type
,
12152 const unsigned char* prelocs
,
12153 size_t reloc_count
,
12154 Output_section
* output_section
,
12155 bool needs_special_offset_handling
,
12156 unsigned char* view
,
12158 section_size_type view_size
,
12159 const Reloc_symbol_changes
* reloc_symbol_changes
)
12161 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12162 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12163 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12164 Powerpc_comdat_behavior
;
12165 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12168 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12170 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12171 Powerpc_comdat_behavior
, Classify_reloc
>(
12177 needs_special_offset_handling
,
12181 reloc_symbol_changes
);
12184 template<int size
, bool big_endian
>
12185 class Powerpc_scan_relocatable_reloc
12188 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12189 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12190 static const int sh_type
= elfcpp::SHT_RELA
;
12192 // Return the symbol referred to by the relocation.
12193 static inline unsigned int
12194 get_r_sym(const Reltype
* reloc
)
12195 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12197 // Return the type of the relocation.
12198 static inline unsigned int
12199 get_r_type(const Reltype
* reloc
)
12200 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12202 // Return the strategy to use for a local symbol which is not a
12203 // section symbol, given the relocation type.
12204 inline Relocatable_relocs::Reloc_strategy
12205 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12207 if (r_type
== 0 && r_sym
== 0)
12208 return Relocatable_relocs::RELOC_DISCARD
;
12209 return Relocatable_relocs::RELOC_COPY
;
12212 // Return the strategy to use for a local symbol which is a section
12213 // symbol, given the relocation type.
12214 inline Relocatable_relocs::Reloc_strategy
12215 local_section_strategy(unsigned int, Relobj
*)
12217 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12220 // Return the strategy to use for a global symbol, given the
12221 // relocation type, the object, and the symbol index.
12222 inline Relocatable_relocs::Reloc_strategy
12223 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12226 && (r_type
== elfcpp::R_PPC_PLTREL24
12227 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12228 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12229 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12230 return Relocatable_relocs::RELOC_SPECIAL
;
12231 return Relocatable_relocs::RELOC_COPY
;
12235 // Scan the relocs during a relocatable link.
12237 template<int size
, bool big_endian
>
12239 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12240 Symbol_table
* symtab
,
12242 Sized_relobj_file
<size
, big_endian
>* object
,
12243 unsigned int data_shndx
,
12244 unsigned int sh_type
,
12245 const unsigned char* prelocs
,
12246 size_t reloc_count
,
12247 Output_section
* output_section
,
12248 bool needs_special_offset_handling
,
12249 size_t local_symbol_count
,
12250 const unsigned char* plocal_symbols
,
12251 Relocatable_relocs
* rr
)
12253 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12255 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12257 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12265 needs_special_offset_handling
,
12266 local_symbol_count
,
12271 // Scan the relocs for --emit-relocs.
12273 template<int size
, bool big_endian
>
12275 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12276 Symbol_table
* symtab
,
12278 Sized_relobj_file
<size
, big_endian
>* object
,
12279 unsigned int data_shndx
,
12280 unsigned int sh_type
,
12281 const unsigned char* prelocs
,
12282 size_t reloc_count
,
12283 Output_section
* output_section
,
12284 bool needs_special_offset_handling
,
12285 size_t local_symbol_count
,
12286 const unsigned char* plocal_syms
,
12287 Relocatable_relocs
* rr
)
12289 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12291 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12292 Emit_relocs_strategy
;
12294 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12296 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12304 needs_special_offset_handling
,
12305 local_symbol_count
,
12310 // Emit relocations for a section.
12311 // This is a modified version of the function by the same name in
12312 // target-reloc.h. Using relocate_special_relocatable for
12313 // R_PPC_PLTREL24 would require duplication of the entire body of the
12314 // loop, so we may as well duplicate the whole thing.
12316 template<int size
, bool big_endian
>
12318 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12319 const Relocate_info
<size
, big_endian
>* relinfo
,
12320 unsigned int sh_type
,
12321 const unsigned char* prelocs
,
12322 size_t reloc_count
,
12323 Output_section
* output_section
,
12324 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12326 Address view_address
,
12328 unsigned char* reloc_view
,
12329 section_size_type reloc_view_size
)
12331 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12333 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12334 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12335 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12336 // Offset from start of insn to d-field reloc.
12337 const int d_offset
= big_endian
? 2 : 0;
12339 Powerpc_relobj
<size
, big_endian
>* const object
12340 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12341 const unsigned int local_count
= object
->local_symbol_count();
12342 unsigned int got2_shndx
= object
->got2_shndx();
12343 Address got2_addend
= 0;
12344 if (got2_shndx
!= 0)
12346 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12347 gold_assert(got2_addend
!= invalid_address
);
12350 const bool relocatable
= parameters
->options().relocatable();
12352 unsigned char* pwrite
= reloc_view
;
12353 bool zap_next
= false;
12354 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12356 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12357 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12360 Reltype
reloc(prelocs
);
12361 Reltype_write
reloc_write(pwrite
);
12363 Address offset
= reloc
.get_r_offset();
12364 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12365 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12366 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12367 const unsigned int orig_r_sym
= r_sym
;
12368 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12369 = reloc
.get_r_addend();
12370 const Symbol
* gsym
= NULL
;
12374 // We could arrange to discard these and other relocs for
12375 // tls optimised sequences in the strategy methods, but for
12376 // now do as BFD ld does.
12377 r_type
= elfcpp::R_POWERPC_NONE
;
12381 // Get the new symbol index.
12382 Output_section
* os
= NULL
;
12383 if (r_sym
< local_count
)
12387 case Relocatable_relocs::RELOC_COPY
:
12388 case Relocatable_relocs::RELOC_SPECIAL
:
12391 r_sym
= object
->symtab_index(r_sym
);
12392 gold_assert(r_sym
!= -1U);
12396 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12398 // We are adjusting a section symbol. We need to find
12399 // the symbol table index of the section symbol for
12400 // the output section corresponding to input section
12401 // in which this symbol is defined.
12402 gold_assert(r_sym
< local_count
);
12404 unsigned int shndx
=
12405 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12406 gold_assert(is_ordinary
);
12407 os
= object
->output_section(shndx
);
12408 gold_assert(os
!= NULL
);
12409 gold_assert(os
->needs_symtab_index());
12410 r_sym
= os
->symtab_index();
12415 gold_unreachable();
12420 gsym
= object
->global_symbol(r_sym
);
12421 gold_assert(gsym
!= NULL
);
12422 if (gsym
->is_forwarder())
12423 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12425 gold_assert(gsym
->has_symtab_index());
12426 r_sym
= gsym
->symtab_index();
12429 // Get the new offset--the location in the output section where
12430 // this relocation should be applied.
12431 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12432 offset
+= offset_in_output_section
;
12435 section_offset_type sot_offset
=
12436 convert_types
<section_offset_type
, Address
>(offset
);
12437 section_offset_type new_sot_offset
=
12438 output_section
->output_offset(object
, relinfo
->data_shndx
,
12440 gold_assert(new_sot_offset
!= -1);
12441 offset
= new_sot_offset
;
12444 // In an object file, r_offset is an offset within the section.
12445 // In an executable or dynamic object, generated by
12446 // --emit-relocs, r_offset is an absolute address.
12449 offset
+= view_address
;
12450 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12451 offset
-= offset_in_output_section
;
12454 // Handle the reloc addend based on the strategy.
12455 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12457 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12459 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12460 addend
= psymval
->value(object
, addend
);
12461 // In a relocatable link, the symbol value is relative to
12462 // the start of the output section. For a non-relocatable
12463 // link, we need to adjust the addend.
12466 gold_assert(os
!= NULL
);
12467 addend
-= os
->address();
12470 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12474 if (addend
>= 32768)
12475 addend
+= got2_addend
;
12477 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12479 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12480 addend
-= d_offset
;
12482 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12484 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12485 addend
-= d_offset
+ 4;
12489 gold_unreachable();
12493 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12494 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12495 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12496 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12498 // First instruction of a global dynamic sequence,
12500 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12501 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12504 case tls::TLSOPT_TO_IE
:
12505 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12506 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12508 case tls::TLSOPT_TO_LE
:
12509 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12510 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12511 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12514 r_type
= elfcpp::R_POWERPC_NONE
;
12515 offset
-= d_offset
;
12522 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12523 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12524 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12525 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12527 // First instruction of a local dynamic sequence,
12529 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12530 if (tls_type
== tls::TLSOPT_TO_LE
)
12532 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12533 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12535 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12536 const Output_section
* os
= relinfo
->layout
->tls_segment()
12538 gold_assert(os
!= NULL
);
12539 gold_assert(os
->needs_symtab_index());
12540 r_sym
= os
->symtab_index();
12541 addend
= dtp_offset
;
12545 r_type
= elfcpp::R_POWERPC_NONE
;
12546 offset
-= d_offset
;
12550 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12551 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12552 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12553 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12555 // First instruction of initial exec sequence.
12556 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12557 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12559 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12560 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12561 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12564 r_type
= elfcpp::R_POWERPC_NONE
;
12565 offset
-= d_offset
;
12569 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12570 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12572 // Second instruction of a global dynamic sequence,
12573 // the __tls_get_addr call
12574 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12575 tls::Tls_optimization tls_type
= this->optimize_tls_gd(final
);
12578 case tls::TLSOPT_TO_IE
:
12579 r_type
= elfcpp::R_POWERPC_NONE
;
12582 case tls::TLSOPT_TO_LE
:
12583 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12584 offset
+= d_offset
;
12591 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12592 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12594 // Second instruction of a local dynamic sequence,
12595 // the __tls_get_addr call
12596 tls::Tls_optimization tls_type
= this->optimize_tls_ld();
12597 if (tls_type
== tls::TLSOPT_TO_LE
)
12599 const Output_section
* os
= relinfo
->layout
->tls_segment()
12601 gold_assert(os
!= NULL
);
12602 gold_assert(os
->needs_symtab_index());
12603 r_sym
= os
->symtab_index();
12604 addend
= dtp_offset
;
12605 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12606 offset
+= d_offset
;
12610 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12612 // Second instruction of an initial exec sequence
12613 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12614 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12616 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12617 offset
+= d_offset
;
12622 reloc_write
.put_r_offset(offset
);
12623 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12624 reloc_write
.put_r_addend(addend
);
12626 pwrite
+= reloc_size
;
12629 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12630 == reloc_view_size
);
12633 // Return the value to use for a dynamic symbol which requires special
12634 // treatment. This is how we support equality comparisons of function
12635 // pointers across shared library boundaries, as described in the
12636 // processor specific ABI supplement.
12638 template<int size
, bool big_endian
>
12640 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12644 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12645 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12646 p
!= this->stub_tables_
.end();
12649 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12650 = (*p
)->find_plt_call_entry(gsym
);
12652 return (*p
)->stub_address() + ent
->off_
;
12655 else if (this->abiversion() >= 2)
12657 Address off
= this->glink_section()->find_global_entry(gsym
);
12658 if (off
!= invalid_address
)
12659 return this->glink_section()->global_entry_address() + off
;
12661 gold_unreachable();
12664 // Return the PLT address to use for a local symbol.
12665 template<int size
, bool big_endian
>
12667 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12668 const Relobj
* object
,
12669 unsigned int symndx
) const
12673 const Sized_relobj
<size
, big_endian
>* relobj
12674 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12675 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12676 p
!= this->stub_tables_
.end();
12679 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12680 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12682 return (*p
)->stub_address() + ent
->off_
;
12685 gold_unreachable();
12688 // Return the PLT address to use for a global symbol.
12689 template<int size
, bool big_endian
>
12691 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12692 const Symbol
* gsym
) const
12696 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12697 p
!= this->stub_tables_
.end();
12700 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12701 = (*p
)->find_plt_call_entry(gsym
);
12703 return (*p
)->stub_address() + ent
->off_
;
12706 else if (this->abiversion() >= 2)
12708 Address off
= this->glink_section()->find_global_entry(gsym
);
12709 if (off
!= invalid_address
)
12710 return this->glink_section()->global_entry_address() + off
;
12712 gold_unreachable();
12715 // Return the offset to use for the GOT_INDX'th got entry which is
12716 // for a local tls symbol specified by OBJECT, SYMNDX.
12717 template<int size
, bool big_endian
>
12719 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12720 const Relobj
* object
,
12721 unsigned int symndx
,
12722 Output_data_got_base
* got
,
12723 unsigned int got_indx
,
12724 uint64_t addend
) const
12726 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12727 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12728 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12730 for (Got_type got_type
= (size
== 32
12731 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
12732 got_type
<= GOT_TYPE_SMALL_TPREL
;
12733 got_type
= Got_type(got_type
+ 1))
12734 if (got_type
!= GOT_TYPE_SMALL
12735 && ppc_object
->local_has_got_offset(symndx
, got_type
, addend
))
12738 = ppc_object
->local_got_offset(symndx
, got_type
, addend
);
12739 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
12741 if (off
== got_indx
* (size
/ 8)
12742 && (size
== 32 || got
== this->got_section(got_type
)))
12744 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
12747 return -dtp_offset
;
12751 gold_unreachable();
12754 // Return the offset to use for the GOT_INDX'th got entry which is
12755 // for global tls symbol GSYM.
12756 template<int size
, bool big_endian
>
12758 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12760 Output_data_got_base
* got
,
12761 unsigned int got_indx
,
12762 uint64_t addend
) const
12764 if (gsym
->type() == elfcpp::STT_TLS
)
12766 for (Got_type got_type
= (size
== 32
12767 ? GOT_TYPE_SMALL_TLSGD
: GOT_TYPE_TLSGD
);
12768 got_type
<= GOT_TYPE_SMALL_TPREL
;
12769 got_type
= Got_type(got_type
+ 1))
12770 if (got_type
!= GOT_TYPE_SMALL
12771 && gsym
->has_got_offset(got_type
, addend
))
12773 unsigned int off
= gsym
->got_offset(got_type
, addend
);
12774 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TLSGD
)
12776 if (off
== got_indx
* (size
/ 8)
12777 && (size
== 32 || got
== this->got_section(got_type
)))
12779 if ((got_type
& ~GOT_TYPE_SMALL
) == GOT_TYPE_TPREL
)
12782 return -dtp_offset
;
12786 gold_unreachable();
12789 // The selector for powerpc object files.
12791 template<int size
, bool big_endian
>
12792 class Target_selector_powerpc
: public Target_selector
12795 Target_selector_powerpc()
12796 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12799 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12800 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12802 ? (big_endian
? "elf64ppc" : "elf64lppc")
12803 : (big_endian
? "elf32ppc" : "elf32lppc")))
12807 do_instantiate_target()
12808 { return new Target_powerpc
<size
, big_endian
>(); }
12811 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12812 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12813 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12814 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12816 // Instantiate these constants for -O0
12817 template<int size
, bool big_endian
>
12818 const typename Output_data_glink
<size
, big_endian
>::Address
12819 Output_data_glink
<size
, big_endian
>::invalid_address
;
12820 template<int size
, bool big_endian
>
12821 const typename Stub_table
<size
, big_endian
>::Address
12822 Stub_table
<size
, big_endian
>::invalid_address
;
12823 template<int size
, bool big_endian
>
12824 const typename Target_powerpc
<size
, big_endian
>::Address
12825 Target_powerpc
<size
, big_endian
>::invalid_address
;
12827 } // End anonymous namespace.